Skip to content

Commit

Permalink
Fix race issue among decoding threads which causes broken frame. (#3735)
Browse files Browse the repository at this point in the history
Trim event timings for multi-thread cooperation.
  • Loading branch information
tyan0 committed Apr 18, 2024
1 parent 1debdae commit 1c23887
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions codec/decoder/plus/src/welsDecoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,11 @@ DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,
SBufferInfo* pDstInfo) {
int iRet = dsErrorFree;
if (m_iThreadCount >= 1) {
SET_EVENT (&m_sReleaseBufferEvent);
iRet = ThreadDecodeFrameInternal (kpSrc, kiSrcLen, ppDst, pDstInfo);
if (m_sReoderingStatus.iNumOfPicts) {
WAIT_EVENT (&m_sBufferingEvent, WELS_DEC_THREAD_WAIT_INFINITE);
RESET_EVENT (&m_sBufferingEvent);
RESET_EVENT (&m_sReleaseBufferEvent);
if (!m_sReoderingStatus.bHasBSlice) {
if (m_sReoderingStatus.iNumOfPicts > 1) {
Expand All @@ -707,7 +709,6 @@ DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,
else {
ReleaseBufferedReadyPictureReorder (NULL, ppDst, pDstInfo);
}
SET_EVENT(&m_sReleaseBufferEvent);
}
return (DECODING_STATE)iRet;
}
Expand Down Expand Up @@ -793,6 +794,10 @@ DECODING_STATE CWelsDecoder::DecodeFrame2WithCtx (PWelsDecoderContext pDecContex
pDecContext->iFrameNum = -1; //initialize
#endif

if (GetThreadCount (pDecContext) >= 1) {
WAIT_EVENT (&m_sReleaseBufferEvent, WELS_DEC_THREAD_WAIT_INFINITE);
}

pDecContext->iFeedbackTidInAu = -1; //initialize
pDecContext->iFeedbackNalRefIdc = -1; //initialize
if (pDstInfo) {
Expand Down Expand Up @@ -875,8 +880,6 @@ DECODING_STATE CWelsDecoder::DecodeFrame2WithCtx (PWelsDecoderContext pDecContex

OutputStatisticsLog (*pDecContext->pDecoderStatistics);
if (GetThreadCount (pDecContext) >= 1) {
WAIT_EVENT (&m_sReleaseBufferEvent, WELS_DEC_THREAD_WAIT_INFINITE);
RESET_EVENT (&m_sBufferingEvent);
BufferingReadyPicture (pDecContext, ppDst, pDstInfo);
SET_EVENT (&m_sBufferingEvent);
} else {
Expand All @@ -901,8 +904,6 @@ DECODING_STATE CWelsDecoder::DecodeFrame2WithCtx (PWelsDecoderContext pDecContex
pDecContext->dDecTime += (iEnd - iStart) / 1e3;

if (GetThreadCount (pDecContext) >= 1) {
WAIT_EVENT (&m_sReleaseBufferEvent, WELS_DEC_THREAD_WAIT_INFINITE);
RESET_EVENT (&m_sBufferingEvent);
BufferingReadyPicture (pDecContext, ppDst, pDstInfo);
SET_EVENT (&m_sBufferingEvent);
} else {
Expand Down

0 comments on commit 1c23887

Please sign in to comment.