e07951b
diff -up firefox-98.0/media/ffvpx/libavcodec/codec_list.c.1667096 firefox-98.0/media/ffvpx/libavcodec/codec_list.c
e07951b
--- firefox-98.0/media/ffvpx/libavcodec/codec_list.c.1667096	2022-03-01 11:15:54.962398882 +0100
e07951b
+++ firefox-98.0/media/ffvpx/libavcodec/codec_list.c	2022-03-01 11:17:46.605000755 +0100
16e6b6b
@@ -11,6 +11,9 @@ static const AVCodec * const codec_list[
85160fd
 #if CONFIG_MP3_DECODER
85160fd
     &ff_mp3_decoder,
85160fd
 #endif
85160fd
+#ifdef CONFIG_LIBFDK_AAC
85160fd
+    &ff_libfdk_aac_decoder,
85160fd
+#endif
e07951b
 #if CONFIG_LIBDAV1D
e07951b
     &ff_libdav1d_decoder,
16e6b6b
 #endif
e07951b
diff -up firefox-98.0/media/ffvpx/libavcodec/libfdk-aacdec.c.1667096 firefox-98.0/media/ffvpx/libavcodec/libfdk-aacdec.c
e07951b
--- firefox-98.0/media/ffvpx/libavcodec/libfdk-aacdec.c.1667096	2022-03-01 11:15:54.963398914 +0100
e07951b
+++ firefox-98.0/media/ffvpx/libavcodec/libfdk-aacdec.c	2022-03-01 11:15:54.963398914 +0100
85160fd
@@ -0,0 +1,409 @@
85160fd
+/*
85160fd
+ * AAC decoder wrapper
85160fd
+ * Copyright (c) 2012 Martin Storsjo
85160fd
+ *
85160fd
+ * This file is part of FFmpeg.
85160fd
+ *
85160fd
+ * Permission to use, copy, modify, and/or distribute this software for any
85160fd
+ * purpose with or without fee is hereby granted, provided that the above
85160fd
+ * copyright notice and this permission notice appear in all copies.
85160fd
+ *
85160fd
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
85160fd
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
85160fd
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
85160fd
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
85160fd
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
85160fd
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
85160fd
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
85160fd
+ */
85160fd
+
85160fd
+#include <fdk-aac/aacdecoder_lib.h>
85160fd
+
85160fd
+#include "libavutil/channel_layout.h"
85160fd
+#include "libavutil/common.h"
85160fd
+#include "libavutil/opt.h"
85160fd
+#include "avcodec.h"
85160fd
+#include "internal.h"
85160fd
+
85160fd
+#ifdef AACDECODER_LIB_VL0
85160fd
+#define FDKDEC_VER_AT_LEAST(vl0, vl1) \
85160fd
+    ((AACDECODER_LIB_VL0 > vl0) || \
85160fd
+     (AACDECODER_LIB_VL0 == vl0 && AACDECODER_LIB_VL1 >= vl1))
85160fd
+#else
85160fd
+#define FDKDEC_VER_AT_LEAST(vl0, vl1) 0
85160fd
+#endif
85160fd
+
85160fd
+#if !FDKDEC_VER_AT_LEAST(2, 5) // < 2.5.10
85160fd
+#define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
85160fd
+#endif
85160fd
+
85160fd
+enum ConcealMethod {
85160fd
+    CONCEAL_METHOD_SPECTRAL_MUTING      =  0,
85160fd
+    CONCEAL_METHOD_NOISE_SUBSTITUTION   =  1,
85160fd
+    CONCEAL_METHOD_ENERGY_INTERPOLATION =  2,
85160fd
+    CONCEAL_METHOD_NB,
85160fd
+};
85160fd
+
85160fd
+typedef struct FDKAACDecContext {
85160fd
+    const AVClass *class;
85160fd
+    HANDLE_AACDECODER handle;
85160fd
+    uint8_t *decoder_buffer;
85160fd
+    int decoder_buffer_size;
85160fd
+    uint8_t *anc_buffer;
85160fd
+    int conceal_method;
85160fd
+    int drc_level;
85160fd
+    int drc_boost;
85160fd
+    int drc_heavy;
85160fd
+    int drc_effect;
85160fd
+    int drc_cut;
85160fd
+    int level_limit;
85160fd
+} FDKAACDecContext;
85160fd
+
85160fd
+
85160fd
+#define DMX_ANC_BUFFSIZE       128
85160fd
+#define DECODER_MAX_CHANNELS     8
85160fd
+#define DECODER_BUFFSIZE      2048 * sizeof(INT_PCM)
85160fd
+
85160fd
+#define OFFSET(x) offsetof(FDKAACDecContext, x)
85160fd
+#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
85160fd
+static const AVOption fdk_aac_dec_options[] = {
85160fd
+    { "conceal", "Error concealment method", OFFSET(conceal_method), AV_OPT_TYPE_INT, { .i64 = CONCEAL_METHOD_NOISE_SUBSTITUTION }, CONCEAL_METHOD_SPECTRAL_MUTING, CONCEAL_METHOD_NB - 1, AD, "conceal" },
85160fd
+    { "spectral", "Spectral muting",      0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_SPECTRAL_MUTING },      INT_MIN, INT_MAX, AD, "conceal" },
85160fd
+    { "noise",    "Noise Substitution",   0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_NOISE_SUBSTITUTION },   INT_MIN, INT_MAX, AD, "conceal" },
85160fd
+    { "energy",   "Energy Interpolation", 0, AV_OPT_TYPE_CONST, { .i64 = CONCEAL_METHOD_ENERGY_INTERPOLATION }, INT_MIN, INT_MAX, AD, "conceal" },
85160fd
+    { "drc_boost", "Dynamic Range Control: boost, where [0] is none and [127] is max boost",
85160fd
+                     OFFSET(drc_boost),      AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 127, AD, NULL    },
85160fd
+    { "drc_cut",   "Dynamic Range Control: attenuation factor, where [0] is none and [127] is max compression",
85160fd
+                     OFFSET(drc_cut),        AV_OPT_TYPE_INT,   { .i64 = -1 }, -1, 127, AD, NULL    },
85160fd
+    { "drc_level", "Dynamic Range Control: reference level, quantized to 0.25dB steps where [0] is 0dB and [127] is -31.75dB",
85160fd
+                     OFFSET(drc_level),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 127, AD, NULL    },
85160fd
+    { "drc_heavy", "Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
85160fd
+                     OFFSET(drc_heavy),      AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 1,   AD, NULL    },
85160fd
+#if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
85160fd
+    { "level_limit", "Signal level limiting", OFFSET(level_limit), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 1, AD },
85160fd
+#endif
85160fd
+#if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
85160fd
+    { "drc_effect","Dynamic Range Control: effect type, where e.g. [0] is none and [6] is general",
85160fd
+                     OFFSET(drc_effect),     AV_OPT_TYPE_INT,   { .i64 = -1},  -1, 8,   AD, NULL    },
85160fd
+#endif
85160fd
+    { NULL }
85160fd
+};
85160fd
+
85160fd
+static const AVClass fdk_aac_dec_class = {
85160fd
+    .class_name = "libfdk-aac decoder",
85160fd
+    .item_name  = av_default_item_name,
85160fd
+    .option     = fdk_aac_dec_options,
85160fd
+    .version    = LIBAVUTIL_VERSION_INT,
85160fd
+};
85160fd
+
85160fd
+static int get_stream_info(AVCodecContext *avctx)
85160fd
+{
85160fd
+    FDKAACDecContext *s   = avctx->priv_data;
85160fd
+    CStreamInfo *info     = aacDecoder_GetStreamInfo(s->handle);
85160fd
+    int channel_counts[0x24] = { 0 };
85160fd
+    int i, ch_error       = 0;
85160fd
+    uint64_t ch_layout    = 0;
85160fd
+
85160fd
+    if (!info) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "Unable to get stream info\n");
85160fd
+        return AVERROR_UNKNOWN;
85160fd
+    }
85160fd
+
85160fd
+    if (info->sampleRate <= 0) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "Stream info not initialized\n");
85160fd
+        return AVERROR_UNKNOWN;
85160fd
+    }
85160fd
+    avctx->sample_rate = info->sampleRate;
85160fd
+    avctx->frame_size  = info->frameSize;
85160fd
+
85160fd
+    for (i = 0; i < info->numChannels; i++) {
85160fd
+        AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
85160fd
+        if (ctype <= ACT_NONE || ctype >= FF_ARRAY_ELEMS(channel_counts)) {
85160fd
+            av_log(avctx, AV_LOG_WARNING, "unknown channel type\n");
85160fd
+            break;
85160fd
+        }
85160fd
+        channel_counts[ctype]++;
85160fd
+    }
85160fd
+    av_log(avctx, AV_LOG_DEBUG,
85160fd
+           "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
85160fd
+           info->numChannels,
85160fd
+           channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
85160fd
+           channel_counts[ACT_BACK],  channel_counts[ACT_LFE],
85160fd
+           channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
85160fd
+           channel_counts[ACT_BACK_TOP]  + channel_counts[ACT_TOP]);
85160fd
+
85160fd
+    switch (channel_counts[ACT_FRONT]) {
85160fd
+    case 4:
85160fd
+        ch_layout |= AV_CH_LAYOUT_STEREO | AV_CH_FRONT_LEFT_OF_CENTER |
85160fd
+                     AV_CH_FRONT_RIGHT_OF_CENTER;
85160fd
+        break;
85160fd
+    case 3:
85160fd
+        ch_layout |= AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER;
85160fd
+        break;
85160fd
+    case 2:
85160fd
+        ch_layout |= AV_CH_LAYOUT_STEREO;
85160fd
+        break;
85160fd
+    case 1:
85160fd
+        ch_layout |= AV_CH_FRONT_CENTER;
85160fd
+        break;
85160fd
+    default:
85160fd
+        av_log(avctx, AV_LOG_WARNING,
85160fd
+               "unsupported number of front channels: %d\n",
85160fd
+               channel_counts[ACT_FRONT]);
85160fd
+        ch_error = 1;
85160fd
+        break;
85160fd
+    }
85160fd
+    if (channel_counts[ACT_SIDE] > 0) {
85160fd
+        if (channel_counts[ACT_SIDE] == 2) {
85160fd
+            ch_layout |= AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT;
85160fd
+        } else {
85160fd
+            av_log(avctx, AV_LOG_WARNING,
85160fd
+                   "unsupported number of side channels: %d\n",
85160fd
+                   channel_counts[ACT_SIDE]);
85160fd
+            ch_error = 1;
85160fd
+        }
85160fd
+    }
85160fd
+    if (channel_counts[ACT_BACK] > 0) {
85160fd
+        switch (channel_counts[ACT_BACK]) {
85160fd
+        case 3:
85160fd
+            ch_layout |= AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | AV_CH_BACK_CENTER;
85160fd
+            break;
85160fd
+        case 2:
85160fd
+            ch_layout |= AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT;
85160fd
+            break;
85160fd
+        case 1:
85160fd
+            ch_layout |= AV_CH_BACK_CENTER;
85160fd
+            break;
85160fd
+        default:
85160fd
+            av_log(avctx, AV_LOG_WARNING,
85160fd
+                   "unsupported number of back channels: %d\n",
85160fd
+                   channel_counts[ACT_BACK]);
85160fd
+            ch_error = 1;
85160fd
+            break;
85160fd
+        }
85160fd
+    }
85160fd
+    if (channel_counts[ACT_LFE] > 0) {
85160fd
+        if (channel_counts[ACT_LFE] == 1) {
85160fd
+            ch_layout |= AV_CH_LOW_FREQUENCY;
85160fd
+        } else {
85160fd
+            av_log(avctx, AV_LOG_WARNING,
85160fd
+                   "unsupported number of LFE channels: %d\n",
85160fd
+                   channel_counts[ACT_LFE]);
85160fd
+            ch_error = 1;
85160fd
+        }
85160fd
+    }
85160fd
+    if (!ch_error &&
85160fd
+        av_get_channel_layout_nb_channels(ch_layout) != info->numChannels) {
85160fd
+        av_log(avctx, AV_LOG_WARNING, "unsupported channel configuration\n");
85160fd
+        ch_error = 1;
85160fd
+    }
85160fd
+    if (ch_error)
85160fd
+        avctx->channel_layout = 0;
85160fd
+    else
85160fd
+        avctx->channel_layout = ch_layout;
85160fd
+
85160fd
+    avctx->channels = info->numChannels;
85160fd
+
85160fd
+    return 0;
85160fd
+}
85160fd
+
85160fd
+static av_cold int fdk_aac_decode_close(AVCodecContext *avctx)
85160fd
+{
85160fd
+    FDKAACDecContext *s = avctx->priv_data;
85160fd
+
85160fd
+    if (s->handle)
85160fd
+        aacDecoder_Close(s->handle);
85160fd
+    av_freep(&s->decoder_buffer);
85160fd
+    av_freep(&s->anc_buffer);
85160fd
+
85160fd
+    return 0;
85160fd
+}
85160fd
+
85160fd
+static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
85160fd
+{
85160fd
+    FDKAACDecContext *s = avctx->priv_data;
85160fd
+    AAC_DECODER_ERROR err;
85160fd
+
85160fd
+    s->handle = aacDecoder_Open(avctx->extradata_size ? TT_MP4_RAW : TT_MP4_ADTS, 1);
85160fd
+    if (!s->handle) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "Error opening decoder\n");
85160fd
+        return AVERROR_UNKNOWN;
85160fd
+    }
85160fd
+
85160fd
+    if (avctx->extradata_size) {
85160fd
+        if ((err = aacDecoder_ConfigRaw(s->handle, &avctx->extradata,
85160fd
+                                        &avctx->extradata_size)) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set extradata\n");
85160fd
+            return AVERROR_INVALIDDATA;
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+    if ((err = aacDecoder_SetParam(s->handle, AAC_CONCEAL_METHOD,
85160fd
+                                   s->conceal_method)) != AAC_DEC_OK) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "Unable to set error concealment method\n");
85160fd
+        return AVERROR_UNKNOWN;
85160fd
+    }
85160fd
+
85160fd
+    if (avctx->request_channel_layout > 0 &&
85160fd
+        avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) {
85160fd
+        int downmix_channels = -1;
85160fd
+
85160fd
+        switch (avctx->request_channel_layout) {
85160fd
+        case AV_CH_LAYOUT_STEREO:
85160fd
+        case AV_CH_LAYOUT_STEREO_DOWNMIX:
85160fd
+            downmix_channels = 2;
85160fd
+            break;
85160fd
+        case AV_CH_LAYOUT_MONO:
85160fd
+            downmix_channels = 1;
85160fd
+            break;
85160fd
+        default:
85160fd
+            av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
85160fd
+            break;
85160fd
+        }
85160fd
+
85160fd
+        if (downmix_channels != -1) {
85160fd
+            if (aacDecoder_SetParam(s->handle, AAC_PCM_MAX_OUTPUT_CHANNELS,
85160fd
+                                    downmix_channels) != AAC_DEC_OK) {
85160fd
+               av_log(avctx, AV_LOG_WARNING, "Unable to set output channels in the decoder\n");
85160fd
+            } else {
85160fd
+               s->anc_buffer = av_malloc(DMX_ANC_BUFFSIZE);
85160fd
+               if (!s->anc_buffer) {
85160fd
+                   av_log(avctx, AV_LOG_ERROR, "Unable to allocate ancillary buffer for the decoder\n");
85160fd
+                   return AVERROR(ENOMEM);
85160fd
+               }
85160fd
+               if (aacDecoder_AncDataInit(s->handle, s->anc_buffer, DMX_ANC_BUFFSIZE)) {
85160fd
+                   av_log(avctx, AV_LOG_ERROR, "Unable to register downmix ancillary buffer in the decoder\n");
85160fd
+                   return AVERROR_UNKNOWN;
85160fd
+               }
85160fd
+            }
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+    if (s->drc_boost != -1) {
85160fd
+        if (aacDecoder_SetParam(s->handle, AAC_DRC_BOOST_FACTOR, s->drc_boost) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set DRC boost factor in the decoder\n");
85160fd
+            return AVERROR_UNKNOWN;
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+    if (s->drc_cut != -1) {
85160fd
+        if (aacDecoder_SetParam(s->handle, AAC_DRC_ATTENUATION_FACTOR, s->drc_cut) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set DRC attenuation factor in the decoder\n");
85160fd
+            return AVERROR_UNKNOWN;
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+    if (s->drc_level != -1) {
85160fd
+        if (aacDecoder_SetParam(s->handle, AAC_DRC_REFERENCE_LEVEL, s->drc_level) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set DRC reference level in the decoder\n");
85160fd
+            return AVERROR_UNKNOWN;
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+    if (s->drc_heavy != -1) {
85160fd
+        if (aacDecoder_SetParam(s->handle, AAC_DRC_HEAVY_COMPRESSION, s->drc_heavy) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set DRC heavy compression in the decoder\n");
85160fd
+            return AVERROR_UNKNOWN;
85160fd
+        }
85160fd
+    }
85160fd
+
85160fd
+#if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
85160fd
+    if (aacDecoder_SetParam(s->handle, AAC_PCM_LIMITER_ENABLE, s->level_limit) != AAC_DEC_OK) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "Unable to set in signal level limiting in the decoder\n");
85160fd
+        return AVERROR_UNKNOWN;
85160fd
+    }
85160fd
+#endif
85160fd
+
85160fd
+#if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
85160fd
+    if (s->drc_effect != -1) {
85160fd
+        if (aacDecoder_SetParam(s->handle, AAC_UNIDRC_SET_EFFECT, s->drc_effect) != AAC_DEC_OK) {
85160fd
+            av_log(avctx, AV_LOG_ERROR, "Unable to set DRC effect type in the decoder\n");
85160fd
+            return AVERROR_UNKNOWN;
85160fd
+        }
85160fd
+    }
85160fd
+#endif
85160fd
+
85160fd
+    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
85160fd
+
85160fd
+    s->decoder_buffer_size = DECODER_BUFFSIZE * DECODER_MAX_CHANNELS;
85160fd
+    s->decoder_buffer = av_malloc(s->decoder_buffer_size);
85160fd
+    if (!s->decoder_buffer)
85160fd
+        return AVERROR(ENOMEM);
85160fd
+
85160fd
+    return 0;
85160fd
+}
85160fd
+
85160fd
+static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
85160fd
+                                int *got_frame_ptr, AVPacket *avpkt)
85160fd
+{
85160fd
+    FDKAACDecContext *s = avctx->priv_data;
85160fd
+    AVFrame *frame = data;
85160fd
+    int ret;
85160fd
+    AAC_DECODER_ERROR err;
85160fd
+    UINT valid = avpkt->size;
85160fd
+
85160fd
+    err = aacDecoder_Fill(s->handle, &avpkt->data, &avpkt->size, &valid);
85160fd
+    if (err != AAC_DEC_OK) {
85160fd
+        av_log(avctx, AV_LOG_ERROR, "aacDecoder_Fill() failed: %x\n", err);
85160fd
+        return AVERROR_INVALIDDATA;
85160fd
+    }
85160fd
+
85160fd
+    err = aacDecoder_DecodeFrame(s->handle, (INT_PCM *) s->decoder_buffer, s->decoder_buffer_size / sizeof(INT_PCM), 0);
85160fd
+    if (err == AAC_DEC_NOT_ENOUGH_BITS) {
85160fd
+        ret = avpkt->size - valid;
85160fd
+        goto end;
85160fd
+    }
85160fd
+    if (err != AAC_DEC_OK) {
85160fd
+        av_log(avctx, AV_LOG_ERROR,
85160fd
+               "aacDecoder_DecodeFrame() failed: %x\n", err);
85160fd
+        ret = AVERROR_UNKNOWN;
85160fd
+        goto end;
85160fd
+    }
85160fd
+
85160fd
+    if ((ret = get_stream_info(avctx)) < 0)
85160fd
+        goto end;
85160fd
+    frame->nb_samples = avctx->frame_size;
85160fd
+
85160fd
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
85160fd
+        goto end;
85160fd
+
85160fd
+    memcpy(frame->extended_data[0], s->decoder_buffer,
85160fd
+           avctx->channels * avctx->frame_size *
85160fd
+           av_get_bytes_per_sample(avctx->sample_fmt));
85160fd
+
85160fd
+    *got_frame_ptr = 1;
85160fd
+    ret = avpkt->size - valid;
85160fd
+
85160fd
+end:
85160fd
+    return ret;
85160fd
+}
85160fd
+
85160fd
+static av_cold void fdk_aac_decode_flush(AVCodecContext *avctx)
85160fd
+{
85160fd
+    FDKAACDecContext *s = avctx->priv_data;
85160fd
+    AAC_DECODER_ERROR err;
85160fd
+
85160fd
+    if (!s->handle)
85160fd
+        return;
85160fd
+
85160fd
+    if ((err = aacDecoder_SetParam(s->handle,
85160fd
+                                   AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
85160fd
+        av_log(avctx, AV_LOG_WARNING, "failed to clear buffer when flushing\n");
85160fd
+}
85160fd
+
85160fd
+AVCodec ff_libfdk_aac_decoder = {
85160fd
+    .name           = "libfdk_aac",
85160fd
+    .long_name      = NULL_IF_CONFIG_SMALL("Fraunhofer FDK AAC"),
85160fd
+    .type           = AVMEDIA_TYPE_AUDIO,
85160fd
+    .id             = AV_CODEC_ID_AAC,
85160fd
+    .priv_data_size = sizeof(FDKAACDecContext),
85160fd
+    .init           = fdk_aac_decode_init,
85160fd
+    .decode         = fdk_aac_decode_frame,
85160fd
+    .close          = fdk_aac_decode_close,
85160fd
+    .flush          = fdk_aac_decode_flush,
85160fd
+    .capabilities   = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
85160fd
+    .priv_class     = &fdk_aac_dec_class,
85160fd
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE |
85160fd
+                      FF_CODEC_CAP_INIT_CLEANUP,
85160fd
+    .wrapper_name   = "libfdk",
85160fd
+};
e07951b
diff -up firefox-98.0/media/ffvpx/libavcodec/moz.build.1667096 firefox-98.0/media/ffvpx/libavcodec/moz.build
e07951b
--- firefox-98.0/media/ffvpx/libavcodec/moz.build.1667096	2022-03-01 11:15:54.963398914 +0100
e07951b
+++ firefox-98.0/media/ffvpx/libavcodec/moz.build	2022-03-01 11:18:00.646453768 +0100
e07951b
@@ -123,6 +123,12 @@ if CONFIG['MOZ_LIBAV_FFT']:
e07951b
         'avfft.c',
e07951b
     ]
85160fd
 
85160fd
+if CONFIG['MOZ_FDK_AAC']:
85160fd
+    SOURCES += [
85160fd
+        'libfdk-aacdec.c',
85160fd
+    ]
85160fd
+    OS_LIBS += CONFIG['MOZ_FDK_AAC_LIBS']
85160fd
+
e07951b
 SYMBOLS_FILE = 'avcodec.symbols'
e07951b
 NoVisibilityFlags()
e07951b
 
e07951b
diff -up firefox-98.0/toolkit/moz.configure.1667096 firefox-98.0/toolkit/moz.configure
e07951b
--- firefox-98.0/toolkit/moz.configure.1667096	2022-03-01 11:15:54.881396269 +0100
e07951b
+++ firefox-98.0/toolkit/moz.configure	2022-03-01 11:15:54.963398914 +0100
e07951b
@@ -1950,6 +1950,15 @@ with only_when(compile_environment):
16e6b6b
 
16e6b6b
     set_config("MOZ_SYSTEM_PNG", True, when="--with-system-png")
85160fd
 
16e6b6b
+# FDK AAC support
16e6b6b
+# ==============================================================
85160fd
+option('--with-system-fdk-aac',
85160fd
+       help='Use system libfdk-aac (located with pkgconfig)')
85160fd
+
85160fd
+system_fdk_aac = pkg_check_modules('MOZ_FDK_AAC', 'fdk-aac',
85160fd
+                                   when='--with-system-fdk-aac')
85160fd
+
85160fd
+set_config('MOZ_FDK_AAC', depends(when=system_fdk_aac)(lambda: True))
85160fd
 
85160fd
 # FFmpeg's ffvpx configuration
85160fd
 # ==============================================================