Fix memory leak in VVC

Plus vps nal is not compulsory in VVC: not a condition for isSuffix()
This commit is contained in:
jcdr428 2022-01-22 20:42:44 +01:00
parent 49f43aa280
commit 97ed057dc4
2 changed files with 11 additions and 15 deletions

View File

@ -14,9 +14,10 @@ static const int MAX_SLICE_HEADER = 64;
VVCStreamReader::VVCStreamReader()
: MPEGStreamReader(),
m_vps(0),
m_vps(new VvcVpsUnit()),
m_sps(0),
m_pps(0),
m_slice(new VvcSliceHeader()),
m_firstFrame(true),
m_frameNum(0),
m_fullPicOrder(0),
@ -37,12 +38,12 @@ VVCStreamReader::~VVCStreamReader()
delete m_vps;
delete m_sps;
delete m_pps;
delete m_slice;
}
CheckStreamRez VVCStreamReader::checkStream(uint8_t* buffer, int len)
{
CheckStreamRez rez;
VvcSliceHeader slice;
uint8_t* end = buffer + len;
for (uint8_t* nal = NALUnit::findNextNAL(buffer, end); nal < end - 4; nal = NALUnit::findNextNAL(nal, end))
@ -55,8 +56,6 @@ CheckStreamRez VVCStreamReader::checkStream(uint8_t* buffer, int len)
switch (nalType)
{
case VvcUnit::NalType::VPS:
if (!m_vps)
m_vps = new VvcVpsUnit();
m_vps->decodeBuffer(nal, nextNal);
if (m_vps->deserialize())
return rez;
@ -87,10 +86,10 @@ CheckStreamRez VVCStreamReader::checkStream(uint8_t* buffer, int len)
// check Frame Depth on first slices
if (isSlice(nalType) && (nal[2] & 0x80))
{
slice.decodeBuffer(nal, FFMIN(nal + MAX_SLICE_HEADER, nextNal));
if (slice.deserialize(m_sps, m_pps))
m_slice->decodeBuffer(nal, FFMIN(nal + MAX_SLICE_HEADER, nextNal));
if (m_slice->deserialize(m_sps, m_pps))
return rez; // not enough buffer or error
m_fullPicOrder = toFullPicOrder(&slice, m_sps->log2_max_pic_order_cnt_lsb);
m_fullPicOrder = toFullPicOrder(m_slice, m_sps->log2_max_pic_order_cnt_lsb);
incTimings();
}
}
@ -218,7 +217,7 @@ bool VVCStreamReader::isSlice(VvcUnit::NalType nalType) const
bool VVCStreamReader::isSuffix(VvcUnit::NalType nalType) const
{
if (!m_sps || !m_vps || !m_pps)
if (!m_sps || !m_pps)
return false;
switch (nalType)
@ -321,15 +320,13 @@ int VVCStreamReader::intDecodeNAL(uint8_t* buff)
}
else
{ // first slice of current frame
VvcSliceHeader slice;
slice.decodeBuffer(curPos, FFMIN(curPos + MAX_SLICE_HEADER, nextNal));
rez = slice.deserialize(m_sps, m_pps);
m_slice->decodeBuffer(curPos, FFMIN(curPos + MAX_SLICE_HEADER, nextNal));
rez = m_slice->deserialize(m_sps, m_pps);
if (rez)
return rez; // not enough buffer or error
// if (slice.slice_type == VVC_IFRAME_SLICE)
if (nalType >= VvcUnit::NalType::IDR_W_RADL)
m_lastIFrame = true;
m_fullPicOrder = toFullPicOrder(&slice, m_sps->log2_max_pic_order_cnt_lsb);
m_fullPicOrder = toFullPicOrder(m_slice, m_sps->log2_max_pic_order_cnt_lsb);
}
}
sliceFound = true;
@ -348,8 +345,6 @@ int VVCStreamReader::intDecodeNAL(uint8_t* buff)
switch (nalType)
{
case VvcUnit::NalType::VPS:
if (!m_vps)
m_vps = new VvcVpsUnit();
m_vps->decodeBuffer(curPos, nextNalWithStartCode);
rez = m_vps->deserialize();
if (rez)

View File

@ -47,6 +47,7 @@ class VVCStreamReader : public MPEGStreamReader
VvcVpsUnit* m_vps;
VvcSpsUnit* m_sps;
VvcPpsUnit* m_pps;
VvcSliceHeader* m_slice;
bool m_firstFrame;
int m_frameNum;