00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 #include "avformat.h"
00028 #include "raw.h"
00029 #include "libavutil/intreadwrite.h"
00030
00031 #define AT1_SU_SIZE 212
00032
00033 static int aea_read_probe(AVProbeData *p)
00034 {
00035 if (p->buf_size <= 2048+212)
00036 return 0;
00037
00038
00039 if (AV_RL32(p->buf)==0x800) {
00040 int bsm_s, bsm_e, inb_s, inb_e, ch;
00041 ch = p->buf[264];
00042 bsm_s = p->buf[2048];
00043 inb_s = p->buf[2048+1];
00044 inb_e = p->buf[2048+210];
00045 bsm_e = p->buf[2048+211];
00046
00047 if (ch != 1 && ch != 2)
00048 return 0;
00049
00050
00051
00052
00053
00054
00055 if (bsm_s == bsm_e && inb_s == inb_e && bsm_s != inb_s)
00056 return AVPROBE_SCORE_MAX / 2;
00057 }
00058 return 0;
00059 }
00060
00061 static int aea_read_header(AVFormatContext *s,
00062 AVFormatParameters *ap)
00063 {
00064 AVStream *st = av_new_stream(s, 0);
00065 if (!st)
00066 return AVERROR(ENOMEM);
00067
00068
00069 url_fskip(s->pb, 264);
00070 st->codec->channels = get_byte(s->pb);
00071 url_fskip(s->pb, 1783);
00072
00073
00074 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00075 st->codec->codec_id = CODEC_ID_ATRAC1;
00076 st->codec->sample_rate = 44100;
00077 st->codec->bit_rate = 292000;
00078
00079 if (st->codec->channels != 1 && st->codec->channels != 2) {
00080 av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels);
00081 return -1;
00082 }
00083
00084 st->codec->channel_layout = (st->codec->channels == 1) ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO;
00085
00086 st->codec->block_align = AT1_SU_SIZE * st->codec->channels;
00087 return 0;
00088 }
00089
00090 static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
00091 {
00092 int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
00093
00094 pkt->stream_index = 0;
00095 if (ret <= 0)
00096 return AVERROR(EIO);
00097
00098 return ret;
00099 }
00100
00101 AVInputFormat aea_demuxer = {
00102 "aea",
00103 NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
00104 0,
00105 aea_read_probe,
00106 aea_read_header,
00107 aea_read_packet,
00108 0,
00109 pcm_read_seek,
00110 .flags= AVFMT_GENERIC_INDEX,
00111 .extensions = "aea",
00112 };
00113