Skip to content

Commit

Permalink
[EncTools] Refactor VPP (intel#131)
Browse files Browse the repository at this point in the history
CS PR2020 + fixes
  • Loading branch information
takulako authored Jul 22, 2021
1 parent 870871c commit e67c278
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 311 deletions.
18 changes: 9 additions & 9 deletions _studio/enctools/include/mfx_enctools.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ class EncTools
mfxFrameAllocator *m_pAllocator;
MFXFrameAllocator *m_pETAllocator;
mfxAllocatorParams *m_pmfxAllocatorParams;
MFXVideoSession m_mfxSession_LA;
MFXVideoSession *m_mfxSession_LA;
MFXVideoSession m_mfxSession_SCD;

std::unique_ptr<MFXVideoVPP> m_pmfxVPP_LA;
std::unique_ptr<MFXVideoVPP> m_pmfxVPP_SCD;
mfxVideoParam m_mfxVppParams;
mfxVideoParam m_mfxVppParams_LA;
mfxVideoParam m_mfxVppParams_AEnc;
mfxFrameAllocResponse m_VppResponse;
Expand All @@ -78,12 +77,14 @@ class EncTools
m_device(0),
m_pAllocator(nullptr),
m_pETAllocator(nullptr),
m_mfxVppParams(),
m_pmfxAllocatorParams(nullptr),
m_mfxSession_LA(nullptr),
m_mfxVppParams_LA(),
m_mfxVppParams_AEnc(),
m_VppResponse(),
m_IntSurfaces_SCD()
{}
m_VppResponse()
{
m_IntSurfaces_SCD.Data.Y = nullptr;
}

virtual ~EncTools() { Close(); }

Expand All @@ -100,12 +101,11 @@ class EncTools

protected:
mfxStatus InitMfxVppParams(mfxEncToolsCtrl const & ctrl);
mfxStatus InitVPP(mfxEncToolsCtrl const& ctrl, MFXVideoSession* pmfxLA_EncSession);
mfxStatus InitVPP(mfxEncToolsCtrl const & ctrl);
mfxStatus CloseVPP();

mfxStatus InitVPPSession(MFXVideoSession* pmfxSession);
mfxStatus VPPSync(MFXVideoSession* pmfxSession, mfxSyncPoint* pSyncp);
mfxStatus VPPDownScaleSurface(MFXVideoSession* m_pmfxSession, MFXVideoVPP* pVPP, mfxSyncPoint* pVppSyncp, mfxFrameSurface1* pInSurface, mfxFrameSurface1* pOutSurface, bool doSync);
mfxStatus VPPDownScaleSurface(MFXVideoSession* m_pmfxSession, MFXVideoVPP* pVPP, mfxSyncPoint* pVppSyncp, mfxFrameSurface1* pInSurface, mfxFrameSurface1* pOutSurface);
};

namespace EncToolsFuncs
Expand Down
5 changes: 2 additions & 3 deletions _studio/enctools/include/mfx_enctools_lpla.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ class LPLA_EncTool
virtual mfxStatus Reset(mfxEncToolsCtrl const & ctrl, mfxExtEncToolsConfig const & pConfig);
virtual mfxStatus Close();
virtual MFXVideoSession* GetEncSession();
virtual mfxStatus StoreLAResults(mfxFrameSurface1* surface, mfxU16 FrameType);
virtual mfxStatus EncodeLA(mfxFrameSurface1* surface, mfxU16 FrameType, mfxSyncPoint *pVppSyncp);
virtual mfxStatus Submit(mfxFrameSurface1 * surface, mfxU16 FrameType);
virtual mfxStatus SaveEncodedFrameSize(mfxFrameSurface1* surface, mfxU16 FrameType);
virtual mfxStatus Submit(mfxFrameSurface1* surface, mfxU16 FrameType, mfxSyncPoint* pEncSyncp);
virtual mfxStatus Query(mfxU32 dispOrder, mfxEncToolsBRCBufferHint *pBufHint);
#if defined (MFX_ENABLE_ENCTOOLS_LPLA)
virtual mfxStatus Query(mfxU32 dispOrder, mfxEncToolsHintQuantMatrix *pCqmHint);
Expand Down
31 changes: 10 additions & 21 deletions _studio/enctools/src/mfx_enctools_aenc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,22 @@ mfxStatus AEnc_EncTool::Init(mfxEncToolsCtrl const & ctrl, mfxExtEncToolsConfig
m_aencPar.SrcFrameWidth = frameInfo->Width;
m_aencPar.SrcFrameHeight = frameInfo->Height;

if (ctrl.IOPattern & MFX_IOPATTERN_IN_SYSTEM_MEMORY)
if (DoDownScaling(*frameInfo))
{
FrameWidth_aligned = frameInfo->Width;
FrameWidth_aligned = ENC_TOOLS_DS_FRAME_WIDTH;
FrameHeight_aligned = ENC_TOOLS_DS_FRAME_HEIGHT;
m_aencPar.FrameWidth = ENC_TOOLS_DS_FRAME_WIDTH;
m_aencPar.FrameHeight = ENC_TOOLS_DS_FRAME_HEIGHT;
m_aencPar.Pitch = ENC_TOOLS_DS_FRAME_WIDTH;
}
else
{
FrameWidth_aligned = frameInfo->Width;
FrameHeight_aligned = frameInfo->Height;
m_aencPar.FrameWidth = frameInfo->CropW ? frameInfo->CropW : frameInfo->Width;
m_aencPar.FrameHeight = frameInfo->CropH ? frameInfo->CropH : frameInfo->Height;
m_aencPar.Pitch = frameInfo->Width;
}
else
{
if (DoDownScaling(*frameInfo))
{
FrameWidth_aligned = ENC_TOOLS_DS_FRAME_WIDTH;
FrameHeight_aligned = ENC_TOOLS_DS_FRAME_HEIGHT;
m_aencPar.FrameWidth = ENC_TOOLS_DS_FRAME_WIDTH;
m_aencPar.FrameHeight = ENC_TOOLS_DS_FRAME_HEIGHT;
m_aencPar.Pitch = ENC_TOOLS_DS_FRAME_WIDTH;
}
else
{
FrameWidth_aligned = frameInfo->Width;
FrameHeight_aligned = frameInfo->Height;
m_aencPar.FrameWidth = frameInfo->CropW ? frameInfo->CropW : frameInfo->Width;
m_aencPar.FrameHeight = frameInfo->CropH ? frameInfo->CropH : frameInfo->Height;
m_aencPar.Pitch = frameInfo->Width;
}
}

m_aencPar.CodecId = ctrl.CodecId;
m_aencPar.ColorFormat = MFX_FOURCC_NV12;
Expand Down
22 changes: 0 additions & 22 deletions _studio/enctools/src/mfx_enctools_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,28 +352,22 @@ unsigned int ConvertMfxFourccToVAFormat(mfxU32 fourcc)
return VA_FOURCC_P208;
case MFX_FOURCC_P010:
return VA_FOURCC_P010;
#if (MFX_VERSION >= 1027)
case MFX_FOURCC_Y210:
return VA_FOURCC_Y210;
case MFX_FOURCC_Y410:
return VA_FOURCC_Y410;
#endif
#if (MFX_VERSION >= MFX_VERSION_NEXT)
case MFX_FOURCC_P016:
return VA_FOURCC_P016;
case MFX_FOURCC_Y216:
return VA_FOURCC_Y216;
case MFX_FOURCC_Y416:
return VA_FOURCC_Y416;
#endif
case MFX_FOURCC_AYUV:
return VA_FOURCC_AYUV;
#if (MFX_VERSION >= 1028)
case MFX_FOURCC_RGB565:
return VA_FOURCC_RGB565;
case MFX_FOURCC_RGBP:
return VA_RT_FORMAT_RGBP;
#endif
default:
assert(!"unsupported fourcc");
return 0;
Expand Down Expand Up @@ -465,19 +459,13 @@ mfxStatus vaapiFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFrame
(VA_FOURCC_P208 != va_fourcc) &&
(VA_FOURCC_P010 != va_fourcc) &&
(VA_FOURCC_YUY2 != va_fourcc) &&
#if (MFX_VERSION >= 1027)
(VA_FOURCC_Y210 != va_fourcc) &&
(VA_FOURCC_Y410 != va_fourcc) &&
#endif
#if (MFX_VERSION >= 1028)
(VA_FOURCC_RGB565 != va_fourcc) &&
(VA_RT_FORMAT_RGBP != va_fourcc) &&
#endif
#if (MFX_VERSION >= MFX_VERSION_NEXT)
(VA_FOURCC_P016 != va_fourcc) &&
(VA_FOURCC_Y216 != va_fourcc) &&
(VA_FOURCC_Y416 != va_fourcc) &&
#endif
(VA_FOURCC_AYUV != va_fourcc)))
{
return MFX_ERR_MEMORY_ALLOC;
Expand Down Expand Up @@ -859,7 +847,6 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
}
else return MFX_ERR_LOCK_MEMORY;
break;
#if (MFX_VERSION >= 1028)
case VA_FOURCC_RGB565:
if (mfx_fourcc == MFX_FOURCC_RGB565)
{
Expand All @@ -876,7 +863,6 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
ptr->G = pBuffer + vaapi_mid->m_image.offsets[1];
ptr->B = pBuffer + vaapi_mid->m_image.offsets[2];
}
#endif
case VA_FOURCC_P208:
if (mfx_fourcc == MFX_FOURCC_NV12)
{
Expand All @@ -885,9 +871,7 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
else return MFX_ERR_LOCK_MEMORY;
break;
case VA_FOURCC_P010:
#if (MFX_VERSION >= MFX_VERSION_NEXT)
case VA_FOURCC_P016:
#endif
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

{
Expand All @@ -906,11 +890,8 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
ptr->A = ptr->V + 3;
}
break;
#if (MFX_VERSION >= 1027)
case VA_FOURCC_Y210:
#if (MFX_VERSION >= MFX_VERSION_NEXT)
case VA_FOURCC_Y216:
#endif
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

{
Expand All @@ -929,8 +910,6 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
ptr->A = 0;
}
break;
#endif
#if (MFX_VERSION >= MFX_VERSION_NEXT)
case VA_FOURCC_Y416:
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;

Expand All @@ -941,7 +920,6 @@ mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
ptr->A = (mfxU8*)(ptr->V16 + 1);
}
break;
#endif
default:
return MFX_ERR_LOCK_MEMORY;
}
Expand Down
13 changes: 1 addition & 12 deletions _studio/enctools/src/mfx_enctools_brc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void SetQPParams(mfxI32 qp, mfxU32 type, BRC_Ctx &ctx, mfxU32 /* rec_num */, mf
ctx.QuantI = mfx::clamp(ctx.QuantI, minQuant, maxQuant);
ctx.QuantP = mfx::clamp(ctx.QuantP, minQuant, maxQuant);
ctx.QuantB = mfx::clamp(ctx.QuantB, minQuant, maxQuant);
//printf("ctx.QuantIDR %d, QuantI %d, ctx.QuantP %d, ctx.QuantB %d, level %d\n", ctx.QuantIDR, ctx.QuantI, ctx.QuantP, ctx.QuantB, level);
//printf("ctx.QuantIDR %d, QuantI %d, ctx.QuantP %d, ctx.QuantB %d, level %d iDQp %d\n", ctx.QuantIDR, ctx.QuantI, ctx.QuantP, ctx.QuantB, level, iDQp);
}

void UpdateQPParams(mfxI32 qp, mfxU32 type , BRC_Ctx &ctx, mfxU32 rec_num, mfxI32 minQuant, mfxI32 maxQuant, mfxU32 level, mfxU32 iDQp, mfxU16 isRef, mfxU16 qpMod, mfxI32 qpDeltaP)
Expand Down Expand Up @@ -937,14 +937,9 @@ mfxStatus BRC_EncTool::UpdateFrame(mfxU32 dispOrder, mfxEncToolsBRCStatus *pFram
bool bIdr = (picType == MFX_FRAMETYPE_IDR);
mfxF64 qstep = QP2Qstep(qpY, m_par.quantOffset);

#if (MFX_VERSION >= 1026)
mfxU16 ParSceneChange = (frameStruct.frameCmplx || frameStruct.LaAvgEncodedSize) ? frameStruct.sceneChange : 0;
mfxU32 ParFrameCmplx = frameStruct.frameCmplx;
if (isIntra && !ParFrameCmplx) ParFrameCmplx = frameStruct.LaAvgEncodedSize;
#else
mfxU16 ParSceneChange = 0;
mfxU32 ParFrameCmplx = 0;
#endif
mfxU16 ParQpModulation = (mfxU16) frameStruct.qpModulation;
if (ParQpModulation == MFX_QP_MODULATION_NOT_DEFINED
&& m_par.gopRefDist == 8 && m_par.bPyr
Expand Down Expand Up @@ -1517,15 +1512,9 @@ mfxStatus BRC_EncTool::ProcessFrame(mfxU32 dispOrder, mfxEncToolsBRCQuantControl
return MFX_ERR_UNDEFINED_BEHAVIOR; // BRC hasn't processed the frame
BRC_FrameStruct frameStruct = *frameStructItr;

#if (MFX_VERSION >= 1026)
mfxU16 ParSceneChange = frameStruct.sceneChange;
mfxU16 ParLongTerm = frameStruct.longTerm;
mfxU32 ParFrameCmplx = frameStruct.frameCmplx;
#else
mfxU16 ParSceneChange = 0;
mfxU16 ParLongTerm = 0;
mfxU32 ParFrameCmplx = 0;
#endif
mfxU16 ParQpModulation = frameStruct.qpModulation;
mfxI32 ParQpDeltaP = 0;
if (ParQpModulation == MFX_QP_MODULATION_NOT_DEFINED
Expand Down
Loading

0 comments on commit e67c278

Please sign in to comment.