Merge pull request #2327 from sijchen/th41
Multiple enhancements and a bug fix
This commit is contained in:
commit
7bfb96b2b6
@ -2500,14 +2500,6 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
|
|||||||
return iRet;
|
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)
|
if (pCodingParam->iEntropyCodingModeFlag)
|
||||||
WelsCabacInit (pCtx);
|
WelsCabacInit (pCtx);
|
||||||
WelsRcInitModule (pCtx, pCtx->pSvcParam->iRCMode);
|
WelsRcInitModule (pCtx, pCtx->pSvcParam->iRCMode);
|
||||||
|
@ -257,7 +257,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
|||||||
int32_t iThreadNum = 0;
|
int32_t iThreadNum = 0;
|
||||||
int32_t iIdx = 0;
|
int32_t iIdx = 0;
|
||||||
int32_t iReturn = ENC_RETURN_SUCCESS;
|
int32_t iReturn = ENC_RETURN_SUCCESS;
|
||||||
bool bWillUseTaskManage = false;
|
|
||||||
|
|
||||||
if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
|
if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
|
||||||
return 1;
|
return 1;
|
||||||
@ -281,15 +280,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
|||||||
WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
|
WelsSnprintf (pSmt->eventNamespace, sizeof (pSmt->eventNamespace), "%p%x", (void*) *ppCtx, getpid());
|
||||||
#endif//!_WIN32
|
#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
|
#ifdef MT_DEBUG
|
||||||
// file handle for MT debug
|
// file handle for MT debug
|
||||||
pSmt->pFSliceDiff = NULL;
|
pSmt->pFSliceDiff = NULL;
|
||||||
@ -344,19 +334,15 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
|||||||
pSmt->pThreadBsBuffer[iIdx] = NULL;
|
pSmt->pThreadBsBuffer[iIdx] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//previous conflict
|
|
||||||
WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace);
|
WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace);
|
||||||
err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);
|
err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);
|
||||||
MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
|
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);
|
iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
|
||||||
WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
|
WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
|
||||||
|
|
||||||
if (bWillUseTaskManage) {
|
|
||||||
(*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice);
|
(*ppCtx)->pTaskManage = IWelsTaskManage::CreateTaskManage (*ppCtx, iNumSpatialLayers, bDynamicSlice);
|
||||||
WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx))
|
WELS_VERIFY_RETURN_PROC_IF (iReturn, (NULL == (*ppCtx)->pTaskManage), FreeMemorySvc (ppCtx))
|
||||||
}
|
|
||||||
|
|
||||||
memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
|
memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
|
||||||
iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage);
|
iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage);
|
||||||
|
@ -201,7 +201,7 @@ WelsErrorType CWelsLoadBalancingSlicingEncodingTask::InitTask() {
|
|||||||
|
|
||||||
m_iSliceStart = WelsTime();
|
m_iSliceStart = WelsTime();
|
||||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
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);
|
m_iSliceIdx, m_iSliceStart);
|
||||||
|
|
||||||
return ENC_RETURN_SUCCESS;
|
return ENC_RETURN_SUCCESS;
|
||||||
@ -212,13 +212,14 @@ void CWelsLoadBalancingSlicingEncodingTask::FinishTask() {
|
|||||||
|
|
||||||
m_pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - m_iSliceStart);
|
m_pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - m_iSliceStart);
|
||||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
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_pCtx->iCodingIndex,
|
||||||
m_iSliceIdx,
|
m_iSliceIdx,
|
||||||
m_pSlice->uiSliceConsumeTime,
|
m_pSlice->uiSliceConsumeTime,
|
||||||
m_iSliceSize,
|
m_iSliceSize,
|
||||||
m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
|
m_pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[m_iSliceIdx].sSliceHeaderExt.sSliceHeader.iFirstMbInSlice,
|
||||||
m_pSlice->iCountMbNumInSlice);
|
m_pSlice->iCountMbNumInSlice,
|
||||||
|
(m_pSlice->uiSliceConsumeTime + m_iSliceStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
//CWelsConstrainedSizeSlicingEncodingTask
|
//CWelsConstrainedSizeSlicingEncodingTask
|
||||||
|
@ -123,7 +123,7 @@ void CWelsTaskManageBase::Uninit() {
|
|||||||
WelsErrorType CWelsTaskManageBase::CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiCurDid) {
|
WelsErrorType CWelsTaskManageBase::CreateTasks (sWelsEncCtx* pEncCtx, const int32_t kiCurDid) {
|
||||||
CWelsBaseTask* pTask = NULL;
|
CWelsBaseTask* pTask = NULL;
|
||||||
int32_t kiTaskCount;
|
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) {
|
if (uiSliceMode != SM_SIZELIMITED_SLICE) {
|
||||||
kiTaskCount = m_iTaskNum[kiCurDid] = pEncCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument.uiSliceNum;
|
kiTaskCount = m_iTaskNum[kiCurDid] = pEncCtx->pSvcParam->sSpatialLayers[kiCurDid].sSliceArgument.uiSliceNum;
|
||||||
|
@ -381,8 +381,11 @@ int CWelsH264SVCEncoder::EncodeFrame (const SSourcePicture* kpSrcPic, SFrameBSIn
|
|||||||
|
|
||||||
const int32_t kiEncoderReturn = EncodeFrameInternal (kpSrcPic, pBsInfo);
|
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;
|
return kiEncoderReturn;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef REC_FRAME_COUNT
|
#ifdef REC_FRAME_COUNT
|
||||||
++ m_uiCountFrameNum;
|
++ m_uiCountFrameNum;
|
||||||
|
@ -1447,15 +1447,19 @@ TEST_F (EncodeDecodeTestAPI, DiffSlicingInDlayerMixed) {
|
|||||||
sParam.bSimulcastAVC = 1;
|
sParam.bSimulcastAVC = 1;
|
||||||
sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
|
sParam.sSpatialLayers[0].iVideoWidth = (iWidth >> 2);
|
||||||
sParam.sSpatialLayers[0].iVideoHeight = (iHeight >> 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[0].sSliceArgument.uiSliceSizeConstraint = 1500;
|
||||||
|
|
||||||
sParam.sSpatialLayers[1].iVideoWidth = iWidth;
|
sParam.sSpatialLayers[1].iVideoWidth = iWidth;
|
||||||
sParam.sSpatialLayers[1].iVideoHeight = iHeight;
|
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.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;;
|
ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
|
||||||
|
|
||||||
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
|
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
|
||||||
@ -1568,14 +1572,18 @@ TEST_F (EncodeDecodeTestAPI, TriggerLoadBalancing) {
|
|||||||
SEncParamExt sParam;
|
SEncParamExt sParam;
|
||||||
encoder_->GetDefaultParams (&sParam);
|
encoder_->GetDefaultParams (&sParam);
|
||||||
prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
|
prepareParamDefault (iSpatialLayerNum, 1, iWidth, iHeight, fFrameRate, &sParam);
|
||||||
sParam.iMultipleThreadIdc = (rand() % 8) + 1;
|
sParam.iMultipleThreadIdc = 4;
|
||||||
sParam.bSimulcastAVC = 1;
|
sParam.bSimulcastAVC = 1;
|
||||||
sParam.sSpatialLayers[0].iVideoWidth = iWidth;
|
sParam.sSpatialLayers[0].iVideoWidth = iWidth;
|
||||||
sParam.sSpatialLayers[0].iVideoHeight = iHeight;
|
sParam.sSpatialLayers[0].iVideoHeight = iHeight;
|
||||||
sParam.sSpatialLayers[0].sSliceArgument.uiSliceMode = SM_FIXEDSLCNUM_SLICE;
|
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.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;;
|
ASSERT_TRUE (rv == cmResultSuccess) << "Init Failed sParam: rv = " << rv;;
|
||||||
|
|
||||||
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
|
unsigned char* pBsBuf[MAX_SPATIAL_LAYER_NUM];
|
||||||
|
Loading…
Reference in New Issue
Block a user