Libav
|
00001 /* 00002 * MD STUDIO audio demuxer 00003 * 00004 * Copyright (c) 2009 Benjamin Larsson 00005 * 00006 * This file is part of FFmpeg. 00007 * 00008 * FFmpeg 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 * FFmpeg 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 FFmpeg; 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 "raw.h" 00025 #include "libavutil/intreadwrite.h" 00026 00027 #define AT1_SU_SIZE 212 00028 00029 static int aea_read_probe(AVProbeData *p) 00030 { 00031 if (p->buf_size <= 2048+212) 00032 return 0; 00033 00034 /* Magic is '00 08 00 00' in Little Endian*/ 00035 if (AV_RL32(p->buf)==0x800) { 00036 int bsm_s, bsm_e, inb_s, inb_e, ch; 00037 ch = p->buf[264]; 00038 bsm_s = p->buf[2048]; 00039 inb_s = p->buf[2048+1]; 00040 inb_e = p->buf[2048+210]; 00041 bsm_e = p->buf[2048+211]; 00042 00043 if (ch != 1 && ch != 2) 00044 return 0; 00045 00046 /* Check so that the redundant bsm bytes and info bytes are valid 00047 * the block size mode bytes have to be the same 00048 * the info bytes have to be the same 00049 */ 00050 if (bsm_s == bsm_e && inb_s == inb_e) 00051 return AVPROBE_SCORE_MAX / 4 + 1; 00052 } 00053 return 0; 00054 } 00055 00056 static int aea_read_header(AVFormatContext *s, 00057 AVFormatParameters *ap) 00058 { 00059 AVStream *st = av_new_stream(s, 0); 00060 if (!st) 00061 return AVERROR(ENOMEM); 00062 00063 /* Parse the amount of channels and skip to pos 2048(0x800) */ 00064 url_fskip(s->pb, 264); 00065 st->codec->channels = get_byte(s->pb); 00066 url_fskip(s->pb, 1783); 00067 00068 00069 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 00070 st->codec->codec_id = CODEC_ID_ATRAC1; 00071 st->codec->sample_rate = 44100; 00072 st->codec->bit_rate = 292000; 00073 00074 if (st->codec->channels != 1 && st->codec->channels != 2) { 00075 av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); 00076 return -1; 00077 } 00078 00079 st->codec->channel_layout = (st->codec->channels == 1) ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO; 00080 00081 st->codec->block_align = AT1_SU_SIZE * st->codec->channels; 00082 return 0; 00083 } 00084 00085 static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) 00086 { 00087 int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); 00088 00089 pkt->stream_index = 0; 00090 if (ret <= 0) 00091 return AVERROR(EIO); 00092 00093 return ret; 00094 } 00095 00096 AVInputFormat aea_demuxer = { 00097 "aea", 00098 NULL_IF_CONFIG_SMALL("MD STUDIO audio"), 00099 0, 00100 aea_read_probe, 00101 aea_read_header, 00102 aea_read_packet, 00103 0, 00104 pcm_read_seek, 00105 .flags= AVFMT_GENERIC_INDEX, 00106 .extensions = "aea", 00107 }; 00108