annotate sierravmd.c @ 6275:287072e5227b libavformat

Add MD5 protocol This is a write-only protocol which computes the md5sum of data written, and on close writes this to the designated output or stdout if none is specified. It can be used to test muxers without writing an actual file.
author mru
date Sun, 18 Jul 2010 20:19:08 +0000
parents 178de7695c6c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
1 /*
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
2 * Sierra VMD Format Demuxer
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
3 * Copyright (c) 2004 The ffmpeg Project
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
15 * Lesser General Public License for more details.
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
16 *
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
20 */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
21
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
22 /**
5969
178de7695c6c Remove explicit filename from Doxygen @file commands.
diego
parents: 5910
diff changeset
23 * @file
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
24 * Sierra VMD file demuxer
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
25 * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
26 * for more information on the Sierra VMD file format, visit:
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
27 * http://www.pcisys.net/~melanson/codecs/
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
28 */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
29
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 4137
diff changeset
30 #include "libavutil/intreadwrite.h"
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
31 #include "avformat.h"
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
32
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
33 #define VMD_HEADER_SIZE 0x0330
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
34 #define BYTES_PER_FRAME_RECORD 16
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
35
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
36 typedef struct {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
37 int stream_index;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3908
diff changeset
38 int64_t frame_offset;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
39 unsigned int frame_size;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
40 int64_t pts;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
41 int keyframe;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
42 unsigned char frame_record[BYTES_PER_FRAME_RECORD];
4102
dcaeec7bd85f The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 3973
diff changeset
43 } vmd_frame;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
44
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
45 typedef struct VmdDemuxContext {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
46 int video_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
47 int audio_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
48
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
49 unsigned int frame_count;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
50 unsigned int frames_per_block;
4102
dcaeec7bd85f The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 3973
diff changeset
51 vmd_frame *frame_table;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
52 unsigned int current_frame;
4131
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
53 int is_indeo3;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
54
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
55 int sample_rate;
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
56 int64_t audio_sample_counter;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
57 int skiphdr;
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
58
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
59 unsigned char vmd_header[VMD_HEADER_SIZE];
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
60 } VmdDemuxContext;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
61
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
62 static int vmd_probe(AVProbeData *p)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
63 {
5187
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
64 int w, h;
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
65 if (p->buf_size < 16)
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
66 return 0;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
67 /* check if the first 2 bytes of the file contain the appropriate size
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
68 * of a VMD header chunk */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
69 if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2)
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
70 return 0;
5187
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
71 w = AV_RL16(&p->buf[12]);
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
72 h = AV_RL16(&p->buf[14]);
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
73 if (!w || w > 2048 || !h || h > 2048)
0394dceb230f Improve sierravmd probe. It is still quite weak, but further improvements
reimar
parents: 5178
diff changeset
74 return 0;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
75
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
76 /* only return half certainty since this check is a bit sketchy */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
77 return AVPROBE_SCORE_MAX / 2;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
78 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
79
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
80 static int vmd_read_header(AVFormatContext *s,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
81 AVFormatParameters *ap)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
82 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 2001
diff changeset
83 VmdDemuxContext *vmd = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2369
diff changeset
84 ByteIOContext *pb = s->pb;
3017
a086b58a3336 Fix a possible use of an uninitialized pointer.
reimar
parents: 2771
diff changeset
85 AVStream *st = NULL, *vst;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
86 unsigned int toc_offset;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
87 unsigned char *raw_frame_table;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
88 int raw_frame_table_size;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3908
diff changeset
89 int64_t current_offset;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
90 int i, j;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
91 unsigned int total_frames;
4268
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
92 int64_t current_audio_pts = 0;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
93 unsigned char chunk[BYTES_PER_FRAME_RECORD];
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
94 int num, den;
1528
32d49970f01a Divide first audio buffer chunk into atomary bufffers.
kostya
parents: 1492
diff changeset
95 int sound_buffers;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
96
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
97 /* fetch the main header, including the 2 header length bytes */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
98 url_fseek(pb, 0, SEEK_SET);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
99 if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
100 return AVERROR(EIO);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
101
4131
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
102 if(vmd->vmd_header[16] == 'i' && vmd->vmd_header[17] == 'v' && vmd->vmd_header[18] == '3')
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
103 vmd->is_indeo3 = 1;
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
104 else
4137
b432c9e98002 Fix a typo that made VMD demuxer always assume Indeo 3 as video codec.
kostya
parents: 4131
diff changeset
105 vmd->is_indeo3 = 0;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
106 /* start up the decoders */
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
107 vst = av_new_stream(s, 0);
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
108 if (!vst)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
109 return AVERROR(ENOMEM);
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
110 av_set_pts_info(vst, 33, 1, 10);
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
111 vmd->video_stream_index = vst->index;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5207
diff changeset
112 vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
4131
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
113 vst->codec->codec_id = vmd->is_indeo3 ? CODEC_ID_INDEO3 : CODEC_ID_VMDVIDEO;
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
114 vst->codec->codec_tag = 0; /* no fourcc */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
115 vst->codec->width = AV_RL16(&vmd->vmd_header[12]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
116 vst->codec->height = AV_RL16(&vmd->vmd_header[14]);
4131
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
117 if(vmd->is_indeo3 && vst->codec->width > 320){
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
118 vst->codec->width >>= 1;
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
119 vst->codec->height >>= 1;
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
120 }
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
121 vst->codec->extradata_size = VMD_HEADER_SIZE;
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
122 vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
123 memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
124
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
125 /* if sample rate is 0, assume no audio */
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
126 vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
127 if (vmd->sample_rate) {
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
128 st = av_new_stream(s, 0);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
129 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
130 return AVERROR(ENOMEM);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
131 vmd->audio_stream_index = st->index;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5207
diff changeset
132 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 815
diff changeset
133 st->codec->codec_id = CODEC_ID_VMDAUDIO;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
134 st->codec->codec_tag = 0; /* no fourcc */
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
135 st->codec->channels = (vmd->vmd_header[811] & 0x80) ? 2 : 1;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 815
diff changeset
136 st->codec->sample_rate = vmd->sample_rate;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
137 st->codec->block_align = AV_RL16(&vmd->vmd_header[806]);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 815
diff changeset
138 if (st->codec->block_align & 0x8000) {
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
139 st->codec->bits_per_coded_sample = 16;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 815
diff changeset
140 st->codec->block_align = -(st->codec->block_align - 0x10000);
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
141 } else {
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
142 st->codec->bits_per_coded_sample = 8;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
143 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
144 st->codec->bit_rate = st->codec->sample_rate *
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
145 st->codec->bits_per_coded_sample * st->codec->channels;
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
146
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
147 /* calculate pts */
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
148 num = st->codec->block_align;
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
149 den = st->codec->sample_rate * st->codec->channels;
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
150 av_reduce(&den, &num, den, num, (1UL<<31)-1);
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
151 av_set_pts_info(vst, 33, num, den);
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
152 av_set_pts_info(st, 33, num, den);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
153 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
154
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
155 toc_offset = AV_RL32(&vmd->vmd_header[812]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
156 vmd->frame_count = AV_RL16(&vmd->vmd_header[6]);
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
157 vmd->frames_per_block = AV_RL16(&vmd->vmd_header[18]);
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
158 url_fseek(pb, toc_offset, SEEK_SET);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
159
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
160 raw_frame_table = NULL;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
161 vmd->frame_table = NULL;
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
162 sound_buffers = AV_RL16(&vmd->vmd_header[808]);
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
163 raw_frame_table_size = vmd->frame_count * 6;
5207
f08a788606d5 Fix overflow check insufficiently improved in r19840.
reimar
parents: 5187
diff changeset
164 if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame) - sound_buffers){
1079
40e81416015d sanity checks some might have been exploitable
michael
parents: 1004
diff changeset
165 av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n");
40e81416015d sanity checks some might have been exploitable
michael
parents: 1004
diff changeset
166 return -1;
40e81416015d sanity checks some might have been exploitable
michael
parents: 1004
diff changeset
167 }
3393
f95ddc69c48d memleak / CID124 RUN2
michael
parents: 3017
diff changeset
168 raw_frame_table = av_malloc(raw_frame_table_size);
4102
dcaeec7bd85f The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 3973
diff changeset
169 vmd->frame_table = av_malloc((vmd->frame_count * vmd->frames_per_block + sound_buffers) * sizeof(vmd_frame));
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
170 if (!raw_frame_table || !vmd->frame_table) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
171 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
172 av_free(vmd->frame_table);
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
173 return AVERROR(ENOMEM);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
174 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 884
diff changeset
175 if (get_buffer(pb, raw_frame_table, raw_frame_table_size) !=
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
176 raw_frame_table_size) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
177 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
178 av_free(vmd->frame_table);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
179 return AVERROR(EIO);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
180 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
181
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
182 total_frames = 0;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
183 for (i = 0; i < vmd->frame_count; i++) {
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
184
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
185 current_offset = AV_RL32(&raw_frame_table[6 * i + 2]);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
186
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
187 /* handle each entry in index block */
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
188 for (j = 0; j < vmd->frames_per_block; j++) {
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
189 int type;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
190 uint32_t size;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
191
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
192 get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD);
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
193 type = chunk[0];
1673
a782462e2497 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 1529
diff changeset
194 size = AV_RL32(&chunk[2]);
4267
ce5b09a7f263 Empty audio chunks in VMD are silent, not skipped
kostya
parents: 4266
diff changeset
195 if(!size && type != 1)
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
196 continue;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
197 switch(type) {
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
198 case 1: /* Audio Chunk */
3017
a086b58a3336 Fix a possible use of an uninitialized pointer.
reimar
parents: 2771
diff changeset
199 if (!st) break;
1528
32d49970f01a Divide first audio buffer chunk into atomary bufffers.
kostya
parents: 1492
diff changeset
200 /* first audio chunk contains several audio buffers */
4266
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
201 vmd->frame_table[total_frames].frame_offset = current_offset;
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
202 vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
203 vmd->frame_table[total_frames].frame_size = size;
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
204 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
205 vmd->frame_table[total_frames].pts = current_audio_pts;
b67df52d56f9 cosmetics: reindent after last commit
kostya
parents: 4265
diff changeset
206 total_frames++;
4268
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
207 if(!current_audio_pts)
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
208 current_audio_pts += sound_buffers;
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
209 else
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
210 current_audio_pts++;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
211 break;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
212 case 2: /* Video Chunk */
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
213 vmd->frame_table[total_frames].frame_offset = current_offset;
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
214 vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
215 vmd->frame_table[total_frames].frame_size = size;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
216 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
4268
85608ac6c804 yet another attempt on fixing synchronization in VMD
kostya
parents: 4267
diff changeset
217 vmd->frame_table[total_frames].pts = i;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
218 total_frames++;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
219 break;
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
220 }
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
221 current_offset += size;
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
222 }
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
223 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
224
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
225 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
226
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
227 vmd->current_frame = 0;
1004
409b399440a3 More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents: 896
diff changeset
228 vmd->frame_count = total_frames;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
229
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
230 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
231 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
232
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
233 static int vmd_read_packet(AVFormatContext *s,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
234 AVPacket *pkt)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
235 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 2001
diff changeset
236 VmdDemuxContext *vmd = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2369
diff changeset
237 ByteIOContext *pb = s->pb;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
238 int ret = 0;
4102
dcaeec7bd85f The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents: 3973
diff changeset
239 vmd_frame *frame;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
240
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
241 if (vmd->current_frame >= vmd->frame_count)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
242 return AVERROR(EIO);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
243
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
244 frame = &vmd->frame_table[vmd->current_frame];
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
245 /* position the stream (will probably be there already) */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
246 url_fseek(pb, frame->frame_offset, SEEK_SET);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
247
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
248 if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD))
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2006
diff changeset
249 return AVERROR(ENOMEM);
775
c5077fdab490 AVPacket.pos
michael
parents: 669
diff changeset
250 pkt->pos= url_ftell(pb);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
251 memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD);
4131
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
252 if(vmd->is_indeo3)
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
253 ret = get_buffer(pb, pkt->data, frame->frame_size);
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
254 else
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
255 ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD,
e9ef9239086b Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents: 4102
diff changeset
256 frame->frame_size);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
257
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
258 if (ret != frame->frame_size) {
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
259 av_free_packet(pkt);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
260 ret = AVERROR(EIO);
387
f2760852ed18 minor VMD system update; still not perfect, but should not crash either
melanson
parents: 338
diff changeset
261 }
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
262 pkt->stream_index = frame->stream_index;
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
263 pkt->pts = frame->pts;
4507
a256f0daadac Add a context to av_log() call.
benoit
parents: 4331
diff changeset
264 av_log(s, AV_LOG_DEBUG, " dispatching %s frame with %d bytes and pts %"PRId64"\n",
1441
ad3b03b7b142 reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents: 1358
diff changeset
265 (frame->frame_record[0] == 0x02) ? "video" : "audio",
ad3b03b7b142 reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents: 1358
diff changeset
266 frame->frame_size + BYTES_PER_FRAME_RECORD,
1492
deaec052eec4 Simplify VMD demuxer (but it still does not work right)
kostya
parents: 1441
diff changeset
267 pkt->pts);
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
268
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
269 vmd->current_frame++;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
270
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
271 return ret;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
272 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
273
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
274 static int vmd_read_close(AVFormatContext *s)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
275 {
2006
2f0154760e5f Get rid of unnecessary pointer casts.
diego
parents: 2001
diff changeset
276 VmdDemuxContext *vmd = s->priv_data;
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
277
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
278 av_free(vmd->frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
279
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
280 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
281 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
282
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
283 AVInputFormat vmd_demuxer = {
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
284 "vmd",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3393
diff changeset
285 NULL_IF_CONFIG_SMALL("Sierra VMD format"),
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
286 sizeof(VmdDemuxContext),
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
287 vmd_probe,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
288 vmd_read_header,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
289 vmd_read_packet,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
290 vmd_read_close,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
291 };