Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Add B pyramid check when configured hevc level #3027

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ const mfxU16 LevelIdxToMfx[] =
MFX_LEVEL_HEVC_62,
};

inline mfxU16 MinRefForPyramid(mfxU16 GopRefDist, bool bField)
{
assert(GopRefDist > 0);
mfxU16 refB = (GopRefDist - 1) / 2;

for (mfxU16 x = refB; x > 2;)
{
x = (x - 1) / 2;
refB -= x;
}

return bField ? ((2 + refB)*2 +1) : (2 + refB);
}

inline mfxU16 MaxTidx(mfxU16 l) { return (LevelIdxToMfx[std::min<mfxU16>(l, MaxLidx)] >= MFX_LEVEL_HEVC_4); }

mfxU16 MfxLevel(mfxU16 l, mfxU16 t) { return LevelIdxToMfx[std::min<mfxU16>(l, MaxLidx)] | (MFX_TIER_HEVC_HIGH * !!t); }
Expand All @@ -163,14 +177,17 @@ mfxU16 HEVCEHW::Base::GetMinLevel(
, mfxU16 PicWidthInLumaSamples
, mfxU16 PicHeightInLumaSamples
, mfxU16 MinRef
, mfxU16 GopRefDist
, mfxU16 NumTileColumns
, mfxU16 NumTileRows
, mfxU32 NumSlice
, mfxU32 BufferSizeInKB
, mfxU32 MaxKbps
, mfxU16 StartLevel)
, mfxU16 StartLevel
, bool isBPyramid
, bool isField)
{
bool bInvalid = frN == 0 || frD == 0;
bool bInvalid = (frN == 0 || frD == 0 || GopRefDist == 0);
if (bInvalid)
return 0;

Expand Down Expand Up @@ -208,6 +225,7 @@ mfxU16 HEVCEHW::Base::GetMinLevel(
|| NumTileColumns > MaxTileCols
|| NumTileRows > MaxTileRows
|| NumSlice > MaxSSPP
|| (isBPyramid && MaxDpbSize < MinRefForPyramid(GopRefDist, isField))
|| bMaxTier;

bNextTier &= !bNextLevel;
Expand All @@ -224,4 +242,4 @@ mfxU16 HEVCEHW::Base::GetMinLevel(



#endif //defined(MFX_ENABLE_H265_VIDEO_ENCODE)
#endif //defined(MFX_ENABLE_H265_VIDEO_ENCODE)
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ namespace Base
, mfxU16 PicWidthInLumaSamples
, mfxU16 PicHeightInLumaSamples
, mfxU16 MinRef
, mfxU16 GopRefDist
, mfxU16 NumTileColumns
, mfxU16 NumTileRows
, mfxU32 NumSlice
, mfxU32 BufferSizeInKB
, mfxU32 MaxKbps
, mfxU16 StartLevel);
, mfxU16 StartLevel
, bool isBPyramid
, bool isField);

} //Base
} //namespace HEVCEHW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3503,12 +3503,15 @@ void Legacy::SetDefaults(
, defPar.base.GetCodedPicWidth(defPar)
, defPar.base.GetCodedPicHeight(defPar)
, par.mfx.NumRefFrame
, par.mfx.GopRefDist
, nCol
, nRow
, par.mfx.NumSlice
, BufferSizeInKB(par.mfx)
, MaxKbps(par.mfx)
, MFX_LEVEL_HEVC_1);
, MFX_LEVEL_HEVC_1
, (pCO2 && (pCO2->BRefType == MFX_B_REF_PYRAMID))
, (par.mfx.FrameInfo.PicStruct & (MFX_PICSTRUCT_FIELD_TOP | MFX_PICSTRUCT_FIELD_BOTTOM)));
};

if (pHEVC)
Expand Down Expand Up @@ -3581,6 +3584,8 @@ mfxStatus Legacy::CheckLevelConstraints(
{
MFX_CHECK(par.mfx.CodecLevel, MFX_ERR_NONE);

mfxExtCodingOption2* pCO2 = ExtBuffer::Get(par);

mfxU16 PicWidthInLumaSamples = defPar.base.GetCodedPicWidth(defPar);
mfxU16 PicHeightInLumaSamples = defPar.base.GetCodedPicHeight(defPar);
mfxU16 MinRef = defPar.base.GetNumRefFrames(defPar);
Expand All @@ -3591,6 +3596,9 @@ mfxStatus Legacy::CheckLevelConstraints(
auto tiles = defPar.base.GetNumTiles(defPar);
auto frND = defPar.base.GetFrameRate(defPar);

bool isBPyramid = (pCO2 && (pCO2->BRefType == MFX_B_REF_PYRAMID));
bool isField = (par.mfx.FrameInfo.PicStruct & (MFX_PICSTRUCT_FIELD_TOP | MFX_PICSTRUCT_FIELD_BOTTOM));

SetIf(MaxKbps
, rc != MFX_RATECONTROL_CQP && rc != MFX_RATECONTROL_ICQ
, [&]() { return defPar.base.GetMaxKbps(defPar); });
Expand All @@ -3601,12 +3609,15 @@ mfxStatus Legacy::CheckLevelConstraints(
, PicWidthInLumaSamples
, PicHeightInLumaSamples
, MinRef
, par.mfx.GopRefDist
, std::get<0>(tiles)
, std::get<1>(tiles)
, NumSlice
, BufferSizeInKB
, MaxKbps
, par.mfx.CodecLevel);
, par.mfx.CodecLevel
, isBPyramid
, isField);

MFX_CHECK(!CheckMinOrClip(par.mfx.CodecLevel, minLevel), MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);

Expand Down