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
37
38 #define VMD_HEADER_SIZE 0x0330
39 #define BYTES_PER_FRAME_RECORD 16
40
48
52
58
62
65
67 {
68 int w,
h, sample_rate;
70 return 0;
71 /* check if the first 2 bytes of the file contain the appropriate size
72 * of a VMD header chunk */
74 return 0;
78 if ((!
w ||
w > 2048 || !
h ||
h > 2048) &&
79 sample_rate != 22050)
80 return 0;
81
82 /* only return half certainty since this check is a bit sketchy */
84 }
85
87 {
91 unsigned int toc_offset;
92 unsigned char *raw_frame_table;
93 int raw_frame_table_size;
97 unsigned int total_frames;
100 int num, den;
101 int sound_buffers;
102
103 /* fetch the main header, including the 2 header length bytes */
107
113 } else {
115 }
116 /* start up the decoders */
118 if (!vst)
124 vst->codecpar->codec_tag = 0; /* no fourcc */
125 vst->codecpar->width =
width;
126 vst->codecpar->height =
height;
127 if(vmd->
is_indeo3 && vst->codecpar->width > 320){
128 vst->codecpar->width >>= 1;
129 vst->codecpar->height >>= 1;
130 }
134 }
135
136 /* if sample rate is 0, assume no audio */
141 if (!st)
152 } else {
154 }
158 /* Shivers 2 stereo audio */
159 /* Frame length is for 1 channel */
162 } else {
164 }
168
169 /* calculate pts */
172 av_reduce(&num, &den, num, den, (1UL<<31)-1);
173 if (vst)
176 }
179
184
185 raw_frame_table =
NULL;
189 raw_frame_table =
av_malloc(raw_frame_table_size);
194 }
195 if (
avio_read(pb, raw_frame_table, raw_frame_table_size) !=
196 raw_frame_table_size) {
199 }
200
201 total_frames = 0;
203
204 current_offset =
AV_RL32(&raw_frame_table[6 *
i + 2]);
205
206 /* handle each entry in index block */
210
216 }
219 if (
size > INT_MAX / 2) {
223 }
225 continue;
227 case 1: /* Audio Chunk */
228 if (!st) break;
229 /* first audio chunk contains several audio buffers */
235 total_frames++;
236 if(!current_audio_pts)
237 current_audio_pts += sound_buffers - 1;
238 else
239 current_audio_pts++;
240 break;
241 case 2: /* Video Chunk */
242 if (!vst)
243 break;
249 total_frames++;
250 break;
251 }
252 current_offset +=
size;
253 }
254 }
255
256
259
264 }
265
268 {
273
276
278 /* position the stream (will probably be there already) */
280
290 else
293
296 }
300 (
frame->frame_record[0] == 0x02) ?
"video" :
"audio",
303
305
307 }
308
310 {
312
314
315 return 0;
316 }
317
327 };