]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/adxdec.c
mpegts: use avcodec_get_type() to set codec_type
[ffmpeg] / libavformat / adxdec.c
index 76b3728b1e7eb51fbf3350ece4fca0ac7b549be1..bce0493b799ea517cbacae6ec0c73653fbc9aeaa 100644 (file)
@@ -24,8 +24,8 @@
  */
 
 #include "libavutil/intreadwrite.h"
-#include "libavcodec/adx.h"
 #include "avformat.h"
+#include "internal.h"
 
 #define BLOCK_SIZE    18
 #define BLOCK_SAMPLES 32
@@ -61,11 +61,10 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
-static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap)
+static int adx_read_header(AVFormatContext *s)
 {
     ADXDemuxerContext *c = s->priv_data;
     AVCodecContext *avctx;
-    int ret;
 
     AVStream *st = avformat_new_stream(s, NULL);
     if (!st)
@@ -77,7 +76,7 @@ static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap)
     c->header_size = avio_rb16(s->pb) + 4;
     avio_seek(s->pb, -4, SEEK_CUR);
 
-    avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE);
+    avctx->extradata = av_mallocz(c->header_size + AV_INPUT_BUFFER_PADDING_SIZE);
     if (!avctx->extradata)
         return AVERROR(ENOMEM);
     if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) {
@@ -86,15 +85,22 @@ static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap)
     }
     avctx->extradata_size = c->header_size;
 
-    ret = ff_adx_decode_header(avctx, avctx->extradata, avctx->extradata_size,
-                               &c->header_size, NULL);
-    if (ret)
-        return ret;
+    if (avctx->extradata_size < 12) {
+        av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n");
+        return AVERROR_INVALIDDATA;
+    }
+    avctx->channels    = AV_RB8(avctx->extradata + 7);
+    avctx->sample_rate = AV_RB32(avctx->extradata + 8);
+
+    if (avctx->channels <= 0) {
+        av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", avctx->channels);
+        return AVERROR_INVALIDDATA;
+    }
 
     st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id    = s->iformat->value;
+    st->codec->codec_id    = s->iformat->raw_codec_id;
 
-    av_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
+    avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate);
 
     return 0;
 }
@@ -106,5 +112,6 @@ AVInputFormat ff_adx_demuxer = {
     .read_header    = adx_read_header,
     .read_packet    = adx_read_packet,
     .extensions     = "adx",
-    .value          = CODEC_ID_ADPCM_ADX,
+    .raw_codec_id   = AV_CODEC_ID_ADPCM_ADX,
+    .flags          = AVFMT_GENERIC_INDEX,
 };