00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/channel_layout.h"
00024 #include "libavutil/intreadwrite.h"
00025 #include "avformat.h"
00026 #include "internal.h"
00027 #include "pcm.h"
00028 #include "rso.h"
00029
00030 static int rso_read_header(AVFormatContext *s)
00031 {
00032 AVIOContext *pb = s->pb;
00033 int id, rate, bps;
00034 unsigned int size;
00035 enum AVCodecID codec;
00036 AVStream *st;
00037
00038 id = avio_rb16(pb);
00039 size = avio_rb16(pb);
00040 rate = avio_rb16(pb);
00041 avio_rb16(pb);
00042
00043 codec = ff_codec_get_id(ff_codec_rso_tags, id);
00044
00045 if (codec == AV_CODEC_ID_ADPCM_IMA_WAV) {
00046 av_log(s, AV_LOG_ERROR, "ADPCM in RSO not implemented\n");
00047 return AVERROR_PATCHWELCOME;
00048 }
00049
00050 bps = av_get_bits_per_sample(codec);
00051 if (!bps) {
00052 av_log_ask_for_sample(s, "could not determine bits per sample\n");
00053 return AVERROR_INVALIDDATA;
00054 }
00055
00056
00057 st = avformat_new_stream(s, NULL);
00058 if (!st)
00059 return AVERROR(ENOMEM);
00060
00061 st->duration = (size * 8) / bps;
00062 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00063 st->codec->codec_tag = id;
00064 st->codec->codec_id = codec;
00065 st->codec->channels = 1;
00066 st->codec->channel_layout = AV_CH_LAYOUT_MONO;
00067 st->codec->sample_rate = rate;
00068 st->codec->block_align = 1;
00069
00070 avpriv_set_pts_info(st, 64, 1, rate);
00071
00072 return 0;
00073 }
00074
00075 AVInputFormat ff_rso_demuxer = {
00076 .name = "rso",
00077 .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO"),
00078 .extensions = "rso",
00079 .read_header = rso_read_header,
00080 .read_packet = ff_pcm_read_packet,
00081 .read_seek = ff_pcm_read_seek,
00082 .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0},
00083 };