Mercurial > libavformat.hg
annotate electronicarts.c @ 2769:bbdec194cf36 libavformat
Convert perror() in av_log() in bktr.c.
Currently untested; someone with the correct OS and hardware should
test it and report if it works.
author | lucabe |
---|---|
date | Mon, 19 Nov 2007 10:33:05 +0000 |
parents | 4cfddd2c98a5 |
children | d52c718e83f9 |
rev | line source |
---|---|
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
1 /* Electronic Arts Multimedia File Demuxer |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
2 * Copyright (c) 2004 The ffmpeg Project |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
3 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
4 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
8 * 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
|
9 * version 2.1 of the License, or (at your option) any later version. |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
10 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
14 * Lesser General Public License for more details. |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
15 * |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
16 * 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
|
17 * 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
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
19 */ |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
20 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
21 /** |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
22 * @file electronicarts.c |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
23 * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.) |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
24 * by Robin Kay (komadori at gekkou.co.uk) |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
25 */ |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
26 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
27 #include "avformat.h" |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
28 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
29 #define SCHl_TAG MKTAG('S', 'C', 'H', 'l') |
2685 | 30 #define SEAD_TAG MKTAG('S', 'E', 'A', 'D') /* Sxxx header */ |
31 #define SNDC_TAG MKTAG('S', 'N', 'D', 'C') /* Sxxx data */ | |
32 #define SEND_TAG MKTAG('S', 'E', 'N', 'D') /* Sxxx end */ | |
2674 | 33 #define ISNh_TAG MKTAG('1', 'S', 'N', 'h') /* 1SNx header */ |
2673 | 34 #define EACS_TAG MKTAG('E', 'A', 'C', 'S') |
2674 | 35 #define ISNd_TAG MKTAG('1', 'S', 'N', 'd') /* 1SNx data */ |
36 #define ISNe_TAG MKTAG('1', 'S', 'N', 'e') /* 1SNx end */ | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
37 #define PT00_TAG MKTAG('P', 'T', 0x0, 0x0) |
2613 | 38 #define GSTR_TAG MKTAG('G', 'S', 'T', 'R') |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
39 #define SCDl_TAG MKTAG('S', 'C', 'D', 'l') |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
40 #define SCEl_TAG MKTAG('S', 'C', 'E', 'l') |
2717 | 41 #define kVGT_TAG MKTAG('k', 'V', 'G', 'T') /* TGV i-frame */ |
42 #define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD i-frame */ | |
43 #define MPCh_TAG MKTAG('M', 'P', 'C', 'h') /* MPEG2 */ | |
2613 | 44 #define MVhd_TAG MKTAG('M', 'V', 'h', 'd') |
45 #define MV0K_TAG MKTAG('M', 'V', '0', 'K') | |
46 #define MV0F_TAG MKTAG('M', 'V', '0', 'F') | |
2717 | 47 #define MVIh_TAG MKTAG('M', 'V', 'I', 'h') /* CMV header */ |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
48 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
49 typedef struct EaDemuxContext { |
2635 | 50 int big_endian; |
51 | |
2631 | 52 int video_codec; |
2613 | 53 AVRational time_base; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
54 int video_stream_index; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
55 |
2631 | 56 int audio_codec; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
57 int audio_stream_index; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
58 int audio_frame_counter; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
59 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
60 int64_t audio_pts; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
61 |
2642 | 62 int bytes; |
2639 | 63 int sample_rate; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
64 int num_channels; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
65 int num_samples; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
66 } EaDemuxContext; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
67 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
68 static uint32_t read_arbitary(ByteIOContext *pb) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
69 uint8_t size, byte; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
70 int i; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
71 uint32_t word; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
72 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
73 size = get_byte(pb); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
74 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
75 word = 0; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
76 for (i = 0; i < size; i++) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
77 byte = get_byte(pb); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
78 word <<= 8; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
79 word |= byte; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
80 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
81 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
82 return word; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
83 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
84 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
85 /* |
2626 | 86 * Process PT/GSTR sound header |
87 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
88 */ |
2626 | 89 static int process_audio_header_elements(AVFormatContext *s) |
90 { | |
2611 | 91 int inHeader = 1; |
2006 | 92 EaDemuxContext *ea = s->priv_data; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
93 ByteIOContext *pb = &s->pb; |
2639 | 94 int compression_type = -1, revision = -1; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
95 |
2642 | 96 ea->bytes = 2; |
2639 | 97 ea->sample_rate = -1; |
2627 | 98 ea->num_channels = 1; |
99 | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
100 while (inHeader) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
101 int inSubheader; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
102 uint8_t byte; |
2612 | 103 byte = get_byte(pb); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
104 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
105 switch (byte) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
106 case 0xFD: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
107 av_log (s, AV_LOG_INFO, "entered audio subheader\n"); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
108 inSubheader = 1; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
109 while (inSubheader) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
110 uint8_t subbyte; |
2612 | 111 subbyte = get_byte(pb); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
112 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
113 switch (subbyte) { |
2639 | 114 case 0x80: |
115 revision = read_arbitary(pb); | |
116 av_log (s, AV_LOG_INFO, "revision (element 0x80) set to 0x%08x\n", revision); | |
117 break; | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
118 case 0x82: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
119 ea->num_channels = read_arbitary(pb); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
120 av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
121 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
122 case 0x83: |
2636
3b95556c8cd4
make compression_type a function local var instead of a context var
aurel
parents:
2635
diff
changeset
|
123 compression_type = read_arbitary(pb); |
3b95556c8cd4
make compression_type a function local var instead of a context var
aurel
parents:
2635
diff
changeset
|
124 av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", compression_type); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
125 break; |
2639 | 126 case 0x84: |
127 ea->sample_rate = read_arbitary(pb); | |
128 av_log (s, AV_LOG_INFO, "sample_rate (element 0x84) set to %i\n", ea->sample_rate); | |
129 break; | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
130 case 0x85: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
131 ea->num_samples = read_arbitary(pb); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
132 av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
133 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
134 case 0x8A: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
135 av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb)); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
136 av_log (s, AV_LOG_INFO, "exited audio subheader\n"); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
137 inSubheader = 0; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
138 break; |
2613 | 139 case 0xFF: |
2625 | 140 av_log (s, AV_LOG_INFO, "end of header block reached (within audio subheader)\n"); |
2613 | 141 inSubheader = 0; |
142 inHeader = 0; | |
143 break; | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
144 default: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
145 av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb)); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
146 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
147 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
148 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
149 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
150 case 0xFF: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
151 av_log (s, AV_LOG_INFO, "end of header block reached\n"); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
152 inHeader = 0; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
153 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
154 default: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
155 av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb)); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
156 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
157 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
158 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
159 |
2637 | 160 switch (compression_type) { |
2638 | 161 case 0: ea->audio_codec = CODEC_ID_PCM_S16LE; break; |
2637 | 162 case 7: ea->audio_codec = CODEC_ID_ADPCM_EA; break; |
2670 | 163 case -1: |
164 switch (revision) { | |
165 case 1: ea->audio_codec = CODEC_ID_ADPCM_EA_R1; break; | |
166 case 2: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break; | |
167 case 3: ea->audio_codec = CODEC_ID_ADPCM_EA_R3; break; | |
168 default: | |
169 av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision); | |
170 return 0; | |
171 } | |
172 break; | |
2637 | 173 default: |
174 av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type); | |
175 return 0; | |
176 } | |
2631 | 177 |
2639 | 178 if (ea->sample_rate == -1) |
179 ea->sample_rate = revision==3 ? 48000 : 22050; | |
180 | |
2626 | 181 return 1; |
182 } | |
183 | |
2673 | 184 /* |
185 * Process EACS sound header | |
186 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx | |
187 */ | |
188 static int process_audio_header_eacs(AVFormatContext *s) | |
189 { | |
190 EaDemuxContext *ea = s->priv_data; | |
191 ByteIOContext *pb = &s->pb; | |
192 int compression_type; | |
193 | |
194 ea->sample_rate = ea->big_endian ? get_be32(pb) : get_le32(pb); | |
195 ea->bytes = get_byte(pb); /* 1=8-bit, 2=16-bit */ | |
196 ea->num_channels = get_byte(pb); | |
197 compression_type = get_byte(pb); | |
198 url_fskip(pb, 13); | |
199 | |
200 switch (compression_type) { | |
201 case 0: | |
202 switch (ea->bytes) { | |
203 case 1: ea->audio_codec = CODEC_ID_PCM_S8; break; | |
204 case 2: ea->audio_codec = CODEC_ID_PCM_S16LE; break; | |
205 } | |
206 break; | |
207 case 1: ea->audio_codec = CODEC_ID_PCM_MULAW; ea->bytes = 1; break; | |
2686 | 208 case 2: ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_EACS; break; |
2673 | 209 default: |
210 av_log (s, AV_LOG_ERROR, "unsupported stream type; audio compression_type=%i\n", compression_type); | |
211 } | |
212 | |
213 return 1; | |
214 } | |
215 | |
2685 | 216 /* |
217 * Process SEAD sound header | |
218 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx | |
219 */ | |
220 static int process_audio_header_sead(AVFormatContext *s) | |
221 { | |
222 EaDemuxContext *ea = s->priv_data; | |
223 ByteIOContext *pb = &s->pb; | |
224 | |
225 ea->sample_rate = get_le32(pb); | |
226 ea->bytes = get_le32(pb); /* 1=8-bit, 2=16-bit */ | |
227 ea->num_channels = get_le32(pb); | |
228 ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_SEAD; | |
229 | |
230 return 1; | |
231 } | |
232 | |
2629 | 233 static int process_video_header_vp6(AVFormatContext *s) |
234 { | |
235 EaDemuxContext *ea = s->priv_data; | |
236 ByteIOContext *pb = &s->pb; | |
237 | |
238 url_fskip(pb, 16); | |
239 ea->time_base.den = get_le32(pb); | |
240 ea->time_base.num = get_le32(pb); | |
2631 | 241 ea->video_codec = CODEC_ID_VP6; |
2629 | 242 |
243 return 1; | |
244 } | |
245 | |
2626 | 246 /* |
247 * Process EA file header | |
248 * Returns 1 if the EA file is valid and successfully opened, 0 otherwise | |
249 */ | |
250 static int process_ea_header(AVFormatContext *s) { | |
251 uint32_t blockid, size = 0; | |
252 EaDemuxContext *ea = s->priv_data; | |
253 ByteIOContext *pb = &s->pb; | |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
254 int i; |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
255 |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
256 for (i=0; i<5 && (!ea->audio_codec || !ea->video_codec); i++) { |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
257 unsigned int startpos = url_ftell(pb); |
2634 | 258 int err = 0; |
2626 | 259 |
2633 | 260 blockid = get_le32(pb); |
2626 | 261 size = get_le32(pb); |
2635 | 262 if (i == 0) |
263 ea->big_endian = size > 0x000FFFFF; | |
264 if (ea->big_endian) | |
265 size = bswap_32(size); | |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
266 |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
267 switch (blockid) { |
2674 | 268 case ISNh_TAG: |
2673 | 269 if (get_le32(pb) != EACS_TAG) { |
270 av_log (s, AV_LOG_ERROR, "unknown 1SNh headerid\n"); | |
271 return 0; | |
272 } | |
273 err = process_audio_header_eacs(s); | |
274 break; | |
275 | |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
276 case SCHl_TAG : |
2633 | 277 blockid = get_le32(pb); |
278 if (blockid == GSTR_TAG) { | |
279 url_fskip(pb, 4); | |
280 } else if (blockid != PT00_TAG) { | |
281 av_log (s, AV_LOG_ERROR, "unknown SCHl headerid\n"); | |
282 return 0; | |
283 } | |
2634 | 284 err = process_audio_header_elements(s); |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
285 break; |
2626 | 286 |
2685 | 287 case SEAD_TAG: |
288 err = process_audio_header_sead(s); | |
289 break; | |
290 | |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
291 case MVhd_TAG : |
2634 | 292 err = process_video_header_vp6(s); |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
293 break; |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
294 } |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
295 |
2634 | 296 if (err < 0) { |
297 av_log(s, AV_LOG_ERROR, "error parsing header: %i\n", err); | |
298 return err; | |
299 } | |
300 | |
2632
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
301 url_fseek(pb, startpos + size, SEEK_SET); |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
302 } |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
303 |
c5118e086450
parse header chunk in a loop (don't depend on a fixed chunk ordering)
aurel
parents:
2631
diff
changeset
|
304 url_fseek(pb, 0, SEEK_SET); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
305 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
306 return 1; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
307 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
308 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
309 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
310 static int ea_probe(AVProbeData *p) |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
311 { |
2661
bed166d88f63
convert a if() into a switch() to ease addition of new tags to probe
aurel
parents:
2647
diff
changeset
|
312 switch (AV_RL32(&p->buf[0])) { |
2675 | 313 case ISNh_TAG: |
2661
bed166d88f63
convert a if() into a switch() to ease addition of new tags to probe
aurel
parents:
2647
diff
changeset
|
314 case SCHl_TAG: |
2685 | 315 case SEAD_TAG: |
2717 | 316 case kVGT_TAG: |
317 case MADk_TAG: | |
318 case MPCh_TAG: | |
2661
bed166d88f63
convert a if() into a switch() to ease addition of new tags to probe
aurel
parents:
2647
diff
changeset
|
319 case MVhd_TAG: |
2717 | 320 case MVIh_TAG: |
2613 | 321 return AVPROBE_SCORE_MAX; |
2661
bed166d88f63
convert a if() into a switch() to ease addition of new tags to probe
aurel
parents:
2647
diff
changeset
|
322 } |
2613 | 323 return 0; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
324 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
325 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
326 static int ea_read_header(AVFormatContext *s, |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
327 AVFormatParameters *ap) |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
328 { |
2006 | 329 EaDemuxContext *ea = s->priv_data; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
330 AVStream *st; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
331 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
332 if (!process_ea_header(s)) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
333 return AVERROR(EIO); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
334 |
2647 | 335 if (ea->video_codec) { |
2614 | 336 /* initialize the video decoder stream */ |
337 st = av_new_stream(s, 0); | |
338 if (!st) | |
339 return AVERROR(ENOMEM); | |
340 ea->video_stream_index = st->index; | |
341 st->codec->codec_type = CODEC_TYPE_VIDEO; | |
2631 | 342 st->codec->codec_id = ea->video_codec; |
2614 | 343 st->codec->codec_tag = 0; /* no fourcc */ |
344 st->codec->time_base = ea->time_base; | |
2613 | 345 } |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
346 |
2644
ad769d06b84c
check if we found an audio track before initializing the audio stream
aurel
parents:
2643
diff
changeset
|
347 if (ea->audio_codec) { |
2645 | 348 /* initialize the audio decoder stream */ |
349 st = av_new_stream(s, 0); | |
350 if (!st) | |
351 return AVERROR(ENOMEM); | |
352 av_set_pts_info(st, 33, 1, ea->sample_rate); | |
353 st->codec->codec_type = CODEC_TYPE_AUDIO; | |
354 st->codec->codec_id = ea->audio_codec; | |
355 st->codec->codec_tag = 0; /* no tag */ | |
356 st->codec->channels = ea->num_channels; | |
357 st->codec->sample_rate = ea->sample_rate; | |
358 st->codec->bits_per_sample = ea->bytes * 8; | |
359 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * | |
360 st->codec->bits_per_sample / 4; | |
361 st->codec->block_align = st->codec->channels*st->codec->bits_per_sample; | |
362 ea->audio_stream_index = st->index; | |
363 ea->audio_frame_counter = 0; | |
2644
ad769d06b84c
check if we found an audio track before initializing the audio stream
aurel
parents:
2643
diff
changeset
|
364 } |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
365 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
366 return 1; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
367 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
368 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
369 static int ea_read_packet(AVFormatContext *s, |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
370 AVPacket *pkt) |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
371 { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
372 EaDemuxContext *ea = s->priv_data; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
373 ByteIOContext *pb = &s->pb; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
374 int ret = 0; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
375 int packet_read = 0; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
376 unsigned int chunk_type, chunk_size; |
2613 | 377 int key = 0; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
378 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
379 while (!packet_read) { |
2640 | 380 chunk_type = get_le32(pb); |
2641 | 381 chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
382 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
383 switch (chunk_type) { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
384 /* audio data */ |
2674 | 385 case ISNh_TAG: |
2673 | 386 /* header chunk also contains data; skip over the header portion*/ |
387 url_fskip(pb, 32); | |
388 chunk_size -= 32; | |
2674 | 389 case ISNd_TAG: |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
390 case SCDl_TAG: |
2685 | 391 case SNDC_TAG: |
2646 | 392 if (!ea->audio_codec) { |
393 url_fskip(pb, chunk_size); | |
394 break; | |
395 } | |
775 | 396 ret = av_get_packet(pb, pkt, chunk_size); |
397 if (ret != chunk_size) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
398 ret = AVERROR(EIO); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
399 else { |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
400 pkt->stream_index = ea->audio_stream_index; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
401 pkt->pts = 90000; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
402 pkt->pts *= ea->audio_frame_counter; |
2639 | 403 pkt->pts /= ea->sample_rate; |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
404 |
2643 | 405 switch (ea->audio_codec) { |
406 case CODEC_ID_ADPCM_EA: | |
885 | 407 /* 2 samples/byte, 1 or 2 samples per frame depending |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
408 * on stereo; chunk also has 12-byte header */ |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
409 ea->audio_frame_counter += ((chunk_size - 12) * 2) / |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
410 ea->num_channels; |
2643 | 411 break; |
412 default: | |
413 ea->audio_frame_counter += chunk_size / | |
414 (ea->bytes * ea->num_channels); | |
415 } | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
416 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
417 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
418 packet_read = 1; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
419 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
420 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
421 /* ending tag */ |
2671
7f320fb9f1c9
avoid infinite loop at the end of files which are not properly terminated
aurel
parents:
2670
diff
changeset
|
422 case 0: |
2674 | 423 case ISNe_TAG: |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
424 case SCEl_TAG: |
2685 | 425 case SEND_TAG: |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
426 ret = AVERROR(EIO); |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
427 packet_read = 1; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
428 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
429 |
2613 | 430 case MV0K_TAG: |
431 key = PKT_FLAG_KEY; | |
432 case MV0F_TAG: | |
433 ret = av_get_packet(pb, pkt, chunk_size); | |
434 if (ret != chunk_size) | |
435 ret = AVERROR_IO; | |
436 else { | |
437 pkt->stream_index = ea->video_stream_index; | |
438 pkt->flags |= key; | |
439 } | |
440 packet_read = 1; | |
441 break; | |
442 | |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
443 default: |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
444 url_fseek(pb, chunk_size, SEEK_CUR); |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
445 break; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
446 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
447 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
448 |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
449 return ret; |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
450 } |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
451 |
1169 | 452 AVInputFormat ea_demuxer = { |
565
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
453 "ea", |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
454 "Electronic Arts Multimedia Format", |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
455 sizeof(EaDemuxContext), |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
456 ea_probe, |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
457 ea_read_header, |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
458 ea_read_packet, |
485a529adaee
Electronic Arts Game Multimedia format demuxer (WVE/UV2/etc.)
melanson
parents:
diff
changeset
|
459 }; |