]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libfdk-aacdec.c
lavc: support extracting audio service type from side data
[ffmpeg] / libavcodec / libfdk-aacdec.c
index b054ebe09ad644774303d9b4bbb4cb1aa9d36237..f789b75bfe64f9dd0b05ab080f2a48178a8bac51 100644 (file)
 #include "avcodec.h"
 #include "internal.h"
 
+/* The version macro is introduced the same time as the setting enum was
+ * changed, so this check should suffice. */
+#ifndef AACDECODER_LIB_VL0
+#define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
+#endif
+
 enum ConcealMethod {
     CONCEAL_METHOD_SPECTRAL_MUTING      =  0,
     CONCEAL_METHOD_NOISE_SUBSTITUTION   =  1,
@@ -43,6 +49,7 @@ typedef struct FDKAACDecContext {
     int drc_boost;
     int drc_heavy;
     int drc_cut;
+    int level_limit;
 } FDKAACDecContext;
 
 
@@ -65,6 +72,9 @@ static const AVOption fdk_aac_dec_options[] = {
                      OFFSET(drc_level),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 127, AD, NULL    },
     { "drc_heavy", "Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
                      OFFSET(drc_heavy),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 1,   AD, NULL    },
+#ifdef AACDECODER_LIB_VL0
+    { "level_limit", "Signal level limiting", OFFSET(level_limit), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 1, AD },
+#endif
     { NULL }
 };
 
@@ -76,7 +86,7 @@ static int get_stream_info(AVCodecContext *avctx)
 {
     FDKAACDecContext *s   = avctx->priv_data;
     CStreamInfo *info     = aacDecoder_GetStreamInfo(s->handle);
-    int channel_counts[9] = { 0 };
+    int channel_counts[0x24] = { 0 };
     int i, ch_error       = 0;
     uint64_t ch_layout    = 0;
 
@@ -94,7 +104,7 @@ static int get_stream_info(AVCodecContext *avctx)
 
     for (i = 0; i < info->numChannels; i++) {
         AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
-        if (ctype <= ACT_NONE || ctype > ACT_TOP) {
+        if (ctype <= ACT_NONE || ctype >= FF_ARRAY_ELEMS(channel_counts)) {
             av_log(avctx, AV_LOG_WARNING, "unknown channel type\n");
             break;
         }
@@ -239,7 +249,7 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
         }
 
         if (downmix_channels != -1) {
-            if (aacDecoder_SetParam(s->handle, AAC_PCM_OUTPUT_CHANNELS,
+            if (aacDecoder_SetParam(s->handle, AAC_PCM_MAX_OUTPUT_CHANNELS,
                                     downmix_channels) != AAC_DEC_OK) {
                av_log(avctx, AV_LOG_WARNING, "Unable to set output channels in the decoder\n");
             } else {
@@ -286,6 +296,13 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
         }
     }
 
+#ifdef AACDECODER_LIB_VL0
+    if (aacDecoder_SetParam(s->handle, AAC_PCM_LIMITER_ENABLE, s->level_limit) != AAC_DEC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set in signal level limiting in the decoder\n");
+        return AVERROR_UNKNOWN;
+    }
+#endif
+
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
 
     return 0;