2007-11-03 22:42:20 +00:00
|
|
|
/*
|
|
|
|
* Electronic Arts .cdata file Demuxer
|
|
|
|
* Copyright (c) 2007 Peter Ross
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2007-11-03 22:42:20 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-11-03 22:42:20 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-11-03 22:42:20 +00:00
|
|
|
* 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
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-11-03 22:42:20 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 14:45:34 +00:00
|
|
|
* @file
|
2007-11-03 22:42:20 +00:00
|
|
|
* Electronic Arts cdata Format Demuxer
|
2010-01-09 03:31:13 +00:00
|
|
|
* by Peter Ross (pross@xvid.org)
|
2007-11-03 22:42:20 +00:00
|
|
|
*
|
|
|
|
* Technical details here:
|
|
|
|
* http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2011-11-29 18:28:15 +00:00
|
|
|
#include "internal.h"
|
2007-11-03 22:42:20 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int channels;
|
|
|
|
unsigned int audio_pts;
|
|
|
|
} CdataDemuxContext;
|
|
|
|
|
|
|
|
static int cdata_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
const uint8_t *b = p->buf;
|
|
|
|
|
|
|
|
if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
|
|
|
|
return AVPROBE_SCORE_MAX/8;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-12 12:20:36 +00:00
|
|
|
static int cdata_read_header(AVFormatContext *s)
|
2007-11-03 22:42:20 +00:00
|
|
|
{
|
|
|
|
CdataDemuxContext *cdata = s->priv_data;
|
2011-02-20 10:04:12 +00:00
|
|
|
AVIOContext *pb = s->pb;
|
2007-11-03 22:42:20 +00:00
|
|
|
unsigned int sample_rate, header;
|
|
|
|
AVStream *st;
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
header = avio_rb16(pb);
|
2007-11-03 22:42:20 +00:00
|
|
|
switch (header) {
|
|
|
|
case 0x0400: cdata->channels = 1; break;
|
|
|
|
case 0x0404: cdata->channels = 2; break;
|
|
|
|
case 0x040C: cdata->channels = 4; break;
|
|
|
|
default:
|
|
|
|
av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2011-02-21 15:43:01 +00:00
|
|
|
sample_rate = avio_rb16(pb);
|
2011-03-15 08:14:38 +00:00
|
|
|
avio_skip(pb, 12);
|
2007-11-03 22:42:20 +00:00
|
|
|
|
2011-06-18 09:43:24 +00:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2007-11-03 22:42:20 +00:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
2010-03-30 23:30:55 +00:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
2007-11-03 22:42:20 +00:00
|
|
|
st->codec->codec_tag = 0; /* no fourcc */
|
2012-08-05 09:11:04 +00:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
|
2007-11-03 22:42:20 +00:00
|
|
|
st->codec->channels = cdata->channels;
|
|
|
|
st->codec->sample_rate = sample_rate;
|
2011-11-29 18:28:15 +00:00
|
|
|
avpriv_set_pts_info(st, 64, 1, sample_rate);
|
2007-11-03 22:42:20 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-03-27 19:09:46 +00:00
|
|
|
int ret = av_get_packet(s->pb, pkt, packet_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2007-11-03 22:42:20 +00:00
|
|
|
pkt->pts = cdata->audio_pts++;
|
2010-03-27 19:09:46 +00:00
|
|
|
return 0;
|
2007-11-03 22:42:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-25 22:03:28 +00:00
|
|
|
AVInputFormat ff_ea_cdata_demuxer = {
|
2011-07-16 20:18:12 +00:00
|
|
|
.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,
|
2007-11-03 22:42:20 +00:00
|
|
|
.extensions = "cdata",
|
|
|
|
};
|