[FFmpeg-devel] [PATCH] Move resetting of channels, sample_rate back to av_find_stream_info.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Jul 11 20:38:29 CEST 2011


Resetting it on codec init would incorrectly clear the values
if av_find_stream_info was already run before, in particular
breaking ffplay.

This should fix ticket #340
(note: completely untested as of yet, sending in for others
to test and review).
---
 libavcodec/aacdec.c |    3 ---
 libavformat/utils.c |    9 +++++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 8a936da..d9f60d6 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -570,9 +570,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
     ac->m4ac.sample_rate = avctx->sample_rate;
 
     if (avctx->extradata_size > 0) {
-        avctx->channels    = 0;
-        avctx->frame_size  = 0;
-        avctx->sample_rate = 0;
         if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac,
                                          avctx->extradata,
                                          avctx->extradata_size) < 0)
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9a7d6b7..62ea5e7 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2253,6 +2253,15 @@ int av_find_stream_info(AVFormatContext *ic)
     for(i=0;i<ic->nb_streams;i++) {
         AVCodec *codec;
         st = ic->streams[i];
+        if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size) {
+            // We need to discard these since they can be plain wrong for
+            // backwards compatible HE-AAC signaling.
+            // But when we have no extradata we need to keep them or we can't
+            // play anything at all.
+            st->codec->sample_rate = 0;
+            st->codec->frame_size = 0;
+            st->codec->channels = 0;
+        }
 
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
             st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list