2007-11-03 23:42:20 +01:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2007-11-03 23:42:20 +01:00
|
|
|
* Electronic Arts cdata Format Demuxer
|
2010-01-09 04:31:13 +01:00
|
|
|
* by Peter Ross (pross@xvid.org)
|
2007-11-03 23:42:20 +01:00
|
|
|
*
|
|
|
|
* Technical details here:
|
|
|
|
* http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2011-11-29 19:28:15 +01:00
|
|
|
#include "internal.h"
|
2007-11-03 23:42:20 +01:00
|
|
|
|
2014-09-22 09:19:33 +02:00
|
|
|
typedef struct CdataDemuxContext {
|
2007-11-03 23:42:20 +01:00
|
|
|
unsigned int channels;
|
|
|
|
unsigned int audio_pts;
|
|
|
|
} CdataDemuxContext;
|
|
|
|
|
|
|
|
static int cdata_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
const uint8_t *b = p->buf;
|
|
|
|
|
2011-04-23 14:09:10 +02:00
|
|
|
if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
|
2007-11-03 23:42:20 +01:00
|
|
|
return AVPROBE_SCORE_MAX/8;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-12 13:20:36 +01:00
|
|
|
static int cdata_read_header(AVFormatContext *s)
|
2007-11-03 23:42:20 +01:00
|
|
|
{
|
|
|
|
CdataDemuxContext *cdata = s->priv_data;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2007-11-03 23:42:20 +01:00
|
|
|
unsigned int sample_rate, header;
|
|
|
|
AVStream *st;
|
2011-04-25 03:52:15 +02:00
|
|
|
int64_t channel_layout = 0;
|
2007-11-03 23:42:20 +01:00
|
|
|
|
2011-02-21 16:43:01 +01:00
|
|
|
header = avio_rb16(pb);
|
2007-11-03 23:42:20 +01:00
|
|
|
switch (header) {
|
|
|
|
case 0x0400: cdata->channels = 1; break;
|
|
|
|
case 0x0404: cdata->channels = 2; break;
|
2011-04-25 03:52:15 +02:00
|
|
|
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;
|
2007-11-03 23:42:20 +01:00
|
|
|
default:
|
|
|
|
av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2011-02-21 16:43:01 +01:00
|
|
|
sample_rate = avio_rb16(pb);
|
2011-04-23 14:09:19 +02:00
|
|
|
avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
|
2007-11-03 23:42:20 +01:00
|
|
|
|
2011-06-18 11:43:24 +02:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2007-11-03 23:42:20 +01:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 20:42:52 +02:00
|
|
|
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
st->codecpar->codec_tag = 0; /* no fourcc */
|
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
|
|
|
|
st->codecpar->channels = cdata->channels;
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->channel_layout = channel_layout;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 20:42:52 +02:00
|
|
|
st->codecpar->sample_rate = sample_rate;
|
2011-11-29 19:28:15 +01:00
|
|
|
avpriv_set_pts_info(st, 64, 1, sample_rate);
|
2007-11-03 23:42:20 +01: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 20:09:46 +01:00
|
|
|
int ret = av_get_packet(s->pb, pkt, packet_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2007-11-03 23:42:20 +01:00
|
|
|
pkt->pts = cdata->audio_pts++;
|
2010-03-27 20:09:46 +01:00
|
|
|
return 0;
|
2007-11-03 23:42:20 +01:00
|
|
|
}
|
|
|
|
|
2011-01-25 23:03:28 +01:00
|
|
|
AVInputFormat ff_ea_cdata_demuxer = {
|
2011-07-16 22:18:12 +02: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 23:42:20 +01:00
|
|
|
.extensions = "cdata",
|
|
|
|
};
|