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
46
50
56
60
63
65 {
68 return 0;
69 /* check if the first 2 bytes of the file contain the appropriate size
70 * of a VMD header chunk */
72 return 0;
76 if ((!
w ||
w > 2048 || !
h ||
h > 2048) &&
78 return 0;
79
80 /* only return half certainty since this check is a bit sketchy */
82 }
83
85 {
89 unsigned int toc_offset;
90 unsigned char *raw_frame_table;
91 int raw_frame_table_size;
92 int64_t current_offset;
95 unsigned int total_frames;
96 int64_t current_audio_pts = 0;
98 int num, den;
99 int sound_buffers;
100
101 /* fetch the main header, including the 2 header length bytes */
105
111 } else {
113 }
114 /* start up the decoders */
116 if (!vst)
122 vst->codecpar->codec_tag = 0; /* no fourcc */
123 vst->codecpar->width =
width;
124 vst->codecpar->height =
height;
125 if(vmd->
is_indeo3 && vst->codecpar->width > 320){
126 vst->codecpar->width >>= 1;
127 vst->codecpar->height >>= 1;
128 }
132 }
133
134 /* if sample rate is 0, assume no audio */
138 if (!st)
149 } else {
151 }
156 /* Shivers 2 stereo audio */
157 /* Frame length is for 1 channel */
161 } else {
164 }
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 };