00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00048
00049
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 {
00059 AVStream *st = avformat_new_stream(s, NULL);
00060 if (!st)
00061 return AVERROR(ENOMEM);
00062
00063
00064 avio_skip(s->pb, 264);
00065 st->codec->channels = avio_r8(s->pb);
00066 avio_skip(s->pb, 1783);
00067
00068
00069 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00070 st->codec->codec_id = AV_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) ? AV_CH_LAYOUT_MONO : AV_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 ff_aea_demuxer = {
00097 .name = "aea",
00098 .long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
00099 .read_probe = aea_read_probe,
00100 .read_header = aea_read_header,
00101 .read_packet = aea_read_packet,
00102 .read_seek = ff_pcm_read_seek,
00103 .flags = AVFMT_GENERIC_INDEX,
00104 .extensions = "aea",
00105 };