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 AVFormatParameters *ap)
00059 {
00060 AVStream *st = avformat_new_stream(s, NULL);
00061 if (!st)
00062 return AVERROR(ENOMEM);
00063
00064
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 .name = "aea",
00099 .long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
00100 .read_probe = aea_read_probe,
00101 .read_header = aea_read_header,
00102 .read_packet = aea_read_packet,
00103 .read_seek = pcm_read_seek,
00104 .flags= AVFMT_GENERIC_INDEX,
00105 .extensions = "aea",
00106 };
00107