annotate iff.c @ 5628:ee642c4e5b5c libavformat

Dont try generic seek if seek request before first index entry and backward. Fixes issue1275
author michael
date Wed, 03 Feb 2010 23:59:48 +0000
parents b3d4ef7e53ad
children 1701ad9b6064
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>
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
5 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
6 * This file is part of FFmpeg.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
7 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
12 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
16 * Lesser General Public License for more details.
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
17 *
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
21 */
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
22
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
23 /**
4331
49c1d3b27727 Use full internal pathname in doxygen @file directives.
diego
parents: 4201
diff changeset
24 * @file libavformat/iff.c
3198
814a32de9ec7 minor typo fixes
diego
parents: 3189
diff changeset
25 * IFF file demuxer
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
26 * by Jaikrishnan Menon
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
27 * for more information on the .iff file format, visit:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
28 * http://wiki.multimedia.cx/index.php?title=IFF
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
29 */
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
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
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
32 #include "avformat.h"
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
33
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
34 #define ID_8SVX MKTAG('8','S','V','X')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
35 #define ID_VHDR MKTAG('V','H','D','R')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
36 #define ID_ATAK MKTAG('A','T','A','K')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
37 #define ID_RLSE MKTAG('R','L','S','E')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
38 #define ID_CHAN MKTAG('C','H','A','N')
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
39 #define ID_PBM MKTAG('P','B','M',' ')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
40 #define ID_ILBM MKTAG('I','L','B','M')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
41 #define ID_BMHD MKTAG('B','M','H','D')
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
42 #define ID_CMAP MKTAG('C','M','A','P')
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
43
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
44 #define ID_FORM MKTAG('F','O','R','M')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
45 #define ID_ANNO MKTAG('A','N','N','O')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
46 #define ID_AUTH MKTAG('A','U','T','H')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
47 #define ID_CHRS MKTAG('C','H','R','S')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
48 #define ID_COPYRIGHT MKTAG('(','c',')',' ')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
49 #define ID_CSET MKTAG('C','S','E','T')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
50 #define ID_FVER MKTAG('F','V','E','R')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
51 #define ID_NAME MKTAG('N','A','M','E')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
52 #define ID_TEXT MKTAG('T','E','X','T')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
53 #define ID_BODY MKTAG('B','O','D','Y')
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
54
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
55 #define LEFT 2
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
56 #define RIGHT 4
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
57 #define STEREO 6
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
58
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
59 #define PACKET_SIZE 1024
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
60
4090
a209d26d63c2 Avoid _t in identifier names, _t is reserved by POSIX.
diego
parents: 3908
diff changeset
61 typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
62 typedef enum {BITMAP_RAW, BITMAP_BYTERUN1} bitmap_compression_type;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
63
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
64 typedef struct {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
65 uint32_t body_size;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
66 uint32_t sent_bytes;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
67 uint32_t audio_frame_count;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
68 } IffDemuxContext;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
69
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
70
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
71 static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size)
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
72 {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
73 uint8_t *end = dest + size;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
74 size = size>>1;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
75
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
76 while(dest < end) {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
77 *dest++ = *src;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
78 *dest++ = *(src+size);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
79 src++;
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
80 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
81 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
82
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
83 static int iff_probe(AVProbeData *p)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
84 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
85 const uint8_t *d = p->buf;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
86
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
87 if ( AV_RL32(d) == ID_FORM &&
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
88 (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
89 return AVPROBE_SCORE_MAX;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
90 return 0;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
91 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
92
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
93 static int iff_read_header(AVFormatContext *s,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
94 AVFormatParameters *ap)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
95 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
96 IffDemuxContext *iff = s->priv_data;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
97 ByteIOContext *pb = s->pb;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
98 AVStream *st;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
99 uint32_t chunk_id, data_size;
3200
a437fb5ca080 Remove unused variable.
diego
parents: 3198
diff changeset
100 int padding, done = 0;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
101 int compression = -1;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
102
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
103 st = av_new_stream(s, 0);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
104 if (!st)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
105 return AVERROR(ENOMEM);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
106
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
107 st->codec->channels = 1;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
108 url_fskip(pb, 8);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
109 // 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
110 st->codec->codec_tag = get_le32(pb);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
111
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
112 while(!done && !url_feof(pb)) {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
113 chunk_id = get_le32(pb);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
114 data_size = get_be32(pb);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
115 padding = data_size & 1;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
116
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
117 switch(chunk_id) {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
118 case ID_VHDR:
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
119 st->codec->codec_type = CODEC_TYPE_AUDIO;
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
120 url_fskip(pb, 12);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
121 st->codec->sample_rate = get_be16(pb);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
122 url_fskip(pb, 1);
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
123 compression = get_byte(pb);
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
124 url_fskip(pb, 4);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
125 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
126
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
127 case ID_BODY:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
128 iff->body_size = data_size;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
129 done = 1;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
130 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
131
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
132 case ID_CHAN:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
133 st->codec->channels = (get_be32(pb) < 6) ? 1 : 2;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
134 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
135
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
136 case ID_CMAP:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
137 st->codec->extradata_size = data_size;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
138 st->codec->extradata = av_malloc(data_size);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
139 if (!st->codec->extradata)
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
140 return AVERROR(ENOMEM);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
141 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
142 return AVERROR(EIO);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
143 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
144
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
145 case ID_BMHD:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
146 st->codec->codec_type = CODEC_TYPE_VIDEO;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
147 st->codec->width = get_be16(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
148 st->codec->height = get_be16(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
149 url_fskip(pb, 4); // x, y offset
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
150 st->codec->bits_per_coded_sample = get_byte(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
151 url_fskip(pb, 1); // masking
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
152 compression = get_byte(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
153 url_fskip(pb, 3); // paddding, transparent
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
154 st->sample_aspect_ratio.num = get_byte(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
155 st->sample_aspect_ratio.den = get_byte(pb);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
156 url_fskip(pb, 4); // source page width, height
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
157 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
158
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
159 default:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
160 url_fseek(pb, data_size + padding, SEEK_CUR);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
161 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
162 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
163 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
164
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
165 switch(st->codec->codec_type) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
166 case CODEC_TYPE_AUDIO:
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
167 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
168
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
169 switch(compression) {
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
170 case COMP_NONE:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
171 st->codec->codec_id = CODEC_ID_PCM_S8;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
172 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
173 case COMP_FIB:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
174 st->codec->codec_id = CODEC_ID_8SVX_FIB;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
175 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
176 case COMP_EXP:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
177 st->codec->codec_id = CODEC_ID_8SVX_EXP;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
178 break;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
179 default:
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
180 av_log(s, AV_LOG_ERROR, "iff: unknown compression method\n");
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
181 return -1;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
182 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
183
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
184 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
185 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
186 st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
187 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
188
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
189 case CODEC_TYPE_VIDEO:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
190 switch (compression) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
191 case BITMAP_RAW:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
192 if (st->codec->codec_tag == ID_ILBM) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
193 st->codec->codec_id = CODEC_ID_IFF_ILBM;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
194 } else {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
195 st->codec->codec_id = CODEC_ID_RAWVIDEO;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
196 st->codec->pix_fmt = PIX_FMT_PAL8;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
197 st->codec->codec_tag = 0;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
198 }
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
199 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
200 case BITMAP_BYTERUN1:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
201 st->codec->codec_id = CODEC_ID_IFF_BYTERUN1;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
202 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
203 default:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
204 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
205 return AVERROR_INVALIDDATA;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
206 }
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
207 break;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
208 default:
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
209 return -1;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
210 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
211
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
212 return 0;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
213 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
214
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
215 int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
216
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
217 static int iff_read_packet(AVFormatContext *s,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
218 AVPacket *pkt)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
219 {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
220 IffDemuxContext *iff = s->priv_data;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
221 ByteIOContext *pb = s->pb;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
222 AVStream *st = s->streams[0];
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
223 int ret;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
224
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
225 if(iff->sent_bytes >= iff->body_size)
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
226 return AVERROR(EIO);
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
227
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
228 if(s->streams[0]->codec->channels == 2) {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
229 uint8_t sample_buffer[PACKET_SIZE];
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
230
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
231 ret = get_buffer(pb, sample_buffer, PACKET_SIZE);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
232 if(av_new_packet(pkt, PACKET_SIZE) < 0) {
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
233 av_log(s, AV_LOG_ERROR, "iff: cannot allocate packet \n");
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
234 return AVERROR(ENOMEM);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
235 }
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
236 interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
237 } else if (s->streams[0]->codec->codec_id == CODEC_ID_RAWVIDEO) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
238 if(av_new_packet(pkt, iff->body_size + AVPALETTE_SIZE) < 0) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
239 return AVERROR(ENOMEM);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
240 }
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
241
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
242 ret = ff_cmap_read_palette(st->codec, (uint32_t*)(pkt->data + iff->body_size));
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
243 if (ret < 0)
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
244 return ret;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
245 av_freep(&st->codec->extradata);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
246 st->codec->extradata_size = 0;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
247
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
248 ret = get_buffer(pb, pkt->data, iff->body_size);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
249 } else if (s->streams[0]->codec->codec_type == CODEC_TYPE_VIDEO) {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
250 ret = av_get_packet(pb, pkt, iff->body_size);
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
251 } else {
3285
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
252 ret = av_get_packet(pb, pkt, PACKET_SIZE);
ccfd981fe0fa IFF stereo support
superdump
parents: 3200
diff changeset
253 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
254
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
255 if(iff->sent_bytes == 0)
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
256 pkt->flags |= PKT_FLAG_KEY;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
257
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
258 if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) {
5626
b3d4ef7e53ad Indentation cleanup
pross
parents: 5625
diff changeset
259 iff->sent_bytes += PACKET_SIZE;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
260 } else {
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
261 iff->sent_bytes = iff->body_size;
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
262 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
263 pkt->stream_index = 0;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
264 if(s->streams[0]->codec->codec_type == CODEC_TYPE_AUDIO) {
5626
b3d4ef7e53ad Indentation cleanup
pross
parents: 5625
diff changeset
265 pkt->pts = iff->audio_frame_count;
b3d4ef7e53ad Indentation cleanup
pross
parents: 5625
diff changeset
266 iff->audio_frame_count += ret / s->streams[0]->codec->channels;
5625
c76c1e0c50a5 Extend IFF demuxer to parse PBM/ILBM bitmap chunks
pross
parents: 4331
diff changeset
267 }
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
268 return ret;
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
269 }
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
270
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
271 AVInputFormat iff_demuxer = {
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
272 "IFF",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3285
diff changeset
273 NULL_IF_CONFIG_SMALL("IFF format"),
3189
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
274 sizeof(IffDemuxContext),
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
275 iff_probe,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
276 iff_read_header,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
277 iff_read_packet,
f016d69a28b6 IFF demuxer
vitor
parents:
diff changeset
278 };