Mercurial > libavformat.hg
annotate iff.c @ 5671:4a65c87ff3fd libavformat
Remove stale function declaration.
Patch by Martin Storsj <$firstname $firstname st>.
author | rbultje |
---|---|
date | Fri, 19 Feb 2010 17:26:33 +0000 |
parents | 1701ad9b6064 |
children | fd3b7b9b63a8 |
rev | line source |
---|---|
3189 | 1 /* |
3198 | 2 * IFF (.iff) file demuxer |
3189 | 3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net> |
5625 | 4 * Copyright (c) 2010 Peter Ross <pross@xvid.org> |
3189 | 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 /** | |
4331
49c1d3b27727
Use full internal pathname in doxygen @file directives.
diego
parents:
4201
diff
changeset
|
24 * @file libavformat/iff.c |
3198 | 25 * IFF file demuxer |
3189 | 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 | |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
4090
diff
changeset
|
31 #include "libavutil/intreadwrite.h" |
3189 | 32 #include "avformat.h" |
33 | |
34 #define ID_8SVX MKTAG('8','S','V','X') | |
35 #define ID_VHDR MKTAG('V','H','D','R') | |
36 #define ID_ATAK MKTAG('A','T','A','K') | |
37 #define ID_RLSE MKTAG('R','L','S','E') | |
38 #define ID_CHAN MKTAG('C','H','A','N') | |
5625 | 39 #define ID_PBM MKTAG('P','B','M',' ') |
40 #define ID_ILBM MKTAG('I','L','B','M') | |
41 #define ID_BMHD MKTAG('B','M','H','D') | |
42 #define ID_CMAP MKTAG('C','M','A','P') | |
3189 | 43 |
44 #define ID_FORM MKTAG('F','O','R','M') | |
45 #define ID_ANNO MKTAG('A','N','N','O') | |
46 #define ID_AUTH MKTAG('A','U','T','H') | |
47 #define ID_CHRS MKTAG('C','H','R','S') | |
48 #define ID_COPYRIGHT MKTAG('(','c',')',' ') | |
49 #define ID_CSET MKTAG('C','S','E','T') | |
50 #define ID_FVER MKTAG('F','V','E','R') | |
51 #define ID_NAME MKTAG('N','A','M','E') | |
52 #define ID_TEXT MKTAG('T','E','X','T') | |
53 #define ID_BODY MKTAG('B','O','D','Y') | |
5660 | 54 #define ID_ANNO MKTAG('A','N','N','O') |
3189 | 55 |
56 #define LEFT 2 | |
57 #define RIGHT 4 | |
58 #define STEREO 6 | |
59 | |
60 #define PACKET_SIZE 1024 | |
61 | |
4090
a209d26d63c2
Avoid _t in identifier names, _t is reserved by POSIX.
diego
parents:
3908
diff
changeset
|
62 typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type; |
5625 | 63 typedef enum {BITMAP_RAW, BITMAP_BYTERUN1} bitmap_compression_type; |
3189 | 64 |
65 typedef struct { | |
66 uint32_t body_size; | |
67 uint32_t sent_bytes; | |
68 uint32_t audio_frame_count; | |
69 } IffDemuxContext; | |
70 | |
3285 | 71 |
72 static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size) | |
73 { | |
74 uint8_t *end = dest + size; | |
75 size = size>>1; | |
76 | |
77 while(dest < end) { | |
78 *dest++ = *src; | |
79 *dest++ = *(src+size); | |
80 src++; | |
81 } | |
82 } | |
83 | |
3189 | 84 static int iff_probe(AVProbeData *p) |
85 { | |
86 const uint8_t *d = p->buf; | |
87 | |
88 if ( AV_RL32(d) == ID_FORM && | |
5625 | 89 (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) ) |
3189 | 90 return AVPROBE_SCORE_MAX; |
91 return 0; | |
92 } | |
93 | |
94 static int iff_read_header(AVFormatContext *s, | |
95 AVFormatParameters *ap) | |
96 { | |
97 IffDemuxContext *iff = s->priv_data; | |
98 ByteIOContext *pb = s->pb; | |
99 AVStream *st; | |
100 uint32_t chunk_id, data_size; | |
3200 | 101 int padding, done = 0; |
5625 | 102 int compression = -1; |
5660 | 103 char *buf; |
3189 | 104 |
105 st = av_new_stream(s, 0); | |
106 if (!st) | |
107 return AVERROR(ENOMEM); | |
108 | |
109 st->codec->channels = 1; | |
5625 | 110 url_fskip(pb, 8); |
111 // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content | |
112 st->codec->codec_tag = get_le32(pb); | |
3189 | 113 |
114 while(!done && !url_feof(pb)) { | |
115 chunk_id = get_le32(pb); | |
116 data_size = get_be32(pb); | |
117 padding = data_size & 1; | |
118 | |
119 switch(chunk_id) { | |
120 case ID_VHDR: | |
5625 | 121 st->codec->codec_type = CODEC_TYPE_AUDIO; |
3189 | 122 url_fskip(pb, 12); |
123 st->codec->sample_rate = get_be16(pb); | |
124 url_fskip(pb, 1); | |
5625 | 125 compression = get_byte(pb); |
3189 | 126 url_fskip(pb, 4); |
127 break; | |
128 | |
129 case ID_BODY: | |
130 iff->body_size = data_size; | |
131 done = 1; | |
132 break; | |
133 | |
134 case ID_CHAN: | |
135 st->codec->channels = (get_be32(pb) < 6) ? 1 : 2; | |
136 break; | |
137 | |
5625 | 138 case ID_CMAP: |
139 st->codec->extradata_size = data_size; | |
140 st->codec->extradata = av_malloc(data_size); | |
141 if (!st->codec->extradata) | |
142 return AVERROR(ENOMEM); | |
143 if (get_buffer(pb, st->codec->extradata, data_size) < 0) | |
144 return AVERROR(EIO); | |
145 break; | |
146 | |
147 case ID_BMHD: | |
148 st->codec->codec_type = CODEC_TYPE_VIDEO; | |
149 st->codec->width = get_be16(pb); | |
150 st->codec->height = get_be16(pb); | |
151 url_fskip(pb, 4); // x, y offset | |
152 st->codec->bits_per_coded_sample = get_byte(pb); | |
153 url_fskip(pb, 1); // masking | |
154 compression = get_byte(pb); | |
155 url_fskip(pb, 3); // paddding, transparent | |
156 st->sample_aspect_ratio.num = get_byte(pb); | |
157 st->sample_aspect_ratio.den = get_byte(pb); | |
158 url_fskip(pb, 4); // source page width, height | |
159 break; | |
160 | |
5660 | 161 case ID_ANNO: |
162 buf = av_malloc(data_size + 1); | |
163 if (!buf) | |
164 break; | |
165 get_buffer(pb, buf, data_size); | |
166 buf[data_size] = 0; | |
167 av_metadata_set2(&s->metadata, "comment", buf, AV_METADATA_DONT_STRDUP_VAL); | |
168 break; | |
169 | |
3189 | 170 default: |
171 url_fseek(pb, data_size + padding, SEEK_CUR); | |
172 break; | |
173 } | |
174 } | |
175 | |
5625 | 176 switch(st->codec->codec_type) { |
177 case CODEC_TYPE_AUDIO: | |
3189 | 178 av_set_pts_info(st, 32, 1, st->codec->sample_rate); |
179 | |
5625 | 180 switch(compression) { |
3189 | 181 case COMP_NONE: |
182 st->codec->codec_id = CODEC_ID_PCM_S8; | |
183 break; | |
184 case COMP_FIB: | |
185 st->codec->codec_id = CODEC_ID_8SVX_FIB; | |
186 break; | |
187 case COMP_EXP: | |
188 st->codec->codec_id = CODEC_ID_8SVX_EXP; | |
189 break; | |
190 default: | |
191 av_log(s, AV_LOG_ERROR, "iff: unknown compression method\n"); | |
192 return -1; | |
193 } | |
194 | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3424
diff
changeset
|
195 st->codec->bits_per_coded_sample = 8; |
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3424
diff
changeset
|
196 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; |
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3424
diff
changeset
|
197 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; |
5625 | 198 break; |
199 | |
200 case CODEC_TYPE_VIDEO: | |
201 switch (compression) { | |
202 case BITMAP_RAW: | |
203 if (st->codec->codec_tag == ID_ILBM) { | |
204 st->codec->codec_id = CODEC_ID_IFF_ILBM; | |
205 } else { | |
206 st->codec->codec_id = CODEC_ID_RAWVIDEO; | |
207 st->codec->pix_fmt = PIX_FMT_PAL8; | |
208 st->codec->codec_tag = 0; | |
209 } | |
210 break; | |
211 case BITMAP_BYTERUN1: | |
212 st->codec->codec_id = CODEC_ID_IFF_BYTERUN1; | |
213 break; | |
214 default: | |
215 av_log(s, AV_LOG_ERROR, "unknown compression method\n"); | |
216 return AVERROR_INVALIDDATA; | |
217 } | |
218 break; | |
219 default: | |
220 return -1; | |
221 } | |
3189 | 222 |
223 return 0; | |
224 } | |
225 | |
5625 | 226 int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal); |
227 | |
3189 | 228 static int iff_read_packet(AVFormatContext *s, |
229 AVPacket *pkt) | |
230 { | |
231 IffDemuxContext *iff = s->priv_data; | |
232 ByteIOContext *pb = s->pb; | |
5625 | 233 AVStream *st = s->streams[0]; |
3189 | 234 int ret; |
235 | |
5625 | 236 if(iff->sent_bytes >= iff->body_size) |
3189 | 237 return AVERROR(EIO); |
3285 | 238 |
239 if(s->streams[0]->codec->channels == 2) { | |
240 uint8_t sample_buffer[PACKET_SIZE]; | |
241 | |
242 ret = get_buffer(pb, sample_buffer, PACKET_SIZE); | |
243 if(av_new_packet(pkt, PACKET_SIZE) < 0) { | |
244 av_log(s, AV_LOG_ERROR, "iff: cannot allocate packet \n"); | |
245 return AVERROR(ENOMEM); | |
246 } | |
247 interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); | |
5625 | 248 } else if (s->streams[0]->codec->codec_id == CODEC_ID_RAWVIDEO) { |
249 if(av_new_packet(pkt, iff->body_size + AVPALETTE_SIZE) < 0) { | |
250 return AVERROR(ENOMEM); | |
251 } | |
252 | |
253 ret = ff_cmap_read_palette(st->codec, (uint32_t*)(pkt->data + iff->body_size)); | |
254 if (ret < 0) | |
255 return ret; | |
256 av_freep(&st->codec->extradata); | |
257 st->codec->extradata_size = 0; | |
258 | |
259 ret = get_buffer(pb, pkt->data, iff->body_size); | |
260 } else if (s->streams[0]->codec->codec_type == CODEC_TYPE_VIDEO) { | |
261 ret = av_get_packet(pb, pkt, iff->body_size); | |
262 } else { | |
3285 | 263 ret = av_get_packet(pb, pkt, PACKET_SIZE); |
264 } | |
3189 | 265 |
266 if(iff->sent_bytes == 0) | |
267 pkt->flags |= PKT_FLAG_KEY; | |
268 | |
5625 | 269 if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) { |
5626 | 270 iff->sent_bytes += PACKET_SIZE; |
5625 | 271 } else { |
272 iff->sent_bytes = iff->body_size; | |
273 } | |
3189 | 274 pkt->stream_index = 0; |
5625 | 275 if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) { |
5626 | 276 pkt->pts = iff->audio_frame_count; |
277 iff->audio_frame_count += ret / s->streams[0]->codec->channels; | |
5625 | 278 } |
3189 | 279 return ret; |
280 } | |
281 | |
282 AVInputFormat iff_demuxer = { | |
283 "IFF", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3285
diff
changeset
|
284 NULL_IF_CONFIG_SMALL("IFF format"), |
3189 | 285 sizeof(IffDemuxContext), |
286 iff_probe, | |
287 iff_read_header, | |
288 iff_read_packet, | |
289 }; |