Mercurial > libavformat.hg
annotate sierravmd.c @ 4194:67ab85a3611d libavformat
cosmetics
author | bcoudurier |
---|---|
date | Sun, 11 Jan 2009 10:36:19 +0000 |
parents | b432c9e98002 |
children | 7d2f3f1b68d8 |
rev | line source |
---|---|
338 | 1 /* |
2 * Sierra VMD Format Demuxer | |
3 * Copyright (c) 2004 The ffmpeg Project | |
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 | 8 * modify it under the terms of the GNU Lesser General Public |
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 | 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 | 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 | |
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 | 20 */ |
21 | |
22 /** | |
23 * @file sierravmd.c | |
24 * Sierra VMD file demuxer | |
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 | 28 */ |
29 | |
30 #include "avformat.h" | |
31 | |
32 #define VMD_HEADER_SIZE 0x0330 | |
33 #define BYTES_PER_FRAME_RECORD 16 | |
34 | |
35 typedef struct { | |
36 int stream_index; | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3908
diff
changeset
|
37 int64_t frame_offset; |
338 | 38 unsigned int frame_size; |
39 int64_t pts; | |
40 int keyframe; | |
41 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
|
42 } vmd_frame; |
338 | 43 |
44 typedef struct VmdDemuxContext { | |
45 int video_stream_index; | |
46 int audio_stream_index; | |
47 | |
48 unsigned int frame_count; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
49 unsigned int frames_per_block; |
4102
dcaeec7bd85f
The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents:
3973
diff
changeset
|
50 vmd_frame *frame_table; |
338 | 51 unsigned int current_frame; |
4131
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
52 int is_indeo3; |
338 | 53 |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
54 int sample_rate; |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
55 int64_t audio_sample_counter; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
56 int skiphdr; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
57 |
338 | 58 unsigned char vmd_header[VMD_HEADER_SIZE]; |
59 } VmdDemuxContext; | |
60 | |
61 static int vmd_probe(AVProbeData *p) | |
62 { | |
63 /* check if the first 2 bytes of the file contain the appropriate size | |
64 * of a VMD header chunk */ | |
1673 | 65 if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2) |
338 | 66 return 0; |
67 | |
68 /* only return half certainty since this check is a bit sketchy */ | |
69 return AVPROBE_SCORE_MAX / 2; | |
70 } | |
71 | |
72 static int vmd_read_header(AVFormatContext *s, | |
73 AVFormatParameters *ap) | |
74 { | |
2006 | 75 VmdDemuxContext *vmd = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2369
diff
changeset
|
76 ByteIOContext *pb = s->pb; |
3017 | 77 AVStream *st = NULL, *vst; |
338 | 78 unsigned int toc_offset; |
79 unsigned char *raw_frame_table; | |
80 int raw_frame_table_size; | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3908
diff
changeset
|
81 int64_t current_offset; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
82 int i, j; |
338 | 83 unsigned int total_frames; |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
84 int64_t pts_inc = 1; |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
85 int64_t current_video_pts = 0, current_audio_pts = 0; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
86 unsigned char chunk[BYTES_PER_FRAME_RECORD]; |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
87 int num, den; |
1528
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
88 int sound_buffers; |
338 | 89 |
90 /* fetch the main header, including the 2 header length bytes */ | |
91 url_fseek(pb, 0, SEEK_SET); | |
92 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
|
93 return AVERROR(EIO); |
338 | 94 |
4131
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
95 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
|
96 vmd->is_indeo3 = 1; |
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
97 else |
4137
b432c9e98002
Fix a typo that made VMD demuxer always assume Indeo 3 as video codec.
kostya
parents:
4131
diff
changeset
|
98 vmd->is_indeo3 = 0; |
338 | 99 /* start up the decoders */ |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
100 vst = av_new_stream(s, 0); |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
101 if (!vst) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
102 return AVERROR(ENOMEM); |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
103 av_set_pts_info(vst, 33, 1, 10); |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
104 vmd->video_stream_index = vst->index; |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
105 vst->codec->codec_type = CODEC_TYPE_VIDEO; |
4131
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
106 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
|
107 vst->codec->codec_tag = 0; /* no fourcc */ |
1673 | 108 vst->codec->width = AV_RL16(&vmd->vmd_header[12]); |
109 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
|
110 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
|
111 vst->codec->width >>= 1; |
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
112 vst->codec->height >>= 1; |
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
113 } |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
114 vst->codec->extradata_size = VMD_HEADER_SIZE; |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
115 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
|
116 memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); |
338 | 117 |
118 /* if sample rate is 0, assume no audio */ | |
1673 | 119 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
|
120 if (vmd->sample_rate) { |
338 | 121 st = av_new_stream(s, 0); |
122 if (!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
123 return AVERROR(ENOMEM); |
338 | 124 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
|
125 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
|
126 st->codec->codec_id = CODEC_ID_VMDAUDIO; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
127 st->codec->codec_tag = 0; /* no fourcc */ |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
128 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
|
129 st->codec->sample_rate = vmd->sample_rate; |
1673 | 130 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
|
131 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
|
132 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
|
133 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
|
134 } else { |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3424
diff
changeset
|
135 st->codec->bits_per_coded_sample = 8; |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
136 } |
885 | 137 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
|
138 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
|
139 |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
140 /* calculate pts */ |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
141 num = st->codec->block_align; |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
142 den = st->codec->sample_rate * st->codec->channels; |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
143 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
|
144 av_set_pts_info(vst, 33, num, den); |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
145 av_set_pts_info(st, 33, num, den); |
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
146 pts_inc = num; |
338 | 147 } |
148 | |
1673 | 149 toc_offset = AV_RL32(&vmd->vmd_header[812]); |
150 vmd->frame_count = AV_RL16(&vmd->vmd_header[6]); | |
151 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
|
152 url_fseek(pb, toc_offset, SEEK_SET); |
338 | 153 |
154 raw_frame_table = NULL; | |
155 vmd->frame_table = NULL; | |
1673 | 156 sound_buffers = AV_RL16(&vmd->vmd_header[808]); |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
157 raw_frame_table_size = vmd->frame_count * 6; |
4102
dcaeec7bd85f
The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents:
3973
diff
changeset
|
158 if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame)){ |
1079 | 159 av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n"); |
160 return -1; | |
161 } | |
3393 | 162 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
|
163 vmd->frame_table = av_malloc((vmd->frame_count * vmd->frames_per_block + sound_buffers) * sizeof(vmd_frame)); |
338 | 164 if (!raw_frame_table || !vmd->frame_table) { |
165 av_free(raw_frame_table); | |
166 av_free(vmd->frame_table); | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
167 return AVERROR(ENOMEM); |
338 | 168 } |
885 | 169 if (get_buffer(pb, raw_frame_table, raw_frame_table_size) != |
338 | 170 raw_frame_table_size) { |
171 av_free(raw_frame_table); | |
172 av_free(vmd->frame_table); | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
173 return AVERROR(EIO); |
338 | 174 } |
175 | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
176 total_frames = 0; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
177 for (i = 0; i < vmd->frame_count; i++) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
178 |
1673 | 179 current_offset = AV_RL32(&raw_frame_table[6 * i + 2]); |
338 | 180 |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
181 /* handle each entry in index block */ |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
182 for (j = 0; j < vmd->frames_per_block; j++) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
183 int type; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
184 uint32_t size; |
338 | 185 |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
186 get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD); |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
187 type = chunk[0]; |
1673 | 188 size = AV_RL32(&chunk[2]); |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
189 if(!size) |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
190 continue; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
191 switch(type) { |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
192 case 1: /* Audio Chunk */ |
3017 | 193 if (!st) break; |
1528
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
194 /* first audio chunk contains several audio buffers */ |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
195 if(current_audio_pts){ |
1529 | 196 vmd->frame_table[total_frames].frame_offset = current_offset; |
197 vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index; | |
198 vmd->frame_table[total_frames].frame_size = size; | |
199 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); | |
200 vmd->frame_table[total_frames].pts = current_audio_pts; | |
201 total_frames++; | |
202 current_audio_pts += pts_inc; | |
1528
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
203 }else{ |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
204 uint32_t flags; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
205 int k; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
206 int noff; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
207 int64_t pos; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
208 |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
209 pos = url_ftell(pb); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
210 url_fseek(pb, current_offset, SEEK_SET); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
211 flags = get_le32(pb); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
212 noff = 4; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
213 url_fseek(pb, pos, SEEK_SET); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
214 av_log(s, AV_LOG_DEBUG, "Sound mapping = %08X (%i bufs)\n", flags, sound_buffers); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
215 for(k = 0; k < sound_buffers - 1; k++){ |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
216 if(flags & 1) { /* silent block */ |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
217 vmd->frame_table[total_frames].frame_size = 0; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
218 }else{ |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
219 vmd->frame_table[total_frames].frame_size = st->codec->block_align + (st->codec->block_align & 1); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
220 } |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
221 noff += vmd->frame_table[total_frames].frame_size; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
222 vmd->frame_table[total_frames].frame_offset = current_offset + noff; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
223 vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
224 memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD); |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
225 vmd->frame_table[total_frames].pts = current_audio_pts; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
226 total_frames++; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
227 current_audio_pts += pts_inc; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
228 flags >>= 1; |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
229 } |
32d49970f01a
Divide first audio buffer chunk into atomary bufffers.
kostya
parents:
1492
diff
changeset
|
230 } |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
231 break; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
232 case 2: /* Video 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; |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
234 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
|
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 vmd->frame_table[total_frames].pts = current_video_pts; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
238 total_frames++; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
239 break; |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
240 } |
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
241 current_offset += size; |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
242 } |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
243 current_video_pts += pts_inc; |
338 | 244 } |
245 | |
246 av_free(raw_frame_table); | |
247 | |
248 vmd->current_frame = 0; | |
1004
409b399440a3
More correct demuxing and timestamp setting fot Sierra VMD
kostya
parents:
896
diff
changeset
|
249 vmd->frame_count = total_frames; |
338 | 250 |
251 return 0; | |
252 } | |
253 | |
254 static int vmd_read_packet(AVFormatContext *s, | |
255 AVPacket *pkt) | |
256 { | |
2006 | 257 VmdDemuxContext *vmd = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2369
diff
changeset
|
258 ByteIOContext *pb = s->pb; |
338 | 259 int ret = 0; |
4102
dcaeec7bd85f
The POSIX namespace shall be held sacrosanct. To that end,
melanson
parents:
3973
diff
changeset
|
260 vmd_frame *frame; |
338 | 261 |
262 if (vmd->current_frame >= vmd->frame_count) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
263 return AVERROR(EIO); |
338 | 264 |
265 frame = &vmd->frame_table[vmd->current_frame]; | |
266 /* position the stream (will probably be there already) */ | |
267 url_fseek(pb, frame->frame_offset, SEEK_SET); | |
268 | |
269 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
|
270 return AVERROR(ENOMEM); |
775 | 271 pkt->pos= url_ftell(pb); |
338 | 272 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
|
273 if(vmd->is_indeo3) |
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
274 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
|
275 else |
e9ef9239086b
Latest Coktel Vision VMDs contained Indeo 3, add demuxer support for it
kostya
parents:
4102
diff
changeset
|
276 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
|
277 frame->frame_size); |
338 | 278 |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
279 if (ret != frame->frame_size) { |
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
280 av_free_packet(pkt); |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
281 ret = AVERROR(EIO); |
387
f2760852ed18
minor VMD system update; still not perfect, but should not crash either
melanson
parents:
338
diff
changeset
|
282 } |
338 | 283 pkt->stream_index = frame->stream_index; |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
284 pkt->pts = frame->pts; |
2369 | 285 av_log(NULL, 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
|
286 (frame->frame_record[0] == 0x02) ? "video" : "audio", |
ad3b03b7b142
reindentation, patch by From: Steve Lhomme, slhomme divxcorp com
diego
parents:
1358
diff
changeset
|
287 frame->frame_size + BYTES_PER_FRAME_RECORD, |
1492
deaec052eec4
Simplify VMD demuxer (but it still does not work right)
kostya
parents:
1441
diff
changeset
|
288 pkt->pts); |
338 | 289 |
290 vmd->current_frame++; | |
291 | |
292 return ret; | |
293 } | |
294 | |
295 static int vmd_read_close(AVFormatContext *s) | |
296 { | |
2006 | 297 VmdDemuxContext *vmd = s->priv_data; |
338 | 298 |
299 av_free(vmd->frame_table); | |
300 | |
301 return 0; | |
302 } | |
303 | |
1169 | 304 AVInputFormat vmd_demuxer = { |
338 | 305 "vmd", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3393
diff
changeset
|
306 NULL_IF_CONFIG_SMALL("Sierra VMD format"), |
338 | 307 sizeof(VmdDemuxContext), |
308 vmd_probe, | |
309 vmd_read_header, | |
310 vmd_read_packet, | |
311 vmd_read_close, | |
312 }; |