Some more work is needed but this works for me. I think we need to redo
the probing for codecs. Here we really need the sample rate from the
container to be able to decode the stream.

The sample_rate_idx() function is written by Ronald.

MvH
Benajmin Larsson
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 5f9dd83..d357de8 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -530,6 +530,23 @@ static void reset_all_predictors(PredictorState *ps)
         reset_predict_state(&ps[i]);
 }
 
+
+static int sample_rate_idx (int rate)
+{
+  if (92017 <= rate)      return 0;
+  else if (75132 <= rate) return 1;
+  else if (55426 <= rate) return 2;
+  else if (46009 <= rate) return 3;
+  else if (37566 <= rate) return 4;
+  else if (27713 <= rate) return 5;
+  else if (23004 <= rate) return 6;
+  else if (18783 <= rate) return 7;
+  else if (13856 <= rate) return 8;
+  else if (11502 <= rate) return 9;
+  else if (9391 <= rate)  return 10;
+  else return 11;
+}
+
 static void reset_predictor_group(PredictorState *ps, int group_num)
 {
     int i;
@@ -555,6 +572,17 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
                                          avctx->extradata,
                                          avctx->extradata_size) < 0)
             return -1;
+    } else {
+        int sr;
+        enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
+
+        sr = sample_rate_idx(avctx->sample_rate);
+        ac->m4ac.sampling_index = sr;
+        ac->m4ac.channels = avctx->channels;
+        // HACK true for mono and stereo
+        ac->m4ac.chan_config = avctx->channels;
+        set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config);
+        output_configure(ac, ac->che_pos, new_che_pos, ac->m4ac.chan_config, OC_GLOBAL_HDR);
     }
 
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 67aa76a..4bc6005 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2162,9 +2162,9 @@ int av_find_stream_info(AVFormatContext *ic)
         AVCodec *codec;
         st = ic->streams[i];
         if (st->codec->codec_id == CODEC_ID_AAC) {
-            st->codec->sample_rate = 0;
+//            st->codec->sample_rate = 0;
             st->codec->frame_size = 0;
-            st->codec->channels = 0;
+//            st->codec->channels = 0;
         }
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
             st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to