From 305c885df9039604ca8ce415c0f84339c44b1b26 Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Sat, 23 Mar 2024 19:25:36 +0900 Subject: [PATCH] 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. --- codec/decoder/core/inc/decoder_context.h | 1 + codec/decoder/core/src/decoder.cpp | 1 - codec/decoder/core/src/decoder_core.cpp | 3 ++- codec/decoder/plus/inc/welsDecoderExt.h | 1 + codec/decoder/plus/src/welsDecoderExt.cpp | 22 +++------------------- 5 files changed, 7 insertions(+), 21 deletions(-) diff --git a/codec/decoder/core/inc/decoder_context.h b/codec/decoder/core/inc/decoder_context.h index 7f9067c54f..fe825058eb 100644 --- a/codec/decoder/core/inc/decoder_context.h +++ b/codec/decoder/core/inc/decoder_context.h @@ -432,6 +432,7 @@ typedef struct TagWelsDecoderContext { #endif bool bNewSeqBegin; bool bNextNewSeqBegin; + int32_t *pStreamSeqNum; int32_t iSeqNum; //for Parse only diff --git a/codec/decoder/core/src/decoder.cpp b/codec/decoder/core/src/decoder.cpp index f296e9211a..64d4be1764 100644 --- a/codec/decoder/core/src/decoder.cpp +++ b/codec/decoder/core/src/decoder.cpp @@ -621,7 +621,6 @@ int32_t WelsOpenDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx) { pCtx->bPrintFrameErrorTraceFlag = true; pCtx->iIgnoredErrorInfoPacketCount = 0; pCtx->bFrameFinish = true; - pCtx->iSeqNum = 0; return iRet; } diff --git a/codec/decoder/core/src/decoder_core.cpp b/codec/decoder/core/src/decoder_core.cpp index 11b4f76101..f16929b89b 100644 --- a/codec/decoder/core/src/decoder_core.cpp +++ b/codec/decoder/core/src/decoder_core.cpp @@ -2262,8 +2262,9 @@ int32_t WelsDecodeInitAccessUnitStart (PWelsDecoderContext pCtx, SBufferInfo* pD pCtx->pLastDecPicInfo->bLastHasMmco5 = false; bool bTmpNewSeqBegin = CheckNewSeqBeginAndUpdateActiveLayerSps (pCtx); if (bTmpNewSeqBegin) - pCtx->iSeqNum++; + (*pCtx->pStreamSeqNum)++; pCtx->bNewSeqBegin = pCtx->bNewSeqBegin || bTmpNewSeqBegin; + pCtx->iSeqNum = *pCtx->pStreamSeqNum; iErr = WelsDecodeAccessUnitStart (pCtx); GetVclNalTemporalId (pCtx); diff --git a/codec/decoder/plus/inc/welsDecoderExt.h b/codec/decoder/plus/inc/welsDecoderExt.h index 9ac4f9a3c8..f5abac3feb 100644 --- a/codec/decoder/plus/inc/welsDecoderExt.h +++ b/codec/decoder/plus/inc/welsDecoderExt.h @@ -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); diff --git a/codec/decoder/plus/src/welsDecoderExt.cpp b/codec/decoder/plus/src/welsDecoderExt.cpp index 22e4fbd591..d07f12aff6 100644 --- a/codec/decoder/plus/src/welsDecoderExt.cpp +++ b/codec/decoder/plus/src/welsDecoderExt.cpp @@ -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; @@ -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 @@ -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);