ref: dcfe76d1ff267220c4ca93da383a30d41fbef65d
parent: 6dc3f72ef8c25058bb5ca4b4279891811e216592
author: huade <huashi@cisco.com>
date: Tue Dec 8 09:09:43 EST 2015
unitfy slice bs writing for multi-thread(sliceindex==0 is the same with others )
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -1792,7 +1792,7 @@
iCountBsLen = iNonVclLayersBsSizeCount + iVclLayersBsSizeCount;
iMaxSliceBufferSize = WELS_MIN (iMaxSliceBufferSize, iTargetSpatialBsSize);
- iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + ((*ppCtx)->iMaxSliceCount - 1) *
+ iTotalLength = (pParam->iMultipleThreadIdc == 1) ? iCountBsLen : (iCountBsLen + (*ppCtx)->iMaxSliceCount *
iMaxSliceBufferSize);
pParam->iNumRefFrame = WELS_CLIP3 (pParam->iNumRefFrame, MIN_REF_PIC_COUNT,
@@ -3998,7 +3998,6 @@
pLayerBsInfo->uiTemporalId = pCtx->uiTemporalId;
pLayerBsInfo->uiQualityId = 0;
pLayerBsInfo->iNalCount = 0;
- pCtx->pSliceBs[0].pBs = pLayerBsInfo->pBsBuf;
pCtx->pTaskManage->ExecuteTasks();
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -259,8 +259,8 @@
return ENC_RETURN_UNEXPECTED;
}
//slice 0
- (*ppCtx)->pSliceBs[0].uiSize = iSlice0Len;
- (*ppCtx)->pSliceBs[0].pBs = (*ppCtx)->pFrameBs;
+ (*ppCtx)->pSliceBs[0].uiSize = iSlice1Len;
+ (*ppCtx)->pSliceBs[0].pBs = (*ppCtx)->pFrameBs + iSlice0Len;
(*ppCtx)->pSliceBs[0].uiBsPos = 0;
(*ppCtx)->pSliceBs[0].pBsBuffer = pSmt->pThreadBsBuffer[0];
if ((iMaxSliceNum == 1) && (!bDynamicSlice)) {
@@ -524,13 +524,11 @@
assert (pSliceBs->bSliceCodedFlag);
#endif//MT_DEBUG_BS_WR
- if (iSliceIdx > 0) {
- // pSlice 0 bs has been written to pFrameBs yet by now, so uiSliceIdx base should be 1
- memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
- pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
+ memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
+ pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
- iLayerSize += pSliceBs->uiBsPos;
- }
+ iLayerSize += pSliceBs->uiBsPos;
+
while (iNalIdx < iCountNal) {
pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
++ iNalIdx;
@@ -555,10 +553,8 @@
while (iIdx < kiCountSlicesCoded) {
pSliceBs = &pCtx->pSliceBs[iSliceIdx];
if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
- if (iSliceIdx > 0) {
- memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
- pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
- }
+ memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
+ pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
const int32_t iCountNal = pSliceBs->iNalIndex;
iLayerSize += pSliceBs->uiBsPos;
@@ -586,8 +582,7 @@
int32_t iNalIdx = 0;
int32_t iNalSize = 0;
int32_t iReturn = ENC_RETURN_SUCCESS;
- int32_t iTotalLeftLength = (iSliceIdx > 0) ? (pSliceBs->uiSize - pSliceBs->uiBsPos)
- : (pCtx->iFrameBsSize - pCtx->iPosBsBuffer);
+ int32_t iTotalLeftLength = pSliceBs->uiSize - pSliceBs->uiBsPos;
SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
uint8_t* pDst = pSliceBs->pBs;
@@ -720,9 +715,6 @@
pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
iEventIdx);
}
- if (0 == iSliceIdx) {
- pEncPEncCtx->iPosBsBuffer += iSliceSize;
- }
pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
@@ -822,9 +814,6 @@
pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
iEventIdx);
}
- if (0 == iSliceIdx) {
- pEncPEncCtx->iPosBsBuffer += iSliceSize;
- }
pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
@@ -936,7 +925,6 @@
pLbi->uiTemporalId = pCtx->uiTemporalId;
pLbi->uiQualityId = 0;
pLbi->iNalCount = 0;
- pCtx->pSliceBs[0].pBs = pLbi->pBsBuf;
iIdx = 0;
while (iIdx < kiEventCnt) {
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -174,9 +174,6 @@
m_iSliceIdx);
return iReturn;
}
- if (0 == m_iSliceIdx) {
- m_pCtx->iPosBsBuffer += m_iSliceSize;
- }
m_pCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (m_pCtx->pCurDqLayer, m_pCtx->pFuncList, m_iSliceIdx);