[FFmpeg-devel] [PATCH]lavc/opus: Use original sample rate for decoding

Carl Eugen Hoyos cehoyos at ag.or.at
Tue Jan 5 16:06:52 CET 2016


Hi!

Attached patch intends to match what opusdec does, sorry if I miss something.

Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index f2b8ecc..df04f05 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -332,6 +332,18 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         return AVERROR_INVALIDDATA;
     }
 
+    avctx->sample_rate = AV_RL32(extradata + 12);
+    if (   avctx->sample_rate != 48000
+        && avctx->sample_rate != 24000
+        && avctx->sample_rate != 16000
+        && avctx->sample_rate != 12000
+        && avctx->sample_rate !=  8000) {
+        av_log(avctx, AV_LOG_WARNING,
+               "Invalid sample rate %d specified in the extradata, using 48000 instead\n",
+               avctx->sample_rate);
+        avctx->sample_rate = 48000;
+    }
+
     s->gain_i = AV_RL16(extradata + 16);
     if (s->gain_i)
         s->gain = ff_exp10(s->gain_i / (20.0 * 256));
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index 95a2435..66f2a19 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -663,7 +663,6 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
     int ret, i, j;
 
     avctx->sample_fmt  = AV_SAMPLE_FMT_FLTP;
-    avctx->sample_rate = 48000;
 
     c->fdsp = avpriv_float_dsp_alloc(0);
     if (!c->fdsp)


More information about the ffmpeg-devel mailing list