Skip to content

Commit

Permalink
[Encode] Fix encode coverity issues
Browse files Browse the repository at this point in the history
Refactor to (1) fix mem leak issue; (2) fix dead code issue; (3) revert some unnecessary check.
  • Loading branch information
perrchen authored and intel-mediadev committed Sep 8, 2023
1 parent d8e2f9d commit 1fafbb6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
9 changes: 4 additions & 5 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4606,9 +4606,9 @@ MOS_STATUS CodechalVdencAvcState::SFDKernel()
imageStateParams->pVDEncHmeMvCost = m_vdencHmeMvCostTbl;
imageStateParams->pVDEncMvCost = m_vdencMvCostTbl;

CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->AddVdencSfdImgBuffer(
&m_resVdencSfdImageStateReadBuffer, imageStateParams));
eStatus = m_hwInterface->AddVdencSfdImgBuffer(&m_resVdencSfdImageStateReadBuffer, imageStateParams);
MOS_Delete(imageStateParams);
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus);

CODECHAL_DEBUG_TOOL(
CODECHAL_ENCODE_CHK_STATUS_RETURN(PopulateEncParam(
Expand Down Expand Up @@ -5295,10 +5295,9 @@ MOS_STATUS CodechalVdencAvcState::HuCBrcUpdate()
}
}

CODECHAL_ENCODE_CHK_STATUS_RETURN(AddVdencBrcImgBuffer(
&m_resVdencBrcImageStatesReadBuffer[m_currRecycledBufIdx],
imageStateParams));
eStatus = AddVdencBrcImgBuffer(&m_resVdencBrcImageStatesReadBuffer[m_currRecycledBufIdx],imageStateParams);
MOS_Delete(imageStateParams);
CODECHAL_ENCODE_CHK_STATUS_RETURN(eStatus);

CODECHAL_DEBUG_TOOL(
CODECHAL_ENCODE_CHK_STATUS_RETURN(PopulatePakParam(
Expand Down
34 changes: 22 additions & 12 deletions media_driver/agnostic/gen12/codec/hal/codechal_vdenc_vp9_g12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4027,24 +4027,30 @@ MOS_STATUS CodechalVdencVp9StateG12::ExecutePictureLevel()
pipeModeSelectParams = m_vdencInterface->CreateMhwVdboxPipeModeSelectParams();
CODECHAL_ENCODE_CHK_NULL_RETURN(pipeModeSelectParams);

auto release_func = [&]()
{
m_vdencInterface->ReleaseMhwVdboxPipeModeSelectParams(pipeModeSelectParams);
pipeModeSelectParams = nullptr;
};

SetHcpPipeModeSelectParams(*pipeModeSelectParams);
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpPipeModeSelectCmd(&cmdBuffer, pipeModeSelectParams));
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpPipeModeSelectCmd(&cmdBuffer, pipeModeSelectParams), release_func);

CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMfxWaitCmd(&cmdBuffer, nullptr, false));
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_miInterface->AddMfxWaitCmd(&cmdBuffer, nullptr, false), release_func);

// Decoded picture
#ifdef _MMC_SUPPORTED
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState);
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]));
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func);
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]), release_func);
#endif
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]));
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_DECODED_SURFACE_ID]), release_func);

// Source input
#ifdef _MMC_SUPPORTED
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState);
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]));
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func);
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]), release_func);
#endif
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]));
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[CODECHAL_HCP_SRC_SURFACE_ID]), release_func);

if (MEDIA_IS_WA(m_waTable, Wa_Vp9UnalignedHeight))
{
Expand All @@ -4064,8 +4070,8 @@ MOS_STATUS CodechalVdencVp9StateG12::ExecutePictureLevel()
uint8_t skipMask = 0xf8;
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++)
{
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState);
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[i]));
CODECHAL_ENCODE_CHK_NULL_WITH_DESTROY_RETURN(m_mmcState, release_func);
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_mmcState->SetSurfaceState(&surfaceParams[i]), release_func);
if (surfaceParams[i].mmcState == MOS_MEMCOMP_DISABLED)
{
skipMask |= (1 << (i - 2));
Expand All @@ -4083,17 +4089,21 @@ MOS_STATUS CodechalVdencVp9StateG12::ExecutePictureLevel()
#endif
for (uint8_t i = CODECHAL_HCP_LAST_SURFACE_ID; i <= CODECHAL_HCP_ALTREF_SURFACE_ID; i++)
{
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[i]));
CODECHAL_ENCODE_CHK_STATUS_WITH_DESTROY_RETURN(m_hcpInterface->AddHcpSurfaceCmd(&cmdBuffer, &surfaceParams[i]), release_func);
}
}


// set HCP_PIPE_BUF_ADDR_STATE values
PMHW_VDBOX_PIPE_BUF_ADDR_PARAMS pipeBufAddrParams = nullptr;
pipeBufAddrParams = CreateHcpPipeBufAddrParams(pipeBufAddrParams);

auto delete_func = [&]()
{
if (pipeModeSelectParams)
{
m_vdencInterface->ReleaseMhwVdboxPipeModeSelectParams(pipeModeSelectParams);
pipeModeSelectParams = nullptr;
}
if (pipeBufAddrParams)
{
MOS_Delete(pipeBufAddrParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,6 @@ MOS_STATUS PreEncBasicFeature::ValidateLowDelayBFrame()
// forward
for (int refIdx = 0; (refIdx < 1) && m_lowDelay; refIdx++)
{
if (refIdx >= CODEC_MAX_NUM_REF_FRAME_HEVC)
{
break;
}

CODEC_PICTURE refPic = m_preEncConfig.RefPicList[0][refIdx];
if (!CodecHal_PictureIsInvalid(refPic) && m_preEncConfig.RefFramePOCList[refPic.FrameIdx] > m_preEncConfig.CurrPicOrderCnt)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ MOS_STATUS EncodeScalabilityMultiPipe::VerifySpaceAvailable(uint32_t requestedSi
{
SCALABILITY_CHK_STATUS_RETURN(MediaScalability::VerifySpaceAvailable(
requestedSize, requestedPatchListSize, bothPatchListAndCmdBufChkSuccess));
if (bothPatchListAndCmdBufChkSuccess = true)
if (bothPatchListAndCmdBufChkSuccess == true)
{
singleTaskPhaseSupportedInPak = m_singleTaskPhaseSupported;
return eStatus;
Expand Down

0 comments on commit 1fafbb6

Please sign in to comment.