annotate ffmpeg/libavformat/aea.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * MD STUDIO audio demuxer
yading@11 3 *
yading@11 4 * Copyright (c) 2009 Benjamin Larsson
yading@11 5 *
yading@11 6 * This file is part of FFmpeg.
yading@11 7 *
yading@11 8 * FFmpeg is free software; you can redistribute it and/or
yading@11 9 * modify it under the terms of the GNU Lesser General Public
yading@11 10 * License as published by the Free Software Foundation; either
yading@11 11 * version 2.1 of the License, or (at your option) any later version.
yading@11 12 *
yading@11 13 * FFmpeg is distributed in the hope that it will be useful,
yading@11 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 16 * Lesser General Public License for more details.
yading@11 17 *
yading@11 18 * You should have received a copy of the GNU Lesser General Public
yading@11 19 * License along with FFmpeg; if not, write to the Free Software
yading@11 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 21 */
yading@11 22
yading@11 23 #include "libavutil/channel_layout.h"
yading@11 24 #include "libavutil/intreadwrite.h"
yading@11 25 #include "avformat.h"
yading@11 26 #include "pcm.h"
yading@11 27
yading@11 28 #define AT1_SU_SIZE 212
yading@11 29
yading@11 30 static int aea_read_probe(AVProbeData *p)
yading@11 31 {
yading@11 32 if (p->buf_size <= 2048+212)
yading@11 33 return 0;
yading@11 34
yading@11 35 /* Magic is '00 08 00 00' in Little Endian*/
yading@11 36 if (AV_RL32(p->buf)==0x800) {
yading@11 37 int bsm_s, bsm_e, inb_s, inb_e, ch;
yading@11 38 ch = p->buf[264];
yading@11 39 bsm_s = p->buf[2048];
yading@11 40 inb_s = p->buf[2048+1];
yading@11 41 inb_e = p->buf[2048+210];
yading@11 42 bsm_e = p->buf[2048+211];
yading@11 43
yading@11 44 if (ch != 1 && ch != 2)
yading@11 45 return 0;
yading@11 46
yading@11 47 /* Check so that the redundant bsm bytes and info bytes are valid
yading@11 48 * the block size mode bytes have to be the same
yading@11 49 * the info bytes have to be the same
yading@11 50 */
yading@11 51 if (bsm_s == bsm_e && inb_s == inb_e)
yading@11 52 return AVPROBE_SCORE_MAX / 4 + 1;
yading@11 53 }
yading@11 54 return 0;
yading@11 55 }
yading@11 56
yading@11 57 static int aea_read_header(AVFormatContext *s)
yading@11 58 {
yading@11 59 AVStream *st = avformat_new_stream(s, NULL);
yading@11 60 if (!st)
yading@11 61 return AVERROR(ENOMEM);
yading@11 62
yading@11 63 /* Parse the amount of channels and skip to pos 2048(0x800) */
yading@11 64 avio_skip(s->pb, 264);
yading@11 65 st->codec->channels = avio_r8(s->pb);
yading@11 66 avio_skip(s->pb, 1783);
yading@11 67
yading@11 68
yading@11 69 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 70 st->codec->codec_id = AV_CODEC_ID_ATRAC1;
yading@11 71 st->codec->sample_rate = 44100;
yading@11 72 st->codec->bit_rate = 292000;
yading@11 73
yading@11 74 if (st->codec->channels != 1 && st->codec->channels != 2) {
yading@11 75 av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels);
yading@11 76 return -1;
yading@11 77 }
yading@11 78
yading@11 79 st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
yading@11 80
yading@11 81 st->codec->block_align = AT1_SU_SIZE * st->codec->channels;
yading@11 82 return 0;
yading@11 83 }
yading@11 84
yading@11 85 static int aea_read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 86 {
yading@11 87 int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
yading@11 88
yading@11 89 pkt->stream_index = 0;
yading@11 90 if (ret <= 0)
yading@11 91 return AVERROR(EIO);
yading@11 92
yading@11 93 return ret;
yading@11 94 }
yading@11 95
yading@11 96 AVInputFormat ff_aea_demuxer = {
yading@11 97 .name = "aea",
yading@11 98 .long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"),
yading@11 99 .read_probe = aea_read_probe,
yading@11 100 .read_header = aea_read_header,
yading@11 101 .read_packet = aea_read_packet,
yading@11 102 .read_seek = ff_pcm_read_seek,
yading@11 103 .flags = AVFMT_GENERIC_INDEX,
yading@11 104 .extensions = "aea",
yading@11 105 };