1 /*
2 * 4X Technologies .4xm File Demuxer (no muxer)
3 * Copyright (c) 2003 The FFmpeg Project
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * 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
34
35 #define RIFF_TAG MKTAG('R', 'I', 'F', 'F')
36 #define FOURXMV_TAG MKTAG('4', 'X', 'M', 'V')
37 #define LIST_TAG MKTAG('L', 'I', 'S', 'T')
38 #define HEAD_TAG MKTAG('H', 'E', 'A', 'D')
39 #define TRK__TAG MKTAG('T', 'R', 'K', '_')
40 #define MOVI_TAG MKTAG('M', 'O', 'V', 'I')
41 #define VTRK_TAG MKTAG('V', 'T', 'R', 'K')
42 #define STRK_TAG MKTAG('S', 'T', 'R', 'K')
43 #define std__TAG MKTAG('s', 't', 'd', '_')
44 #define name_TAG MKTAG('n', 'a', 'm', 'e')
45 #define vtrk_TAG MKTAG('v', 't', 'r', 'k')
46 #define strk_TAG MKTAG('s', 't', 'r', 'k')
47 #define ifrm_TAG MKTAG('i', 'f', 'r', 'm')
48 #define pfrm_TAG MKTAG('p', 'f', 'r', 'm')
49 #define cfrm_TAG MKTAG('c', 'f', 'r', 'm')
50 #define ifr2_TAG MKTAG('i', 'f', 'r', '2')
51 #define pfr2_TAG MKTAG('p', 'f', 'r', '2')
52 #define cfr2_TAG MKTAG('c', 'f', 'r', '2')
53 #define snd__TAG MKTAG('s', 'n', 'd', '_')
54
55 #define vtrk_SIZE 0x44
56 #define strk_SIZE 0x28
57
58 #define GET_LIST_HEADER() \
59 fourcc_tag = avio_rl32(pb); \
60 size = avio_rl32(pb); \
61 if (fourcc_tag != LIST_TAG) \
62 return AVERROR_INVALIDDATA; \
63 fourcc_tag = avio_rl32(pb);
64
73
78
82
84 {
87 return 0;
88
90 }
91
94 int left)
95 {
97 /* check that there is enough data */
98 if (size !=
vtrk_SIZE || left < size + 8) {
100 }
101
102 /* allocate a new AVStream */
104 if (!st)
106
108
110
113
121
122 return 0;
123 }
124
125
128 int left)
129 {
131 int track;
132 /* check that there is enough data */
133 if (size !=
strk_SIZE || left < size + 8)
135
137 if ((
unsigned)track >= UINT_MAX /
sizeof(
AudioTrack) - 1) {
140 }
141
148 }
154
160 }
164 }
165
166 /* allocate a new AVStream */
168 if (!st)
170
173
175
186
191 } else
193
194 return 0;
195 }
196
198 {
200 unsigned int fourcc_tag;
202 int header_size;
206
210
211 /* skip the first 3 32-bit numbers */
213
214 /* check for LIST-HEAD */
216 header_size = size - 4;
217 if (fourcc_tag !=
HEAD_TAG || header_size < 0)
219
220 /* allocate space for the header and load the whole thing */
222 if (!header)
224 if (
avio_read(pb, header, header_size) != header_size) {
227 }
228
229 /* take the lazy approach and search for any and all vtrk and strk chunks */
230 for (i = 0; i < header_size - 8; i++) {
231 fourcc_tag =
AV_RL32(&header[i]);
232 size =
AV_RL32(&header[i + 4]);
233 if (size > header_size - i - 8 && (fourcc_tag ==
vtrk_TAG || fourcc_tag ==
strk_TAG)) {
234 av_log(s,
AV_LOG_ERROR,
"chunk larger than array %d>%d\n", size, header_size - i - 8);
236 }
237
239 if (header_size - i < 16) {
242 goto fail;
243 }
245 }
else if (fourcc_tag ==
vtrk_TAG) {
246 if ((ret =
parse_vtrk(s, fourxm, header + i, size,
247 header_size - i)) < 0)
248 goto fail;
249
251 }
else if (fourcc_tag ==
strk_TAG) {
252 if ((ret =
parse_strk(s, fourxm, header + i, size,
253 header_size - i)) < 0)
254 goto fail;
255
257 }
258 }
259
260 /* skip over the LIST-MOVI chunk (which is where the stream should be */
264 goto fail;
265 }
266
268 /* initialize context members */
269 fourxm->
video_pts = -1;
/* first frame will push to 0 */
270
271 return 0;
272 fail:
276 }
277
280 {
283 unsigned int fourcc_tag;
286 unsigned int track_number;
287 int packet_read = 0;
290
291 while (!packet_read) {
294 fourcc_tag =
AV_RL32(&header[0]);
298 switch (fourcc_tag) {
300 /* this is a good time to bump the video pts */
302
303 /* skip the LIST-* tag and move on to the next fourcc */
305 break;
306
313 /* allocate 8 more bytes than 'size' to account for fourcc
314 * and size */
320 memcpy(pkt->
data, header, 8);
322
323 if (ret < 0) {
325 } else {
326 packet_read = 1;
328 }
329 break;
330
334 size -= 8;
335
336 if (track_number < fourxm->track_count &&
339 if (ret < 0)
344 packet_read = 1;
345
346 /* pts accounting */
347 audio_frame_count =
size;
352 audio_frame_count *= 2;
353 } else
354 audio_frame_count /=
357 } else {
359 }
360 break;
361
362 default:
364 break;
365 }
366 }
368 }
369
371 {
373
375
376 return 0;
377 }
378
387 };