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 "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
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
00047
00048
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
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