Skip to content

Commit

Permalink
Fix regression in PR#3707 for multi-thread decoding (#3734)
Browse files Browse the repository at this point in the history
* Fix regression in PR#3707 for multi-thread decoding

The variable iSeqNum introduced in PR#3707 should be common within
the decoder, however each decoding thread in the same decoder had
its own one. Due to this issue, multi-thread decoding failed.
This patch fixes that.

* Fix segfault caused in WelsDecodeInitAccessUnitStart()

... if CWelsDecoder::InitDecoderCtx() is not called.
  • Loading branch information
tyan0 authored Apr 1, 2024
1 parent c59550a commit c0e5ea2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
1 change: 1 addition & 0 deletions codec/decoder/core/inc/decoder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ typedef struct TagWelsDecoderContext {
#endif
bool bNewSeqBegin;
bool bNextNewSeqBegin;
int32_t *pStreamSeqNum;
int32_t iSeqNum;

//for Parse only
Expand Down
10 changes: 8 additions & 2 deletions codec/decoder/core/src/decoder_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,9 +2261,15 @@ int32_t WelsDecodeInitAccessUnitStart (PWelsDecoderContext pCtx, SBufferInfo* pD
pCtx->bAuReadyFlag = false;
pCtx->pLastDecPicInfo->bLastHasMmco5 = false;
bool bTmpNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps (pCtx);
if (bTmpNewSeqBegin)
pCtx->iSeqNum++;
if (bTmpNewSeqBegin) {
if (pCtx->pStreamSeqNum)
(*pCtx->pStreamSeqNum)++;
else
pCtx->iSeqNum++;
}
pCtx->bNewSeqBegin = pCtx->bNewSeqBegin || bTmpNewSeqBegin;
if (pCtx->pStreamSeqNum)
pCtx->iSeqNum = *pCtx->pStreamSeqNum;
iErr = WelsDecodeAccessUnitStart (pCtx);
GetVclNalTemporalId (pCtx);

Expand Down
1 change: 1 addition & 0 deletions codec/decoder/plus/inc/welsDecoderExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class CWelsDecoder : public ISVCDecoder {
SVlcTable m_sVlcTable;
SWelsLastDecPicInfo m_sLastDecPicInfo;
SDecoderStatistics m_sDecoderStatistics;// For real time debugging
int32_t m_iStreamSeqNum;

private:
int32_t InitDecoder (const SDecodingParam* pParam);
Expand Down
22 changes: 3 additions & 19 deletions codec/decoder/plus/src/welsDecoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ CWelsDecoder::CWelsDecoder (void)
m_DecCtxActiveCount (0),
m_pDecThrCtx (NULL),
m_pLastDecThrCtx (NULL),
m_iLastBufferedIdx (0) {
m_iLastBufferedIdx (0),
m_iStreamSeqNum (0) {
#ifdef OUTPUT_BIT_STREAM
char chFileName[1024] = { 0 }; //for .264
int iBufUsed = 0;
Expand Down Expand Up @@ -417,6 +418,7 @@ int32_t CWelsDecoder::InitDecoderCtx (PWelsDecoderContext& pCtx, const SDecoding
pCtx->pPictInfoList = m_sPictInfoList;
pCtx->pPictReoderingStatus = &m_sReoderingStatus;
pCtx->pCsDecoder = &m_csDecoder;
pCtx->pStreamSeqNum = &m_iStreamSeqNum;
WelsDecoderDefaults (pCtx, &m_pWelsTrace->m_sLogCtx);
WelsDecoderSpsPpsDefaults (pCtx->sSpsPpsCtx);
//check param and update decoder context
Expand Down Expand Up @@ -1137,24 +1139,6 @@ DECODING_STATE CWelsDecoder::ReorderPicturesInDisplay(PWelsDecoderContext pDecCo
m_bIsBaseline = pDecContext->pSps->uiProfileIdc == 66 || pDecContext->pSps->uiProfileIdc == 83;
if (!m_bIsBaseline) {
if (pDstInfo->iBufferStatus == 1) {
if (pDecContext->pSliceHeader->eSliceType == B_SLICE &&
((pDecContext->iSeqNum == m_sReoderingStatus.iLastWrittenSeqNum) ?
(pDecContext->pSliceHeader->iPicOrderCntLsb <= m_sReoderingStatus.iLastWrittenPOC + 2) :
(pDecContext->iSeqNum - m_sReoderingStatus.iLastWrittenSeqNum == 1 && pDecContext->pSliceHeader->iPicOrderCntLsb == 0))) {
m_sReoderingStatus.iLastWrittenPOC = pDecContext->pSliceHeader->iPicOrderCntLsb;
m_sReoderingStatus.iLastWrittenSeqNum = pDecContext->iSeqNum;
//issue #3478, use b-slice type to determine correct picture order as the first priority as POC order is not as reliable as based on b-slice
ppDst[0] = pDstInfo->pDst[0];
ppDst[1] = pDstInfo->pDst[1];
ppDst[2] = pDstInfo->pDst[2];
#if defined (_DEBUG)
#ifdef _MOTION_VECTOR_DUMP_
fprintf (stderr, "Output POC: #%d uiDecodingTimeStamp=%d\n", pDecContext->pSliceHeader->iPicOrderCntLsb,
pDecContext->uiDecodingTimeStamp);
#endif
#endif
return iRet;
}
BufferingReadyPicture(pDecContext, ppDst, pDstInfo);
if (!m_sReoderingStatus.bHasBSlice && m_sReoderingStatus.iNumOfPicts > 1) {
ReleaseBufferedReadyPictureNoReorder (pDecContext, ppDst, pDstInfo);
Expand Down

0 comments on commit c0e5ea2

Please sign in to comment.