ref: 2df092bcaef189b0689738fdfc1fc7a8a790d2d6
parent: 01016b1c83b019d731e73c0bf513cd79ea3223ff
author: sijchen <sijchen@cisco.com>
date: Tue Nov 24 08:31:41 EST 2015
refactor multi-thread logic
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -4037,6 +4037,12 @@
pCtx->pTaskManage->ExecuteTasks();
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
+ if (pCtx->iEncoderError) {
+ WelsLog (pLogCtx, WELS_LOG_ERROR,
+ "WelsEncoderEncodeExt(), multi-slice (mode %d) encoding error!",
+ pParam->sSliceArgument.uiSliceMode);
+ return pCtx->iEncoderError;
+ }
}
// THREAD_FULLY_FIRE_MODE && SM_SIZELIMITED_SLICE
else if ((SM_SIZELIMITED_SLICE == pParam->sSliceArgument.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -604,23 +604,19 @@
pSliceBs = &pCtx->pSliceBs[iSliceIdx];
if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
if (iSliceIdx > 0) {
- int32_t iNalIdx = 0;
- const int32_t iCountNal = pSliceBs->iNalIndex;
-
memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
+ }
- iLayerSize += pSliceBs->uiBsPos;
-
- while (iNalIdx < iCountNal) {
- pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
- ++ iNalIdx;
- }
- pLbi->iNalCount += iCountNal;
- iNalIdxBase += iCountNal;
- } else {
- iLayerSize += pSliceBs->uiBsPos;
+ const int32_t iCountNal = pSliceBs->iNalIndex;
+ iLayerSize += pSliceBs->uiBsPos;
+ int32_t iNalIdx = 0;
+ while (iNalIdx < iCountNal) {
+ pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
+ ++ iNalIdx;
}
+ pLbi->iNalCount += iCountNal;
+ iNalIdxBase += iCountNal;
}
iSliceIdx += kiPartitionCnt;
@@ -709,7 +705,7 @@
if (WELS_THREAD_ERROR_WAIT_OBJECT_0 == iWaitRet) { // start pSlice coding signal waited
int iLayerIndex = pEncPEncCtx->pOut->iLayerBsIndex;
SFrameBSInfo* pFrameBsInfo = pPrivateData->pFrameBsInfo;
- SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo [iLayerIndex];
+ //SLayerBSInfo* pLbi = &pFrameBsInfo->sLayerInfo [iLayerIndex];
const int32_t kiCurDid = pEncPEncCtx->uiDependencyId;
SWelsSvcCodingParam* pCodingParam = pEncPEncCtx->pSvcParam;
@@ -874,29 +870,18 @@
WelsUnloadNalForSlice (pSliceBs);
- if (0 == iSliceIdx) {
- iReturn = WriteSliceBs (pEncPEncCtx, pLbi->pBsBuf,
- &pLbi->pNalLengthInByte[pLbi->iNalCount],
- pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer,
+ int32_t iLeftBufferSize = (iSliceIdx > 0) ? (pSliceBs->uiSize - pSliceBs->uiBsPos) : (pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer);
+ iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0],
+ iLeftBufferSize,
iSliceIdx, iSliceSize);
- pLbi->iNalCount += pSliceBs->iNalIndex;
- if (ENC_RETURN_SUCCESS != iReturn) {
- uiThrdRet = iReturn;
- WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
- pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
- iEventIdx);
- }
+ if (ENC_RETURN_SUCCESS != iReturn) {
+ uiThrdRet = iReturn;
+ WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
+ pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
+ iEventIdx);
+ }
+ if (0 == iSliceIdx) {
pEncPEncCtx->iPosBsBuffer += iSliceSize;
- } else {
- iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0],
- pSliceBs->uiSize - pSliceBs->uiBsPos,
- iSliceIdx, iSliceSize);
- if (ENC_RETURN_SUCCESS != iReturn) {
- uiThrdRet = iReturn;
- WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
- pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
- iEventIdx);
- }
}
pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);