00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <string.h>
00023
00024 #include "libavutil/channel_layout.h"
00025 #include "avformat.h"
00026
00027 static int apc_probe(AVProbeData *p)
00028 {
00029 if (!strncmp(p->buf, "CRYO_APC", 8))
00030 return AVPROBE_SCORE_MAX;
00031
00032 return 0;
00033 }
00034
00035 static int apc_read_header(AVFormatContext *s)
00036 {
00037 AVIOContext *pb = s->pb;
00038 AVStream *st;
00039
00040 avio_rl32(pb);
00041 avio_rl32(pb);
00042 avio_rl32(pb);
00043
00044 st = avformat_new_stream(s, NULL);
00045 if (!st)
00046 return AVERROR(ENOMEM);
00047
00048 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00049 st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_APC;
00050
00051 avio_rl32(pb);
00052 st->codec->sample_rate = avio_rl32(pb);
00053
00054 st->codec->extradata_size = 2 * 4;
00055 st->codec->extradata = av_malloc(st->codec->extradata_size +
00056 FF_INPUT_BUFFER_PADDING_SIZE);
00057 if (!st->codec->extradata)
00058 return AVERROR(ENOMEM);
00059
00060
00061 avio_read(pb, st->codec->extradata, 2 * 4);
00062
00063 if (avio_rl32(pb)) {
00064 st->codec->channels = 2;
00065 st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
00066 } else {
00067 st->codec->channels = 1;
00068 st->codec->channel_layout = AV_CH_LAYOUT_MONO;
00069 }
00070
00071 st->codec->bits_per_coded_sample = 4;
00072 st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels
00073 * st->codec->sample_rate;
00074 st->codec->block_align = 1;
00075
00076 return 0;
00077 }
00078
00079 #define MAX_READ_SIZE 4096
00080
00081 static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
00082 {
00083 if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
00084 return AVERROR(EIO);
00085 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
00086 pkt->stream_index = 0;
00087 return 0;
00088 }
00089
00090 AVInputFormat ff_apc_demuxer = {
00091 .name = "apc",
00092 .long_name = NULL_IF_CONFIG_SMALL("CRYO APC"),
00093 .read_probe = apc_probe,
00094 .read_header = apc_read_header,
00095 .read_packet = apc_read_packet,
00096 };