1 /* Electronic Arts Multimedia File Demuxer
2 * Copyright (c) 2004 The FFmpeg project
3 * Copyright (c) 2006-2008 Peter Ross
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 * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
25 * by Robin Kay (komadori at gekkou.co.uk)
26 */
27
28 #include <inttypes.h>
29
35
36 #define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
37 #define SEAD_TAG MKTAG('S', 'E', 'A', 'D') /* Sxxx header */
38 #define SNDC_TAG MKTAG('S', 'N', 'D', 'C') /* Sxxx data */
39 #define SEND_TAG MKTAG('S', 'E', 'N', 'D') /* Sxxx end */
40 #define SHEN_TAG MKTAG('S', 'H', 'E', 'N') /* SxEN header */
41 #define SDEN_TAG MKTAG('S', 'D', 'E', 'N') /* SxEN data */
42 #define SEEN_TAG MKTAG('S', 'E', 'E', 'N') /* SxEN end */
43 #define ISNh_TAG MKTAG('1', 'S', 'N', 'h') /* 1SNx header */
44 #define EACS_TAG MKTAG('E', 'A', 'C', 'S')
45 #define ISNd_TAG MKTAG('1', 'S', 'N', 'd') /* 1SNx data */
46 #define ISNe_TAG MKTAG('1', 'S', 'N', 'e') /* 1SNx end */
47 #define PT00_TAG MKTAG('P', 'T', 0x0, 0x0)
48 #define GSTR_TAG MKTAG('G', 'S', 'T', 'R')
49 #define SCDl_TAG MKTAG('S', 'C', 'D', 'l')
50 #define SCEl_TAG MKTAG('S', 'C', 'E', 'l')
51 #define kVGT_TAG MKTAG('k', 'V', 'G', 'T') /* TGV I-frame */
52 #define fVGT_TAG MKTAG('f', 'V', 'G', 'T') /* TGV P-frame */
53 #define mTCD_TAG MKTAG('m', 'T', 'C', 'D') /* MDEC */
54 #define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD I-frame */
55 #define MADm_TAG MKTAG('M', 'A', 'D', 'm') /* MAD P-frame */
56 #define MADe_TAG MKTAG('M', 'A', 'D', 'e') /* MAD lqp-frame */
57 #define MPCh_TAG MKTAG('M', 'P', 'C', 'h') /* MPEG-2 */
58 #define TGQs_TAG MKTAG('T', 'G', 'Q', 's') /* TGQ I-frame (appears in .TGQ files) */
59 #define pQGT_TAG MKTAG('p', 'Q', 'G', 'T') /* TGQ I-frame (appears in .UV files) */
60 #define pIQT_TAG MKTAG('p', 'I', 'Q', 'T') /* TQI/UV2 I-frame (.UV2/.WVE) */
61 #define MVhd_TAG MKTAG('M', 'V', 'h', 'd')
62 #define MV0K_TAG MKTAG('M', 'V', '0', 'K')
63 #define MV0F_TAG MKTAG('M', 'V', '0', 'F')
64 #define AVhd_TAG MKTAG('A', 'V', 'h', 'd')
65 #define AV0K_TAG MKTAG('A', 'V', '0', 'K')
66 #define AV0F_TAG MKTAG('A', 'V', '0', 'F')
67 #define MVIh_TAG MKTAG('M', 'V', 'I', 'h') /* CMV header */
68 #define MVIf_TAG MKTAG('M', 'V', 'I', 'f') /* CMV I-frame */
69 #define AVP6_TAG MKTAG('A', 'V', 'P', '6')
70
78
81
83
85
88
93
97
99 {
102 uint32_t word;
103
105
106 word = 0;
109 word <<= 8;
111 }
112
113 return word;
114 }
115
117 {
120 int in_header = 1;
121 int compression_type = -1, revision = -1, revision2 = -1;
122
126
128 int in_subheader;
131
132 switch (byte) {
133 case 0xFD:
135 in_subheader = 1;
137 uint8_t subbyte;
139
140 switch (subbyte) {
141 case 0x80:
144 "revision (element 0x80) set to 0x%08x\n", revision);
145 break;
146 case 0x82:
149 "num_channels (element 0x82) set to 0x%08x\n",
151 break;
152 case 0x83:
155 "compression_type (element 0x83) set to 0x%08x\n",
156 compression_type);
157 break;
158 case 0x84:
161 "sample_rate (element 0x84) set to %i\n",
163 break;
164 case 0x85:
167 "num_samples (element 0x85) set to 0x%08x\n",
169 break;
170 case 0x8A:
172 "element 0x%02x set to 0x%08"PRIx32"\n",
175 in_subheader = 0;
176 break;
177 case 0xA0:
180 "revision2 (element 0xA0) set to 0x%08x\n",
181 revision2);
182 break;
183 case 0xFF:
185 "end of header block reached (within audio subheader)\n");
186 in_subheader = 0;
187 in_header = 0;
188 break;
189 default:
191 "element 0x%02x set to 0x%08"PRIx32"\n",
193 break;
194 }
195 }
196 break;
197 case 0xFF:
199 in_header = 0;
200 break;
201 case 0x1B:
204 break;
205 default:
207 "header element 0x%02x set to 0x%08"PRIx32"\n",
209 break;
210 }
211 }
212
213 switch (compression_type) {
214 case 0:
216 break;
217 case 7:
219 break;
220 case -1:
221 switch (revision) {
222 case 1:
224 break;
225 case 2:
227 break;
228 case 3:
230 break;
231 case -1:
232 break;
233 default:
235 return 0;
236 }
237 switch (revision2) {
238 case 8:
240 break;
241 case 10:
242 switch (revision) {
243 case -1:
246 default:
248 return 0;
249 }
250 break;
251 case 15:
252 case 16:
254 break;
255 case -1:
256 break;
257 default:
260 return 0;
261 }
262 break;
263 default:
265 "stream type; compression_type=%i",
266 compression_type);
267 return 0;
268 }
269
274
275 return 1;
276 }
277
279 {
282 int compression_type;
283
287 compression_type =
avio_r8(pb);
289
290 switch (compression_type) {
291 case 0:
293 case 1:
295 break;
296 case 2:
298 break;
299 }
300 break;
301 case 1:
304 break;
305 case 2:
307 break;
308 default:
310 "stream type; audio compression_type=%i",
311 compression_type);
312 }
313 }
314
316 {
319
324 }
325
327 {
332 if (!
video->time_base.num)
335 }
336
338 {
340
346 if (
video->time_base.den <= 0 ||
video->time_base.num <= 0) {
349 }
351
352 return 1;
353 }
354
356 {
357 int fps;
358
361 if (fps)
364 }
365
366 /* Process EA file header.
367 * Return 1 if the EA file is valid and successfully opened, 0 otherwise. */
369 {
370 uint32_t blockid,
size = 0;
374
377 int err = 0;
378
385
389 }
390
391 switch (blockid) {
395 return 0;
396 }
398 break;
399
405 }
else if ((blockid & 0xFF) != (
PT00_TAG & 0xFF)) {
407 }
408 ea->
platform = (blockid >> 16) & 0xFF;
410 break;
411
414 break;
415
418 break;
419
422 break;
423
426 break;
427
430 break;
431
437 break;
438
443 break;
444
449 break;
450
453 break;
454
460 }
461 break;
462 }
463
464 if (err < 0) {
466 return err;
467 }
468
470 }
471
473
474 return 1;
475 }
476
478 {
479 unsigned big_endian,
size;
480
492 break;
493 default:
494 return 0;
495 }
497 big_endian =
size > 0x000FFFFF;
498 if (big_endian)
501 return 0;
502
504 }
505
507 {
509
511 return 0;
512
513 /* initialize the video decoder stream */
515 if (!st)
520 // parsing is necessary to make FFmpeg generate correct timestamps
527 if (
video->time_base.num)
531 return 0;
532 }
533
535 {
538
541
544
548 "Unsupported number of channels: %d\n", ea->
num_channels);
549 goto no_audio;
550 }
554 goto no_audio;
555 }
558 "Invalid number of bytes per sample: %d\n", ea->
bytes);
559 goto no_audio;
560 }
561
562 /* initialize the audio decoder stream */
564 if (!st)
580 return 0;
581 }
582 no_audio:
584
587 return 0;
588 }
589
591 {
594 int partial_packet = 0;
595 int hit_end = 0;
596 unsigned int chunk_type, chunk_size;
597 int ret = 0, packet_read = 0,
key = 0, vp6a;
599
600 while ((!packet_read && !hit_end) || partial_packet) {
605 if (chunk_size < 8)
607 chunk_size -= 8;
608
609 switch (chunk_type) {
610 /* audio data */
612 /* header chunk also contains data; skip over the header portion */
613 if (chunk_size < 32)
616 chunk_size -= 32;
623 break;
626 if (chunk_size < 12)
630 chunk_size -= 12;
632 if (chunk_size < 8)
635 chunk_size -= 8;
636 }
637
638 if (partial_packet) {
641 partial_packet = 0;
642 }
643
644 if (!chunk_size)
645 continue;
646
651
661 }
664 else
666 break;
669 break;
673 break;
676 break;
677 default:
679 }
680
681 packet_read = 1;
682 break;
683
684 /* ending tag */
685 case 0:
692
698 break;
699 }
700 }
703 hit_end = 1;
704 break;
705
716 if (chunk_size > INT_MAX - 8)
718 avio_seek(pb, -8, SEEK_CUR);
// include chunk preamble
719 chunk_size += 8;
720 goto get_video_packet;
721
723 if (chunk_size < 8)
725
727 chunk_size -= 8;
728 goto get_video_packet;
729
737 get_video_packet:
738 if (!chunk_size)
739 continue;
740 if (chunk_size > INT_MAX - 3)
742
744
745 if (partial_packet) {
747 } else {
748 if (vp6a)
751 if (
ret >= 0 && vp6a)
753 }
754 packet_read = 1;
755
757 partial_packet = 0;
758 break;
759 }
760 partial_packet = vp6a || chunk_type ==
MVIh_TAG;
763 else
766 break;
767
768 default:
770 break;
771 }
772 }
773
774 if (
ret >= 0 && hit_end && !packet_read)
776
778 }
779
780 #define OFFSET(x) offsetof(EaDemuxContext, x)
781 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
785 };
786
792 };
793
802 };