9abf2433 |
/*
* Electronic Arts .cdata file Demuxer
* Copyright (c) 2007 Peter Ross
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** |
ba87f080 |
* @file |
9abf2433 |
* Electronic Arts cdata Format Demuxer |
8600106a |
* by Peter Ross (pross@xvid.org) |
9abf2433 |
*
* Technical details here:
* http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
*/
#include "avformat.h" |
c3f9ebf7 |
#include "internal.h" |
9abf2433 |
typedef struct {
unsigned int channels;
unsigned int audio_pts;
} CdataDemuxContext;
static int cdata_probe(AVProbeData *p)
{
const uint8_t *b = p->buf;
|
db62d898 |
if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14)) |
9abf2433 |
return AVPROBE_SCORE_MAX/8;
return 0;
}
|
6e9651d1 |
static int cdata_read_header(AVFormatContext *s) |
9abf2433 |
{
CdataDemuxContext *cdata = s->priv_data; |
ae628ec1 |
AVIOContext *pb = s->pb; |
9abf2433 |
unsigned int sample_rate, header;
AVStream *st; |
f27ac6d8 |
int64_t channel_layout = 0; |
9abf2433 |
|
b7effd4e |
header = avio_rb16(pb); |
9abf2433 |
switch (header) {
case 0x0400: cdata->channels = 1; break;
case 0x0404: cdata->channels = 2; break; |
f27ac6d8 |
case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break;
case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break; |
9abf2433 |
default:
av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
return -1;
};
|
b7effd4e |
sample_rate = avio_rb16(pb); |
c2a8f125 |
avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11); |
9abf2433 |
|
3b3bbdd3 |
st = avformat_new_stream(s, NULL); |
9abf2433 |
if (!st)
return AVERROR(ENOMEM); |
72415b2a |
st->codec->codec_type = AVMEDIA_TYPE_AUDIO; |
9abf2433 |
st->codec->codec_tag = 0; /* no fourcc */ |
36ef5369 |
st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; |
9abf2433 |
st->codec->channels = cdata->channels; |
f27ac6d8 |
st->codec->channel_layout = channel_layout; |
9abf2433 |
st->codec->sample_rate = sample_rate; |
c3f9ebf7 |
avpriv_set_pts_info(st, 64, 1, sample_rate); |
9abf2433 |
cdata->audio_pts = 0;
return 0;
}
static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
{
CdataDemuxContext *cdata = s->priv_data;
int packet_size = 76*cdata->channels;
|
36031c20 |
int ret = av_get_packet(s->pb, pkt, packet_size);
if (ret < 0)
return ret; |
9abf2433 |
pkt->pts = cdata->audio_pts++; |
36031c20 |
return 0; |
9abf2433 |
}
|
c6610a21 |
AVInputFormat ff_ea_cdata_demuxer = { |
dfc2c4d9 |
.name = "ea_cdata",
.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
.priv_data_size = sizeof(CdataDemuxContext),
.read_probe = cdata_probe,
.read_header = cdata_read_header,
.read_packet = cdata_read_packet, |
9abf2433 |
.extensions = "cdata",
}; |