FFmpeg: libavformat/iff.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
4 * Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.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
23 /**
24 * @file
25 * IFF file demuxer
26 * by Jaikrishnan Menon
27 * for more information on the .iff file format, visit:
28 * http://wiki.multimedia.cx/index.php?title=IFF
29 */
30
31 #include <inttypes.h>
32
43
44 #define ID_8SVX MKTAG('8','S','V','X')
45 #define ID_16SV MKTAG('1','6','S','V')
46 #define ID_MAUD MKTAG('M','A','U','D')
47 #define ID_MHDR MKTAG('M','H','D','R')
48 #define ID_MDAT MKTAG('M','D','A','T')
49 #define ID_VHDR MKTAG('V','H','D','R')
50 #define ID_ATAK MKTAG('A','T','A','K')
51 #define ID_RLSE MKTAG('R','L','S','E')
52 #define ID_CHAN MKTAG('C','H','A','N')
53 #define ID_PBM MKTAG('P','B','M',' ')
54 #define ID_ILBM MKTAG('I','L','B','M')
55 #define ID_BMHD MKTAG('B','M','H','D')
56 #define ID_DGBL MKTAG('D','G','B','L')
57 #define ID_CAMG MKTAG('C','A','M','G')
58 #define ID_CMAP MKTAG('C','M','A','P')
59 #define ID_ACBM MKTAG('A','C','B','M')
60 #define ID_DEEP MKTAG('D','E','E','P')
61 #define ID_RGB8 MKTAG('R','G','B','8')
62 #define ID_RGBN MKTAG('R','G','B','N')
63 #define ID_DSD MKTAG('D','S','D',' ')
64 #define ID_DST MKTAG('D','S','T',' ')
65 #define ID_DSTC MKTAG('D','S','T','C')
66 #define ID_DSTF MKTAG('D','S','T','F')
67 #define ID_FRTE MKTAG('F','R','T','E')
68 #define ID_ANIM MKTAG('A','N','I','M')
69 #define ID_ANHD MKTAG('A','N','H','D')
70 #define ID_DLTA MKTAG('D','L','T','A')
71 #define ID_DPAN MKTAG('D','P','A','N')
72
73 #define ID_FORM MKTAG('F','O','R','M')
74 #define ID_FRM8 MKTAG('F','R','M','8')
75 #define ID_ANNO MKTAG('A','N','N','O')
76 #define ID_AUTH MKTAG('A','U','T','H')
77 #define ID_CHRS MKTAG('C','H','R','S')
78 #define ID_COPYRIGHT MKTAG('(','c',')',' ')
79 #define ID_CSET MKTAG('C','S','E','T')
80 #define ID_FVER MKTAG('F','V','E','R')
81 #define ID_NAME MKTAG('N','A','M','E')
82 #define ID_TEXT MKTAG('T','E','X','T')
83 #define ID_ABIT MKTAG('A','B','I','T')
84 #define ID_BODY MKTAG('B','O','D','Y')
85 #define ID_DBOD MKTAG('D','B','O','D')
86 #define ID_DPEL MKTAG('D','P','E','L')
87 #define ID_DLOC MKTAG('D','L','O','C')
88 #define ID_TVDC MKTAG('T','V','D','C')
89
93
94 /**
95 * This number of bytes if added at the beginning of each AVPacket
96 * which contain additional information about video properties
97 * which has to be shared between demuxer and decoder.
98 * This number may change between frames, e.g. the demuxer might
99 * set it to smallest possible size of 2 to indicate that there's
100 * no extradata changing in this frame.
101 */
102 #define IFF_EXTRA_VIDEO_SIZE 41
103
109
119 unsigned bpp;
///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
120 unsigned ham;
///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
121 unsigned flags;
///< 1 for EHB, 0 is no extra half darkening
124 uint8_t
tvdc[32];
///< TVDC lookup table
127
128 /* Metadata string read */
130 const char *
const tag,
131 const unsigned data_size)
132 {
133 uint8_t *buf = ((data_size + 1) == 0) ?
NULL :
av_malloc(data_size + 1);
134
135 if (!buf)
137
138 if (
avio_read(
s->pb, buf, data_size) != data_size) {
141 }
142 buf[data_size] = 0;
144 return 0;
145 }
146
148 {
149 const uint8_t *d = p->
buf;
150
164 return 0;
165 }
166
171 };
172
173
174 #define DSD_SLFT MKTAG('S','L','F','T')
175 #define DSD_SRGT MKTAG('S','R','G','T')
176 #define DSD_MLFT MKTAG('M','L','F','T')
177 #define DSD_MRGT MKTAG('M','R','G','T')
178 #define DSD_C MKTAG('C',' ',' ',' ')
179 #define DSD_LS MKTAG('L','S',' ',' ')
180 #define DSD_RS MKTAG('R','S',' ',' ')
181 #define DSD_LFE MKTAG('L','F','E',' ')
182
186
191
196 };
197
200 { 0 }, { 0 },
202 };
203
205 "dsd_source_comment",
206 "analogue_source_comment",
207 "pcm_source_comment",
208 };
209
211 "general_remark",
212 "operator_name",
213 "creating_machine",
214 "timezone",
215 "file_revision"
216 };
217
219 {
221
226 const char * metadata_tag =
NULL;
227
228 if (
size >= INT64_MAX)
230
232 case MKTAG(
'D',
'I',
'A',
'R'): metadata_tag =
"artist";
break;
233 case MKTAG(
'D',
'I',
'T',
'I'): metadata_tag =
"title";
break;
234 }
235
236 if (metadata_tag &&
size > 4) {
242 }
243 }
244
246 }
247
248 return 0;
249 }
250
252 {
254 char abss[24];
256 int dsd_layout[6];
258
263
264 if (
size >= INT64_MAX)
266
268 case MKTAG(
'A',
'B',
'S',
'S'):
276 break;
277
278 case MKTAG(
'C',
'H',
'N',
'L'):
283 if (size < 2 + st->codecpar->ch_layout.nb_channels * 4)
287 break;
288 }
296 break;
297 }
298 }
299 break;
300
301 case MKTAG(
'C',
'M',
'P',
'R'):
310 }
311 break;
312
313 case MKTAG(
'F',
'S',
' ',
' '):
317 break;
318
319 case MKTAG(
'I',
'D',
'3',
' '):
321 if (id3v2_extra_meta) {
326 }
328 }
329
333 }
334 break;
335
336 case MKTAG(
'L',
'S',
'C',
'O'):
345 }
346 break;
347 }
348
350 }
351
352 return 0;
353 }
354
356 {
359 uint32_t chunk_id;
360 uint64_t chunk_pos, data_pos, data_size;
362
363 if (
s->nb_streams < 1)
365
370
374
375 if (data_size < 1 || data_size >= INT64_MAX)
377
378 switch (chunk_id) {
383 return 0;
384 }
388 if (data_size & 1)
392 pkt->
duration =
s->streams[0]->codecpar->sample_rate / 75;
394
397 return 0;
398
400 return 0;
401
403 if (data_size < 4)
405 s->streams[0]->duration =
avio_rb32(pb) * (uint64_t)
s->streams[0]->codecpar->sample_rate / 75;
406
407 break;
408 }
409
411 }
412
414 }
415
416 static const uint8_t
deep_rgb24[] = {0, 0, 0, 3, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
417 static const uint8_t
deep_rgba[] = {0, 0, 0, 4, 0, 1, 0, 8, 0, 2, 0, 8, 0, 3, 0, 8};
418 static const uint8_t
deep_bgra[] = {0, 0, 0, 4, 0, 3, 0, 8, 0, 2, 0, 8, 0, 1, 0, 8};
419 static const uint8_t
deep_argb[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 1, 0, 8, 0, 2, 0, 8};
420 static const uint8_t
deep_abgr[] = {0, 0, 0, 4, 0,17, 0, 8, 0, 3, 0, 8, 0, 2, 0, 8};
421
423 {
427 uint8_t *buf;
428 uint32_t chunk_id;
429 uint64_t data_size;
430 uint32_t screenmode = 0, num, den;
431 unsigned transparency = 0;
432 unsigned masking = 0; // no mask
433 uint8_t fmt[16];
434 int fmt_size;
435
437 if (!st)
439
443 // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
447 }
452
454 uint64_t orig_pos;
455 int res;
456 const char *metadata_tag =
NULL;
461
462 if (data_size >= INT64_MAX)
464
465 switch(chunk_id) {
468
469 if (data_size < 14)
473 if (data_size >= 16) {
476 }
477 break;
478
481
482 if (data_size < 32)
489 if (!den)
502 break;
503
513
520 }
521 break;
522
524 if (data_size < 4)
528 } else {
530 }
531 break;
532
534 if (data_size < 4)
537 break;
538
540 if (data_size < 3 || data_size > 768 || data_size % 3) {
542 data_size);
544 }
547 if (res < 0)
548 return res;
553 }
554 break;
555
558 if (data_size <= 8)
564 if (data_size >= 10)
566 if (data_size >= 11)
568 if (data_size >= 14) {
571 }
572 if (data_size >= 16) {
575 }
576 break;
577
579 break;
580
584 break;
585
587 if (data_size < 4 || (data_size & 3))
589 if ((fmt_size =
avio_read(pb, fmt,
sizeof(fmt))) < 0)
590 return fmt_size;
601 else {
604 }
605 break;
606
609 if (data_size < 8)
617 break;
618
620 if (data_size < 4)
624 break;
625
627 if (data_size <
sizeof(iff->
tvdc))
630 if (res < 0)
631 return res;
632 break;
633
635 case ID_TEXT: metadata_tag =
"comment";
break;
636 case ID_AUTH: metadata_tag =
"artist";
break;
638 case ID_NAME: metadata_tag =
"title";
break;
639
640 /* DSD tags */
641
642 case MKTAG(
'F',
'V',
'E',
'R'):
643 if (data_size < 4)
648 break;
649
650 case MKTAG(
'D',
'I',
'I',
'N'):
652 if (res < 0)
653 return res;
654 break;
655
656 case MKTAG(
'P',
'R',
'O',
'P'):
657 if (data_size < 4)
661 break;
662 }
664 if (res < 0)
665 return res;
666 break;
667
668 case MKTAG(
'C',
'O',
'M',
'T'):
669 if (data_size < 2)
672 for (
i = 0;
i < nb_comments;
i++) {
676 int metadata_size;
677
683 snprintf(
tmp,
sizeof(
tmp),
"%04d-%02d-%02d %02d:%02d", year, mon, day, hour,
min);
685
689 case 1:
691 tag =
"channel_comment";
692 else {
695 }
696 break;
697 case 2:
699 break;
700 case 3:
702 break;
703 default:
705 }
706
710 return res;
711 }
712
713 if (metadata_size & 1)
715 }
716 break;
717 }
718
719 if (metadata_tag) {
722 return res;
723 }
724 }
726 }
727
730 else
732
736
748 } else {
751 }
757 break;
760 break;
763 break;
764 default:
767 return -1;
768 }
769 }
770
779 break;
780
785 if ((screenmode & 0x800
/* Hold And Modify */) && iff->
bpp <= 8) {
786 iff->
ham = iff->
bpp > 6 ? 6 : 4;
788 }
789 iff->
flags = (screenmode & 0x80
/* Extra HalfBrite */) && iff->
bpp <= 8;
792
797 }
802 bytestream_put_byte(&buf, iff->
bpp);
803 bytestream_put_byte(&buf, iff->
ham);
804 bytestream_put_byte(&buf, iff->
flags);
806 bytestream_put_byte(&buf, iff->
masking);
809 break;
810 default:
811 return -1;
812 }
813
814 return 0;
815 }
816
818 {
820
824 unsigned chunk = bytestream2_get_le32(&gb);
825 unsigned size = bytestream2_get_be32(&gb);
826
829 break;
831 return bytestream2_get_be32(&gb);
832 } else {
834 }
835 }
836 return 10;
837 }
838
841 {
847
852
858 } else {
862 }
865 uint64_t data_size, orig_pos;
866 uint32_t chunk_id, chunk_id2;
867
871
876
880 break;
881 }
else if (chunk_id ==
ID_FORM &&
883 continue;
884 } else {
886 }
887 }
901 } else {
903 }
904
909 }
910
919 };
svx8_compression_type svx8_compression
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
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
enum AVMediaType codec_type
General type of the encoded data.
#define AV_CHANNEL_LAYOUT_STEREO
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_EOF
End of file.
@ AV_CODEC_ID_PCM_S16BE_PLANAR
void ff_id3v2_read(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta, unsigned int max_search_size)
Read an ID3v2 tag, including supported extra metadata.
unsigned masking
masking method used
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
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 type
int64_t duration
Decoding: duration of the stream, in stream time base.
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
unsigned int avio_rb32(AVIOContext *s)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
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.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
uint8_t tvdc[32]
TVDC lookup table.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
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_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
uint64_t avio_rb64(AVIOContext *s)
This structure contains the data a format has to probe a file.
AVChannelLayout ch_layout
Audio only.
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
int sample_rate
Audio only.
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
int extradata_size
Size of the extradata content in bytes.
unsigned int avio_rl32(AVIOContext *s)
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
unsigned flags
1 for EHB, 0 is no extra half darkening
An AVChannelLayout holds information about the channel layout of audio data.
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int avio_r8(AVIOContext *s)
int flags
A combination of AV_PKT_FLAG values.
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
int block_align
Audio only.
unsigned bitmap_compression
delta compression method used
const uint32_t * dsd_layout
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
unsigned int avio_rb16(AVIOContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
unsigned bpp
bits per plane to decode (differs from bits_per_coded_sample if HAM)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static int ref[MAX_W *MAX_W]
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
static int read_probe(const AVProbeData *p)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
#define avpriv_request_sample(...)
unsigned ham
0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
#define AV_CHANNEL_LAYOUT_MONO
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
int64_t pos
byte position in stream, -1 if unknown
@ AV_CODEC_ID_PCM_S8_PLANAR
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
unsigned transparency
transparency color index in palette
#define AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT1
int is_64bit
chunk size is 64-bit
unsigned maud_compression
#define av_fourcc2str(fourcc)
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Generated on Fri Aug 22 2025 13:58:25 for FFmpeg by
doxygen
1.8.17