• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/adxdec.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Justin Ruggles
00003  *
00004  * This file is part of Libav.
00005  *
00006  * Libav is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * Libav is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with Libav; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "libavutil/intreadwrite.h"
00027 #include "libavcodec/adx.h"
00028 #include "avformat.h"
00029 #include "internal.h"
00030 
00031 #define BLOCK_SIZE    18
00032 #define BLOCK_SAMPLES 32
00033 
00034 typedef struct ADXDemuxerContext {
00035     int header_size;
00036 } ADXDemuxerContext;
00037 
00038 static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
00039 {
00040     ADXDemuxerContext *c = s->priv_data;
00041     AVCodecContext *avctx = s->streams[0]->codec;
00042     int ret, size;
00043 
00044     size = BLOCK_SIZE * avctx->channels;
00045 
00046     pkt->pos = avio_tell(s->pb);
00047     pkt->stream_index = 0;
00048 
00049     ret = av_get_packet(s->pb, pkt, size);
00050     if (ret != size) {
00051         av_free_packet(pkt);
00052         return ret < 0 ? ret : AVERROR(EIO);
00053     }
00054     if (AV_RB16(pkt->data) & 0x8000) {
00055         av_free_packet(pkt);
00056         return AVERROR_EOF;
00057     }
00058     pkt->size     = size;
00059     pkt->duration = 1;
00060     pkt->pts      = (pkt->pos - c->header_size) / size;
00061 
00062     return 0;
00063 }
00064 
00065 static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap)
00066 {
00067     ADXDemuxerContext *c = s->priv_data;
00068     AVCodecContext *avctx;
00069     int ret;
00070 
00071     AVStream *st = avformat_new_stream(s, NULL);
00072     if (!st)
00073         return AVERROR(ENOMEM);
00074     avctx = s->streams[0]->codec;
00075 
00076     if (avio_rb16(s->pb) != 0x8000)
00077         return AVERROR_INVALIDDATA;
00078     c->header_size = avio_rb16(s->pb) + 4;
00079     avio_seek(s->pb, -4, SEEK_CUR);
00080 
00081     avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
00082     if (!avctx->extradata)
00083         return AVERROR(ENOMEM);
00084     if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
00085         av_freep(&avctx->extradata);
00086         return AVERROR(EIO);
00087     }
00088     avctx->extradata_size = c->header_size;
00089 
00090     ret = avpriv_adx_decode_header(avctx, avctx->extradata,
00091                                    avctx->extradata_size, &c->header_size,
00092                                    NULL);
00093     if (ret)
00094         return ret;
00095 
00096     st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
00097     st->codec->codec_id    = s->iformat->value;
00098 
00099     avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
00100 
00101     return 0;
00102 }
00103 
00104 AVInputFormat ff_adx_demuxer = {
00105     .name           = "adx",
00106     .long_name      = NULL_IF_CONFIG_SMALL("CRI ADX"),
00107     .priv_data_size = sizeof(ADXDemuxerContext),
00108     .read_header    = adx_read_header,
00109     .read_packet    = adx_read_packet,
00110     .extensions     = "adx",
00111     .value          = CODEC_ID_ADPCM_ADX,
00112     .flags          = AVFMT_GENERIC_INDEX,
00113 };
Generated on Sat Mar 17 2012 12:57:42 for Libav by doxygen 1.7.1