Mercurial > libavformat.hg
annotate sierravmd.c @ 1291:185190bdc185 libavformat
Clarified API for numbered sequences, patch by Michel Bardiaux % mbardiaux A mediaxim P be %
Original thread:
Date: Aug 30, 2006 4:54 PM
Subject: [Ffmpeg-devel] [PATCH] Clarified API for numbered sequences
author | gpoirier |
---|---|
date | Mon, 04 Sep 2006 09:57:47 +0000 |
parents | d18cc9a1fd02 |
children | 0899bfe4105c |
rev | line source |
---|---|
338 | 1 /* |
2 * Sierra VMD Format Demuxer | |
3 * Copyright (c) 2004 The ffmpeg Project | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
338 | 18 */ |
19 | |
20 /** | |
21 * @file sierravmd.c | |
22 * Sierra VMD file demuxer | |
23 * 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
|
24 * 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
|
25 * http://www.pcisys.net/~melanson/codecs/ |
338 | 26 */ |
27 | |
28 #include "avformat.h" | |
29 | |
30 #define VMD_HEADER_SIZE 0x0330 | |
31 #define BYTES_PER_FRAME_RECORD 16 | |
32 | |
33 typedef struct { | |
34 int stream_index; | |
35 offset_t frame_offset; | |
36 unsigned int frame_size; | |
37 int64_t pts; | |
38 int keyframe; | |
39 unsigned char frame_record[BYTES_PER_FRAME_RECORD]; | |
40 } vmd_frame_t; | |
41 | |
42 typedef struct VmdDemuxContext { | |
43 int video_stream_index; | |
44 int audio_stream_index; | |
45 | |
46 unsigned int audio_type; | |
47 unsigned int audio_samplerate; | |
48 unsigned int audio_bits; | |
49 unsigned int audio_channels; | |
50 | |
51 unsigned int frame_count; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
52 unsigned int frames_per_block; |
338 | 53 vmd_frame_t *frame_table; |
54 unsigned int current_frame; | |
55 | |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
56 int sample_rate; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
57 int64_t audio_sample_counter; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
58 int audio_frame_divisor; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
59 int audio_block_align; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
60 int skiphdr; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
61 |
338 | 62 unsigned char vmd_header[VMD_HEADER_SIZE]; |
63 } VmdDemuxContext; | |
64 | |
65 static int vmd_probe(AVProbeData *p) | |
66 { | |
67 if (p->buf_size < 2) | |
68 return 0; | |
69 | |
70 /* check if the first 2 bytes of the file contain the appropriate size | |
71 * of a VMD header chunk */ | |
72 if (LE_16(&p->buf[0]) != VMD_HEADER_SIZE - 2) | |
73 return 0; | |
74 | |
75 /* only return half certainty since this check is a bit sketchy */ | |
76 return AVPROBE_SCORE_MAX / 2; | |
77 } | |
78 | |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
79 /* This is a support function to determine the duration, in sample |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
80 * frames, of a particular audio chunk, taking into account silent |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
81 * encodings. */ |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
82 static int vmd_calculate_audio_duration(unsigned char *audio_chunk, |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
83 int audio_chunk_size, int block_align) |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
84 { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
85 unsigned char *p = audio_chunk + 16; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
86 unsigned char *p_end = audio_chunk + audio_chunk_size; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
87 int total_samples = 0; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
88 unsigned int sound_flags; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
89 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
90 if (audio_chunk_size < 16) |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
91 return 0; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
92 if (audio_chunk_size == block_align + 16) |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
93 return block_align; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
94 if (audio_chunk_size == block_align + 17) |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
95 return block_align; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
96 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
97 sound_flags = LE_32(p); |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
98 p += 4; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
99 while (p < p_end) { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
100 total_samples += block_align; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
101 if ((sound_flags & 0x01) == 0) |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
102 p += block_align; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
103 sound_flags >>= 1; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
104 } |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
105 av_log(NULL,0,"Got %i samples for size %i map %08X\n", total_samples, audio_chunk_size, LE_32(audio_chunk)); |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
106 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
107 return total_samples; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
108 } |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
109 |
338 | 110 static int vmd_read_header(AVFormatContext *s, |
111 AVFormatParameters *ap) | |
112 { | |
113 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; | |
114 ByteIOContext *pb = &s->pb; | |
115 AVStream *st; | |
116 unsigned int toc_offset; | |
117 unsigned char *raw_frame_table; | |
118 int raw_frame_table_size; | |
119 offset_t current_offset; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
120 int i, j; |
338 | 121 unsigned int total_frames; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
122 int64_t video_pts_inc = 0; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
123 int64_t current_video_pts = 0; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
124 unsigned char chunk[BYTES_PER_FRAME_RECORD]; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
125 int lastframe = 0; |
338 | 126 |
127 /* fetch the main header, including the 2 header length bytes */ | |
128 url_fseek(pb, 0, SEEK_SET); | |
129 if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) | |
482 | 130 return AVERROR_IO; |
338 | 131 |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
132 vmd->audio_sample_counter = 0; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
133 vmd->audio_frame_divisor = 1; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
134 vmd->audio_block_align = 1; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
135 |
338 | 136 /* start up the decoders */ |
137 st = av_new_stream(s, 0); | |
138 if (!st) | |
139 return AVERROR_NOMEM; | |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
387
diff
changeset
|
140 av_set_pts_info(st, 33, 1, 90000); |
338 | 141 vmd->video_stream_index = st->index; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
142 st->codec->codec_type = CODEC_TYPE_VIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
143 st->codec->codec_id = CODEC_ID_VMDVIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
144 st->codec->codec_tag = 0; /* no fourcc */ |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
145 st->codec->width = LE_16(&vmd->vmd_header[12]); |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
146 st->codec->height = LE_16(&vmd->vmd_header[14]); |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
147 st->codec->time_base.num = 1; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
148 st->codec->time_base.den = 10; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
149 st->codec->extradata_size = VMD_HEADER_SIZE; |
884
2ece9c9dd94c
malloc padding to avoid reading past the malloc()ed area.
henry
parents:
881
diff
changeset
|
150 st->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
151 memcpy(st->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); |
338 | 152 |
153 /* if sample rate is 0, assume no audio */ | |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
154 vmd->sample_rate = LE_16(&vmd->vmd_header[804]); |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
155 if (vmd->sample_rate) { |
338 | 156 st = av_new_stream(s, 0); |
157 if (!st) | |
158 return AVERROR_NOMEM; | |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
387
diff
changeset
|
159 av_set_pts_info(st, 33, 1, 90000); |
338 | 160 vmd->audio_stream_index = st->index; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
161 st->codec->codec_type = CODEC_TYPE_AUDIO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
162 st->codec->codec_id = CODEC_ID_VMDAUDIO; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
163 st->codec->codec_tag = 0; /* no fourcc */ |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
164 st->codec->channels = vmd->audio_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
|
165 st->codec->sample_rate = vmd->sample_rate; |
885 | 166 st->codec->block_align = vmd->audio_block_align = |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
167 LE_16(&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
|
168 if (st->codec->block_align & 0x8000) { |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
169 st->codec->bits_per_sample = 16; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
170 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
|
171 vmd->audio_block_align = -(vmd->audio_block_align - 0x10000); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
172 } else { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
173 st->codec->bits_per_sample = 8; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
174 } |
885 | 175 st->codec->bit_rate = st->codec->sample_rate * |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
176 st->codec->bits_per_sample * st->codec->channels; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
177 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
178 /* for calculating pts */ |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
179 vmd->audio_frame_divisor = st->codec->channels; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
180 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
181 video_pts_inc = 90000; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
182 video_pts_inc *= st->codec->block_align; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
815
diff
changeset
|
183 video_pts_inc /= st->codec->sample_rate; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
184 video_pts_inc /= st->codec->channels; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
185 } else { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
186 /* if no audio, assume 10 frames/second */ |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
187 video_pts_inc = 90000 / 10; |
338 | 188 } |
189 | |
190 toc_offset = LE_32(&vmd->vmd_header[812]); | |
191 vmd->frame_count = LE_16(&vmd->vmd_header[6]); | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
192 vmd->frames_per_block = LE_16(&vmd->vmd_header[18]); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
193 url_fseek(pb, toc_offset, SEEK_SET); |
338 | 194 |
195 raw_frame_table = NULL; | |
196 vmd->frame_table = NULL; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
197 raw_frame_table_size = vmd->frame_count * 6; |
338 | 198 raw_frame_table = av_malloc(raw_frame_table_size); |
1079 | 199 if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame_t)){ |
200 av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n"); | |
201 return -1; | |
202 } | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
203 vmd->frame_table = av_malloc(vmd->frame_count * vmd->frames_per_block * sizeof(vmd_frame_t)); |
338 | 204 if (!raw_frame_table || !vmd->frame_table) { |
205 av_free(raw_frame_table); | |
206 av_free(vmd->frame_table); | |
207 return AVERROR_NOMEM; | |
208 } | |
885 | 209 if (get_buffer(pb, raw_frame_table, raw_frame_table_size) != |
338 | 210 raw_frame_table_size) { |
211 av_free(raw_frame_table); | |
212 av_free(vmd->frame_table); | |
482 | 213 return AVERROR_IO; |
338 | 214 } |
215 | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
216 total_frames = 0; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
217 for (i = 0; i < vmd->frame_count; i++) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
218 |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
219 current_offset = LE_32(&raw_frame_table[6 * i + 2]); |
338 | 220 |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
221 /* handle each entry in index block */ |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
222 for (j = 0; j < vmd->frames_per_block; j++) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
223 int type; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
224 uint32_t size; |
338 | 225 |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
226 get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
227 type = chunk[0]; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
228 size = LE_32(&chunk[2]); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
229 if(!size) |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
230 continue; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
231 switch(type) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
232 case 1: /* Audio Chunk */ |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
233 vmd->frame_table[total_frames].frame_offset = current_offset; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
234 vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
235 vmd->frame_table[total_frames].frame_size = size; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
236 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
237 total_frames++; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
238 break; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
239 case 2: /* Video Chunk */ |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
240 vmd->frame_table[total_frames].frame_offset = current_offset; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
241 vmd->frame_table[total_frames].frame_size = size; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
242 vmd->frame_table[total_frames].stream_index = vmd->video_stream_index; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
243 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
244 vmd->frame_table[total_frames].pts = current_video_pts; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
245 if (lastframe) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
246 vmd->frame_table[lastframe].pts = current_video_pts - video_pts_inc; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
247 } |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
248 lastframe = total_frames; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
249 total_frames++; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
250 break; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
251 } |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
252 current_offset += size; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
253 } |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
254 current_video_pts += video_pts_inc; |
338 | 255 } |
256 | |
257 av_free(raw_frame_table); | |
258 | |
259 vmd->current_frame = 0; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
260 vmd->frame_count = total_frames; |
338 | 261 |
262 return 0; | |
263 } | |
264 | |
265 static int vmd_read_packet(AVFormatContext *s, | |
266 AVPacket *pkt) | |
267 { | |
268 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; | |
269 ByteIOContext *pb = &s->pb; | |
270 int ret = 0; | |
271 vmd_frame_t *frame; | |
272 | |
273 if (vmd->current_frame >= vmd->frame_count) | |
482 | 274 return AVERROR_IO; |
338 | 275 |
276 frame = &vmd->frame_table[vmd->current_frame]; | |
277 /* position the stream (will probably be there already) */ | |
278 url_fseek(pb, frame->frame_offset, SEEK_SET); | |
279 | |
280 if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD)) | |
281 return AVERROR_NOMEM; | |
775 | 282 pkt->pos= url_ftell(pb); |
338 | 283 memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD); |
885 | 284 ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD, |
338 | 285 frame->frame_size); |
286 | |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
287 if (ret != frame->frame_size) { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
288 av_free_packet(pkt); |
482 | 289 ret = AVERROR_IO; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
290 } |
338 | 291 pkt->stream_index = frame->stream_index; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
292 if (frame->frame_record[0] == 0x02) |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
293 pkt->pts = frame->pts; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
294 else { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
295 pkt->pts = vmd->audio_sample_counter; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
296 pkt->pts *= 90000; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
297 pkt->pts /= vmd->sample_rate; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
298 pkt->pts /= vmd->audio_channels; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
299 vmd->audio_sample_counter += vmd_calculate_audio_duration( |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
300 pkt->data, pkt->size, vmd->audio_block_align); |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
301 |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
302 } |
881 | 303 av_log(NULL, AV_LOG_INFO, " dispatching %s frame with %d bytes and pts %"PRId64" (%0.1f sec)\n", |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
304 (frame->frame_record[0] == 0x02) ? "video" : "audio", |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
305 frame->frame_size + BYTES_PER_FRAME_RECORD, |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
306 pkt->pts, (float)(pkt->pts / 90000.0)); |
338 | 307 |
308 vmd->current_frame++; | |
309 | |
310 return ret; | |
311 } | |
312 | |
313 static int vmd_read_close(AVFormatContext *s) | |
314 { | |
315 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; | |
316 | |
317 av_free(vmd->frame_table); | |
318 | |
319 return 0; | |
320 } | |
321 | |
1169 | 322 AVInputFormat vmd_demuxer = { |
338 | 323 "vmd", |
324 "Sierra VMD format", | |
325 sizeof(VmdDemuxContext), | |
326 vmd_probe, | |
327 vmd_read_header, | |
328 vmd_read_packet, | |
329 vmd_read_close, | |
330 }; |