Statistics
| Branch: | Revision:

ffmpeg / libavformat / electronicarts.c @ 470bce2b

History | View | Annotate | Download (17 KB)

1 ad81a9fe Mike Melanson
/* Electronic Arts Multimedia File Demuxer
2
 * Copyright (c) 2004  The ffmpeg Project
3 b2f181c2 Peter Ross
 * Copyright (c) 2006-2008 Peter Ross
4 ad81a9fe Mike Melanson
 *
5 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8 ad81a9fe Mike Melanson
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
11 ad81a9fe Mike Melanson
 *
12 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
13 ad81a9fe Mike Melanson
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
19 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ad81a9fe Mike Melanson
 */
21
22
/**
23
 * @file electronicarts.c
24
 * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
25
 * by Robin Kay (komadori at gekkou.co.uk)
26
 */
27
28
#include "avformat.h"
29
30
#define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
31 7bb65d89 Peter Ross
#define SEAD_TAG MKTAG('S', 'E', 'A', 'D')    /* Sxxx header */
32
#define SNDC_TAG MKTAG('S', 'N', 'D', 'C')    /* Sxxx data */
33
#define SEND_TAG MKTAG('S', 'E', 'N', 'D')    /* Sxxx end */
34 ebc22cc2 Peter Ross
#define SHEN_TAG MKTAG('S', 'H', 'E', 'N')    /* SxEN header */
35
#define SDEN_TAG MKTAG('S', 'D', 'E', 'N')    /* SxEN data */
36
#define SEEN_TAG MKTAG('S', 'E', 'E', 'N')    /* SxEN end */
37 94e8c227 Aurelien Jacobs
#define ISNh_TAG MKTAG('1', 'S', 'N', 'h')    /* 1SNx header */
38 98168220 Aurelien Jacobs
#define EACS_TAG MKTAG('E', 'A', 'C', 'S')
39 94e8c227 Aurelien Jacobs
#define ISNd_TAG MKTAG('1', 'S', 'N', 'd')    /* 1SNx data */
40
#define ISNe_TAG MKTAG('1', 'S', 'N', 'e')    /* 1SNx end */
41 ad81a9fe Mike Melanson
#define PT00_TAG MKTAG('P', 'T', 0x0, 0x0)
42 d3e412d0 Aurelien Jacobs
#define GSTR_TAG MKTAG('G', 'S', 'T', 'R')
43 ad81a9fe Mike Melanson
#define SCDl_TAG MKTAG('S', 'C', 'D', 'l')
44
#define SCEl_TAG MKTAG('S', 'C', 'E', 'l')
45 968fc6b9 Aurelien Jacobs
#define kVGT_TAG MKTAG('k', 'V', 'G', 'T')    /* TGV i-frame */
46 bbf020e9 Peter Ross
#define fVGT_TAG MKTAG('f', 'V', 'G', 'T')    /* TGV p-frame */
47 d9d9a8c0 Peter Ross
#define mTCD_TAG MKTAG('m', 'T', 'C', 'D')    /* MDEC */
48 968fc6b9 Aurelien Jacobs
#define MADk_TAG MKTAG('M', 'A', 'D', 'k')    /* MAD i-frame */
49
#define MPCh_TAG MKTAG('M', 'P', 'C', 'h')    /* MPEG2 */
50 d2299316 Peter Ross
#define TGQs_TAG MKTAG('T', 'G', 'Q', 's')    /* TGQ i-frame (appears in .TGQ files) */
51
#define pQGT_TAG MKTAG('p', 'Q', 'G', 'T')    /* TGQ i-frame (appears in .UV files) */
52 d3e412d0 Aurelien Jacobs
#define MVhd_TAG MKTAG('M', 'V', 'h', 'd')
53
#define MV0K_TAG MKTAG('M', 'V', '0', 'K')
54
#define MV0F_TAG MKTAG('M', 'V', '0', 'F')
55 968fc6b9 Aurelien Jacobs
#define MVIh_TAG MKTAG('M', 'V', 'I', 'h')    /* CMV header */
56 b2f181c2 Peter Ross
#define MVIf_TAG MKTAG('M', 'V', 'I', 'f')    /* CMV i-frame */
57 ad81a9fe Mike Melanson
58
typedef struct EaDemuxContext {
59 97e5dcc0 Aurelien Jacobs
    int big_endian;
60
61 696c3068 Carl Eugen Hoyos
    enum CodecID video_codec;
62 d3e412d0 Aurelien Jacobs
    AVRational time_base;
63 d9d9a8c0 Peter Ross
    int width, height;
64 ad81a9fe Mike Melanson
    int video_stream_index;
65
66 696c3068 Carl Eugen Hoyos
    enum CodecID audio_codec;
67 ad81a9fe Mike Melanson
    int audio_stream_index;
68
    int audio_frame_counter;
69
70
    int64_t audio_pts;
71
72 ffbd0bcd Aurelien Jacobs
    int bytes;
73 6c867e04 Aurelien Jacobs
    int sample_rate;
74 ad81a9fe Mike Melanson
    int num_channels;
75
    int num_samples;
76
} EaDemuxContext;
77
78
static uint32_t read_arbitary(ByteIOContext *pb) {
79
    uint8_t size, byte;
80
    int i;
81
    uint32_t word;
82
83
    size = get_byte(pb);
84
85
    word = 0;
86
    for (i = 0; i < size; i++) {
87
        byte = get_byte(pb);
88
        word <<= 8;
89
        word |= byte;
90
    }
91
92
    return word;
93
}
94
95
/*
96 215eb102 Aurelien Jacobs
 * Process PT/GSTR sound header
97
 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
98 ad81a9fe Mike Melanson
 */
99 215eb102 Aurelien Jacobs
static int process_audio_header_elements(AVFormatContext *s)
100
{
101 a066c5b7 Aurelien Jacobs
    int inHeader = 1;
102 e4141433 Nicholas Tung
    EaDemuxContext *ea = s->priv_data;
103 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
104 725d86bf Aurelien Jacobs
    int compression_type = -1, revision = -1, revision2 = -1;
105 ad81a9fe Mike Melanson
106 ffbd0bcd Aurelien Jacobs
    ea->bytes = 2;
107 6c867e04 Aurelien Jacobs
    ea->sample_rate = -1;
108 9853ce80 Aurelien Jacobs
    ea->num_channels = 1;
109
110 ad81a9fe Mike Melanson
    while (inHeader) {
111
        int inSubheader;
112
        uint8_t byte;
113 c03c4cac Aurelien Jacobs
        byte = get_byte(pb);
114 ad81a9fe Mike Melanson
115
        switch (byte) {
116
        case 0xFD:
117
            av_log (s, AV_LOG_INFO, "entered audio subheader\n");
118
            inSubheader = 1;
119
            while (inSubheader) {
120
                uint8_t subbyte;
121 c03c4cac Aurelien Jacobs
                subbyte = get_byte(pb);
122 ad81a9fe Mike Melanson
123
                switch (subbyte) {
124 6c867e04 Aurelien Jacobs
                case 0x80:
125
                    revision = read_arbitary(pb);
126
                    av_log (s, AV_LOG_INFO, "revision (element 0x80) set to 0x%08x\n", revision);
127
                    break;
128 ad81a9fe Mike Melanson
                case 0x82:
129
                    ea->num_channels = read_arbitary(pb);
130
                    av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
131
                    break;
132
                case 0x83:
133 e5d34ab6 Aurelien Jacobs
                    compression_type = read_arbitary(pb);
134
                    av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", compression_type);
135 ad81a9fe Mike Melanson
                    break;
136 6c867e04 Aurelien Jacobs
                case 0x84:
137
                    ea->sample_rate = read_arbitary(pb);
138
                    av_log (s, AV_LOG_INFO, "sample_rate (element 0x84) set to %i\n", ea->sample_rate);
139
                    break;
140 ad81a9fe Mike Melanson
                case 0x85:
141
                    ea->num_samples = read_arbitary(pb);
142
                    av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
143
                    break;
144
                case 0x8A:
145
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
146
                    av_log (s, AV_LOG_INFO, "exited audio subheader\n");
147
                    inSubheader = 0;
148
                    break;
149 725d86bf Aurelien Jacobs
                case 0xA0:
150
                    revision2 = read_arbitary(pb);
151
                    av_log (s, AV_LOG_INFO, "revision2 (element 0xA0) set to 0x%08x\n", revision2);
152
                    break;
153 d3e412d0 Aurelien Jacobs
                case 0xFF:
154 d51bd73c Aurelien Jacobs
                    av_log (s, AV_LOG_INFO, "end of header block reached (within audio subheader)\n");
155 d3e412d0 Aurelien Jacobs
                    inSubheader = 0;
156
                    inHeader = 0;
157
                    break;
158 ad81a9fe Mike Melanson
                default:
159
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
160
                    break;
161
                }
162
            }
163
            break;
164
        case 0xFF:
165
            av_log (s, AV_LOG_INFO, "end of header block reached\n");
166
            inHeader = 0;
167
            break;
168
        default:
169
            av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
170
            break;
171
        }
172
    }
173
174 93fa8b2b Aurelien Jacobs
    switch (compression_type) {
175 fd402a5a Aurelien Jacobs
    case  0: ea->audio_codec = CODEC_ID_PCM_S16LE; break;
176 93fa8b2b Aurelien Jacobs
    case  7: ea->audio_codec = CODEC_ID_ADPCM_EA; break;
177 e7583962 Peter Ross
    case -1:
178
        switch (revision) {
179
        case  1: ea->audio_codec = CODEC_ID_ADPCM_EA_R1; break;
180
        case  2: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
181
        case  3: ea->audio_codec = CODEC_ID_ADPCM_EA_R3; break;
182 725d86bf Aurelien Jacobs
        case -1: break;
183 e7583962 Peter Ross
        default:
184
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision);
185
            return 0;
186
        }
187 725d86bf Aurelien Jacobs
        switch (revision2) {
188
        case  8: ea->audio_codec = CODEC_ID_PCM_S16LE_PLANAR; break;
189 6819af82 Peter Ross
        case 10: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
190 fc7ed9a6 Peter Ross
        case 16: ea->audio_codec = CODEC_ID_MP3; break;
191 af8ed96f Peter Ross
        case -1: break;
192 725d86bf Aurelien Jacobs
        default:
193
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2);
194
            return 0;
195
        }
196 e7583962 Peter Ross
        break;
197 93fa8b2b Aurelien Jacobs
    default:
198
        av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type);
199
        return 0;
200
    }
201 af704ee4 Aurelien Jacobs
202 6c867e04 Aurelien Jacobs
    if (ea->sample_rate == -1)
203
        ea->sample_rate = revision==3 ? 48000 : 22050;
204
205 215eb102 Aurelien Jacobs
    return 1;
206
}
207
208 98168220 Aurelien Jacobs
/*
209
 * Process EACS sound header
210
 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
211
 */
212
static int process_audio_header_eacs(AVFormatContext *s)
213
{
214
    EaDemuxContext *ea = s->priv_data;
215 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
216 98168220 Aurelien Jacobs
    int compression_type;
217
218
    ea->sample_rate  = ea->big_endian ? get_be32(pb) : get_le32(pb);
219
    ea->bytes        = get_byte(pb);   /* 1=8-bit, 2=16-bit */
220
    ea->num_channels = get_byte(pb);
221
    compression_type = get_byte(pb);
222
    url_fskip(pb, 13);
223
224
    switch (compression_type) {
225
    case 0:
226
        switch (ea->bytes) {
227
        case 1: ea->audio_codec = CODEC_ID_PCM_S8;    break;
228
        case 2: ea->audio_codec = CODEC_ID_PCM_S16LE; break;
229
        }
230
        break;
231
    case 1: ea->audio_codec = CODEC_ID_PCM_MULAW; ea->bytes = 1; break;
232 fac84d3c Peter Ross
    case 2: ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_EACS; break;
233 98168220 Aurelien Jacobs
    default:
234
        av_log (s, AV_LOG_ERROR, "unsupported stream type; audio compression_type=%i\n", compression_type);
235
    }
236
237
    return 1;
238
}
239
240 7bb65d89 Peter Ross
/*
241
 * Process SEAD sound header
242
 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
243
 */
244
static int process_audio_header_sead(AVFormatContext *s)
245
{
246
    EaDemuxContext *ea = s->priv_data;
247 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
248 7bb65d89 Peter Ross
249
    ea->sample_rate  = get_le32(pb);
250
    ea->bytes        = get_le32(pb);  /* 1=8-bit, 2=16-bit */
251
    ea->num_channels = get_le32(pb);
252
    ea->audio_codec  = CODEC_ID_ADPCM_IMA_EA_SEAD;
253
254
    return 1;
255
}
256
257 d9d9a8c0 Peter Ross
static int process_video_header_mdec(AVFormatContext *s)
258
{
259
    EaDemuxContext *ea = s->priv_data;
260
    ByteIOContext *pb = s->pb;
261
    url_fskip(pb, 4);
262
    ea->width  = get_le16(pb);
263
    ea->height = get_le16(pb);
264
    ea->time_base = (AVRational){1,15};
265
    ea->video_codec = CODEC_ID_MDEC;
266
    return 1;
267
}
268
269 f4097430 Aurelien Jacobs
static int process_video_header_vp6(AVFormatContext *s)
270
{
271
    EaDemuxContext *ea = s->priv_data;
272 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
273 f4097430 Aurelien Jacobs
274
    url_fskip(pb, 16);
275
    ea->time_base.den = get_le32(pb);
276
    ea->time_base.num = get_le32(pb);
277 af704ee4 Aurelien Jacobs
    ea->video_codec = CODEC_ID_VP6;
278 f4097430 Aurelien Jacobs
279
    return 1;
280
}
281
282 215eb102 Aurelien Jacobs
/*
283
 * Process EA file header
284
 * Returns 1 if the EA file is valid and successfully opened, 0 otherwise
285
 */
286
static int process_ea_header(AVFormatContext *s) {
287
    uint32_t blockid, size = 0;
288
    EaDemuxContext *ea = s->priv_data;
289 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
290 f8cab062 Aurelien Jacobs
    int i;
291
292
    for (i=0; i<5 && (!ea->audio_codec || !ea->video_codec); i++) {
293
        unsigned int startpos = url_ftell(pb);
294 2c82386d Aurelien Jacobs
        int err = 0;
295 215eb102 Aurelien Jacobs
296 fa34563b Aurelien Jacobs
        blockid = get_le32(pb);
297 215eb102 Aurelien Jacobs
        size = get_le32(pb);
298 97e5dcc0 Aurelien Jacobs
        if (i == 0)
299
            ea->big_endian = size > 0x000FFFFF;
300
        if (ea->big_endian)
301
            size = bswap_32(size);
302 f8cab062 Aurelien Jacobs
303
        switch (blockid) {
304 94e8c227 Aurelien Jacobs
            case ISNh_TAG:
305 98168220 Aurelien Jacobs
                if (get_le32(pb) != EACS_TAG) {
306
                    av_log (s, AV_LOG_ERROR, "unknown 1SNh headerid\n");
307
                    return 0;
308
                }
309
                err = process_audio_header_eacs(s);
310
                break;
311
312 f8cab062 Aurelien Jacobs
            case SCHl_TAG :
313 ebc22cc2 Peter Ross
            case SHEN_TAG :
314 fa34563b Aurelien Jacobs
                blockid = get_le32(pb);
315
                if (blockid == GSTR_TAG) {
316
                    url_fskip(pb, 4);
317 a07f1178 Peter Ross
                } else if ((blockid & 0xFFFF)!=PT00_TAG) {
318 fa34563b Aurelien Jacobs
                    av_log (s, AV_LOG_ERROR, "unknown SCHl headerid\n");
319
                    return 0;
320
                }
321 2c82386d Aurelien Jacobs
                err = process_audio_header_elements(s);
322 f8cab062 Aurelien Jacobs
                break;
323
324 7bb65d89 Peter Ross
            case SEAD_TAG:
325
                err = process_audio_header_sead(s);
326
                break;
327
328 b2f181c2 Peter Ross
            case MVIh_TAG :
329
                ea->video_codec = CODEC_ID_CMV;
330
                ea->time_base = (AVRational){0,0};
331
                break;
332
333 bbf020e9 Peter Ross
            case kVGT_TAG:
334
                ea->video_codec = CODEC_ID_TGV;
335
                ea->time_base = (AVRational){0,0};
336
                break;
337
338 d9d9a8c0 Peter Ross
            case mTCD_TAG :
339
                err = process_video_header_mdec(s);
340
                break;
341
342 d3302b70 Peter Ross
            case MPCh_TAG:
343
                ea->video_codec = CODEC_ID_MPEG2VIDEO;
344
                break;
345
346 d2299316 Peter Ross
            case pQGT_TAG:
347
            case TGQs_TAG:
348
                ea->video_codec = CODEC_ID_TGQ;
349
                break;
350
351 f8cab062 Aurelien Jacobs
            case MVhd_TAG :
352 2c82386d Aurelien Jacobs
                err = process_video_header_vp6(s);
353 f8cab062 Aurelien Jacobs
                break;
354
        }
355
356 2c82386d Aurelien Jacobs
        if (err < 0) {
357
            av_log(s, AV_LOG_ERROR, "error parsing header: %i\n", err);
358
            return err;
359
        }
360
361 f8cab062 Aurelien Jacobs
        url_fseek(pb, startpos + size, SEEK_SET);
362
    }
363 215eb102 Aurelien Jacobs
364 f8cab062 Aurelien Jacobs
    url_fseek(pb, 0, SEEK_SET);
365 ad81a9fe Mike Melanson
366
    return 1;
367
}
368
369
370
static int ea_probe(AVProbeData *p)
371
{
372 39fe9d79 Aurelien Jacobs
    switch (AV_RL32(&p->buf[0])) {
373 97e6ee20 Aurelien Jacobs
    case ISNh_TAG:
374 39fe9d79 Aurelien Jacobs
    case SCHl_TAG:
375 7bb65d89 Peter Ross
    case SEAD_TAG:
376 ebc22cc2 Peter Ross
    case SHEN_TAG:
377 968fc6b9 Aurelien Jacobs
    case kVGT_TAG:
378
    case MADk_TAG:
379
    case MPCh_TAG:
380 39fe9d79 Aurelien Jacobs
    case MVhd_TAG:
381 968fc6b9 Aurelien Jacobs
    case MVIh_TAG:
382 d3e412d0 Aurelien Jacobs
        return AVPROBE_SCORE_MAX;
383 39fe9d79 Aurelien Jacobs
    }
384 d3e412d0 Aurelien Jacobs
    return 0;
385 ad81a9fe Mike Melanson
}
386
387
static int ea_read_header(AVFormatContext *s,
388
                          AVFormatParameters *ap)
389
{
390 e4141433 Nicholas Tung
    EaDemuxContext *ea = s->priv_data;
391 ad81a9fe Mike Melanson
    AVStream *st;
392
393
    if (!process_ea_header(s))
394 6f3e0b21 Panagiotis Issaris
        return AVERROR(EIO);
395 ad81a9fe Mike Melanson
396 ab89dbd4 Aurelien Jacobs
    if (ea->video_codec) {
397 227a388d Aurelien Jacobs
        /* initialize the video decoder stream */
398
        st = av_new_stream(s, 0);
399
        if (!st)
400
            return AVERROR(ENOMEM);
401
        ea->video_stream_index = st->index;
402
        st->codec->codec_type = CODEC_TYPE_VIDEO;
403 af704ee4 Aurelien Jacobs
        st->codec->codec_id = ea->video_codec;
404 227a388d Aurelien Jacobs
        st->codec->codec_tag = 0;  /* no fourcc */
405
        st->codec->time_base = ea->time_base;
406 d9d9a8c0 Peter Ross
        st->codec->width = ea->width;
407
        st->codec->height = ea->height;
408 d3e412d0 Aurelien Jacobs
    }
409 ad81a9fe Mike Melanson
410 c611463f Aurelien Jacobs
    if (ea->audio_codec) {
411 a2c9473d Aurelien Jacobs
        /* initialize the audio decoder stream */
412
        st = av_new_stream(s, 0);
413
        if (!st)
414
            return AVERROR(ENOMEM);
415
        av_set_pts_info(st, 33, 1, ea->sample_rate);
416
        st->codec->codec_type = CODEC_TYPE_AUDIO;
417
        st->codec->codec_id = ea->audio_codec;
418
        st->codec->codec_tag = 0;  /* no tag */
419
        st->codec->channels = ea->num_channels;
420
        st->codec->sample_rate = ea->sample_rate;
421 dd1c8f3e Luca Abeni
        st->codec->bits_per_coded_sample = ea->bytes * 8;
422 a2c9473d Aurelien Jacobs
        st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
423 dd1c8f3e Luca Abeni
            st->codec->bits_per_coded_sample / 4;
424
        st->codec->block_align = st->codec->channels*st->codec->bits_per_coded_sample;
425 a2c9473d Aurelien Jacobs
        ea->audio_stream_index = st->index;
426
        ea->audio_frame_counter = 0;
427 c611463f Aurelien Jacobs
    }
428 ad81a9fe Mike Melanson
429
    return 1;
430
}
431
432
static int ea_read_packet(AVFormatContext *s,
433
                          AVPacket *pkt)
434
{
435
    EaDemuxContext *ea = s->priv_data;
436 899681cd Björn Axelsson
    ByteIOContext *pb = s->pb;
437 ad81a9fe Mike Melanson
    int ret = 0;
438
    int packet_read = 0;
439
    unsigned int chunk_type, chunk_size;
440 d3e412d0 Aurelien Jacobs
    int key = 0;
441 fc7ed9a6 Peter Ross
    int num_samples;
442 ad81a9fe Mike Melanson
443
    while (!packet_read) {
444 78168450 Aurelien Jacobs
        chunk_type = get_le32(pb);
445 597958ad Aurelien Jacobs
        chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8;
446 ad81a9fe Mike Melanson
447
        switch (chunk_type) {
448
        /* audio data */
449 94e8c227 Aurelien Jacobs
        case ISNh_TAG:
450 98168220 Aurelien Jacobs
            /* header chunk also contains data; skip over the header portion*/
451
            url_fskip(pb, 32);
452
            chunk_size -= 32;
453 94e8c227 Aurelien Jacobs
        case ISNd_TAG:
454 ad81a9fe Mike Melanson
        case SCDl_TAG:
455 7bb65d89 Peter Ross
        case SNDC_TAG:
456 ebc22cc2 Peter Ross
        case SDEN_TAG:
457 018d0ff9 Aurelien Jacobs
            if (!ea->audio_codec) {
458
                url_fskip(pb, chunk_size);
459
                break;
460 fc7ed9a6 Peter Ross
            } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||
461
                       ea->audio_codec == CODEC_ID_MP3) {
462
                num_samples = get_le32(pb);
463
                url_fskip(pb, 8);
464 725d86bf Aurelien Jacobs
                chunk_size -= 12;
465 018d0ff9 Aurelien Jacobs
            }
466 2692067a Michael Niedermayer
            ret = av_get_packet(pb, pkt, chunk_size);
467
            if (ret != chunk_size)
468 6f3e0b21 Panagiotis Issaris
                ret = AVERROR(EIO);
469 ad81a9fe Mike Melanson
            else {
470
                    pkt->stream_index = ea->audio_stream_index;
471
                    pkt->pts = 90000;
472
                    pkt->pts *= ea->audio_frame_counter;
473 6c867e04 Aurelien Jacobs
                    pkt->pts /= ea->sample_rate;
474 ad81a9fe Mike Melanson
475 200f41ad Aurelien Jacobs
                    switch (ea->audio_codec) {
476
                    case CODEC_ID_ADPCM_EA:
477 115329f1 Diego Biurrun
                    /* 2 samples/byte, 1 or 2 samples per frame depending
478 ad81a9fe Mike Melanson
                     * on stereo; chunk also has 12-byte header */
479
                    ea->audio_frame_counter += ((chunk_size - 12) * 2) /
480
                        ea->num_channels;
481 200f41ad Aurelien Jacobs
                        break;
482 fc7ed9a6 Peter Ross
                    case CODEC_ID_PCM_S16LE_PLANAR:
483
                    case CODEC_ID_MP3:
484
                        ea->audio_frame_counter += num_samples;
485
                        break;
486 200f41ad Aurelien Jacobs
                    default:
487
                        ea->audio_frame_counter += chunk_size /
488
                            (ea->bytes * ea->num_channels);
489
                    }
490 ad81a9fe Mike Melanson
            }
491
492
            packet_read = 1;
493
            break;
494
495
        /* ending tag */
496 44626387 Aurelien Jacobs
        case 0:
497 94e8c227 Aurelien Jacobs
        case ISNe_TAG:
498 ad81a9fe Mike Melanson
        case SCEl_TAG:
499 7bb65d89 Peter Ross
        case SEND_TAG:
500 ebc22cc2 Peter Ross
        case SEEN_TAG:
501 6f3e0b21 Panagiotis Issaris
            ret = AVERROR(EIO);
502 ad81a9fe Mike Melanson
            packet_read = 1;
503
            break;
504
505 b2f181c2 Peter Ross
        case MVIh_TAG:
506 bbf020e9 Peter Ross
        case kVGT_TAG:
507 d2299316 Peter Ross
        case pQGT_TAG:
508
        case TGQs_TAG:
509 b2f181c2 Peter Ross
            key = PKT_FLAG_KEY;
510
        case MVIf_TAG:
511 bbf020e9 Peter Ross
        case fVGT_TAG:
512 b2f181c2 Peter Ross
            url_fseek(pb, -8, SEEK_CUR);     // include chunk preamble
513
            chunk_size += 8;
514
            goto get_video_packet;
515
516 d9d9a8c0 Peter Ross
        case mTCD_TAG:
517
            url_fseek(pb, 8, SEEK_CUR);  // skip ea dct header
518
            chunk_size -= 8;
519
            goto get_video_packet;
520
521 d3e412d0 Aurelien Jacobs
        case MV0K_TAG:
522 d3302b70 Peter Ross
        case MPCh_TAG:
523 d3e412d0 Aurelien Jacobs
            key = PKT_FLAG_KEY;
524
        case MV0F_TAG:
525 b2f181c2 Peter Ross
get_video_packet:
526 d3e412d0 Aurelien Jacobs
            ret = av_get_packet(pb, pkt, chunk_size);
527
            if (ret != chunk_size)
528
                ret = AVERROR_IO;
529
            else {
530
                pkt->stream_index = ea->video_stream_index;
531
                pkt->flags |= key;
532
            }
533
            packet_read = 1;
534
            break;
535
536 ad81a9fe Mike Melanson
        default:
537
            url_fseek(pb, chunk_size, SEEK_CUR);
538
            break;
539
        }
540
    }
541
542
    return ret;
543
}
544
545 ff70e601 Måns Rullgård
AVInputFormat ea_demuxer = {
546 ad81a9fe Mike Melanson
    "ea",
547 bde15e74 Stefano Sabatini
    NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia Format"),
548 ad81a9fe Mike Melanson
    sizeof(EaDemuxContext),
549
    ea_probe,
550
    ea_read_header,
551
    ea_read_packet,
552
};