annotate ffmpeg/libavformat/eacdata.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * Electronic Arts .cdata file Demuxer
yading@11 3 * Copyright (c) 2007 Peter Ross
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 /**
yading@11 23 * @file
yading@11 24 * Electronic Arts cdata Format Demuxer
yading@11 25 * by Peter Ross (pross@xvid.org)
yading@11 26 *
yading@11 27 * Technical details here:
yading@11 28 * http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
yading@11 29 */
yading@11 30
yading@11 31 #include "avformat.h"
yading@11 32 #include "internal.h"
yading@11 33
yading@11 34 typedef struct {
yading@11 35 unsigned int channels;
yading@11 36 unsigned int audio_pts;
yading@11 37 } CdataDemuxContext;
yading@11 38
yading@11 39 static int cdata_probe(AVProbeData *p)
yading@11 40 {
yading@11 41 const uint8_t *b = p->buf;
yading@11 42
yading@11 43 if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
yading@11 44 return AVPROBE_SCORE_MAX/8;
yading@11 45 return 0;
yading@11 46 }
yading@11 47
yading@11 48 static int cdata_read_header(AVFormatContext *s)
yading@11 49 {
yading@11 50 CdataDemuxContext *cdata = s->priv_data;
yading@11 51 AVIOContext *pb = s->pb;
yading@11 52 unsigned int sample_rate, header;
yading@11 53 AVStream *st;
yading@11 54 int64_t channel_layout = 0;
yading@11 55
yading@11 56 header = avio_rb16(pb);
yading@11 57 switch (header) {
yading@11 58 case 0x0400: cdata->channels = 1; break;
yading@11 59 case 0x0404: cdata->channels = 2; break;
yading@11 60 case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break;
yading@11 61 case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
yading@11 62 default:
yading@11 63 av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
yading@11 64 return -1;
yading@11 65 };
yading@11 66
yading@11 67 sample_rate = avio_rb16(pb);
yading@11 68 avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
yading@11 69
yading@11 70 st = avformat_new_stream(s, NULL);
yading@11 71 if (!st)
yading@11 72 return AVERROR(ENOMEM);
yading@11 73 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 74 st->codec->codec_tag = 0; /* no fourcc */
yading@11 75 st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
yading@11 76 st->codec->channels = cdata->channels;
yading@11 77 st->codec->channel_layout = channel_layout;
yading@11 78 st->codec->sample_rate = sample_rate;
yading@11 79 avpriv_set_pts_info(st, 64, 1, sample_rate);
yading@11 80
yading@11 81 cdata->audio_pts = 0;
yading@11 82 return 0;
yading@11 83 }
yading@11 84
yading@11 85 static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 86 {
yading@11 87 CdataDemuxContext *cdata = s->priv_data;
yading@11 88 int packet_size = 76*cdata->channels;
yading@11 89
yading@11 90 int ret = av_get_packet(s->pb, pkt, packet_size);
yading@11 91 if (ret < 0)
yading@11 92 return ret;
yading@11 93 pkt->pts = cdata->audio_pts++;
yading@11 94 return 0;
yading@11 95 }
yading@11 96
yading@11 97 AVInputFormat ff_ea_cdata_demuxer = {
yading@11 98 .name = "ea_cdata",
yading@11 99 .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
yading@11 100 .priv_data_size = sizeof(CdataDemuxContext),
yading@11 101 .read_probe = cdata_probe,
yading@11 102 .read_header = cdata_read_header,
yading@11 103 .read_packet = cdata_read_packet,
yading@11 104 .extensions = "cdata",
yading@11 105 };