Skip to content

Commit 1c23887

Browse files
authored
Fix race issue among decoding threads which causes broken frame. (#3735)
Trim event timings for multi-thread cooperation.
1 parent 1debdae commit 1c23887

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

codec/decoder/plus/src/welsDecoderExt.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,11 @@ DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,
695695
SBufferInfo* pDstInfo) {
696696
int iRet = dsErrorFree;
697697
if (m_iThreadCount >= 1) {
698+
SET_EVENT (&m_sReleaseBufferEvent);
698699
iRet = ThreadDecodeFrameInternal (kpSrc, kiSrcLen, ppDst, pDstInfo);
699700
if (m_sReoderingStatus.iNumOfPicts) {
700701
WAIT_EVENT (&m_sBufferingEvent, WELS_DEC_THREAD_WAIT_INFINITE);
702+
RESET_EVENT (&m_sBufferingEvent);
701703
RESET_EVENT (&m_sReleaseBufferEvent);
702704
if (!m_sReoderingStatus.bHasBSlice) {
703705
if (m_sReoderingStatus.iNumOfPicts > 1) {
@@ -707,7 +709,6 @@ DECODING_STATE CWelsDecoder::DecodeFrameNoDelay (const unsigned char* kpSrc,
707709
else {
708710
ReleaseBufferedReadyPictureReorder (NULL, ppDst, pDstInfo);
709711
}
710-
SET_EVENT(&m_sReleaseBufferEvent);
711712
}
712713
return (DECODING_STATE)iRet;
713714
}
@@ -793,6 +794,10 @@ DECODING_STATE CWelsDecoder::DecodeFrame2WithCtx (PWelsDecoderContext pDecContex
793794
pDecContext->iFrameNum = -1; //initialize
794795
#endif
795796

797+
if (GetThreadCount (pDecContext) >= 1) {
798+
WAIT_EVENT (&m_sReleaseBufferEvent, WELS_DEC_THREAD_WAIT_INFINITE);
799+
}
800+
796801
pDecContext->iFeedbackTidInAu = -1; //initialize
797802
pDecContext->iFeedbackNalRefIdc = -1; //initialize
798803
if (pDstInfo) {
@@ -875,8 +880,6 @@ DECODING_STATE CWelsDecoder::DecodeFrame2WithCtx (PWelsDecoderContext pDecContex
875880

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

903906
if (GetThreadCount (pDecContext) >= 1) {
904-
WAIT_EVENT (&m_sReleaseBufferEvent, WELS_DEC_THREAD_WAIT_INFINITE);
905-
RESET_EVENT (&m_sBufferingEvent);
906907
BufferingReadyPicture (pDecContext, ppDst, pDstInfo);
907908
SET_EVENT (&m_sBufferingEvent);
908909
} else {

0 commit comments

Comments
 (0)