Statistics
| Branch: | Revision:

ffmpeg / libavformat / electronicarts.c @ aecf157e

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