Skip to content

Commit

Permalink
Update the parameter naming (#6421)
Browse files Browse the repository at this point in the history
Co-authored-by: minjian <[email protected]>
  • Loading branch information
gfxVPLsdm and LesterMinGSE authored Jan 15, 2024
1 parent fbd41a4 commit 7bc1f13
Showing 1 changed file with 64 additions and 35 deletions.
99 changes: 64 additions & 35 deletions _studio/mfx_lib/encode_hw/av1/agnostic/base/av1ehw_base_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void General::SetSupported(ParamSupport& blocks)
auto& buf_dst = *(mfxExtCodingOption2*)pDst;

MFX_COPY_FIELD(BRefType);
MFX_COPY_FIELD(MinQPI);
MFX_COPY_FIELD(MinQPP);
MFX_COPY_FIELD(MinQPB);
MFX_COPY_FIELD(MaxQPI);
MFX_COPY_FIELD(MaxQPP);
MFX_COPY_FIELD(MaxQPB);
});

blocks.m_ebCopySupported[MFX_EXTBUFF_ENCODER_RESET_OPTION].emplace_back(
Expand Down Expand Up @@ -365,6 +371,12 @@ void General::SetInherited(ParamInheritance& par)
{
INIT_EB(mfxExtCodingOption2);
INHERIT_OPT(BRefType);
INHERIT_OPT(MinQPI);
INHERIT_OPT(MinQPP);
INHERIT_OPT(MinQPB);
INHERIT_OPT(MaxQPI);
INHERIT_OPT(MaxQPP);
INHERIT_OPT(MaxQPB);
});

par.m_ebInheritDefault[MFX_EXTBUFF_CODING_OPTION3].emplace_back(
Expand Down Expand Up @@ -2052,9 +2064,22 @@ inline void SetTaskBRCParams(
if(par.mfx.RateControlMethod == MFX_RATECONTROL_CQP)
return;

const mfxExtAV1AuxData& auxPar = ExtBuffer::Get(par);
task.MinBaseQIndex = auxPar.QP.MinBaseQIndex;
task.MaxBaseQIndex = auxPar.QP.MaxBaseQIndex;
const mfxExtCodingOption2& CO2 = ExtBuffer::Get(par);
if (task.FrameType & MFX_FRAMETYPE_I)
{
task.MinBaseQIndex = CO2.MinQPI;
task.MaxBaseQIndex = CO2.MaxQPI;
}
else if (task.FrameType & MFX_FRAMETYPE_P)
{
task.MinBaseQIndex = CO2.MinQPP;
task.MaxBaseQIndex = CO2.MaxQPP;
}
else if (task.FrameType & MFX_FRAMETYPE_B)
{
task.MinBaseQIndex = CO2.MinQPB;
task.MaxBaseQIndex = CO2.MaxQPB;
}
}

inline void SetTaskEncodeOrders(
Expand Down Expand Up @@ -2940,11 +2965,14 @@ void SetDefaultBRC(
SetDefault<mfxU16>(par.mfx.ICQQuality, 26);
}

mfxExtAV1AuxData* pAuxPar = ExtBuffer::Get(par);
if (pAuxPar && par.mfx.RateControlMethod != MFX_RATECONTROL_CQP)
if (pCO2 && par.mfx.RateControlMethod != MFX_RATECONTROL_CQP)
{
SetDefault(pAuxPar->QP.MinBaseQIndex, AV1_MIN_Q_INDEX);
SetDefault(pAuxPar->QP.MaxBaseQIndex, AV1_MAX_Q_INDEX);
SetDefault(pCO2->MinQPI, AV1_MIN_Q_INDEX);
SetDefault(pCO2->MinQPP, AV1_MIN_Q_INDEX);
SetDefault(pCO2->MinQPB, AV1_MIN_Q_INDEX);
SetDefault(pCO2->MaxQPI, AV1_MAX_Q_INDEX);
SetDefault(pCO2->MaxQPP, AV1_MAX_Q_INDEX);
SetDefault(pCO2->MaxQPB, AV1_MAX_Q_INDEX);
}

if (pCO3)
Expand Down Expand Up @@ -3180,14 +3208,15 @@ mfxU32 CheckBufferSizeInKB(mfxVideoParam& par, const Defaults::Param& defPar)
return changed;
}

inline mfxU32 CheckAndFixQP(mfxU16& qp, const mfxU16 minQP, const mfxU16 maxQP)
template<class T, class U>
inline mfxU32 CheckAndFixQP(T& qp, const U minQP, const U maxQP)
{
mfxU32 changed = 0;

if (qp)
{
changed += CheckMinOrClip<mfxU16>(qp, minQP);
changed += CheckMaxOrClip<mfxU16>(qp, maxQP);
changed += CheckMinOrClip<T, U>(qp, minQP);
changed += CheckMaxOrClip<T, U>(qp, maxQP);
}

return changed;
Expand Down Expand Up @@ -3240,12 +3269,31 @@ mfxStatus General::CheckRateControl(
mfxExtCodingOption2* pCO2 = ExtBuffer::Get(par);
if (pCO2)
{
changed += CheckOrZero<mfxU8>(pCO2->MinQPI, 0, minQP);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPI, 0, maxQP);
changed += CheckOrZero<mfxU8>(pCO2->MinQPP, 0, minQP);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPP, 0, maxQP);
changed += CheckOrZero<mfxU8>(pCO2->MinQPB, 0, minQP);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPB, 0, maxQP);
// some apps would only set MinQP or MaxQP
bool bInvalid = (pCO2->MaxQPI && pCO2->MinQPI && pCO2->MaxQPI < pCO2->MinQPI)
|| (pCO2->MaxQPP && pCO2->MinQPP && pCO2->MaxQPP < pCO2->MinQPP)
|| (pCO2->MaxQPB && pCO2->MinQPB && pCO2->MaxQPB < pCO2->MinQPB);

MFX_CHECK(!bInvalid, MFX_ERR_INVALID_VIDEO_PARAM);

if (bCQP)
{
changed += CheckOrZero<mfxU8>(pCO2->MinQPI, 0);
changed += CheckOrZero<mfxU8>(pCO2->MinQPP, 0);
changed += CheckOrZero<mfxU8>(pCO2->MinQPB, 0);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPI, 0);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPP, 0);
changed += CheckOrZero<mfxU8>(pCO2->MaxQPB, 0);
}
else
{
changed += CheckAndFixQP(pCO2->MinQPI, minQP, maxQP);
changed += CheckAndFixQP(pCO2->MinQPP, minQP, maxQP);
changed += CheckAndFixQP(pCO2->MinQPB, minQP, maxQP);
changed += CheckAndFixQP(pCO2->MaxQPI, minQP, maxQP);
changed += CheckAndFixQP(pCO2->MaxQPP, minQP, maxQP);
changed += CheckAndFixQP(pCO2->MaxQPB, minQP, maxQP);
}
}

mfxExtCodingOption3* pCO3 = ExtBuffer::Get(par);
Expand Down Expand Up @@ -3277,25 +3325,6 @@ mfxStatus General::CheckRateControl(
changed += !!std::count_if(std::begin(pCO3->QPOffset), std::end(pCO3->QPOffset), CheckQPOffset);
}

mfxExtAV1AuxData* pAuxPar = ExtBuffer::Get(par);
if (pAuxPar)
{
if (bCQP)
{
changed += CheckOrZero<mfxU8>(pAuxPar->QP.MinBaseQIndex, 0);
changed += CheckOrZero<mfxU8>(pAuxPar->QP.MaxBaseQIndex, 0);
}
else
{
if (pAuxPar->QP.MinBaseQIndex || pAuxPar->QP.MaxBaseQIndex)
{
changed += CheckRangeOrClip(pAuxPar->QP.MinBaseQIndex, minQP, maxQP);
changed += CheckRangeOrClip(pAuxPar->QP.MaxBaseQIndex, minQP, maxQP);
changed += CheckMaxOrClip(pAuxPar->QP.MinBaseQIndex, pAuxPar->QP.MaxBaseQIndex);
}
}
}

MFX_CHECK(!changed, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);

return MFX_ERR_NONE;
Expand Down

0 comments on commit 7bc1f13

Please sign in to comment.