Skip to content

Commit

Permalink
[Encode] clean coverity issues
Browse files Browse the repository at this point in the history
clean coverity issues.
  • Loading branch information
DaShi-Git authored and intel-mediadev committed Sep 4, 2023
1 parent df03e48 commit d1336b4
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 36 deletions.
21 changes: 10 additions & 11 deletions media_driver/agnostic/common/codec/hal/codechal_encode_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5544,19 +5544,14 @@ MOS_STATUS CodechalEncodeAvcEnc::SetSequenceStructs()
dwSlidingWindowSize = MOS_MIN((uint32_t)(seqParams->FramesPer100Sec / 100), 60);
}

if (seqParams->FramesPer100Sec)
if (seqParams->FramesPer100Sec == 0)
{
m_maxNumSlicesAllowed = CodecHalAvcEncode_GetMaxNumSlicesAllowed(
(CODEC_AVC_PROFILE_IDC)(seqParams->Profile),
(CODEC_AVC_LEVEL_IDC)(seqParams->Level),
seqParams->FramesPer100Sec);
}
else
{
CODECHAL_ENCODE_ASSERTMESSAGE("FramesPer100Sec is zero, cannot get MaxNumSliceAllowed.");
eStatus = MOS_STATUS_INVALID_PARAMETER;
return MOS_STATUS_INVALID_PARAMETER;
}

m_maxNumSlicesAllowed = CodecHalAvcEncode_GetMaxNumSlicesAllowed(
(CODEC_AVC_PROFILE_IDC)(seqParams->Profile),
(CODEC_AVC_LEVEL_IDC)(seqParams->Level),
seqParams->FramesPer100Sec);

return eStatus;
}
Expand Down Expand Up @@ -5920,6 +5915,10 @@ MOS_STATUS CodechalEncodeAvcEnc::InitializePicture(const EncoderParams& params)
m_madEnabled = params.bMADEnabled;

m_avcSeqParams[spsidx] = (PCODEC_AVC_ENCODE_SEQUENCE_PARAMS)(params.pSeqParams);
if (ppsidx >= CODEC_AVC_MAX_PPS_NUM)
{
return MOS_STATUS_INVALID_PARAMETER;
}
m_avcPicParams[ppsidx] = (PCODEC_AVC_ENCODE_PIC_PARAMS)(params.pPicParams);
m_avcQCParams = (PCODECHAL_ENCODE_AVC_QUALITY_CTRL_PARAMS)params.pAVCQCParams;
m_avcRoundingParams = (PCODECHAL_ENCODE_AVC_ROUNDING_PARAMS)params.pAVCRoundingParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@ MOS_STATUS CodechalEncodeHevcBase::SetPictureStructs()
}
for (uint32_t i = 0; i <= numRef; i++)
{
if (i >= CODEC_MAX_NUM_REF_FRAME_HEVC)
{
return MOS_STATUS_INVALID_PARAMETER;
}
CODEC_PICTURE refPic = slcParams->RefPicList[ll][i];
if (!CodecHal_PictureIsInvalid(refPic) &&
!CodecHal_PictureIsInvalid(m_hevcPicParams->RefFrameList[refPic.FrameIdx]))
Expand Down
10 changes: 7 additions & 3 deletions media_driver/agnostic/common/codec/hal/codechal_encode_mpeg2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2715,9 +2715,13 @@ MOS_STATUS CodechalEncodeMpeg2::InitializePicture(const EncoderParams& params)
CODECHAL_ENCODE_CHK_STATUS_RETURN(DumpSliceParams(
m_sliceParams));)

CODECHAL_ENCODE_CHK_STATUS_RETURN(SetStatusReportParams(
m_refList[m_currReconstructedPic.FrameIdx]));

if (m_currReconstructedPic.FrameIdx >= CODECHAL_NUM_UNCOMPRESSED_SURFACE_MPEG2)
{
return MOS_STATUS_INVALID_PARAMETER;
}
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetStatusReportParams(
m_refList[m_currReconstructedPic.FrameIdx]));

m_bitstreamUpperBound = m_encodeParams.dwBitstreamSize;

return eStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,10 @@ MOS_STATUS CodechalEncodeVp8::SetPictureStructs()
else
{
m_averagePFrameQp = averageQp;
if (m_vp8SeqParams->GopPicSize == 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
m_pFramePositionInGop = m_vp8SeqParams->RateControlMethod == RATECONTROL_CQP ? 0 : (m_storeData - 1) % m_vp8SeqParams->GopPicSize;
}

Expand Down
19 changes: 7 additions & 12 deletions media_driver/agnostic/common/codec/hal/codechal_vdenc_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4093,20 +4093,15 @@ MOS_STATUS CodechalVdencAvcState::SetSequenceStructs()
m_slidingWindowSize = MOS_MIN((uint32_t)(seqParams->FramesPer100Sec / 100), 60);
}

if (seqParams->FramesPer100Sec)
if (seqParams->FramesPer100Sec == 0)
{
m_maxNumSlicesAllowed = CodecHalAvcEncode_GetMaxNumSlicesAllowed(
(CODEC_AVC_PROFILE_IDC)(seqParams->Profile),
(CODEC_AVC_LEVEL_IDC)(seqParams->Level),
seqParams->FramesPer100Sec);
}
else
{
CODECHAL_ENCODE_ASSERTMESSAGE("FramesPer100Sec is zero, cannot get MaxNumSliceAllowed.");
eStatus = MOS_STATUS_INVALID_PARAMETER;
return MOS_STATUS_INVALID_PARAMETER;
}
m_maxNumSlicesAllowed = CodecHalAvcEncode_GetMaxNumSlicesAllowed(
(CODEC_AVC_PROFILE_IDC)(seqParams->Profile),
(CODEC_AVC_LEVEL_IDC)(seqParams->Level),
seqParams->FramesPer100Sec);


m_lookaheadDepth = seqParams->LookaheadDepth;
if (m_lookaheadDepth > 0)
{
Expand Down Expand Up @@ -4274,7 +4269,7 @@ MOS_STATUS CodechalVdencAvcState::SetPictureStructs()
if ((m_lookaheadDepth > 0) && (m_prevTargetFrameSize > 0))
{
int64_t targetBufferFulness = (int64_t)m_targetBufferFulness;
targetBufferFulness += (int64_t)(m_prevTargetFrameSize << 3) - (int64_t)m_averageFrameSize;
targetBufferFulness += (((int64_t)m_prevTargetFrameSize) << 3) - (int64_t)m_averageFrameSize;
m_targetBufferFulness = targetBufferFulness < 0 ?
0 : (targetBufferFulness > 0xFFFFFFFF ? 0xFFFFFFFF : (uint32_t)targetBufferFulness);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ MOS_STATUS CodechalVdencHevcState::SetPictureStructs()
if ((m_lookaheadDepth > 0) && (m_prevTargetFrameSize > 0))
{
int64_t targetBufferFulness = (int64_t)m_targetBufferFulness;
targetBufferFulness += (int64_t)(m_prevTargetFrameSize << 3) - (int64_t)m_averageFrameSize;
targetBufferFulness += (((int64_t)m_prevTargetFrameSize) << 3) - (int64_t)m_averageFrameSize;
m_targetBufferFulness = targetBufferFulness < 0 ? 0 : (targetBufferFulness > 0xFFFFFFFF ? 0xFFFFFFFF : (uint32_t)targetBufferFulness);
}

Expand Down Expand Up @@ -3230,7 +3230,7 @@ MOS_STATUS CodechalVdencHevcState::GetStatusReport(
if (m_prevTargetFrameSize > 0)
{
int64_t encTargetBufferFulness = (int64_t)m_targetBufferFulness;
encTargetBufferFulness += (int64_t)(m_prevTargetFrameSize << 3) - (int64_t)m_averageFrameSize;
encTargetBufferFulness += (((int64_t)m_prevTargetFrameSize) << 3) - (int64_t)m_averageFrameSize;
m_targetBufferFulness = encTargetBufferFulness < 0 ?
0 : (encTargetBufferFulness > 0xFFFFFFFF ? 0xFFFFFFFF : (uint32_t)encTargetBufferFulness);
int32_t deltaBits = (int32_t)((int64_t)(encodeStatus->lookaheadStatus.targetBufferFulness) + m_bufferFulnessError - (int64_t)(m_targetBufferFulness));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5992,8 +5992,12 @@ MOS_STATUS CodechalVdencVp9State::InitializePicture(const EncoderParams& params)
m_scalingEnabled = m_hmeSupported;
m_useRawForRef = m_vp9SeqParams->SeqFlags.fields.bUseRawReconRef;

CODECHAL_ENCODE_CHK_STATUS_RETURN(SetStatusReportParams(m_refList[m_currReconstructedPic.FrameIdx]));

if (m_currReconstructedPic.FrameIdx >= m_numUncompressedSurface)
{
return MOS_STATUS_INVALID_PARAMETER;
}
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetStatusReportParams(m_refList[m_currReconstructedPic.FrameIdx]));

CODECHAL_DEBUG_TOOL(
m_debugInterface->m_currPic = m_vp9PicParams->CurrOriginalPic;
m_debugInterface->m_bufferDumpFrameNum = m_storeData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ class MhwVdboxHcpInterfaceGeneric : public MhwVdboxHcpInterface

MHW_FUNCTION_ENTER;

MHW_MI_CHK_NULL(cmdBuffer);
MHW_MI_CHK_NULL(m_osInterface);
MHW_MI_CHK_NULL(hevcSliceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,10 @@ MOS_STATUS CodechalVdencAvcStateG12::SetPictureStructs()
CODECHAL_ENCODE_ASSERTMESSAGE("ROI/DirtyROI disabled for TCBRC\n");
m_avcPicParam->NumDirtyROI = m_avcPicParam->NumROI = 0;
}
if (m_avcSeqParam->FramesPer100Sec == 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
m_avcPicParam->TargetFrameSize = uint32_t(m_avcSeqParam->TargetBitRate * (100. / 8) / m_avcSeqParam->FramesPer100Sec);
}

Expand Down
4 changes: 4 additions & 0 deletions media_driver/agnostic/gen12/hw/vdbox/mhw_vdbox_vdenc_g12_X.h
Original file line number Diff line number Diff line change
Expand Up @@ -2522,6 +2522,10 @@ class MhwVdboxVdencInterfaceG12X : public MhwVdboxVdencInterfaceG12<mhw_vdbox_vd
refFrameId = hevcSlcParams->RefPicList[1][0].FrameIdx;
diffPoc = ((refFrameId >= CODEC_MAX_NUM_REF_FRAME_HEVC) ? 0x0 : hevcPicParams->RefFramePOCList[refFrameId]) - hevcPicParams->CurrPicOrderCnt;
cmd.DW3.PocNumberForRefid0InL1 = CodecHal_Clip3(-16, 16, -diffPoc);
if (refFrameId >= CODEC_MAX_NUM_REF_FRAME_HEVC)
{
return MOS_STATUS_INVALID_PARAMETER;
}
cmd.DW2.LongTermReferenceFlagsL1 = CodecHal_PictureIsLongTermRef(hevcPicParams->RefFrameList[refFrameId]);

cmd.DW3.PocNumberForRefid1InL1 = cmd.DW3.PocNumberForRefid1InL0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ namespace decode
DECODE_FUNC_CALL();

// override internal reference list with anchor_frame_list passed from APP
if (picParams.m_anchorFrameNum > CODECHAL_MAX_DPB_NUM_LST_AV1)
{
return MOS_STATUS_INVALID_PARAMETER;
}
for (auto i = 0; i < picParams.m_anchorFrameNum; i++)
{
DECODE_CHK_STATUS(m_allocator->GetSurfaceInfo(&picParams.m_anchorFrameList[i]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ namespace encode
MEMCPY_CONST(INIT_InstRateThreshP0, instRateThresholdP);
#undef MEMCPY_CONST

if (dmem->INIT_FrameRateM == 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
double inputBitsPerFrame = ((double)dmem->INIT_MaxRate * (double)dmem->INIT_FrameRateD) / (double)dmem->INIT_FrameRateM;
double bpsRatio = inputBitsPerFrame / ((double)dmem->INIT_BufSize / brcSettings.devStdFPS);
bpsRatio = MOS_CLAMP_MIN_MAX(bpsRatio, brcSettings.bpsRatioLow, brcSettings.bpsRatioHigh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ namespace encode
const uint32_t segMapPitch = MOS_ALIGN_CEIL(CurFrameWidth, m_segmentMapBlockSize) / m_segmentMapBlockSize;
const uint32_t segMapHeight = MOS_ALIGN_CEIL(CurFrameHeight, m_segmentMapBlockSize) / m_segmentMapBlockSize;

const uint64_t minSegmentMapDataSize = segMapPitch * segMapHeight; // 1 byte per segment Id
const uint64_t minSegmentMapDataSize = (uint64_t)segMapPitch * (uint64_t)segMapHeight; // 1 byte per segment Id

if (m_segmentMapDataSize < minSegmentMapDataSize)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ MOS_STATUS AvcBasicFeature::SetPictureStructs()
if ((m_lookaheadDepth > 0) && (m_prevTargetFrameSize > 0))
{
int64_t targetBufferFulness = (int64_t)m_targetBufferFulness;
targetBufferFulness += (int64_t)(m_prevTargetFrameSize << 3) - (int64_t)m_averageFrameSize;
targetBufferFulness += (((int64_t)m_prevTargetFrameSize) << 3) - (int64_t)m_averageFrameSize;
m_targetBufferFulness = (uint32_t)MOS_CLAMP_MIN_MAX(targetBufferFulness, 0, 0xFFFFFFFF);
}
m_prevTargetFrameSize = picParams->TargetFrameSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ MOS_STATUS AvcVdencPreEnc::PreparePreEncConfig(void *params)
m_preEncConfig.GopRefDist = (uint8_t)m_avcSeqParams->GopRefDist;

uint8_t depth = 0;
uint32_t poc = m_preEncConfig.CurrPicOrderCnt % m_preEncConfig.GopRefDist;
uint32_t poc = 0;
if (m_preEncConfig.GopRefDist = 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
poc = m_preEncConfig.CurrPicOrderCnt % m_preEncConfig.GopRefDist;


if (poc == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ MHW_SETPAR_DECL_SRC(VDENC_AVC_IMG_STATE, AvcReferenceFrames)
{
auto id = slcParams->RefPicList[LIST_1][0].FrameIdx;
params.longtermReferenceFrameBwdRef0Indicator = (id < CODEC_AVC_MAX_NUM_REF_FRAME) && CodecHal_PictureIsLongTermRef(picParams->RefFrameList[id]);
if (id >= CODEC_AVC_MAX_NUM_REF_FRAME)
{
return MOS_STATUS_INVALID_PARAMETER;
}
id = m_picIdx[id].ucPicIdx;
params.bwdRefIdx0ReferencePicture = m_refList[id]->ucFrameId;
refPoc[1][0] = (uint8_t)m_refList[id]->iFieldOrderCnt[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ class AvcReferenceFrames : public mhw::vdbox::vdenc::Itf::ParSetting, public mhw
uint16_t m_pictureCodingType = 0; //!< I, P, or B frame
CODEC_PIC_ID m_picIdx[CODEC_AVC_MAX_NUM_REF_FRAME] = {}; //!< Picture index
PCODEC_REF_LIST m_refList[CODEC_AVC_NUM_UNCOMPRESSED_SURFACE] = {}; //!< Pointer to reference pictures
CODEC_AVC_FRAME_STORE_ID m_frameStoreID[CODEC_AVC_MAX_NUM_REF_FRAME]; //!< Refer to CODEC_AVC_FRAME_STORE_ID
CODEC_AVC_FRAME_STORE_ID m_frameStoreID[CODEC_AVC_MAX_NUM_REF_FRAME] = {}; //!< Refer to CODEC_AVC_FRAME_STORE_ID
PCODEC_REF_LIST m_currRefList = nullptr; //!< Current reference list

// B-frame
uint32_t m_distScaleFactorList0[CODEC_AVC_MAX_NUM_REF_FRAME * 2]; //!< the DistScaleFactor used to derive temporal direct motion vector
uint32_t m_distScaleFactorList0[CODEC_AVC_MAX_NUM_REF_FRAME * 2] = {}; //!< the DistScaleFactor used to derive temporal direct motion vector
uint32_t m_biWeight = 0; //!< Bidirectional Weight

AvcBasicFeature *m_basicFeature = nullptr; //!< AVC paramter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ namespace encode
if (hevcSeqParams->RateControlMethod == RATECONTROL_CBR)
{
// Assume max padding num < target frame size derived from target bit rate and frame rate
if (hevcSeqParams->FrameRate.Denominator == 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
uint32_t actualFrameRate = hevcSeqParams->FrameRate.Numerator / hevcSeqParams->FrameRate.Denominator;
uint64_t reservedPart = (uint64_t)hevcSeqParams->TargetBitRate / 8 / (uint64_t)actualFrameRate * 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,10 @@ namespace encode {
m_jpegHuffmanTable->m_huffmanData[i + 2].m_tableClass = m_jpegHuffmanTable->m_huffmanData[i].m_tableClass;
m_jpegHuffmanTable->m_huffmanData[i + 2].m_tableID = m_jpegHuffmanTable->m_huffmanData[i].m_tableID;

if ((i + 2) >= JPEG_NUM_ENCODE_HUFF_BUFF)
{
return MOS_STATUS_INVALID_PARAMETER;
}
ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy(&m_jpegHuffmanTable->m_huffmanData[i + 2].m_bits[0],
sizeof(uint8_t) * JPEG_NUM_HUFF_TABLE_AC_BITS,
&m_jpegHuffmanTable->m_huffmanData[i].m_bits[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class Vp9EncodeBrc : public MediaFeature, public mhw::vdbox::huc::Itf::ParSettin
bool m_vdencBrcEnabled = false; //!< Vdenc bitrate control enabled flag

// BRC Resources/Buffers
HucBrcBuffers m_brcBuffers;
HucBrcBuffers m_brcBuffers = {};
uint32_t m_brcHistoryBufferSize = 0; //!< Bitrate control history buffer size
uint32_t m_vdencBrcStatsBufferSize = 0; //!< VDENC bitrate control buffer size
MOS_RESOURCE m_resFrameStatStreamOutBuffer = {0}; //!< Frame statistics stream out buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ MOS_STATUS Vp9Segmentation::Update(void *params)
}
// Need to index properly when more than one temporal layer is present
ENCODE_ASSERT(vp9SeqParams->FrameRate[0].uiDenominator > 0);
if (vp9SeqParams->FrameRate[0].uiDenominator == 0)
{
return MOS_STATUS_INVALID_PARAMETER;
}
uint32_t frameRate = vp9SeqParams->FrameRate[0].uiNumerator / vp9SeqParams->FrameRate[0].uiDenominator;

if (!m_mbBrcEnabled)
Expand Down

0 comments on commit d1336b4

Please sign in to comment.