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
36
37 #define VMD_HEADER_SIZE 0x0330
38 #define BYTES_PER_FRAME_RECORD 16
39
47
51
57
61
64
66 {
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;
77 if ((!
w ||
w > 2048 || !
h ||
h > 2048) &&
79 return 0;
80
81 /* only return half certainty since this check is a bit sketchy */
83 }
84
86 {
90 unsigned int toc_offset;
91 unsigned char *raw_frame_table;
92 int raw_frame_table_size;
96 unsigned int total_frames;
99 int num, den;
100 int sound_buffers;
101
102 /* fetch the main header, including the 2 header length bytes */
106
112 } else {
114 }
115 /* start up the decoders */
117 if (!vst)
123 vst->codecpar->codec_tag = 0; /* no fourcc */
124 vst->codecpar->width =
width;
125 vst->codecpar->height =
height;
126 if(vmd->
is_indeo3 && vst->codecpar->width > 320){
127 vst->codecpar->width >>= 1;
128 vst->codecpar->height >>= 1;
129 }
133 }
134
135 /* if sample rate is 0, assume no audio */
140 if (!st)
151 } else {
153 }
157 /* Shivers 2 stereo audio */
158 /* Frame length is for 1 channel */
161 } else {
163 }
167
168 /* calculate pts */
171 av_reduce(&num, &den, num, den, (1UL<<31)-1);
172 if (vst)
175 }
178
183
184 raw_frame_table =
NULL;
188 raw_frame_table =
av_malloc(raw_frame_table_size);
193 }
194 if (
avio_read(pb, raw_frame_table, raw_frame_table_size) !=
195 raw_frame_table_size) {
198 }
199
200 total_frames = 0;
202
203 current_offset =
AV_RL32(&raw_frame_table[6 *
i + 2]);
204
205 /* handle each entry in index block */
209
215 }
218 if (
size > INT_MAX / 2) {
222 }
224 continue;
226 case 1: /* Audio Chunk */
227 if (!st) break;
228 /* first audio chunk contains several audio buffers */
234 total_frames++;
235 if(!current_audio_pts)
236 current_audio_pts += sound_buffers - 1;
237 else
238 current_audio_pts++;
239 break;
240 case 2: /* Video Chunk */
241 if (!vst)
242 break;
248 total_frames++;
249 break;
250 }
251 current_offset +=
size;
252 }
253 }
254
255
258
263 }
264
267 {
272
275
277 /* position the stream (will probably be there already) */
279
289 else
292
295 }
299 (
frame->frame_record[0] == 0x02) ?
"video" :
"audio",
302
304
306 }
307
309 {
311
313
314 return 0;
315 }
316
326 };