Skip to content

Commit

Permalink
[AV1e/lib] Fix AV1 CQP reset buffer not enough issue (#6340)
Browse files Browse the repository at this point in the history
In most of CQP/ICQ cases, user will set BufferSizeInKB field as 0 for first Init as these two modes doesn't require VBV buffer size input.
But in reset usages, app might repeatly calls GetVideoParam and Reset for CQP/ICQ cases. And BufferSizeInKB returned from GetVideoParam() will be used in 2nd, 3rd Init...
And for temporal unit cache concerns, BufferSizeInKB (recommended bitstream buffer size) is multiplied by the number of cached frames in RAB cases.
In these cases, BufferSizeInKB might be multiplied and increased for each reset, and bitstream buffer size check might fail and returns MFX_ERR_NOT_ENOUGH_BUFFER.
This commit moves buffer size multiplication to required BufferSize calculation for CQP/ICQ, instead of multplication in GetVideoParam to fix the mentioned issue.

Co-authored-by: Xue, Maxim <[email protected]>
  • Loading branch information
gfxVPLsdm and MaximIntel authored Jan 8, 2024
1 parent 90dfeac commit e1b0327
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@ namespace Base

inline bool isValid(DpbFrame const & frame) { return IDX_INVALID != frame.Rec.Idx; }

inline bool HaveRABFrames(const mfxVideoParam& par)
{
return par.mfx.GopPicSize > 2 && par.mfx.GopRefDist > 1;
}

inline std::tuple<mfxU32, mfxU32> GetRealResolution(const mfxVideoParam& vp)
{
const mfxExtAV1ResolutionParam* pRsPar = ExtBuffer::Get(vp);
Expand Down Expand Up @@ -1235,6 +1240,7 @@ namespace Base
TChain<mfxU16> GetNumTemporalLayers;
TChain<mfxU8> GetNumReorderFrames;
TChain<bool> GetNonStdReordering;
TChain<mfxU32> GetTemporalUnitCacheSize;
TChain<std::tuple<mfxU16, mfxU16, mfxU16>> GetMaxNumRef;
TChain<std::tuple<mfxU32, mfxU32>> GetFrameRate;
TChain<std::tuple<mfxU16, mfxU16, mfxU16>> GetQPMFX; //I,P,B
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1715,11 +1715,10 @@ void General::GetVideoParam(const FeatureBlocks& blocks, TPushGVP Push)
, [this, &blocks](mfxVideoParam& out, StorageR& global) -> mfxStatus
{
out.mfx.LowPower = MFX_CODINGOPTION_ON;
if (HaveRABFrames(out))
if (out.mfx.RateControlMethod == MFX_RATECONTROL_CBR || out.mfx.RateControlMethod == MFX_RATECONTROL_VBR)
{
auto defPar = GetRTDefaults(global);
const mfxU32 numCacheFrames = (defPar.base.GetBRefType(defPar) != MFX_B_REF_PYRAMID) ? mfxU32(2)
: mfxU32(defPar.base.GetNumBPyramidLayers(defPar)) + 1;
const mfxU32 numCacheFrames = defPar.base.GetTemporalUnitCacheSize(defPar);
BufferSizeInKB(out.mfx) = BufferSizeInKB(out.mfx) * numCacheFrames;
}

Expand Down Expand Up @@ -2891,7 +2890,7 @@ void SetDefaultGOP(
SetIf(pCO3->PRefType, !pCO3->PRefType, [&]() { return defPar.base.GetPRefType(defPar); });

// change default to LDB when RAB
if (General::HaveRABFrames(par))
if (HaveRABFrames(par))
SetDefault<mfxU16>(pCO3->GPB, MFX_CODINGOPTION_ON);
else
SetDefault<mfxU16>(pCO3->GPB, MFX_CODINGOPTION_OFF);
Expand Down Expand Up @@ -3155,12 +3154,13 @@ mfxU32 CheckBufferSizeInKB(mfxVideoParam& par, const Defaults::Param& defPar)
if (!par.mfx.BufferSizeInKB)
return changed;

mfxU32 minSizeInKB = 0;
const bool bCqpOrIcq = par.mfx.RateControlMethod == MFX_RATECONTROL_CQP
mfxU32 minSizeInKB = 0;
const bool bCqpOrIcq = par.mfx.RateControlMethod == MFX_RATECONTROL_CQP
|| par.mfx.RateControlMethod == MFX_RATECONTROL_ICQ;
if (bCqpOrIcq)
{
minSizeInKB = General::GetRawBytes(defPar) / 1000;
const mfxU32 numCacheFrames = defPar.base.GetTemporalUnitCacheSize(defPar);
minSizeInKB = General::GetRawBytes(defPar) / 1000 * numCacheFrames;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 Intel Corporation
// Copyright (c) 2019-2023 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -218,10 +218,6 @@ namespace Base
TTaskIt ReorderWrap(const ExtBuffer::Param<mfxVideoParam> & par, TTaskIt begin, TTaskIt end, bool flush);
static mfxU32 GetRawBytes(const Defaults::Param& par);
static bool IsInVideoMem(const mfxVideoParam& par);
static bool HaveRABFrames(const mfxVideoParam& par)
{
return par.mfx.GopPicSize > 2 && par.mfx.GopRefDist > 1;
}

mfxU16 GetMaxRaw(const mfxVideoParam& par)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ class GetDefault
auto GetFromMaxKbps = [&]() { return defPar.base.GetMaxKbps(defPar) / 4; };
auto GetFromRawBytes = [&]()
{
return General::GetRawBytes(defPar) / 1000;
const mfxU32 numCacheFrames = defPar.base.GetTemporalUnitCacheSize(defPar);
return General::GetRawBytes(defPar) / 1000 * numCacheFrames;
};

SetIf(defaultSize, bUseMaxKbps, GetFromMaxKbps);
Expand Down Expand Up @@ -669,6 +670,20 @@ class GetDefault
&& par.mvp.mfx.NumRefFrame > 2;
}

static mfxU32 TemporalUnitCacheSize(
Defaults::TChain<mfxU32>::TExt
, const Defaults::Param& par)
{
mfxU32 numCacheFrames = 1;
if (HaveRABFrames(par.mvp))
{
numCacheFrames = (par.base.GetBRefType(par) != MFX_B_REF_PYRAMID) ? mfxU32(2)
: mfxU32(par.base.GetNumBPyramidLayers(par)) + 1;
}

return numCacheFrames;
}

static mfxU16 FrameType(
Defaults::TGetFrameType::TExt
, const Defaults::Param& par
Expand Down Expand Up @@ -953,6 +968,7 @@ class GetDefault
PUSH_DEFAULT(PreReorderInfo);
PUSH_DEFAULT(NumReorderFrames);
PUSH_DEFAULT(NonStdReordering);
PUSH_DEFAULT(TemporalUnitCacheSize);
PUSH_DEFAULT(LoopFilterLevels);
PUSH_DEFAULT(CDEF);
PUSH_DEFAULT(MBBRC);
Expand Down

0 comments on commit e1b0327

Please sign in to comment.