FFmpeg: libavformat/argo_brp.c Source File
Go to the documentation of this file. 1 /*
2 * Argonaut Games BRP Demuxer
3 *
4 * Copyright (C) 2020 Zane van Iperen (zane@zanevaniperen.com)
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
30
31 #define BRP_TAG MKTAG('B', 'R', 'P', 'P')
32 #define BRP_FILE_HEADER_SIZE 12
33 #define BRP_BLOCK_HEADER_SIZE 12
34 #define BRP_STREAM_HEADER_SIZE 20
35 #define BRP_MAX_STREAMS 32 /* Soft cap, but even this is overkill. */
36 #define BRP_BASF_LOOKAHEAD 10 /* How many blocks to search for the first BASF one. */
37 #define BVID_HEADER_SIZE 16
38 #define MASK_HEADER_SIZE 12
39 #define BRP_MIN_BUFFER_SIZE FFMAX3(FFMAX3(BRP_FILE_HEADER_SIZE, \
40 BRP_BLOCK_HEADER_SIZE, \
41 BRP_STREAM_HEADER_SIZE), \
42 BVID_HEADER_SIZE, \
43 MASK_HEADER_SIZE)
44
45 #define BRP_CODEC_ID_BVID MKTAG('B', 'V', 'I', 'D')
46 #define BRP_CODEC_ID_BASF MKTAG('B', 'A', 'S', 'F')
47 #define BRP_CODEC_ID_MASK MKTAG('M', 'A', 'S', 'K')
48
54
60
67
73
80 union
81 {
82 /* If codec_id == BRP_CODEC_ID_BVID */
84 /* If codec_id == BRP_CODEC_ID_BASF */
86 /* If codec_id == BRP_CODEC_ID_MASK */
90
94
95 struct {
100
102 {
104 return 0;
105
107 }
108
110 void *buf, size_t bufsz)
111 {
115
125 } else {
127
130
131 return 1;
132 }
133
138 }
139
141
144
147
148 return 0;
149 }
150
152 {
157
162
166
169
173 }
174
175 /* Build the stream info. */
180
183
188
194
195 /* This should always be the case. */
198
199 /* Timestamps are in milliseconds. */
203
206 }
else if (
ret > 0) {
208 continue;
209 }
210
213
216
221
224
225 /* These are from 1990's games, sanity check this. */
226 if (bvid->
width >= 65536 || bvid->
height >= 65536 ||
229 }
230
236 /*
237 * It would make the demuxer significantly more complicated
238 * to support multiple BASF streams. I've never seen a file
239 * with more than one.
240 */
244 }
245
250
253
257
259
263
265 } else {
266 av_assert0(0);
/* Caught above, should never happen. */
267 }
268 }
269
270 /* Try to find the first BASF chunk. */
277
280
283
285
287
293
297
299 break;
300
303 }
304
306 /* Don't error here, as there may still be a valid video stream. */
308 goto done;
309 }
310
312
315
320
322
323 /*
324 * Special Case Hack. It seems that in files where the BASF block isn't first,
325 * v1.1 streams are allowed to be non-22050...
326 * Bump the version to 1.2 so ff_argo_asf_fill_stream() doesn't "correct" it.
327 *
328 * Found in Alien Odyssey games files in:
329 * ./GRAPHICS/COMMBUNK/{{COMADD1,COMM2_{1,2,3E},COMM3_{2,3,4,5,6}},FADE{1,2}}.BRP
330 *
331 * Either this format really inconsistent, or FX Fighter and Croc just ignored the
332 * sample rate field...
333 */
336
339
340 /* Convert ms to samples. */
343
344 done:
347 }
348 return 0;
349 }
350
352 {
360
365
369
370 if (
blk.stream_id == -1)
372
373 if (
blk.stream_id < -1 ||
blk.stream_id >=
s->nb_streams)
375
376 st =
s->streams[
blk.stream_id];
378
382
385
387
388 /* Ensure the chunk attributes are the same. */
394
396 }
397
402
409 } else {
411 }
412
414 return 0;
415 }
416
418 .
p.
name =
"argo_brp",
424 };
@ AV_ROUND_UP
Round toward +infinity.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
struct ArgoBRPDemuxContext::@360 basf
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
const FFInputFormat ff_argo_brp_demuxer
enum AVMediaType codec_type
General type of the encoded data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
static int read_extradata(AVFormatContext *s, const ArgoBRPStreamHeader *hdr, void *buf, size_t bufsz)
#define BRP_MIN_BUFFER_SIZE
#define BRP_CODEC_ID_MASK
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static int argo_brp_read_header(AVFormatContext *s)
int ff_argo_asf_fill_stream(AVFormatContext *s, AVStream *st, const ArgoASFFileHeader *fhdr, const ArgoASFChunkHeader *ckhdr)
#define BRP_CODEC_ID_BASF
#define ASF_FILE_HEADER_SIZE
ArgoBRPStreamHeader streams[BRP_MAX_STREAMS]
static int argo_brp_read_packet(AVFormatContext *s, AVPacket *pkt)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define BRP_BLOCK_HEADER_SIZE
int64_t duration
Decoding: duration of the stream, in stream time base.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define BRP_FILE_HEADER_SIZE
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static int read_header(FFV1Context *f)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int ff_argo_asf_validate_file_header(AVFormatContext *s, const ArgoASFFileHeader *hdr)
This structure contains the data a format has to probe a file.
int sample_rate
Audio only.
int64_t nb_frames
number of frames in this stream if known or 0
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define BRP_BASF_LOOKAHEAD
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define BRP_STREAM_HEADER_SIZE
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void ff_argo_asf_parse_chunk_header(ArgoASFChunkHeader *hdr, const uint8_t *buf)
static int argo_brp_probe(const AVProbeData *p)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
#define ASF_CHUNK_HEADER_SIZE
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define BRP_CODEC_ID_BVID
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define ASF_MIN_BUFFER_SIZE
static int read_probe(const AVProbeData *p)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
void ff_argo_asf_parse_file_header(ArgoASFFileHeader *hdr, const uint8_t *buf)
#define avpriv_request_sample(...)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Generated on Fri Aug 22 2025 13:59:24 for FFmpeg by
doxygen
1.8.17