annotate iff.c @ 6491:b7f807b4cd88 libavformat tip

In mov demuxer, check that nb_streams is valid before using it in read_dac3
author bcoudurier
date Tue, 28 Sep 2010 00:33:21 +0000
parents 7d8e6562ce1a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
1 /*
3198
814a32de9ec7 minor typo fixes
diego
parents: 3189
diff changeset
2 * IFF (.iff) file demuxer
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
4 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
5 * Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
6 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
7 * This file is part of FFmpeg.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
8 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
13 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
17 * Lesser General Public License for more details.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
18 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
22 */
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
23
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
24 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5913
diff changeset
25 * @file
3198
814a32de9ec7 minor typo fixes
diego
parents: 3189
diff changeset
26 * IFF file demuxer
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
27 * by Jaikrishnan Menon
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
28 * for more information on the .iff file format, visit:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
29 * http://wiki.multimedia.cx/index.php?title=IFF
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
30 */
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
31
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 4090
diff changeset
32 #include "libavutil/intreadwrite.h"
5773
fd3b7b9b63a8 IFF: move ff_cmap_read_palette() prototype to a header file
mru
parents: 5660
diff changeset
33 #include "libavcodec/iff.h"
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
34 #include "avformat.h"
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
35
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
36 #define ID_8SVX MKTAG('8','S','V','X')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
37 #define ID_VHDR MKTAG('V','H','D','R')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
38 #define ID_ATAK MKTAG('A','T','A','K')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
39 #define ID_RLSE MKTAG('R','L','S','E')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
40 #define ID_CHAN MKTAG('C','H','A','N')
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
41 #define ID_PBM MKTAG('P','B','M',' ')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
42 #define ID_ILBM MKTAG('I','L','B','M')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
43 #define ID_BMHD MKTAG('B','M','H','D')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
44 #define ID_CMAP MKTAG('C','M','A','P')
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
45
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
46 #define ID_FORM MKTAG('F','O','R','M')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
47 #define ID_ANNO MKTAG('A','N','N','O')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
48 #define ID_AUTH MKTAG('A','U','T','H')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
49 #define ID_CHRS MKTAG('C','H','R','S')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
50 #define ID_COPYRIGHT MKTAG('(','c',')',' ')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
51 #define ID_CSET MKTAG('C','S','E','T')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
52 #define ID_FVER MKTAG('F','V','E','R')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
53 #define ID_NAME MKTAG('N','A','M','E')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
54 #define ID_TEXT MKTAG('T','E','X','T')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
55 #define ID_BODY MKTAG('B','O','D','Y')
5660
1701ad9b6064 Support IFF ANNO (annotation) chunk type
pross
parents: 5626
diff changeset
56 #define ID_ANNO MKTAG('A','N','N','O')
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
57
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
58 #define LEFT 2
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
59 #define RIGHT 4
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
60 #define STEREO 6
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
61
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
62 #define PACKET_SIZE 1024
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
63
5971
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
64 typedef enum {
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
65 COMP_NONE,
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
66 COMP_FIB,
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
67 COMP_EXP
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
68 } svx8_compression_type;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
69
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
70 typedef enum {
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
71 BITMAP_RAW,
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
72 BITMAP_BYTERUN1
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
73 } bitmap_compression_type;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
74
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
75 typedef struct {
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
76 uint64_t body_pos;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
77 uint32_t body_size;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
78 uint32_t sent_bytes;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
79 uint32_t audio_frame_count;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
80 } IffDemuxContext;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
81
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
82
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
83 static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size)
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
84 {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
85 uint8_t *end = dest + size;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
86 size = size>>1;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
87
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
88 while(dest < end) {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
89 *dest++ = *src;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
90 *dest++ = *(src+size);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
91 src++;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
92 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
93 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
94
5994
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
95 /* Metadata string read */
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
96 static int get_metadata(AVFormatContext *s,
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
97 const char *const tag,
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
98 const unsigned data_size)
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
99 {
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
100 uint8_t *buf = ((data_size + 1) == 0) ? NULL : av_malloc(data_size + 1);
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
101
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
102 if (!buf)
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
103 return AVERROR(ENOMEM);
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
104
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
105 if (get_buffer(s->pb, buf, data_size) < 0) {
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
106 av_free(buf);
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
107 return AVERROR(EIO);
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
108 }
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
109 buf[data_size] = 0;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
110 av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL);
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
111 return 0;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
112 }
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
113
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
114 static int iff_probe(AVProbeData *p)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
115 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
116 const uint8_t *d = p->buf;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
117
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
118 if ( AV_RL32(d) == ID_FORM &&
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
119 (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) )
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
120 return AVPROBE_SCORE_MAX;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
121 return 0;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
122 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
123
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
124 static int iff_read_header(AVFormatContext *s,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
125 AVFormatParameters *ap)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
126 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
127 IffDemuxContext *iff = s->priv_data;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
128 ByteIOContext *pb = s->pb;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
129 AVStream *st;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
130 uint32_t chunk_id, data_size;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
131 int compression = -1;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
132
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
133 st = av_new_stream(s, 0);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
134 if (!st)
5985
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
135 return AVERROR(ENOMEM);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
136
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
137 st->codec->channels = 1;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
138 url_fskip(pb, 8);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
139 // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
140 st->codec->codec_tag = get_le32(pb);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
141
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
142 while(!url_feof(pb)) {
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
143 uint64_t orig_pos;
5994
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
144 int res;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
145 const char *metadata_tag = NULL;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
146 chunk_id = get_le32(pb);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
147 data_size = get_be32(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
148 orig_pos = url_ftell(pb);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
149
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
150 switch(chunk_id) {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
151 case ID_VHDR:
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5773
diff changeset
152 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
153
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
154 if (data_size < 14)
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
155 return AVERROR_INVALIDDATA;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
156 url_fskip(pb, 12);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
157 st->codec->sample_rate = get_be16(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
158 if (data_size >= 16) {
5985
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
159 url_fskip(pb, 1);
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
160 compression = get_byte(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
161 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
162 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
163
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
164 case ID_BODY:
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
165 iff->body_pos = url_ftell(pb);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
166 iff->body_size = data_size;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
167 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
168
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
169 case ID_CHAN:
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
170 if (data_size < 4)
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
171 return AVERROR_INVALIDDATA;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
172 st->codec->channels = (get_be32(pb) < 6) ? 1 : 2;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
173 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
174
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
175 case ID_CMAP:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
176 st->codec->extradata_size = data_size;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
177 st->codec->extradata = av_malloc(data_size);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
178 if (!st->codec->extradata)
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
179 return AVERROR(ENOMEM);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
180 if (get_buffer(pb, st->codec->extradata, data_size) < 0)
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
181 return AVERROR(EIO);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
182 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
183
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
184 case ID_BMHD:
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5773
diff changeset
185 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
186 if (data_size <= 8)
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
187 return AVERROR_INVALIDDATA;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
188 st->codec->width = get_be16(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
189 st->codec->height = get_be16(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
190 url_fskip(pb, 4); // x, y offset
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
191 st->codec->bits_per_coded_sample = get_byte(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
192 if (data_size >= 11) {
5985
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
193 url_fskip(pb, 1); // masking
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
194 compression = get_byte(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
195 }
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
196 if (data_size >= 16) {
5985
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
197 url_fskip(pb, 3); // paddding, transparent
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
198 st->sample_aspect_ratio.num = get_byte(pb);
35c3858d457f Reindent after rr22977.
rbultje
parents: 5984
diff changeset
199 st->sample_aspect_ratio.den = get_byte(pb);
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
200 }
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
201 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
202
5660
1701ad9b6064 Support IFF ANNO (annotation) chunk type
pross
parents: 5626
diff changeset
203 case ID_ANNO:
5994
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
204 case ID_TEXT:
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
205 metadata_tag = "comment";
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
206 break;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
207
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
208 case ID_AUTH:
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
209 metadata_tag = "artist";
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
210 break;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
211
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
212 case ID_COPYRIGHT:
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
213 metadata_tag = "copyright";
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
214 break;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
215
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
216 case ID_NAME:
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
217 metadata_tag = "title";
5660
1701ad9b6064 Support IFF ANNO (annotation) chunk type
pross
parents: 5626
diff changeset
218 break;
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
219 }
5660
1701ad9b6064 Support IFF ANNO (annotation) chunk type
pross
parents: 5626
diff changeset
220
5994
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
221 if (metadata_tag) {
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
222 if ((res = get_metadata(s, metadata_tag, data_size)) < 0) {
6261
7d8e6562ce1a remove redundant text and whitespaces from iff demuxer av_log() statements
pross
parents: 6002
diff changeset
223 av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!", metadata_tag);
5994
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
224 return res;
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
225 }
672248acc077 Parse IFF metadata.
cehoyos
parents: 5985
diff changeset
226 }
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
227 url_fskip(pb, data_size - (url_ftell(pb) - orig_pos) + (data_size & 1));
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
228 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
229
5984
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
230 url_fseek(pb, iff->body_pos, SEEK_SET);
55c714a8fb00 Make the IFF demuxer a little more standards-compliant, e.g. respect the size
rbultje
parents: 5971
diff changeset
231
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
232 switch(st->codec->codec_type) {
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5773
diff changeset
233 case AVMEDIA_TYPE_AUDIO:
5971
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
234 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
235
5971
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
236 switch(compression) {
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
237 case COMP_NONE:
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
238 st->codec->codec_id = CODEC_ID_PCM_S8;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
239 break;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
240 case COMP_FIB:
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
241 st->codec->codec_id = CODEC_ID_8SVX_FIB;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
242 break;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
243 case COMP_EXP:
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
244 st->codec->codec_id = CODEC_ID_8SVX_EXP;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
245 break;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
246 default:
6261
7d8e6562ce1a remove redundant text and whitespaces from iff demuxer av_log() statements
pross
parents: 6002
diff changeset
247 av_log(s, AV_LOG_ERROR, "unknown compression method\n");
5971
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
248 return -1;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
249 }
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
250
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
251 st->codec->bits_per_coded_sample = 8;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
252 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample;
43548500ffbc Reindent / reformat some code with broken indenting.
rbultje
parents: 5969
diff changeset
253 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
254 break;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
255
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5773
diff changeset
256 case AVMEDIA_TYPE_VIDEO:
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
257 switch (compression) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
258 case BITMAP_RAW:
6002
5b6f32f1546f Reindent after r23112.
rbultje
parents: 6001
diff changeset
259 st->codec->codec_id = CODEC_ID_IFF_ILBM;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
260 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
261 case BITMAP_BYTERUN1:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
262 st->codec->codec_id = CODEC_ID_IFF_BYTERUN1;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
263 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
264 default:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
265 av_log(s, AV_LOG_ERROR, "unknown compression method\n");
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
266 return AVERROR_INVALIDDATA;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
267 }
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
268 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
269 default:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
270 return -1;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
271 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
272
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
273 return 0;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
274 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
275
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
276 static int iff_read_packet(AVFormatContext *s,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
277 AVPacket *pkt)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
278 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
279 IffDemuxContext *iff = s->priv_data;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
280 ByteIOContext *pb = s->pb;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
281 AVStream *st = s->streams[0];
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
282 int ret;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
283
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
284 if(iff->sent_bytes >= iff->body_size)
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
285 return AVERROR(EIO);
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
286
5996
39d22a65f36a Replace usage of s->streams[0]->* with st->*, which is shorter.
rbultje
parents: 5994
diff changeset
287 if(st->codec->channels == 2) {
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
288 uint8_t sample_buffer[PACKET_SIZE];
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
289
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
290 ret = get_buffer(pb, sample_buffer, PACKET_SIZE);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
291 if(av_new_packet(pkt, PACKET_SIZE) < 0) {
6261
7d8e6562ce1a remove redundant text and whitespaces from iff demuxer av_log() statements
pross
parents: 6002
diff changeset
292 av_log(s, AV_LOG_ERROR, "cannot allocate packet\n");
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
293 return AVERROR(ENOMEM);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
294 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
295 interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
5996
39d22a65f36a Replace usage of s->streams[0]->* with st->*, which is shorter.
rbultje
parents: 5994
diff changeset
296 } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
297 ret = av_get_packet(pb, pkt, iff->body_size);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
298 } else {
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
299 ret = av_get_packet(pb, pkt, PACKET_SIZE);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
300 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
301
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
302 if(iff->sent_bytes == 0)
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
303 pkt->flags |= AV_PKT_FLAG_KEY;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
304
5996
39d22a65f36a Replace usage of s->streams[0]->* with st->*, which is shorter.
rbultje
parents: 5994
diff changeset
305 if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
5626
b3d4ef7e53ad Indentation cleanup
pross
parents: 5625
diff changeset
306 iff->sent_bytes += PACKET_SIZE;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
307 } else {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
308 iff->sent_bytes = iff->body_size;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
309 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
310 pkt->stream_index = 0;
5996
39d22a65f36a Replace usage of s->streams[0]->* with st->*, which is shorter.
rbultje
parents: 5994
diff changeset
311 if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
5626
b3d4ef7e53ad Indentation cleanup
pross
parents: 5625
diff changeset
312 pkt->pts = iff->audio_frame_count;
5996
39d22a65f36a Replace usage of s->streams[0]->* with st->*, which is shorter.
rbultje
parents: 5994
diff changeset
313 iff->audio_frame_count += ret / st->codec->channels;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
314 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
315 return ret;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
316 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
317
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
318 AVInputFormat iff_demuxer = {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
319 "IFF",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3285
diff changeset
320 NULL_IF_CONFIG_SMALL("IFF format"),
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
321 sizeof(IffDemuxContext),
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
322 iff_probe,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
323 iff_read_header,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
324 iff_read_packet,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
325 };