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

Commit

Permalink
[AVCe] Fix for SW BRC Reset, LA Bpyr is on
Browse files Browse the repository at this point in the history
  • Loading branch information
ogolikov authored and dvrogozh committed Feb 5, 2019
1 parent 838c2bb commit 10d5482
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 51 deletions.
95 changes: 74 additions & 21 deletions _studio/mfx_lib/encode_hw/h264/src/mfx_h264_encode_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,65 @@ void ImplementationAvc::DestroyDanglingCmResources()
}
}
}
/*Class for modifying and restoring VideoParams.
Needed for initialization some components */
class ModifiedVideoParams
{
public:
ModifiedVideoParams() :
m_bInit(false),
m_RateControlMethod(0),
m_LookAheadDepth(0),
m_MaxKbps(0)
{}
void ModifyForDDI(MfxVideoParam & par, bool bSWBRC)
{
if (!bSWBRC)
return;
if (!m_bInit)
SaveParams(par);
// in the case of SWBRC driver works in CQP mode
par.mfx.RateControlMethod = MFX_RATECONTROL_CQP;
}
void ModifyForBRC(MfxVideoParam & par, bool bSWBRC)
{
mfxExtCodingOption2 & extOpt2 = GetExtBufferRef(par);
if (!(bSWBRC && extOpt2.MaxSliceSize))
return;
if (!m_bInit)
SaveParams(par);
// int the case of MaxSliceSize BRC works in VBR mode (instead LA)
par.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
par.mfx.MaxKbps = par.mfx.TargetKbps * 2;
extOpt2.LookAheadDepth = 0;
}
void Restore(MfxVideoParam & par)
{
if (!m_bInit)
return;
mfxExtCodingOption2 & extOpt2 = GetExtBufferRef(par);
par.mfx.RateControlMethod = m_RateControlMethod;
par.mfx.MaxKbps = m_MaxKbps;
extOpt2.LookAheadDepth = m_LookAheadDepth;
m_bInit = false;
}

private:
bool m_bInit;
mfxU16 m_RateControlMethod;
mfxU16 m_LookAheadDepth;
mfxU16 m_MaxKbps;

protected:
void SaveParams(MfxVideoParam & par)
{
mfxExtCodingOption2 & extOpt2 = GetExtBufferRef(par);
m_RateControlMethod = par.mfx.RateControlMethod;
m_LookAheadDepth= extOpt2.LookAheadDepth;
m_MaxKbps = par.mfx.MaxKbps;
m_bInit = true;
}
};

mfxStatus ImplementationAvc::Init(mfxVideoParam * par)
{
Expand Down Expand Up @@ -812,28 +871,16 @@ mfxStatus ImplementationAvc::Init(mfxVideoParam * par)
if (m_enabledSwBrc)
{
m_brc.SetImpl(CreateBrc(m_video));
mfxU16 storedRateControlMethod = m_video.mfx.RateControlMethod;
mfxU16 storedLookAheadDepth = extOpt2.LookAheadDepth;
mfxU16 storedMaxKbps = m_video.mfx.MaxKbps;

if (extOpt2.MaxSliceSize)
{
m_video.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
m_video.mfx.MaxKbps = m_video.mfx.TargetKbps*2;
extOpt2.LookAheadDepth = 0;
}
// to change m_video before BRC Init and DDI init
ModifiedVideoParams mod_params;
mod_params.ModifyForBRC(m_video, true);
m_brc.Init(m_video);
if (extOpt2.MaxSliceSize)
{
m_video.mfx.RateControlMethod = MFX_RATECONTROL_VBR;
m_video.mfx.MaxKbps = storedMaxKbps;
extOpt2.LookAheadDepth = storedLookAheadDepth;
}
m_video.mfx.RateControlMethod = MFX_RATECONTROL_CQP;
mod_params.Restore(m_video);
mod_params.ModifyForDDI(m_video, true);
sts = m_ddi->CreateAccelerationService(m_video);
if (sts != MFX_ERR_NONE)
return MFX_WRN_PARTIAL_ACCELERATION;
m_video.mfx.RateControlMethod = storedRateControlMethod;
mod_params.Restore(m_video);
}
else
{
Expand Down Expand Up @@ -1402,7 +1449,11 @@ mfxStatus ImplementationAvc::Reset(mfxVideoParam *par)
m_emulatorForAsyncPart = m_emulatorForSyncPart;

m_hrd.Reset(newPar);
// to change m_video before DDI Reset
ModifiedVideoParams mod_par;
mod_par.ModifyForDDI(newPar, m_enabledSwBrc);
m_ddi->Reset(newPar);
mod_par.Restore(newPar);

m_1stFieldStatus = MFX_ERR_NONE;
m_fieldCounter = 0;
Expand Down Expand Up @@ -1507,15 +1558,17 @@ mfxStatus ImplementationAvc::Reset(mfxVideoParam *par)
}
m_video = newPar;

if (IsOn(extOpt2New.ExtBRC))
if (m_enabledSwBrc)
{
mfxExtEncoderResetOption & resetOption = GetExtBufferRef(newPar);
if (isIdrRequired)
{
resetOption.StartNewSequence = true;
mfxExtEncoderResetOption & resetOption = GetExtBufferRef(newPar);
resetOption.StartNewSequence = MFX_CODINGOPTION_ON;
}
mod_par.ModifyForBRC(newPar, true);
sts = m_brc.Reset(newPar);
MFX_CHECK_STS(sts);
mod_par.Restore(newPar);
}
return checkStatus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2523,11 +2523,13 @@ mfxStatus MfxHwH264Encode::CodeAsSkipFrame( VideoCORE & core,
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
}
if (task.GetFrameType() & MFX_FRAMETYPE_P)
else
{
DpbFrame& refFrame = task.m_dpb[0][task.m_list0[0][0] & 127];
mfxI32 fid = task.m_fid[0];
MFX_CHECK(task.m_list0[fid].Size(), MFX_ERR_UNDEFINED_BEHAVIOR);
DpbFrame& refFrame = task.m_dpb[0][task.m_list0[fid][0] & 127];
mfxFrameData curr = {};
mfxFrameData ref = {};
mfxFrameData ref = {};
curr.MemId = task.m_midRaw;
ref.MemId = refFrame.m_midRec;

Expand All @@ -2536,10 +2538,6 @@ mfxStatus MfxHwH264Encode::CodeAsSkipFrame( VideoCORE & core,
sts = core.DoFastCopyWrapper(&surfDst,MFX_MEMTYPE_INTERNAL_FRAME|MFX_MEMTYPE_DXVA2_DECODER_TARGET|MFX_MEMTYPE_FROM_ENCODE, &surfSrc, MFX_MEMTYPE_INTERNAL_FRAME|MFX_MEMTYPE_DXVA2_DECODER_TARGET|MFX_MEMTYPE_FROM_ENCODE);

}
if (task.GetFrameType() & MFX_FRAMETYPE_B)
{
task.m_ctrl.SkipFrame = 1;
}

return sts;
}
Expand Down
29 changes: 6 additions & 23 deletions _studio/mfx_lib/shared/src/mfx_h264_enc_common_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4466,7 +4466,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike(

if (!CheckRangeDflt(extOpt2->SkipFrame, 0, 3, 0)) changed = true;

if ( extOpt2->SkipFrame && hwCaps.SkipFrame == 0 && par.mfx.RateControlMethod != MFX_RATECONTROL_CQP && par.mfx.RateControlMethod != MFX_RATECONTROL_LA_HRD)
if ( extOpt2->SkipFrame && hwCaps.SkipFrame == 0 && par.mfx.RateControlMethod != MFX_RATECONTROL_CQP)
{
extOpt2->SkipFrame = 0;
changed = true;
Expand Down Expand Up @@ -4572,19 +4572,7 @@ mfxStatus MfxHwH264Encode::CheckVideoParamQueryLike(
if (!CheckRangeDflt(extOpt2->MinQPP, 0, (extOpt2->MaxQPP ? extOpt2->MaxQPP : 51), 0)) changed = true;
if (!CheckRangeDflt(extOpt2->MinQPB, 0, (extOpt2->MaxQPB ? extOpt2->MaxQPB : 51), 0)) changed = true;
}
if ((extOpt3->WinBRCSize > 0 && (par.mfx.RateControlMethod != MFX_RATECONTROL_VBR && par.mfx.RateControlMethod != MFX_RATECONTROL_QVBR)) || (par.mfx.RateControlMethod == MFX_RATECONTROL_LA_HRD))
{
if (extOpt2->SkipFrame!=0 && extOpt2->SkipFrame != MFX_SKIPFRAME_INSERT_DUMMY)
{
extOpt2->SkipFrame = MFX_SKIPFRAME_INSERT_DUMMY;
changed = true;
}
if (extOpt2->BRefType != MFX_B_REF_OFF && extOpt2->BRefType != 0)
{
extOpt2->BRefType = MFX_B_REF_OFF;
changed = true;
}
}

if (!CheckTriStateOption(extOpt3->BRCPanicMode)) changed = true;
if (IsOff(extOpt3->BRCPanicMode)
&& (bRateControlLA(par.mfx.RateControlMethod)
Expand Down Expand Up @@ -5502,10 +5490,6 @@ void MfxHwH264Encode::SetDefaults(
}
}

if ((!extOpt2->SkipFrame) && ((extOpt3->WinBRCSize > 0 && (par.mfx.RateControlMethod != MFX_RATECONTROL_VBR && par.mfx.RateControlMethod != MFX_RATECONTROL_QVBR)) || par.mfx.RateControlMethod == MFX_RATECONTROL_LA_HRD))
{
extOpt2->SkipFrame = MFX_SKIPFRAME_INSERT_DUMMY;
}

//WA for MVC quality problem on progressive content.
if (IsMvcProfile(par.mfx.CodecProfile)) {
Expand Down Expand Up @@ -5585,12 +5569,11 @@ void MfxHwH264Encode::SetDefaults(
if (platform >= MFX_HW_HSW && platform != MFX_HW_VLV &&
IsDyadic(par.calcParam.scale, par.calcParam.numTemporalLayer) &&
par.mfx.GopRefDist >= 4 &&
IsPowerOf2(par.mfx.GopRefDist) &&
par.mfx.GopPicSize % par.mfx.GopRefDist == 0 &&
!bRateControlLA(par.mfx.RateControlMethod) &&
(!par.mfx.NumRefFrame || par.mfx.NumRefFrame >= GetMinNumRefFrameForPyramid(par)))
(!par.mfx.NumRefFrame || par.mfx.NumRefFrame >= GetMinNumRefFrameForPyramid(par)) &&
(!IsMvcProfile(par.mfx.CodecProfile) || (IsPowerOf2(par.mfx.GopRefDist) && (par.mfx.GopPicSize % par.mfx.GopRefDist) == 0)) &&
par.mfx.FrameInfo.PicStruct == MFX_PICSTRUCT_PROGRESSIVE)
{
extOpt2->BRefType = mfxU16(par.mfx.FrameInfo.PicStruct == MFX_PICSTRUCT_PROGRESSIVE ? MFX_B_REF_PYRAMID : MFX_B_REF_OFF);
extOpt2->BRefType = MFX_B_REF_PYRAMID;
}
else
{
Expand Down

0 comments on commit 10d5482

Please sign in to comment.