annotate ffmpeg/libavformat/adxdec.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 * Copyright (c) 2011 Justin Ruggles
yading@11 3 *
yading@11 4 * This file is part of Libav.
yading@11 5 *
yading@11 6 * Libav is free software; you can redistribute it and/or
yading@11 7 * modify it under the terms of the GNU Lesser General Public
yading@11 8 * License as published by the Free Software Foundation; either
yading@11 9 * version 2.1 of the License, or (at your option) any later version.
yading@11 10 *
yading@11 11 * Libav is distributed in the hope that it will be useful,
yading@11 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 14 * Lesser General Public License for more details.
yading@11 15 *
yading@11 16 * You should have received a copy of the GNU Lesser General Public
yading@11 17 * License along with Libav; if not, write to the Free Software
yading@11 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 19 */
yading@11 20
yading@11 21 /**
yading@11 22 * @file
yading@11 23 * CRI ADX demuxer
yading@11 24 */
yading@11 25
yading@11 26 #include "libavutil/intreadwrite.h"
yading@11 27 #include "libavcodec/adx.h"
yading@11 28 #include "avformat.h"
yading@11 29 #include "internal.h"
yading@11 30
yading@11 31 #define BLOCK_SIZE 18
yading@11 32 #define BLOCK_SAMPLES 32
yading@11 33
yading@11 34 typedef struct ADXDemuxerContext {
yading@11 35 int header_size;
yading@11 36 } ADXDemuxerContext;
yading@11 37
yading@11 38 static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 39 {
yading@11 40 ADXDemuxerContext *c = s->priv_data;
yading@11 41 AVCodecContext *avctx = s->streams[0]->codec;
yading@11 42 int ret, size;
yading@11 43
yading@11 44 size = BLOCK_SIZE * avctx->channels;
yading@11 45
yading@11 46 pkt->pos = avio_tell(s->pb);
yading@11 47 pkt->stream_index = 0;
yading@11 48
yading@11 49 ret = av_get_packet(s->pb, pkt, size);
yading@11 50 if (ret != size) {
yading@11 51 av_free_packet(pkt);
yading@11 52 return ret < 0 ? ret : AVERROR(EIO);
yading@11 53 }
yading@11 54 if (AV_RB16(pkt->data) & 0x8000) {
yading@11 55 av_free_packet(pkt);
yading@11 56 return AVERROR_EOF;
yading@11 57 }
yading@11 58 pkt->size = size;
yading@11 59 pkt->duration = 1;
yading@11 60 pkt->pts = (pkt->pos - c->header_size) / size;
yading@11 61
yading@11 62 return 0;
yading@11 63 }
yading@11 64
yading@11 65 static int adx_read_header(AVFormatContext *s)
yading@11 66 {
yading@11 67 ADXDemuxerContext *c = s->priv_data;
yading@11 68 AVCodecContext *avctx;
yading@11 69 int ret;
yading@11 70
yading@11 71 AVStream *st = avformat_new_stream(s, NULL);
yading@11 72 if (!st)
yading@11 73 return AVERROR(ENOMEM);
yading@11 74 avctx = s->streams[0]->codec;
yading@11 75
yading@11 76 if (avio_rb16(s->pb) != 0x8000)
yading@11 77 return AVERROR_INVALIDDATA;
yading@11 78 c->header_size = avio_rb16(s->pb) + 4;
yading@11 79 avio_seek(s->pb, -4, SEEK_CUR);
yading@11 80
yading@11 81 avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
yading@11 82 if (!avctx->extradata)
yading@11 83 return AVERROR(ENOMEM);
yading@11 84 if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
yading@11 85 av_freep(&avctx->extradata);
yading@11 86 return AVERROR(EIO);
yading@11 87 }
yading@11 88 avctx->extradata_size = c->header_size;
yading@11 89
yading@11 90 ret = avpriv_adx_decode_header(avctx, avctx->extradata,
yading@11 91 avctx->extradata_size, &c->header_size,
yading@11 92 NULL);
yading@11 93 if (ret)
yading@11 94 return ret;
yading@11 95
yading@11 96 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 97 st->codec->codec_id = s->iformat->raw_codec_id;
yading@11 98
yading@11 99 avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
yading@11 100
yading@11 101 return 0;
yading@11 102 }
yading@11 103
yading@11 104 AVInputFormat ff_adx_demuxer = {
yading@11 105 .name = "adx",
yading@11 106 .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
yading@11 107 .priv_data_size = sizeof(ADXDemuxerContext),
yading@11 108 .read_header = adx_read_header,
yading@11 109 .read_packet = adx_read_packet,
yading@11 110 .extensions = "adx",
yading@11 111 .raw_codec_id = AV_CODEC_ID_ADPCM_ADX,
yading@11 112 .flags = AVFMT_GENERIC_INDEX,
yading@11 113 };