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 */
139 if (!st)
150 } else {
152 }
156 /* Shivers 2 stereo audio */
157 /* Frame length is for 1 channel */
160 } else {
162 }
166
167 /* calculate pts */
170 av_reduce(&num, &den, num, den, (1UL<<31)-1);
171 if (vst)
174 }
177
182
183 raw_frame_table =
NULL;
187 raw_frame_table =
av_malloc(raw_frame_table_size);
192 }
193 if (
avio_read(pb, raw_frame_table, raw_frame_table_size) !=
194 raw_frame_table_size) {
197 }
198
199 total_frames = 0;
201
202 current_offset =
AV_RL32(&raw_frame_table[6 *
i + 2]);
203
204 /* handle each entry in index block */
208
214 }
217 if (
size > INT_MAX / 2) {
221 }
223 continue;
225 case 1: /* Audio Chunk */
226 if (!st) break;
227 /* first audio chunk contains several audio buffers */
233 total_frames++;
234 if(!current_audio_pts)
235 current_audio_pts += sound_buffers - 1;
236 else
237 current_audio_pts++;
238 break;
239 case 2: /* Video Chunk */
240 if (!vst)
241 break;
247 total_frames++;
248 break;
249 }
250 current_offset +=
size;
251 }
252 }
253
254
257
262 }
263
266 {
271
274
276 /* position the stream (will probably be there already) */
278
288 else
291
294 }
298 (
frame->frame_record[0] == 0x02) ?
"video" :
"audio",
301
303
305 }
306
308 {
310
312
313 return 0;
314 }
315
325 };