annotate ffmpeg/libavformat/rsodec.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 * RSO demuxer
yading@11 3 * Copyright (c) 2001 Fabrice Bellard (original AU code)
yading@11 4 * Copyright (c) 2010 Rafael Carre
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 "internal.h"
yading@11 27 #include "pcm.h"
yading@11 28 #include "rso.h"
yading@11 29
yading@11 30 static int rso_read_header(AVFormatContext *s)
yading@11 31 {
yading@11 32 AVIOContext *pb = s->pb;
yading@11 33 int id, rate, bps;
yading@11 34 unsigned int size;
yading@11 35 enum AVCodecID codec;
yading@11 36 AVStream *st;
yading@11 37
yading@11 38 id = avio_rb16(pb);
yading@11 39 size = avio_rb16(pb);
yading@11 40 rate = avio_rb16(pb);
yading@11 41 avio_rb16(pb); /* play mode ? (0x0000 = don't loop) */
yading@11 42
yading@11 43 codec = ff_codec_get_id(ff_codec_rso_tags, id);
yading@11 44
yading@11 45 if (codec == AV_CODEC_ID_ADPCM_IMA_WAV) {
yading@11 46 avpriv_report_missing_feature(s, "ADPCM in RSO");
yading@11 47 return AVERROR_PATCHWELCOME;
yading@11 48 }
yading@11 49
yading@11 50 bps = av_get_bits_per_sample(codec);
yading@11 51 if (!bps) {
yading@11 52 avpriv_request_sample(s, "Unknown bits per sample");
yading@11 53 return AVERROR_PATCHWELCOME;
yading@11 54 }
yading@11 55
yading@11 56 /* now we are ready: build format streams */
yading@11 57 st = avformat_new_stream(s, NULL);
yading@11 58 if (!st)
yading@11 59 return AVERROR(ENOMEM);
yading@11 60
yading@11 61 st->duration = (size * 8) / bps;
yading@11 62 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 63 st->codec->codec_tag = id;
yading@11 64 st->codec->codec_id = codec;
yading@11 65 st->codec->channels = 1;
yading@11 66 st->codec->channel_layout = AV_CH_LAYOUT_MONO;
yading@11 67 st->codec->sample_rate = rate;
yading@11 68 st->codec->block_align = 1;
yading@11 69
yading@11 70 avpriv_set_pts_info(st, 64, 1, rate);
yading@11 71
yading@11 72 return 0;
yading@11 73 }
yading@11 74
yading@11 75 AVInputFormat ff_rso_demuxer = {
yading@11 76 .name = "rso",
yading@11 77 .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
yading@11 78 .extensions = "rso",
yading@11 79 .read_header = rso_read_header,
yading@11 80 .read_packet = ff_pcm_read_packet,
yading@11 81 .read_seek = ff_pcm_read_seek,
yading@11 82 .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0},
yading@11 83 };