On 15/10/14 13:40, Martin Storsjö wrote:
From: Omer Osman <[email protected]>

The FDK decoder is capable of producing mono and stereo downmix from
multichannel streams. These streams may contain metadata that control
the downmix process. The decoder reqires an Ancillary Buffer in order to
                                   ^^^^^^^
requires

  static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
@@ -227,14 +277,24 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, 
void *data,
              av_log(avctx, AV_LOG_ERROR, "ff_get_buffer() failed\n");
              return ret;
          }
-        buf = frame->extended_data[0];
-        buf_size = avctx->channels * frame->nb_samples *
-                   av_get_bytes_per_sample(avctx->sample_fmt);
+
+        if (s->anc_buffer) {
+            buf_size = DECODER_BUFFSIZE * DECODER_MAX_CHANNELS;
+            buf = s->decoder_buffer;
+        } else {
+            buf = frame->extended_data[0];
+            buf_size = avctx->channels * frame->nb_samples *
+                       av_get_bytes_per_sample(avctx->sample_fmt);
+        }
      } else {
-        buf_size = 50 * 1024;
-        buf = tmpptr = av_malloc(buf_size);
-        if (!buf)
+        buf_size = DECODER_BUFFSIZE * DECODER_MAX_CHANNELS;
+
+        if (!s->decoder_buffer)
+            s->decoder_buffer = av_malloc(buf_size);
+        if (!s->decoder_buffer)
              return AVERROR(ENOMEM);
+
+        buf = tmpptr = s->decoder_buffer;

if buf_size could change across calls might be a good idea realloc the buffer again?

      }

      err = aacDecoder_DecodeFrame(s->handle, (INT_PCM *) buf, buf_size, 0);
@@ -262,16 +322,20 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, 
void *data,
              av_log(avctx, AV_LOG_ERROR, "ff_get_buffer() failed\n");
              goto end;
          }
-        memcpy(frame->extended_data[0], tmpptr,
+    }
+    if (s->decoder_buffer) {
+        memcpy(frame->extended_data[0], buf,
                 avctx->channels * avctx->frame_size *
                 av_get_bytes_per_sample(avctx->sample_fmt));
+
+        if (!s->anc_buffer)
+            av_freep(&s->decoder_buffer);

or if anc_buffer is set the buffer is already at its largest possible?

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to