Mercurial > libavformat.hg
annotate 4xm.c @ 3805:d8a6432c76f3 libavformat
use strlen and do not write useless trailing 0 according to specs
author | bcoudurier |
---|---|
date | Sat, 30 Aug 2008 22:24:19 +0000 |
parents | 7a0230981402 |
children | 1d3d17de20ba |
rev | line source |
---|---|
137 | 1 /* |
2 * 4X Technologies .4xm File Demuxer (no muxer) | |
3 * Copyright (c) 2003 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 |
137 | 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. |
137 | 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, |
137 | 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:
885
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
137 | 20 */ |
21 | |
22 /** | |
23 * @file 4xm.c | |
24 * 4X Technologies file demuxer | |
25 * by Mike Melanson (melanson@pcisys.net) | |
26 * for more information on the .4xm file format, visit: | |
27 * http://www.pcisys.net/~melanson/codecs/ | |
28 */ | |
29 | |
30 #include "avformat.h" | |
31 | |
386
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
32 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
33 #define _4XMV_TAG MKTAG('4', 'X', 'M', 'V') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
34 #define LIST_TAG MKTAG('L', 'I', 'S', 'T') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
35 #define HEAD_TAG MKTAG('H', 'E', 'A', 'D') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
36 #define TRK__TAG MKTAG('T', 'R', 'K', '_') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
37 #define MOVI_TAG MKTAG('M', 'O', 'V', 'I') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
38 #define VTRK_TAG MKTAG('V', 'T', 'R', 'K') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
39 #define STRK_TAG MKTAG('S', 'T', 'R', 'K') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
40 #define std__TAG MKTAG('s', 't', 'd', '_') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
41 #define name_TAG MKTAG('n', 'a', 'm', 'e') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
42 #define vtrk_TAG MKTAG('v', 't', 'r', 'k') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
43 #define strk_TAG MKTAG('s', 't', 'r', 'k') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
44 #define ifrm_TAG MKTAG('i', 'f', 'r', 'm') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
45 #define pfrm_TAG MKTAG('p', 'f', 'r', 'm') |
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
46 #define cfrm_TAG MKTAG('c', 'f', 'r', 'm') |
2377
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
47 #define ifr2_TAG MKTAG('i', 'f', 'r', '2') |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
48 #define pfr2_TAG MKTAG('p', 'f', 'r', '2') |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
49 #define cfr2_TAG MKTAG('c', 'f', 'r', '2') |
386
c152849ee643
remove numerous definitions of BE_*/LE_* macros; convert FOURCC_TAG ->
melanson
parents:
317
diff
changeset
|
50 #define snd__TAG MKTAG('s', 'n', 'd', '_') |
137 | 51 |
52 #define vtrk_SIZE 0x44 | |
53 #define strk_SIZE 0x28 | |
54 | |
55 #define GET_LIST_HEADER() \ | |
143 | 56 fourcc_tag = get_le32(pb); \ |
137 | 57 size = get_le32(pb); \ |
58 if (fourcc_tag != LIST_TAG) \ | |
59 return AVERROR_INVALIDDATA; \ | |
143 | 60 fourcc_tag = get_le32(pb); |
137 | 61 |
62 typedef struct AudioTrack { | |
63 int sample_rate; | |
64 int bits; | |
65 int channels; | |
143 | 66 int stream_index; |
145 | 67 int adpcm; |
137 | 68 } AudioTrack; |
69 | |
70 typedef struct FourxmDemuxContext { | |
71 int width; | |
72 int height; | |
143 | 73 int video_stream_index; |
137 | 74 int track_count; |
75 AudioTrack *tracks; | |
76 int selected_track; | |
143 | 77 |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
78 int64_t audio_pts; |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
79 int64_t video_pts; |
317 | 80 float fps; |
137 | 81 } FourxmDemuxContext; |
82 | |
83 static int fourxm_probe(AVProbeData *p) | |
84 { | |
1673 | 85 if ((AV_RL32(&p->buf[0]) != RIFF_TAG) || |
86 (AV_RL32(&p->buf[8]) != _4XMV_TAG)) | |
137 | 87 return 0; |
88 | |
89 return AVPROBE_SCORE_MAX; | |
90 } | |
91 | |
92 static int fourxm_read_header(AVFormatContext *s, | |
143 | 93 AVFormatParameters *ap) |
137 | 94 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
95 ByteIOContext *pb = s->pb; |
137 | 96 unsigned int fourcc_tag; |
97 unsigned int size; | |
98 int header_size; | |
2006 | 99 FourxmDemuxContext *fourxm = s->priv_data; |
137 | 100 unsigned char *header; |
101 int i; | |
102 int current_track = -1; | |
103 AVStream *st; | |
104 | |
105 fourxm->track_count = 0; | |
106 fourxm->tracks = NULL; | |
107 fourxm->selected_track = 0; | |
317 | 108 fourxm->fps = 1.0; |
137 | 109 |
110 /* skip the first 3 32-bit numbers */ | |
111 url_fseek(pb, 12, SEEK_CUR); | |
112 | |
113 /* check for LIST-HEAD */ | |
114 GET_LIST_HEADER(); | |
115 header_size = size - 4; | |
116 if (fourcc_tag != HEAD_TAG) | |
117 return AVERROR_INVALIDDATA; | |
118 | |
119 /* allocate space for the header and load the whole thing */ | |
120 header = av_malloc(header_size); | |
121 if (!header) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
122 return AVERROR(ENOMEM); |
137 | 123 if (get_buffer(pb, header, header_size) != header_size) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
124 return AVERROR(EIO); |
137 | 125 |
126 /* take the lazy approach and search for any and all vtrk and strk chunks */ | |
127 for (i = 0; i < header_size - 8; i++) { | |
1673 | 128 fourcc_tag = AV_RL32(&header[i]); |
129 size = AV_RL32(&header[i + 4]); | |
137 | 130 |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
131 if (fourcc_tag == std__TAG) { |
1673 | 132 fourxm->fps = av_int2flt(AV_RL32(&header[i + 12])); |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
133 } else if (fourcc_tag == vtrk_TAG) { |
137 | 134 /* check that there is enough data */ |
135 if (size != vtrk_SIZE) { | |
136 av_free(header); | |
137 return AVERROR_INVALIDDATA; | |
138 } | |
1673 | 139 fourxm->width = AV_RL32(&header[i + 36]); |
140 fourxm->height = AV_RL32(&header[i + 40]); | |
143 | 141 |
142 /* allocate a new AVStream */ | |
143 st = av_new_stream(s, 0); | |
144 if (!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
145 return AVERROR(ENOMEM); |
740 | 146 av_set_pts_info(st, 60, 1, fourxm->fps); |
143 | 147 |
148 fourxm->video_stream_index = st->index; | |
149 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
150 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:
775
diff
changeset
|
151 st->codec->codec_id = CODEC_ID_4XM; |
2410
9b58a031620e
Change 4xm demuxer and video decoder to pass the video format version in
rtogni
parents:
2379
diff
changeset
|
152 st->codec->extradata_size = 4; |
9b58a031620e
Change 4xm demuxer and video decoder to pass the video format version in
rtogni
parents:
2379
diff
changeset
|
153 st->codec->extradata = av_malloc(4); |
9b58a031620e
Change 4xm demuxer and video decoder to pass the video format version in
rtogni
parents:
2379
diff
changeset
|
154 AV_WL32(st->codec->extradata, AV_RL32(&header[i + 16])); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
155 st->codec->width = fourxm->width; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
156 st->codec->height = fourxm->height; |
143 | 157 |
2379 | 158 i += 8 + size; |
137 | 159 } else if (fourcc_tag == strk_TAG) { |
160 /* check that there is enough data */ | |
161 if (size != strk_SIZE) { | |
162 av_free(header); | |
163 return AVERROR_INVALIDDATA; | |
164 } | |
1673 | 165 current_track = AV_RL32(&header[i + 8]); |
137 | 166 if (current_track + 1 > fourxm->track_count) { |
141 | 167 fourxm->track_count = current_track + 1; |
639 | 168 if((unsigned)fourxm->track_count >= UINT_MAX / sizeof(AudioTrack)) |
169 return -1; | |
885 | 170 fourxm->tracks = av_realloc(fourxm->tracks, |
141 | 171 fourxm->track_count * sizeof(AudioTrack)); |
137 | 172 if (!fourxm->tracks) { |
173 av_free(header); | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
174 return AVERROR(ENOMEM); |
137 | 175 } |
176 } | |
1673 | 177 fourxm->tracks[current_track].adpcm = AV_RL32(&header[i + 12]); |
178 fourxm->tracks[current_track].channels = AV_RL32(&header[i + 36]); | |
179 fourxm->tracks[current_track].sample_rate = AV_RL32(&header[i + 40]); | |
180 fourxm->tracks[current_track].bits = AV_RL32(&header[i + 44]); | |
137 | 181 i += 8 + size; |
143 | 182 |
183 /* allocate a new AVStream */ | |
184 st = av_new_stream(s, current_track); | |
185 if (!st) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2006
diff
changeset
|
186 return AVERROR(ENOMEM); |
143 | 187 |
740 | 188 av_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate); |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
386
diff
changeset
|
189 |
143 | 190 fourxm->tracks[current_track].stream_index = st->index; |
191 | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
192 st->codec->codec_type = CODEC_TYPE_AUDIO; |
1450
1580c48ba4b9
Do not set audio codec_tag to 1, that would be PCM audio.
diego
parents:
1358
diff
changeset
|
193 st->codec->codec_tag = 0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
194 st->codec->channels = fourxm->tracks[current_track].channels; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
195 st->codec->sample_rate = fourxm->tracks[current_track].sample_rate; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
196 st->codec->bits_per_sample = fourxm->tracks[current_track].bits; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
197 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
198 st->codec->bits_per_sample; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
199 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample; |
145 | 200 if (fourxm->tracks[current_track].adpcm) |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
201 st->codec->codec_id = CODEC_ID_ADPCM_4XM; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
202 else if (st->codec->bits_per_sample == 8) |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
203 st->codec->codec_id = CODEC_ID_PCM_U8; |
143 | 204 else |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
205 st->codec->codec_id = CODEC_ID_PCM_S16LE; |
137 | 206 } |
207 } | |
208 | |
209 av_free(header); | |
210 | |
211 /* skip over the LIST-MOVI chunk (which is where the stream should be */ | |
212 GET_LIST_HEADER(); | |
213 if (fourcc_tag != MOVI_TAG) | |
214 return AVERROR_INVALIDDATA; | |
215 | |
143 | 216 /* initialize context members */ |
740 | 217 fourxm->video_pts = -1; /* first frame will push to 0 */ |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
218 fourxm->audio_pts = 0; |
137 | 219 |
220 return 0; | |
221 } | |
222 | |
223 static int fourxm_read_packet(AVFormatContext *s, | |
143 | 224 AVPacket *pkt) |
137 | 225 { |
226 FourxmDemuxContext *fourxm = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
227 ByteIOContext *pb = s->pb; |
137 | 228 unsigned int fourcc_tag; |
145 | 229 unsigned int size, out_size; |
137 | 230 int ret = 0; |
231 int track_number; | |
232 int packet_read = 0; | |
143 | 233 unsigned char header[8]; |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
234 int audio_frame_count; |
137 | 235 |
236 while (!packet_read) { | |
237 | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
238 if ((ret = get_buffer(s->pb, header, 8)) < 0) |
143 | 239 return ret; |
1673 | 240 fourcc_tag = AV_RL32(&header[0]); |
241 size = AV_RL32(&header[4]); | |
137 | 242 if (url_feof(pb)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
243 return AVERROR(EIO); |
137 | 244 switch (fourcc_tag) { |
245 | |
144 | 246 case LIST_TAG: |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
247 /* this is a good time to bump the video pts */ |
740 | 248 fourxm->video_pts ++; |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
249 |
144 | 250 /* skip the LIST-* tag and move on to the next fourcc */ |
251 get_le32(pb); | |
252 break; | |
253 | |
137 | 254 case ifrm_TAG: |
255 case pfrm_TAG: | |
2377
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
256 case cfrm_TAG: |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
257 case ifr2_TAG: |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
258 case pfr2_TAG: |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
259 case cfr2_TAG: |
2a44e9c75bf3
pass *fr2 chunks to decoder (Toy-Story2_better-image-quality.4xa contains them)
michael
parents:
2274
diff
changeset
|
260 { |
143 | 261 |
262 /* allocate 8 more bytes than 'size' to account for fourcc | |
263 * and size */ | |
643 | 264 if (size + 8 < size || av_new_packet(pkt, size + 8)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
265 return AVERROR(EIO); |
143 | 266 pkt->stream_index = fourxm->video_stream_index; |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
267 pkt->pts = fourxm->video_pts; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
268 pkt->pos = url_ftell(s->pb); |
143 | 269 memcpy(pkt->data, header, 8); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
270 ret = get_buffer(s->pb, &pkt->data[8], size); |
143 | 271 |
272 if (ret < 0) | |
273 av_free_packet(pkt); | |
274 else | |
275 packet_read = 1; | |
139 | 276 break; |
277 } | |
143 | 278 |
137 | 279 case snd__TAG: |
280 track_number = get_le32(pb); | |
145 | 281 out_size= get_le32(pb); |
282 size-=8; | |
283 | |
137 | 284 if (track_number == fourxm->selected_track) { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2410
diff
changeset
|
285 ret= av_get_packet(s->pb, pkt, size); |
775 | 286 if(ret<0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
287 return AVERROR(EIO); |
885 | 288 pkt->stream_index = |
143 | 289 fourxm->tracks[fourxm->selected_track].stream_index; |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
290 pkt->pts = fourxm->audio_pts; |
775 | 291 packet_read = 1; |
143 | 292 |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
293 /* pts accounting */ |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
294 audio_frame_count = size; |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
295 if (fourxm->tracks[fourxm->selected_track].adpcm) |
885 | 296 audio_frame_count -= |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
297 2 * (fourxm->tracks[fourxm->selected_track].channels); |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
298 audio_frame_count /= |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
299 fourxm->tracks[fourxm->selected_track].channels; |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
300 if (fourxm->tracks[fourxm->selected_track].adpcm) |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
301 audio_frame_count *= 2; |
885 | 302 else |
316
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
303 audio_frame_count /= |
9aa23c6d396e
use the proper file framerate (specified by a float); account the pts
melanson
parents:
254
diff
changeset
|
304 (fourxm->tracks[fourxm->selected_track].bits / 8); |
740 | 305 fourxm->audio_pts += audio_frame_count; |
143 | 306 |
137 | 307 } else { |
308 url_fseek(pb, size, SEEK_CUR); | |
309 } | |
310 break; | |
311 | |
312 default: | |
313 url_fseek(pb, size, SEEK_CUR); | |
314 break; | |
315 } | |
316 } | |
317 return ret; | |
318 } | |
319 | |
320 static int fourxm_read_close(AVFormatContext *s) | |
321 { | |
2006 | 322 FourxmDemuxContext *fourxm = s->priv_data; |
137 | 323 |
324 av_free(fourxm->tracks); | |
325 | |
326 return 0; | |
327 } | |
328 | |
1169 | 329 AVInputFormat fourxm_demuxer = { |
137 | 330 "4xm", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
2771
diff
changeset
|
331 NULL_IF_CONFIG_SMALL("4X Technologies format"), |
137 | 332 sizeof(FourxmDemuxContext), |
333 fourxm_probe, | |
334 fourxm_read_header, | |
335 fourxm_read_packet, | |
336 fourxm_read_close, | |
337 }; |