Libav 0.7.1
|
00001 /* 00002 * CRYO APC audio format demuxer 00003 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include <string.h> 00023 #include "avformat.h" 00024 00025 static int apc_probe(AVProbeData *p) 00026 { 00027 if (!strncmp(p->buf, "CRYO_APC", 8)) 00028 return AVPROBE_SCORE_MAX; 00029 00030 return 0; 00031 } 00032 00033 static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap) 00034 { 00035 AVIOContext *pb = s->pb; 00036 AVStream *st; 00037 00038 avio_rl32(pb); /* CRYO */ 00039 avio_rl32(pb); /* _APC */ 00040 avio_rl32(pb); /* 1.20 */ 00041 00042 st = av_new_stream(s, 0); 00043 if (!st) 00044 return AVERROR(ENOMEM); 00045 00046 st->codec->codec_type = AVMEDIA_TYPE_AUDIO; 00047 st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; 00048 00049 avio_rl32(pb); /* number of samples */ 00050 st->codec->sample_rate = avio_rl32(pb); 00051 00052 st->codec->extradata_size = 2 * 4; 00053 st->codec->extradata = av_malloc(st->codec->extradata_size + 00054 FF_INPUT_BUFFER_PADDING_SIZE); 00055 if (!st->codec->extradata) 00056 return AVERROR(ENOMEM); 00057 00058 /* initial predictor values for adpcm decoder */ 00059 avio_read(pb, st->codec->extradata, 2 * 4); 00060 00061 st->codec->channels = 1; 00062 if (avio_rl32(pb)) 00063 st->codec->channels = 2; 00064 00065 st->codec->bits_per_coded_sample = 4; 00066 st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels 00067 * st->codec->sample_rate; 00068 st->codec->block_align = 1; 00069 00070 return 0; 00071 } 00072 00073 #define MAX_READ_SIZE 4096 00074 00075 static int apc_read_packet(AVFormatContext *s, AVPacket *pkt) 00076 { 00077 if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0) 00078 return AVERROR(EIO); 00079 pkt->stream_index = 0; 00080 return 0; 00081 } 00082 00083 AVInputFormat ff_apc_demuxer = { 00084 "apc", 00085 NULL_IF_CONFIG_SMALL("CRYO APC format"), 00086 0, 00087 apc_probe, 00088 apc_read_header, 00089 apc_read_packet, 00090 };