Skip to content

Commit

Permalink
Merge pull request cisco#3302 from xiaotianshi2/threading-decoding-up…
Browse files Browse the repository at this point in the history
…date

Add thread decoding support for multi-slice frame. Note: In each call…
  • Loading branch information
huili2 authored Jun 29, 2020
2 parents e7ca9df + 0961948 commit 9746a6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions codec/decoder/core/src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in
}
CheckAndFinishLastPic (pCtx, ppDst, pDstBufInfo);
if (pCtx->bAuReadyFlag && pCtx->pAccessUnitList->uiAvailUnitsNum != 0) {
if (pCtx->pThreadCtx == NULL) {
if (GetThreadCount (pCtx) <= 1) {
ConstructAccessUnit (pCtx, ppDst, pDstBufInfo);
} else {
pCtx->pAccessUnitList->uiAvailUnitsNum = 1;
Expand Down Expand Up @@ -873,11 +873,11 @@ int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const in
if (IS_PARAM_SETS_NALS (pCtx->sCurNalHead.eNalUnitType)) {
iRet = ParseNonVclNal (pCtx, pNalPayload, iDstIdx - iConsumedBytes, pSrcNal - 3, iSrcIdx + 3);
}
if (pCtx->pThreadCtx == NULL) {
if (GetThreadCount (pCtx) <= 1) {
CheckAndFinishLastPic (pCtx, ppDst, pDstBufInfo);
}
if (pCtx->bAuReadyFlag && pCtx->pAccessUnitList->uiAvailUnitsNum != 0) {
if (pCtx->pThreadCtx == NULL) {
if (GetThreadCount (pCtx) <= 1) {
ConstructAccessUnit (pCtx, ppDst, pDstBufInfo);
} else {
pCtx->pAccessUnitList->uiAvailUnitsNum = 1;
Expand Down
24 changes: 19 additions & 5 deletions codec/decoder/core/src/decoder_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ int32_t InitConstructAccessUnit (PWelsDecoderContext pCtx, SBufferInfo* pDstInfo
*/
int32_t ConstructAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBufferInfo* pDstInfo) {
int32_t iErr = ERR_NONE;
if (pCtx->pThreadCtx == NULL) {
if (GetThreadCount (pCtx) <= 1) {
iErr = InitConstructAccessUnit (pCtx, pDstInfo);
if (ERR_NONE != iErr) {
return iErr;
Expand Down Expand Up @@ -2550,7 +2550,7 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf
isNewFrame = pCtx->pDec == NULL;
}
if (pCtx->pDec == NULL) {
if (pLastThreadCtx != NULL) {
if (pLastThreadCtx != NULL && iIdx == 0) {
pLastThreadCtx->pDec->bUsedAsRef = pLastThreadCtx->pCtx->uiNalRefIdc > 0;
if (pLastThreadCtx->pDec->bUsedAsRef) {
for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) {
Expand Down Expand Up @@ -2686,7 +2686,19 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf
if (pCtx->bNewSeqBegin) {
iPrevFrameNum = 0;
} else if (pLastThreadCtx->pDec != NULL) {
iPrevFrameNum = pLastThreadCtx->pDec->iFrameNum;
if (pLastThreadCtx->pDec->uiTimeStamp == pCtx->uiTimeStamp - 1) {
iPrevFrameNum = pLastThreadCtx->pDec->iFrameNum;
if (iPrevFrameNum == -1) iPrevFrameNum = pLastThreadCtx->pCtx->iFrameNum;
} else {
int32_t id = pThreadCtx->sThreadInfo.uiThrNum;
for (int32_t i = 0; i < iThreadCount; ++i) {
if (pThreadCtx[i - id].pCtx->uiTimeStamp == pCtx->uiTimeStamp - 1) {
if (pThreadCtx[i - id].pDec != NULL) iPrevFrameNum = pThreadCtx[i - id].pDec->iFrameNum;
if (iPrevFrameNum == -1) iPrevFrameNum = pThreadCtx[i - id].pCtx->iFrameNum;
break;
}
}
}
} else {
iPrevFrameNum = pCtx->bNewSeqBegin ? 0 : pLastThreadCtx->pCtx->iFrameNum;
}
Expand Down Expand Up @@ -2734,8 +2746,10 @@ int32_t DecodeCurrentAccessUnit (PWelsDecoderContext pCtx, uint8_t** ppDst, SBuf
ComputeColocatedTemporalScaling (pCtx);

if (iThreadCount > 1) {
memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t));
SET_EVENT (&pThreadCtx->sSliceDecodeStart);
if (iIdx == 0) {
memset (&pCtx->lastReadyHeightOffset[0][0], -1, LIST_A * MAX_REF_PIC_COUNT * sizeof (int16_t));
SET_EVENT (&pThreadCtx->sSliceDecodeStart);
}
iRet = WelsDecodeAndConstructSlice (pCtx);
} else {
iRet = WelsDecodeSlice (pCtx, bFreshSliceAvailable, pNalCur);
Expand Down
7 changes: 7 additions & 0 deletions codec/decoder/plus/src/welsDecoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,13 @@ DECODING_STATE CWelsDecoder::ParseAccessUnit (SWelsDecoderThreadCTX& sThreadCtx)
sThreadCtx.pCtx->iImgHeightInPixel = m_pLastDecThrCtx->pCtx->iImgHeightInPixel;
}
}

//if threadCount > 1, then each thread must contain exact one complete frame.
if (GetThreadCount (sThreadCtx.pCtx) > 1) {
sThreadCtx.pCtx->pAccessUnitList->uiAvailUnitsNum = 0;
sThreadCtx.pCtx->pAccessUnitList->uiActualUnitsNum = 0;
}

int32_t iRet = DecodeFrame2WithCtx (sThreadCtx.pCtx, sThreadCtx.kpSrc, sThreadCtx.kiSrcLen, sThreadCtx.ppDst,
&sThreadCtx.sDstInfo);

Expand Down

0 comments on commit 9746a6b

Please sign in to comment.