00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00031 #include "avformat.h"
00032
00033 typedef struct {
00034 unsigned int channels;
00035 unsigned int audio_pts;
00036 } CdataDemuxContext;
00037
00038 static int cdata_probe(AVProbeData *p)
00039 {
00040 const uint8_t *b = p->buf;
00041
00042 if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
00043 return AVPROBE_SCORE_MAX/8;
00044 return 0;
00045 }
00046
00047 static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap)
00048 {
00049 CdataDemuxContext *cdata = s->priv_data;
00050 AVIOContext *pb = s->pb;
00051 unsigned int sample_rate, header;
00052 AVStream *st;
00053 int64_t channel_layout = 0;
00054
00055 header = avio_rb16(pb);
00056 switch (header) {
00057 case 0x0400: cdata->channels = 1; break;
00058 case 0x0404: cdata->channels = 2; break;
00059 case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break;
00060 case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
00061 default:
00062 av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
00063 return -1;
00064 };
00065
00066 sample_rate = avio_rb16(pb);
00067 avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
00068
00069 st = av_new_stream(s, 0);
00070 if (!st)
00071 return AVERROR(ENOMEM);
00072 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00073 st->codec->codec_tag = 0;
00074 st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS;
00075 st->codec->channels = cdata->channels;
00076 st->codec->channel_layout = channel_layout;
00077 st->codec->sample_rate = sample_rate;
00078 st->codec->sample_fmt = AV_SAMPLE_FMT_S16;
00079 av_set_pts_info(st, 64, 1, sample_rate);
00080
00081 cdata->audio_pts = 0;
00082 return 0;
00083 }
00084
00085 static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
00086 {
00087 CdataDemuxContext *cdata = s->priv_data;
00088 int packet_size = 76*cdata->channels;
00089
00090 int ret = av_get_packet(s->pb, pkt, packet_size);
00091 if (ret < 0)
00092 return ret;
00093 pkt->pts = cdata->audio_pts++;
00094 return 0;
00095 }
00096
00097 AVInputFormat ff_ea_cdata_demuxer = {
00098 "ea_cdata",
00099 NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
00100 sizeof(CdataDemuxContext),
00101 cdata_probe,
00102 cdata_read_header,
00103 cdata_read_packet,
00104 .extensions = "cdata",
00105 };