ref: 7bfb96b2b6ac2466294081eb73c4c0c5a27ec932
parent: b940e2cdf8937a59db9ef606b89134ebc2eb3fef
parent: 5cad0f9bba0dae49e9ce0d45cabe33d8bed157ed
author: ruil2 <ruil2@cisco.com>
date: Wed Jan 13 08:07:58 EST 2016
Merge pull request #2327 from sijchen/th41 Multiple enhancements and a bug fix
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -2500,14 +2500,6 @@
return iRet;
}
- if (pCodingParam->iMultipleThreadIdc > 1) {
- iRet = CreateSliceThreads (pCtx);
- if (iRet != 0) {
- WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), CreateSliceThreads failed return %d.", iRet);
- FreeMemorySvc (&pCtx);
- return iRet;
- }
- }
if (pCodingParam->iEntropyCodingModeFlag)
WelsCabacInit (pCtx);
WelsRcInitModule (pCtx, pCtx->pSvcParam->iRCMode);
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -257,7 +257,6 @@
int32_t iThreadNum = 0;
int32_t iIdx = 0;
int32_t iReturn = ENC_RETURN_SUCCESS;
- bool bWillUseTaskManage = false;
if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
return 1;
@@ -281,15 +280,6 @@
WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
#endif//!_WIN32
- iIdx = 0;
- while (iIdx < iNumSpatialLayers) {
- SSliceArgument* pSliceArgument = &pPara->sSpatialLayers[iIdx].sSliceArgument;
- if (pSliceArgument->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pSliceArgument->uiSliceMode == SM_RASTER_SLICE || pSliceArgument->uiSliceMode == SM_SIZELIMITED_SLICE) {
- bWillUseTaskManage = true;
- }
- ++ iIdx;
- }
-
#ifdef MT_DEBUG
// file handle for MT debug
pSmt->pFSliceDiff = NULL;
@@ -344,19 +334,15 @@
pSmt->pThreadBsBuffer[iIdx] = NULL;
}
- //previous conflict
WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace);
err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);
MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
- //previous conflict ends
iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
- if (bWillUseTaskManage) {
- (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice);
- WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx))
- }
+ (*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice);
+ WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx))
memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage);
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -201,7 +201,7 @@
m_iSliceStart = WelsTime();
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
- "[MT] CWelsLoadBalancingSlicingEncodingTask()InitTask for m_iSliceIdx %d at %" PRId64,
+ "[MT] CWelsLoadBalancingSlicingEncodingTask()InitTask for m_iSliceIdx %d at time=%" PRId64,
m_iSliceIdx, m_iSliceStart);
return ENC_RETURN_SUCCESS;
@@ -212,13 +212,14 @@
m_pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - m_iSliceStart);
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
- "[MT] CWelsLoadBalancingSlicingEncodingTask()FinishTask, coding_idx %d, um_iSliceIdx %d, uiSliceConsumeTime %d, m_iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d",
+ "[MT] CWelsLoadBalancingSlicingEncodingTask()FinishTask, coding_idx %d, um_iSliceIdx %d, uiSliceConsumeTime %d, m_iSliceSize %d, iFirstMbInSlice %d, count_num_mb_in_slice %d at time=%" PRId64,
m_pCtx->iCodingIndex,
m_iSliceIdx,
m_pSlice->uiSliceConsumeTime,
m_iSliceSize,
m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
- m_pSlice->iCountMbNumInSlice);
+ m_pSlice->iCountMbNumInSlice,
+ (m_pSlice->uiSliceConsumeTime + m_iSliceStart));
}
//CWelsConstrainedSizeSlicingEncodingTask
--- a/codec/encoder/core/src/wels_task_management.cpp
+++ b/codec/encoder/core/src/wels_task_management.cpp
@@ -123,7 +123,7 @@
WelsErrorType CWelsTaskManageBase::CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiCurDid) {
CWelsBaseTask* pTask = NULL;
int32_t kiTaskCount;
- uint32_t uiSliceMode = pEncCtx->pSvcParam->sSpatialLayers[0].sSliceArgument.uiSliceMode;
+ uint32_t uiSliceMode = pEncCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument.uiSliceMode;
if (uiSliceMode != SM_SIZELIMITED_SLICE) {
kiTaskCount = m_iTaskNum[kiCurDid] = pEncCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument.uiSliceNum;
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -381,8 +381,11 @@
const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
- if (kiEncoderReturn != cmResultSuccess)
+ if (kiEncoderReturn != cmResultSuccess) {
+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_DEBUG,
+ "CWelsH264SVCEncoder::EncodeFrame() not succeed, err=%d", kiEncoderReturn);
return kiEncoderReturn;
+ }
#ifdef REC_FRAME_COUNT
++ m_uiCountFrameNum;
--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -1447,15 +1447,19 @@
sParam.bSimulcastAVC = 1;
sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
sParam.sSpatialLayers[0].iVideoHeight = (iHeight >> 2);
- sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_SIZELIMITED_SLICE;
+ sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_FIXEDSLCNUM_SLICE;
sParam.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1500;
sParam.sSpatialLayers[1].iVideoWidth = iWidth;
sParam.sSpatialLayers[1].iVideoHeight = iHeight;
- sParam.sSpatialLayers[1].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
+ sParam.sSpatialLayers[1].sSliceArgument.uiSliceMode = (rand() % 2) ? SM_SIZELIMITED_SLICE : SM_FIXEDSLCNUM_SLICE;
sParam.sSpatialLayers[1].sSliceArgument.uiSliceNum = 1;
+ sParam.sSpatialLayers[1].sSliceArgument.uiSliceSizeConstraint = 1500;
- int rv = encoder_->InitializeExt (&sParam);
+ int iTraceLevel = WELS_LOG_QUIET;
+ int rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+
+ rv = encoder_->InitializeExt (&sParam);
ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
@@ -1568,14 +1572,18 @@
SEncParamExt sParam;
encoder_->GetDefaultParams (&sParam);
prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
- sParam.iMultipleThreadIdc = (rand() % 8) + 1;
+ sParam.iMultipleThreadIdc = 4;
sParam.bSimulcastAVC = 1;
sParam.sSpatialLayers[0].iVideoWidth = iWidth;
sParam.sSpatialLayers[0].iVideoHeight = iHeight;
sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
+ //TODO: use this after the buffer problem is fixed. sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = (rand()%2) ? SM_FIXEDSLCNUM_SLICE : SM_SIZELIMITED_SLICE;
sParam.sSpatialLayers[0].sSliceArgument.uiSliceNum = sParam.iMultipleThreadIdc;
+ sParam.sSpatialLayers[0].sSliceArgument.uiSliceSizeConstraint = 1000;
- int rv = encoder_->InitializeExt (&sParam);
+ int iTraceLevel = WELS_LOG_QUIET;
+ int rv = encoder_->SetOption (ENCODER_OPTION_TRACE_LEVEL, &iTraceLevel);
+ rv = encoder_->InitializeExt (&sParam);
ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];