Skip to content

Commit

Permalink
Bypass vpp if HEVC VDEnc is used
Browse files Browse the repository at this point in the history
Signed-off-by: Chen, Tianmi <[email protected]>
  • Loading branch information
TianmiChen committed Aug 19, 2022
1 parent bd848db commit a4d34b4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
44 changes: 31 additions & 13 deletions omx_components/src/mfx_omx_venc_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2466,8 +2466,8 @@ mfxStatus MfxOmxVencComponent::ProcessBuffer(void)

{
MfxOmxAutoLock lock(m_encoderMutex);
if (!m_bInitialized) mfx_res = InitEncoder();
if ((MFX_ERR_NONE == mfx_res) && !m_bVppDetermined) mfx_res = InitVPP();
if (!m_bInitialized && m_bVppDetermined) mfx_res = InitEncoder();
}
if ((MFX_ERR_NONE == mfx_res) && !m_bChangeOutputPortSettings && m_bVppDetermined)
{
Expand Down Expand Up @@ -2544,6 +2544,19 @@ mfxStatus MfxOmxVencComponent::InitEncoder(void)
m_OmxMfxVideoParams.enableExtParam(MFX_EXTBUFF_AVC_TEMPORAL_LAYERS);
}

if (MFX_CODEC_HEVC == m_MfxVideoParams.mfx.CodecId)
{
if (MFX_CODINGOPTION_ON == m_MfxVideoParams.mfx.LowPower)
{
mfxFrameSurface1 *pSrf = m_pSurfaces->GetCustomBuffer();
if (pSrf && (MFX_FOURCC_RGB4 == pSrf->Info.FourCC))
{
m_MfxVideoParams.mfx.FrameInfo.FourCC = MFX_FOURCC_RGB4;
m_MfxVideoParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV444;
}
}
}

MFX_OMX_AT__mfxVideoParam_enc(m_MfxVideoParams);

MFX_OMX_LOG_INFO_IF(g_OmxLogLevel, "AsyncDepth %d", m_MfxVideoParams.AsyncDepth);
Expand Down Expand Up @@ -2603,18 +2616,23 @@ mfxStatus MfxOmxVencComponent::InitVPP(void)
MFX_OMX_AUTO_TRACE_I32(pSrf->Info.FourCC);
if (MFX_FOURCC_RGB4 == pSrf->Info.FourCC)
{
MfxOmxVppWrappParam param;

param.session = &m_Session;
param.frame_info = &(pSrf->Info);
param.allocator = m_pDevice->GetFrameAllocator();
param.conversion = ARGB_TO_NV12;

MFX_OMX_LOG_INFO_IF(g_OmxLogLevel, "VPP initialization ...");
mfx_res = m_VPP.Init(&param);
MFX_OMX_AUTO_TRACE_I32(mfx_res);
MFX_OMX_LOG_INFO_IF(g_OmxLogLevel, "VPP initialized with sts %d", mfx_res);
m_inputVppType = param.conversion;
if ((MFX_CODINGOPTION_ON == m_MfxVideoParams.mfx.LowPower) &&
(MFX_CODEC_HEVC == m_MfxVideoParams.mfx.CodecId)) {
m_inputVppType = CONVERT_NONE;
} else {
MfxOmxVppWrappParam param;

param.session = &m_Session;
param.frame_info = &(pSrf->Info);
param.allocator = m_pDevice->GetFrameAllocator();
param.conversion = ARGB_TO_NV12;

MFX_OMX_LOG_INFO_IF(g_OmxLogLevel, "VPP initialization ...");
mfx_res = m_VPP.Init(&param);
MFX_OMX_AUTO_TRACE_I32(mfx_res);
MFX_OMX_LOG_INFO_IF(g_OmxLogLevel, "VPP initialized with sts %d", mfx_res);
m_inputVppType = param.conversion;
}
}
else
{
Expand Down
39 changes: 27 additions & 12 deletions omx_utils/src/mfx_omx_vaapi_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ mfxStatus MfxOmxVaapiFrameAllocator::CreateSurfaceFromGralloc(const mfxU8* handl
mfxU32 va_fourcc = ConvertGrallocFourccToVAFormat(info.format);
mfxU32 rt_format = ConvertVAFourccToVARTFormat(va_fourcc);

VASurfaceAttrib attribs[2];
VASurfaceAttrib attribs[3];
MFX_OMX_ZERO_MEMORY(attribs);

VASurfaceAttribExternalBuffers surfExtBuf;
Expand All @@ -516,17 +516,27 @@ mfxStatus MfxOmxVaapiFrameAllocator::CreateSurfaceFromGralloc(const mfxU8* handl
surfExtBuf.pixel_format = va_fourcc;
surfExtBuf.width = width;
surfExtBuf.height = height;
surfExtBuf.pitches[0] = info.pitch;
surfExtBuf.pitches[1] = info.pitch;
surfExtBuf.pitches[2] = 0;
surfExtBuf.pitches[3] = 0;
surfExtBuf.offsets[0] = 0;
surfExtBuf.offsets[1] = info.pitch * ((height + 31) & ~31); // Gralloc buffer has been aligned with 32 pixels
surfExtBuf.offsets[2] = 0;
surfExtBuf.offsets[3] = 0;
surfExtBuf.data_size = info.pitch * ((height + 31) & ~31) * 1.5;
surfExtBuf.num_planes = 2;
surfExtBuf.num_buffers = 1;
if (VA_FOURCC_RGBA == va_fourcc)
{
surfExtBuf.pitches[0] = info.pitch;
surfExtBuf.data_size = info.pitch * height;
surfExtBuf.num_planes = info.numOfPlanes;
surfExtBuf.num_buffers = 1;
}
else
{
surfExtBuf.pitches[0] = info.pitch;
surfExtBuf.pitches[1] = info.pitch;
surfExtBuf.pitches[2] = 0;
surfExtBuf.pitches[3] = 0;
surfExtBuf.offsets[0] = 0;
surfExtBuf.offsets[1] = info.pitch * ((height + 31) & ~31); // Gralloc buffer has been aligned with 32 pixels
surfExtBuf.offsets[2] = 0;
surfExtBuf.offsets[3] = 0;
surfExtBuf.data_size = info.pitch * ((height + 31) & ~31) * 1.5;
surfExtBuf.num_planes = 2;
surfExtBuf.num_buffers = 1;
}
#ifdef MFX_OMX_USE_PRIME
surfExtBuf.buffers = (uintptr_t *)&(info.prime);
surfExtBuf.flags = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
Expand All @@ -549,6 +559,11 @@ mfxStatus MfxOmxVaapiFrameAllocator::CreateSurfaceFromGralloc(const mfxU8* handl
attribs[1].value.type = VAGenericValueTypePointer;
attribs[1].value.value.p = (void *)&surfExtBuf;

attribs[2].type = (VASurfaceAttribType)VASurfaceAttribUsageHint;
attribs[2].flags = VA_SURFACE_ATTRIB_SETTABLE;
attribs[2].value.type = VAGenericValueTypeInteger;
attribs[2].value.value.i = bIsDecodeTarget ? VA_SURFACE_ATTRIB_USAGE_HINT_DECODER : VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;

VAStatus va_res = vaCreateSurfaces(m_dpy, rt_format,
width, height,
&surface, 1,
Expand Down

0 comments on commit a4d34b4

Please sign in to comment.