Skip to content

Commit

Permalink
Fix race issue among decoding threads which causes broken frame.
Browse files Browse the repository at this point in the history
Trim event timings for multi-thread cooperation.
  • Loading branch information
tyan0 committed Mar 24, 2024
1 parent 4f01c15 commit 860bc68
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 @@ -693,9 +693,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 @@ -705,7 +707,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 @@ -791,6 +792,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 @@ -873,8 +878,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 @@ -899,8 +902,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 860bc68

Please sign in to comment.