Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b936ccc authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AAC decoder: implement support for output loudness query

Bug: 148385721
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: If0bdae0ecc3f8d396b3522aa9abf0620b3dddc7a
parent 41ce3372
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#define DRC_DEFAULT_MOBILE_DRC_BOOST 1.0 /* maximum compression of dynamic range for mobile conf */
#define DRC_DEFAULT_MOBILE_DRC_HEAVY C2Config::DRC_COMPRESSION_HEAVY   /* switch for heavy compression for mobile conf */
#define DRC_DEFAULT_MOBILE_DRC_EFFECT 3  /* MPEG-D DRC effect type; 3 => Limited playback range */
#define DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS (0.25) /* decoder output loudness; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
#define DRC_DEFAULT_MOBILE_ENC_LEVEL (0.25) /* encoder target level; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
#define MAX_CHANNEL_COUNT            8  /* maximum number of audio channels that can be decoded */
// names of properties that can be used to override the default DRC settings
@@ -190,6 +191,13 @@ public:
                })
                .withSetter(Setter<decltype(*mDrcEffectType)>::StrictValueWithNoDeps)
                .build());

        addParameter(
                DefineParam(mDrcOutputLoudness, C2_PARAMKEY_DRC_OUTPUT_LOUDNESS)
                .withDefault(new C2StreamDrcOutputLoudnessTuning::output(0u, DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS))
                .withFields({C2F(mDrcOutputLoudness, value).inRange(-57.75, 0.25)})
                .withSetter(Setter<decltype(*mDrcOutputLoudness)>::StrictValueWithNoDeps)
                .build());
    }

    bool isAdts() const { return mAacFormat->value == C2Config::AAC_PACKAGING_ADTS; }
@@ -204,6 +212,7 @@ public:
    int32_t getDrcBoostFactor() const { return mDrcBoostFactor->value * 127. + 0.5; }
    int32_t getDrcAttenuationFactor() const { return mDrcAttenuationFactor->value * 127. + 0.5; }
    int32_t getDrcEffectType() const { return mDrcEffectType->value; }
    int32_t getDrcOutputLoudness() const { return (mDrcOutputLoudness->value <= 0 ? -mDrcOutputLoudness->value * 4. + 0.5 : -1); }

private:
    std::shared_ptr<C2StreamSampleRateInfo::output> mSampleRate;
@@ -218,6 +227,7 @@ private:
    std::shared_ptr<C2StreamDrcBoostFactorTuning::input> mDrcBoostFactor;
    std::shared_ptr<C2StreamDrcAttenuationFactorTuning::input> mDrcAttenuationFactor;
    std::shared_ptr<C2StreamDrcEffectTypeTuning::input> mDrcEffectType;
    std::shared_ptr<C2StreamDrcOutputLoudnessTuning::output> mDrcOutputLoudness;
    // TODO Add : C2StreamAacSbrModeTuning
};

@@ -632,6 +642,7 @@ void C2SoftAacDec::process(

        INT prevSampleRate = mStreamInfo->sampleRate;
        INT prevNumChannels = mStreamInfo->numChannels;
        INT prevOutLoudness = mStreamInfo->outputLoudness;

        aacDecoder_Fill(mAACDecoder,
                        inBuffer,
@@ -795,6 +806,23 @@ void C2SoftAacDec::process(
                }
            }
            ALOGV("size = %zu", size);

            if (mStreamInfo->outputLoudness != prevOutLoudness) {
                C2StreamDrcOutputLoudnessTuning::output
                        drcOutLoudness(0u, (float) (mStreamInfo->outputLoudness*-0.25));

                std::vector<std::unique_ptr<C2SettingResult>> failures;
                c2_status_t err = mIntf->config(
                                    { &drcOutLoudness },
                                    C2_MAY_BLOCK,
                                    &failures);
                if (err == OK) {
                    work->worklets.front()->output.configUpdate.push_back(
                        C2Param::Copy(drcOutLoudness));
                } else {
                    ALOGE("Getting output loudness failed");
                }
            }
        } while (decoderErr == AAC_DEC_OK);
    }

+9 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ struct C2Config {
    enum bitrate_mode_t : uint32_t;         ///< bitrate control mode
    enum drc_compression_mode_t : int32_t;  ///< DRC compression mode
    enum drc_effect_type_t : int32_t;       ///< DRC effect type
    enum drc_output_loudness : int32_t;     ///< DRC output loudness
    enum intra_refresh_mode_t : uint32_t;   ///< intra refresh modes
    enum level_t : uint32_t;                ///< coding level
    enum ordinal_key_t : uint32_t;          ///< work ordering keys
@@ -218,6 +219,7 @@ enum C2ParamIndexKind : C2Param::type_index_t {
    kParamIndexDrcBoostFactor, // drc, float (0-1)
    kParamIndexDrcAttenuationFactor, // drc, float (0-1)
    kParamIndexDrcEffectType, // drc, enum
    kParamIndexDrcOutputLoudness, // drc, float (dBFS)

    /* ============================== platform-defined parameters ============================== */

@@ -1941,6 +1943,13 @@ typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::drc_effect_type_t>,
        C2StreamDrcEffectTypeTuning;
constexpr char C2_PARAMKEY_DRC_EFFECT_TYPE[] = "coding.drc.effect-type";

/**
 * DRC output loudness in dBFS. Retrieved during decoding
 */
 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcOutputLoudness>
        C2StreamDrcOutputLoudnessTuning;
 constexpr char C2_PARAMKEY_DRC_OUTPUT_LOUDNESS[] = "output.drc.output-loudness";

/* --------------------------------------- AAC components --------------------------------------- */

/**
+17 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#define DRC_DEFAULT_MOBILE_DRC_BOOST 127 /* maximum compression of dynamic range for mobile conf */
#define DRC_DEFAULT_MOBILE_DRC_HEAVY 1   /* switch for heavy compression for mobile conf */
#define DRC_DEFAULT_MOBILE_DRC_EFFECT 3  /* MPEG-D DRC effect type; 3 => Limited playback range */
#define DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS -1 /* decoder output loudness; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
#define DRC_DEFAULT_MOBILE_ENC_LEVEL (-1) /* encoder target level; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
// names of properties that can be used to override the default DRC settings
#define PROP_DRC_OVERRIDE_REF_LEVEL  "aac_drc_reference_level"
@@ -814,6 +815,22 @@ void CCodecConfig::initializeStandardParams() {
            }
        }));

    add(ConfigMapper(KEY_AAC_DRC_OUTPUT_LOUDNESS, C2_PARAMKEY_DRC_OUTPUT_LOUDNESS, "value")
        .limitTo(D::OUTPUT & D::DECODER & D::READ)
        .withMappers([](C2Value v) -> C2Value {
            int32_t value;
            if (!v.get(&value) || value < -1) {
                value = DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS;
            }
            return float(-0.25 * c2_min(value, 127));
        },[](C2Value v) -> C2Value {
            float value;
            if (v.get(&value)) {
                return (int32_t) (-4. * value);
            }
            return C2Value();
        }));

    add(ConfigMapper(KEY_AAC_MAX_OUTPUT_CHANNEL_COUNT, C2_PARAMKEY_MAX_CHANNEL_COUNT, "value")
        .limitTo(D::AUDIO & (D::CONFIG | D::PARAM | D::READ)));

+5 −0
Original line number Diff line number Diff line
@@ -2187,6 +2187,10 @@ status_t ACodec::configureCodec(
                // value is unknown
                drc.effectType = -2; // valid values are -1 and over
            }
            if (!msg->findInt32("aac-drc-output-loudness", &drc.outputLoudness)) {
                // value is unknown
                drc.outputLoudness = -1;
            }

            err = setupAACCodec(
                    encoder, numChannels, sampleRate, bitrate, aacProfile,
@@ -2876,6 +2880,7 @@ status_t ACodec::setupAACCodec(
    presentation.nEncodedTargetLevel = drc.encodedTargetLevel;
    presentation.nPCMLimiterEnable = pcmLimiterEnable;
    presentation.nDrcEffectType = drc.effectType;
    presentation.nDrcOutputLoudness = drc.outputLoudness;

    status_t res = mOMXNode->setParameter(
            OMX_IndexParamAudioAac, &profile, sizeof(profile));
+1 −0
Original line number Diff line number Diff line
@@ -476,6 +476,7 @@ private:
        int32_t targetRefLevel;
        int32_t encodedTargetLevel;
        int32_t effectType;
        int32_t outputLoudness;
    } drcParams_t;

    status_t setupAACCodec(
Loading