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

Commit ab1d9925 authored by Fyodor Kyslov's avatar Fyodor Kyslov Committed by Android (Google) Code Review
Browse files

Merge "av1encoder: Implment CQ bitrate control mode"

parents f22e7387 58d8dea8
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -64,7 +64,8 @@ C2SoftAomEnc::IntfImpl::IntfImpl(const std::shared_ptr<C2ReflectorHelper>& helpe
                                 0u, C2Config::BITRATE_VARIABLE))
                         .withFields({C2F(mBitrateMode, value)
                                              .oneOf({C2Config::BITRATE_CONST,
                                                      C2Config::BITRATE_VARIABLE})})
                                                      C2Config::BITRATE_VARIABLE,
                                                      C2Config::BITRATE_IGNORE})})
                         .withSetter(Setter<decltype(*mBitrateMode)>::StrictValueWithNoDeps)
                         .build());

@@ -87,6 +88,12 @@ C2SoftAomEnc::IntfImpl::IntfImpl(const std::shared_ptr<C2ReflectorHelper>& helpe
                         .withSetter(BitrateSetter)
                         .build());

    addParameter(DefineParam(mQuality, C2_PARAMKEY_QUALITY)
                         .withDefault(new C2StreamQualityTuning::output(0u, 80))
                         .withFields({C2F(mQuality, value).inRange(0, 100)})
                         .withSetter(Setter<decltype(*mQuality)>::NonStrictValueWithNoDeps)
                         .build());

    addParameter(DefineParam(mIntraRefresh, C2_PARAMKEY_INTRA_REFRESH)
                         .withConstValue(new C2StreamIntraRefreshTuning::output(
                                 0u, C2Config::INTRA_REFRESH_DISABLED, 0.))
@@ -293,6 +300,12 @@ c2_status_t C2SoftAomEnc::onFlush_sm() {
    return onStop();
}

// c2Quality is in range of 0-100 (the more - the better),
// for AOM quality we are using a range of 15-50 (the less - the better)
static int MapC2QualityToAOMQuality (int c2Quality) {
    return 15 + 35 * (100 - c2Quality) / 100;
}

aom_codec_err_t C2SoftAomEnc::setupCodecParameters() {
    aom_codec_err_t codec_return = AOM_CODEC_OK;

@@ -391,6 +404,15 @@ aom_codec_err_t C2SoftAomEnc::setupCodecParameters() {
    codec_return = aom_codec_control(mCodecContext, AV1E_SET_MAX_REFERENCE_FRAMES, 3);
    if (codec_return != AOM_CODEC_OK) goto BailOut;

    if (mBitrateControlMode == AOM_Q) {
        const int aomCQLevel = MapC2QualityToAOMQuality(mQuality->value);
        ALOGV("Set Q from %d to CQL %d",
              mQuality->value, aomCQLevel);

        codec_return = aom_codec_control(mCodecContext, AOME_SET_CQ_LEVEL, aomCQLevel);
        if (codec_return != AOM_CODEC_OK) goto BailOut;
    }

    ColorAspects sfAspects;
    if (!C2Mapper::map(mColorAspects->primaries, &sfAspects.mPrimaries)) {
        sfAspects.mPrimaries = android::ColorAspects::PrimariesUnspecified;
@@ -438,6 +460,7 @@ status_t C2SoftAomEnc::initEncoder() {
        mIntraRefresh = mIntf->getIntraRefresh_l();
        mRequestSync = mIntf->getRequestSync_l();
        mColorAspects = mIntf->getCodedColorAspects_l();
        mQuality = mIntf->getQuality_l();
    }


@@ -445,6 +468,9 @@ status_t C2SoftAomEnc::initEncoder() {
        case C2Config::BITRATE_CONST:
            mBitrateControlMode = AOM_CBR;
            break;
        case C2Config::BITRATE_IGNORE:
            mBitrateControlMode = AOM_Q;
            break;
        case C2Config::BITRATE_VARIABLE:
            [[fallthrough]];
        default:
@@ -484,7 +510,7 @@ status_t C2SoftAomEnc::initEncoder() {
    mCodecConfiguration->g_timebase.den = 1000000;
    // rc_target_bitrate is in kbps, mBitrate in bps
    mCodecConfiguration->rc_target_bitrate = (mBitrate->value + 500) / 1000;
    mCodecConfiguration->rc_end_usage = AOM_CBR;
    mCodecConfiguration->rc_end_usage = mBitrateControlMode == AOM_Q ? AOM_Q : AOM_CBR;
    // Disable frame drop - not allowed in MediaCodec now.
    mCodecConfiguration->rc_dropframe_thresh = 0;
    // Disable lagged encoding.
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ struct C2SoftAomEnc : public SimpleC2Component {
    std::shared_ptr<C2StreamIntraRefreshTuning::output> mIntraRefresh;
    std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamQualityTuning::output> mQuality;
    std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
    std::shared_ptr<C2StreamRequestSyncFrameTuning::output> mRequestSync;
    std::shared_ptr<C2StreamColorAspectsInfo::output> mColorAspects;
@@ -127,6 +128,7 @@ class C2SoftAomEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
    }
    std::shared_ptr<C2StreamFrameRateInfo::output> getFrameRate_l() const { return mFrameRate; }
    std::shared_ptr<C2StreamBitrateInfo::output> getBitrate_l() const { return mBitrate; }
    std::shared_ptr<C2StreamQualityTuning::output> getQuality_l() const { return mQuality; }
    std::shared_ptr<C2StreamBitrateModeTuning::output> getBitrateMode_l() const {
        return mBitrateMode;
    }
@@ -152,6 +154,7 @@ class C2SoftAomEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
    std::shared_ptr<C2StreamRequestSyncFrameTuning::output> mRequestSync;
    std::shared_ptr<C2StreamSyncFrameIntervalTuning::output> mSyncFramePeriod;
    std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
    std::shared_ptr<C2StreamQualityTuning::output> mQuality;
    std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
    std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
    std::shared_ptr<C2StreamColorAspectsInfo::input> mColorAspects;
+2 −1
Original line number Diff line number Diff line
@@ -124,7 +124,8 @@
            <Limit name="block-size" value="16x16" />
            <Limit name="block-count" range="1-3600" />
            <Limit name="bitrate" range="1-40000000" />
            <Feature name="bitrate-modes" value="VBR,CBR" />
            <Limit name="quality" range="0-100"  default="80" />
            <Feature name="bitrate-modes" value="VBR,CBR,CQ" />
        </MediaCodec>
    </Encoders>
</Included>
+2 −1
Original line number Diff line number Diff line
@@ -357,7 +357,8 @@
            <Limit name="block-size" value="16x16" />
            <Limit name="block-count" range="1-8200" />
            <Limit name="bitrate" range="1-40000000" />
            <Feature name="bitrate-modes" value="VBR,CBR" />
            <Limit name="quality" range="0-100"  default="80" />
            <Feature name="bitrate-modes" value="VBR,CBR,CQ" />
            <Attribute name="software-codec" />
        </MediaCodec>
    </Encoders>