ref: 4a4ade1201e8864533a38bab337ecb01f345cc65
parent: a422180695b1c16d897210e10bccd0ac1dd43660
author: huade <[email protected]>
date: Thu Nov 26 04:32:33 EST 2015
refact WriteSliceBs()
--- a/codec/encoder/core/inc/slice_multi_threading.h
+++ b/codec/encoder/core/inc/slice_multi_threading.h
@@ -98,11 +98,7 @@
#endif//defined(MT_DEBUG)
void SetOneSliceBsBufferUnderMultithread(sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx);
-int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pDst,
- int32_t* pNalLen,
- int32_t iTotalLeftLength,
- const int32_t iSliceIdx,
- int32_t& iSliceSize);
+int32_t WriteSliceBs (sWelsEncCtx* pCtx,SWelsSliceBs* pSliceBs,const int32_t iSliceIdx,int32_t& iSliceSize);
}
#endif//SVC_SLICE_MULTIPLE_THREADING_H__
--- a/codec/encoder/core/inc/wels_task_encoder.h
+++ b/codec/encoder/core/inc/wels_task_encoder.h
@@ -49,7 +49,7 @@
extern int32_t WriteSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, uint8_t* pFrameBsBuffer,
const int32_t iSliceIdx,
int32_t& iSliceSize);
-extern int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pSliceBsBuf, const int32_t iSliceIdx, int32_t& iSliceSize);
+extern int32_t WriteSliceBs (sWelsEncCtx* pCtx,SWelsSliceBs* pSliceBs,const int32_t iSliceIdx, int32_t& iSliceSize);
class CWelsSliceEncodingTask : public CWelsBaseTask {
public:
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -628,31 +628,30 @@
return iLayerSize;
}
-int32_t WriteSliceBs (sWelsEncCtx* pCtx, uint8_t* pDst,
- int32_t* pNalLen,
- int32_t iTotalLeftLength,
- const int32_t iSliceIdx,
- int32_t& iSliceSize) {
- SWelsSliceBs* pSliceBs = &pCtx->pSliceBs[iSliceIdx];
- SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
-
+int32_t WriteSliceBs (sWelsEncCtx* pCtx,SWelsSliceBs* pSliceBs,const int32_t iSliceIdx,int32_t& iSliceSize) {
const int32_t kiNalCnt = pSliceBs->iNalIndex;
int32_t iNalIdx = 0;
int32_t iNalSize = 0;
- int32_t iReturn = ENC_RETURN_SUCCESS;
- iSliceSize = 0;
+ int32_t iReturn = ENC_RETURN_SUCCESS;
+ int32_t iTotalLeftLength = (iSliceIdx > 0) ? (pSliceBs->uiSize - pSliceBs->uiBsPos)
+ : (pCtx->iFrameBsSize - pCtx->iPosBsBuffer);
+ SNalUnitHeaderExt* pNalHdrExt = &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt;
+ uint8_t* pDst = pSliceBs->pBs;
+
assert (kiNalCnt <= 2);
if (kiNalCnt > 2)
return 0;
+ iSliceSize = 0;
while (iNalIdx < kiNalCnt) {
iNalSize = 0;
iReturn = WelsEncodeNal (&pSliceBs->sNalList[iNalIdx], pNalHdrExt, iTotalLeftLength - iSliceSize,
pDst, &iNalSize);
WELS_VERIFY_RETURN_IFNEQ (iReturn, ENC_RETURN_SUCCESS)
- pNalLen[iNalIdx] = iNalSize;
- iSliceSize += iNalSize;
- pDst += iNalSize;
+
+ pSliceBs->iNalLen[iNalIdx] = iNalSize;
+ iSliceSize += iNalSize;
+ pDst += iNalSize;
++ iNalIdx;
}
pSliceBs->uiBsPos = iSliceSize;
@@ -761,13 +760,7 @@
WelsUnloadNalForSlice (pSliceBs);
- int32_t iLeftBufferSize = (iSliceIdx > 0) ?
- (pSliceBs->uiSize - pSliceBs->uiBsPos)
- : (pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer);
- iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs,
- &pSliceBs->iNalLen[0],
- iLeftBufferSize,
- iSliceIdx, iSliceSize);
+ iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs, iSliceIdx, iSliceSize);
if (ENC_RETURN_SUCCESS != iReturn) {
uiThrdRet = iReturn;
WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
@@ -869,10 +862,7 @@
WelsUnloadNalForSlice (pSliceBs);
- int32_t iLeftBufferSize = (iSliceIdx > 0) ? (pSliceBs->uiSize - pSliceBs->uiBsPos) : (pEncPEncCtx->iFrameBsSize - pEncPEncCtx->iPosBsBuffer);
- iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs->pBs, &pSliceBs->iNalLen[0],
- iLeftBufferSize,
- iSliceIdx, iSliceSize);
+ iReturn = WriteSliceBs (pEncPEncCtx, pSliceBs, iSliceIdx, iSliceSize);
if (ENC_RETURN_SUCCESS != iReturn) {
uiThrdRet = iReturn;
WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -165,12 +165,8 @@
WelsUnloadNalForSlice (m_pSliceBs);
m_iSliceSize = 0;
- int32_t iLeftBufferSize = (m_iSliceIdx > 0) ? (m_pSliceBs->uiSize - (int32_t) (m_pSliceBs->sBsWrite.pCurBuf -
- m_pSliceBs->sBsWrite.pStartBuf)) : (m_pCtx->iFrameBsSize - m_pCtx->iPosBsBuffer);
- iReturn = WriteSliceBs (m_pCtx, m_pSliceBs->pBs,
- &m_pSliceBs->iNalLen[0],
- iLeftBufferSize,
- m_iSliceIdx, m_iSliceSize);
+ iReturn = WriteSliceBs (m_pCtx, m_pSliceBs, m_iSliceIdx, m_iSliceSize);
+
if (ENC_RETURN_SUCCESS != iReturn) {
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING,
"[MT] CWelsSliceEncodingTask ExecuteTask(), WriteSliceBs not successful: coding_idx %d, um_iSliceIdx %d",