1 /*
2 * Sierra VMD Format Demuxer
3 * Copyright (c) 2004 The ffmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Sierra VMD file demuxer
25 * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
26 * for more information on the Sierra VMD file format, visit:
27 * http://www.pcisys.net/~melanson/codecs/
28 */
29
35
36 #define VMD_HEADER_SIZE 0x0330
37 #define BYTES_PER_FRAME_RECORD 16
38
47
51
57
61
64
66 {
67 int w, h;
69 return 0;
70 /* check if the first 2 bytes of the file contain the appropriate size
71 * of a VMD header chunk */
73 return 0;
76 if (!w || w > 2048 || !h || h > 2048)
77 return 0;
78
79 /* only return half certainty since this check is a bit sketchy */
81 }
82
84 {
88 unsigned int toc_offset;
89 unsigned char *raw_frame_table;
90 int raw_frame_table_size;
91 int64_t current_offset;
92 int i, j;
93 unsigned int total_frames;
94 int64_t current_audio_pts = 0;
96 int num, den;
97 int sound_buffers;
98
99 /* fetch the main header, including the 2 header length bytes */
103
106 else
108 /* start up the decoders */
110 if (!vst)
116 vst->codec->codec_tag = 0; /* no fourcc */
119 if(vmd->
is_indeo3 && vst->codec->width > 320){
120 vst->codec->width >>= 1;
121 vst->codec->height >>= 1;
122 }
126
127 /* if sample rate is 0, assume no audio */
131 if (!st)
140 } else {
143 }
149 } else {
151 }
154
155 /* calculate pts */
158 av_reduce(&num, &den, num, den, (1UL<<31)-1);
161 }
162
167
168 raw_frame_table =
NULL;
174 return -1;
175 }
176 raw_frame_table =
av_malloc(raw_frame_table_size);
182 }
183 if (
avio_read(pb, raw_frame_table, raw_frame_table_size) !=
184 raw_frame_table_size) {
188 }
189
190 total_frames = 0;
192
193 current_offset =
AV_RL32(&raw_frame_table[6 * i + 2]);
194
195 /* handle each entry in index block */
197 int type;
199
201 type = chunk[0];
203 if(!size && type != 1)
204 continue;
205 switch(type) {
206 case 1: /* Audio Chunk */
207 if (!st) break;
208 /* first audio chunk contains several audio buffers */
214 total_frames++;
215 if(!current_audio_pts)
216 current_audio_pts += sound_buffers - 1;
217 else
218 current_audio_pts++;
219 break;
220 case 2: /* Video Chunk */
226 total_frames++;
227 break;
228 }
229 current_offset +=
size;
230 }
231 }
232
234
237
238 return 0;
239 }
240
243 {
246 int ret = 0;
248
251
253 /* position the stream (will probably be there already) */
255
264 else
267
271 }
278
280
281 return ret;
282 }
283
285 {
287
289
290 return 0;
291 }
292
301 };