Libav 0.7.1
|
00001 /* 00002 * MD STUDIO audio demuxer 00003 * 00004 * Copyright (c) 2009 Benjamin Larsson 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #include "avformat.h" 00024 #include "pcm.h" 00025 #include "libavutil/intreadwrite.h" 00026 #include "libavutil/audioconvert.h" 00027 00028 #define AT1_SU_SIZE 212 00029 00030 static int aea_read_probe(AVProbeData *p) 00031 { 00032 if (p->buf_size <= 2048+212) 00033 return 0; 00034 00035 /* Magic is '00 08 00 00' in Little Endian*/ 00036 if (AV_RL32(p->buf)==0x800) { 00037 int bsm_s, bsm_e, inb_s, inb_e, ch; 00038 ch = p->buf[264]; 00039 bsm_s = p->buf[2048]; 00040 inb_s = p->buf[2048+1]; 00041 inb_e = p->buf[2048+210]; 00042 bsm_e = p->buf[2048+211]; 00043 00044 if (ch != 1 && ch != 2) 00045 return 0; 00046 00047 /* Check so that the redundant bsm bytes and info bytes are valid 00048 * the block size mode bytes have to be the same 00049 * the info bytes have to be the same 00050 */ 00051 if (bsm_s == bsm_e && inb_s == inb_e) 00052 return AVPROBE_SCORE_MAX / 4 + 1; 00053 } 00054 return 0; 00055 } 00056 00057 static int aea_read_header(AVFormatContext *s, 00058 AVFormatParameters *ap) 00059 { 00060 AVStream *st = av_new_stream(s, 0); 00061 if (!st) 00062 return AVERROR(ENOMEM); 00063 00064 /* Parse the amount of channels and skip to pos 2048(0x800) */ 00065 avio_skip(s->pb, 264); 00066 st->codec->channels = avio_r8(s->pb); 00067 avio_skip(s->pb, 1783); 00068 00069 00070 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 00071 st->codec->codec_id = CODEC_ID_ATRAC1; 00072 st->codec->sample_rate = 44100; 00073 st->codec->bit_rate = 292000; 00074 00075 if (st->codec->channels != 1 && st->codec->channels != 2) { 00076 av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); 00077 return -1; 00078 } 00079 00080 st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; 00081 00082 st->codec->block_align = AT1_SU_SIZE * st->codec->channels; 00083 return 0; 00084 } 00085 00086 static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) 00087 { 00088 int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); 00089 00090 pkt->stream_index = 0; 00091 if (ret <= 0) 00092 return AVERROR(EIO); 00093 00094 return ret; 00095 } 00096 00097 AVInputFormat ff_aea_demuxer = { 00098 "aea", 00099 NULL_IF_CONFIG_SMALL("MD STUDIO audio"), 00100 0, 00101 aea_read_probe, 00102 aea_read_header, 00103 aea_read_packet, 00104 0, 00105 pcm_read_seek, 00106 .flags= AVFMT_GENERIC_INDEX, 00107 .extensions = "aea", 00108 }; 00109