History

Threaded decoding enhancement:

1. Distinguish non-threaded decoding with m_iThreadCount = 0 from one-thread decoding with m_iThreadCount=1. 2. Removed the use of bAvailable of PPicture and replaced by the use of iRefCount to more preciously represent the picture's being-use counts in both threaded and non-threaded mode.

xiaotiansf committed 7 years ago

Commit e7f5f6a1 parent 033c6a014 files · +125 −104Browse files

Showing the changes to codec/decoder/core/src/decoder_core.cpp (1 of 14 files). Show all

Unified · Split

codec/decoder/core/src/decoder_core.cpp+26−39
@@ -221,17 +221,17 @@ static inline int32_t DecodeFrameConstruction (PWelsDecoderContext pCtx, uint8_t · 220 unmodified lines
221221 ppDst[1] = ppDst[1] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
222222 ppDst[2] = ppDst[2] + pCtx->sFrameCrop.iTopOffset * pPic->iLinesize[1] + pCtx->sFrameCrop.iLeftOffset;
223223 pDstInfo->iBufferStatus = 1;
224− if (pCtx->pThreadCtx != NULL && pPic->bIsComplete == false) {
224+ if (GetThreadCount (pCtx) > 1 && pPic->bIsComplete == false) {
225225 pPic->bIsComplete = true;
226226 }
227− if (pCtx->pThreadCtx != NULL) {
227+ if (GetThreadCount (pCtx) > 1) {
228228 uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;
229229 for (uint32_t i = 0; i < uiMbHeight; ++i) {
230230 SET_EVENT (&pCtx->pDec->pReadyEvent[i]);
231231 }
232232 }
233233 bool bOutResChange = false;
234− if (pCtx->pThreadCtx == NULL || pCtx->pLastThreadCtx == NULL) {
234+ if (GetThreadCount (pCtx) <= 1 || pCtx->pLastThreadCtx == NULL) {
235235 bOutResChange = (pCtx->iLastImgWidthInPixel != pDstInfo->UsrData.sSystemBuffer.iWidth)
236236 || (pCtx->iLastImgHeightInPixel != pDstInfo->UsrData.sSystemBuffer.iHeight);
237237 } else {
@@ -2282,7 +2282,7 @@ int32_t WelsDecodeInitAccessUnitStart (PWelsDecoderContext pCtx, SBufferInfo* pD · 2044 unmodified lines
22822282 */
22832283 int32_t AllocPicBuffOnNewSeqBegin (PWelsDecoderContext pCtx) {
22842284 //try to allocate or relocate DPB memory only when new sequence is coming.
2285− if (pCtx->pThreadCtx == NULL) {
2285+ if (GetThreadCount (pCtx) <= 1) {
22862286 WelsResetRefPic (pCtx); //clear ref pPic when IDR NAL
22872287 }
22882288 int32_t iErr = SyncPictureResolutionExt (pCtx, pCtx->pSps->iMbWidth, pCtx->pSps->iMbHeight);
@@ -2418,7 +2418,7 @@ void WelsDqLayerDecodeStart (PWelsDecoderContext pCtx, PNalUnit pCurNal, PSps pS · 129 unmodified lines
24182418
24192419 int32_t InitRefPicList (PWelsDecoderContext pCtx, const uint8_t kuiNRi, int32_t iPoc) {
24202420 int32_t iRet = ERR_NONE;
2421− if (pCtx->pThreadCtx != NULL && pCtx->bNewSeqBegin) {
2421+ if (GetThreadCount (pCtx) > 1 && pCtx->bNewSeqBegin) {
24222422 WelsResetRefPic (pCtx);
24232423 }
24242424 if (pCtx->eSliceType == B_SLICE) {
@@ -2542,7 +2542,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 117 unmodified lines
25422542 }
25432543 }
25442544 bool isNewFrame = true;
2545− if (pThreadCtx != NULL) {
2545+ if (GetThreadCount (pCtx) > 1) {
25462546 isNewFrame = pCtx->pDec == NULL;
25472547 }
25482548 if (pCtx->pDec == NULL) {
@@ -2553,7 +2553,6 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 4 unmodified lines
25532553 uint32_t i = 0;
25542554 while (i < MAX_DPB_COUNT && pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i]) {
25552555 pLastThreadCtx->pDec->pRefPic[listIdx][i] = pLastThreadCtx->pCtx->sRefPic.pRefList[listIdx][i];
2556− pLastThreadCtx->pDec->pRefPic[listIdx][i]->bAvailableFlag = false;
25572556 ++i;
25582557 }
25592558 }
@@ -2563,30 +2562,8 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 3 unmodified lines
25632562 } else {
25642563 pCtx->sRefPic = pLastThreadCtx->pCtx->sRefPic;
25652564 }
2566− //printf ("last uiDecodingTimeStamp = %d\n", pLastThreadCtx->pCtx->uiDecodingTimeStamp);
2567− for (int32_t i = 0; i < pCtx->sRefPic.uiRefCount[LIST_0]; ++i) {
2568− if (pCtx->sRefPic.pRefList[LIST_0][i] != NULL) {
2569− pCtx->sRefPic.pRefList[LIST_0][i]->bAvailableFlag = false;
2570− }
2571− }
2572− for (int32_t i = 0; i < pCtx->sRefPic.uiRefCount[LIST_1]; ++i) {
2573− if (pCtx->sRefPic.pRefList[LIST_1][i] != NULL) {
2574− pCtx->sRefPic.pRefList[LIST_1][i]->bAvailableFlag = false;
2575− }
2576− }
25772565 }
25782566 pCtx->pDec = PrefetchPic (pCtx->pPicBuff);
2579− if (pThreadCtx != NULL) {
2580− if (pCtx->pDec != NULL) {
2581− pCtx->pDec->bAvailableFlag = false;
2582− pCtx->pDec->bIsUngroupedMultiSlice = false;
2583− pThreadCtx->pDec = pCtx->pDec;
2584− uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;
2585− for (uint32_t i = 0; i < uiMbHeight; ++i) {
2586− RESET_EVENT (&pCtx->pDec->pReadyEvent[i]);
2587− }
2588− }
2589− }
25902567 if (pCtx->iTotalNumMbRec != 0)
25912568 pCtx->iTotalNumMbRec = 0;
25922569
@@ -2598,6 +2575,15 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 5 unmodified lines
25982575 pCtx->iErrorCode |= dsOutOfMemory;
25992576 return ERR_INFO_REF_COUNT_OVERFLOW;
26002577 }
2578+ if (pThreadCtx != NULL) {
2579+ pCtx->pDec->bIsUngroupedMultiSlice = false;
2580+ pThreadCtx->pDec = pCtx->pDec;
2581+ if (GetThreadCount (pCtx) > 1) ++pCtx->pDec->iRefCount;
2582+ uint32_t uiMbHeight = (pCtx->pDec->iHeightInPixel + 15) >> 4;
2583+ for (uint32_t i = 0; i < uiMbHeight; ++i) {
2584+ RESET_EVENT (&pCtx->pDec->pReadyEvent[i]);
2585+ }
2586+ }
26012587 pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding
26022588 } else if (pCtx->iTotalNumMbRec == 0) { //pDec != NULL, already start
26032589 pCtx->pDec->bNewSeqBegin = pCtx->bNewSeqBegin; //set flag for start decoding
@@ -2743,7 +2729,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 139 unmodified lines
27432729 if (pSh->eSliceType == B_SLICE && !pSh->iDirectSpatialMvPredFlag)
27442730 ComputeColocatedTemporalScaling (pCtx);
27452731
2746− if (pThreadCtx != NULL) {
2732+ if (GetThreadCount (pCtx) > 1) {
27472733 memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t));
27482734 SET_EVENT (&pThreadCtx->sSliceDecodeStart);
27492735 iRet = WelsDecodeAndConstructSlice (pCtx);
@@ -2765,14 +2751,14 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 15 unmodified lines
27652751 }
27662752 }
27672753
2768− if (pThreadCtx == NULL && bReconstructSlice) {
2754+ if (GetThreadCount (pCtx) <= 1 && bReconstructSlice) {
27692755 if ((iRet = WelsDecodeConstructSlice (pCtx, pNalCur)) != ERR_NONE) {
27702756 pCtx->pDec->bIsComplete = false; // reconstruction error, directly set the flag false
27712757 return iRet;
27722758 }
27732759 }
27742760 if (bAllRefComplete && pCtx->eSliceType != I_SLICE) {
2775− if (pCtx->pThreadCtx == NULL) {
2761+ if (GetThreadCount (pCtx) <= 1) {
27762762 if (pCtx->sRefPic.uiRefCount[LIST_0] > 0) {
27772763 bAllRefComplete &= CheckRefPicturesComplete (pCtx);
27782764 } else {
@@ -2829,17 +2815,18 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 50 unmodified lines
28292815 }
28302816 }
28312817
2832− if (pThreadCtx != NULL && pCtx->uiDecodingTimeStamp > 1 && pCtx->pLastDecPicInfo->uiDecodingTimeStamp > 0) {
2818+ if (GetThreadCount (pCtx) > 1 && pCtx->uiDecodingTimeStamp > 1 && pCtx->pLastDecPicInfo->uiDecodingTimeStamp > 0) {
28332819 while (pCtx->uiDecodingTimeStamp > pCtx->pLastDecPicInfo->uiDecodingTimeStamp + 1) {
28342820 WelsSleep (1);
28352821 }
28362822 }
2837− if (pThreadCtx != NULL) {
2823+
2824+ if (GetThreadCount (pCtx) >= 1) {
28382825 pCtx->pLastDecPicInfo->uiDecodingTimeStamp = pCtx->uiDecodingTimeStamp;
28392826 }
28402827 iRet = DecodeFrameConstruction (pCtx, ppDst, pDstInfo);
28412828 if (iRet) {
2842− if (pThreadCtx != NULL) {
2829+ if (GetThreadCount (pCtx) > 1) {
28432830 SET_EVENT (&pThreadCtx->sSliceDecodeFinsh);
28442831 }
28452832 return iRet;
@@ -2847,7 +2834,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 1 unmodified line
28472834
28482835 pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb = pCtx->pDec; //store latest decoded picture for EC
28492836 pCtx->bUsedAsRef = pCtx->uiNalRefIdc > 0;
2850− if (pCtx->pThreadCtx == NULL) {
2837+ if (GetThreadCount (pCtx) <= 1) {
28512838 if (pCtx->bUsedAsRef) {
28522839 for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
28532840 uint32_t i = 0;
@@ -2870,7 +2857,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 16 unmodified lines
28702857 pCtx->pDec->iLinesize,
28712858 pCtx->sExpandPicFunc.pfExpandLumaPicture, pCtx->sExpandPicFunc.pfExpandChromaPicture);
28722859 }
2873− } else {
2860+ } else if (GetThreadCount (pCtx) > 1) {
28742861 SET_EVENT (&pThreadCtx->sImageReady);
28752862 }
28762863 pCtx->pDec = NULL; //after frame decoding, always set to NULL
@@ -2881,7 +2868,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 4 unmodified lines
28812868 pCtx->pLastDecPicInfo->iPrevFrameNum = pSh->iFrameNum;
28822869 if (pCtx->pLastDecPicInfo->bLastHasMmco5)
28832870 pCtx->pLastDecPicInfo->iPrevFrameNum = 0;
2884− if (pThreadCtx != NULL) {
2871+ if (GetThreadCount (pCtx) > 1) {
28852872 int32_t threadCount = pThreadCtx->sThreadInfo.uiThrMaxNum;
28862873 int32_t id = pThreadCtx->sThreadInfo.uiThrNum;
28872874 for (int32_t i = 0; i < threadCount; ++i) {
@@ -2899,7 +2886,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf · 11 unmodified lines
28992886 }
29002887 }
29012888 }
2902− if (pThreadCtx != NULL) {
2889+ if (GetThreadCount (pCtx) > 1) {
29032890 SET_EVENT (&pThreadCtx->sSliceDecodeFinsh);
29042891 }
29052892 return ERR_NONE;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t