remove unneeded codes and add some logs
This commit is contained in:
parent
3350cf75a5
commit
3e0ee69812
@ -37,9 +37,6 @@
|
||||
*
|
||||
*************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "WelsTaskThread.h"
|
||||
|
||||
namespace WelsCommon {
|
||||
|
@ -37,8 +37,6 @@
|
||||
*
|
||||
*************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "WelsThreadPool.h"
|
||||
|
||||
@ -167,7 +165,6 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::QueueTask (IWelsTask* pTask) {
|
||||
AddTaskToWaitedList (pTask);
|
||||
|
||||
SignalThread();
|
||||
|
||||
return WELS_THREAD_ERROR_OK;
|
||||
}
|
||||
|
||||
|
@ -4004,6 +4004,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
||||
int32_t iRet = 0;
|
||||
// THREAD_FULLY_FIRE_MODE/THREAD_PICK_UP_MODE for any mode of non-SM_DYN_SLICE
|
||||
if ((SM_DYN_SLICE != pParam->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
|
||||
|
||||
iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
|
||||
if (iLayerNum + 1 >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info for further writing as followed
|
||||
WelsLog (pLogCtx, WELS_LOG_ERROR,
|
||||
@ -4017,108 +4018,17 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
|
||||
iSliceCount);
|
||||
return ENC_RETURN_UNEXPECTED;
|
||||
}
|
||||
if (SM_AUTO_SLICE == pParam->sSliceCfg.uiSliceMode) {
|
||||
if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE
|
||||
#if defined(MT_DEBUG)
|
||||
int64_t t_bs_append = 0;
|
||||
#endif
|
||||
//note: the old codes are removed at commit: 8caeac1
|
||||
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
|
||||
pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER;
|
||||
pLayerBsInfo->uiSpatialId = pCtx->uiDependencyId;
|
||||
pLayerBsInfo->uiTemporalId = pCtx->uiTemporalId;
|
||||
pLayerBsInfo->uiQualityId = 0;
|
||||
pLayerBsInfo->iNalCount = 0;
|
||||
pCtx->pSliceBs[0].pBs = pLayerBsInfo->pBsBuf;
|
||||
|
||||
pCtx->iActiveThreadsNum = iSliceCount;
|
||||
// to fire slice coding threads
|
||||
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
|
||||
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
|
||||
&pCtx->pSliceThreading->pThreadMasterEvent[0],
|
||||
pFbi, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
|
||||
if (iRet) {
|
||||
WelsLog (pLogCtx, WELS_LOG_ERROR,
|
||||
"[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
|
||||
iRet, pSvcParam->iCountThreadsNum, iSliceCount, pParam->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
|
||||
return ENC_RETURN_UNEXPECTED;
|
||||
}
|
||||
|
||||
WelsMultipleEventsWaitAllBlocking (iSliceCount, &pCtx->pSliceThreading->pSliceCodedEvent[0],
|
||||
&pCtx->pSliceThreading->pSliceCodedMasterEvent);
|
||||
|
||||
|
||||
// all slices are finished coding here
|
||||
WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
|
||||
|
||||
// append exclusive slice 0 bs to pFrameBs
|
||||
#if defined(MT_DEBUG)
|
||||
t_bs_append = WelsTime();
|
||||
#endif//MT_DEBUG
|
||||
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
|
||||
#if defined(MT_DEBUG)
|
||||
t_bs_append = WelsTime() - t_bs_append;
|
||||
if (pCtx->pSliceThreading->pFSliceDiff) {
|
||||
fprintf (pCtx->pSliceThreading->pFSliceDiff,
|
||||
"%6" PRId64 " us consumed at AppendSliceToFrameBs() for coding_idx: %d iDid: %d qid: %d\n",
|
||||
t_bs_append, pCtx->iCodingIndex, iCurDid, 0);
|
||||
}
|
||||
#endif//MT_DEBUG
|
||||
} else { //THREAD_PICK_UP_MODE
|
||||
int32_t iNumThreadsRunning = 0;
|
||||
int32_t iNumThreadsScheduled = 0;
|
||||
int32_t iIndexOfSliceToBeCoded = 0;
|
||||
|
||||
pCtx->iActiveThreadsNum = pSvcParam->iCountThreadsNum;
|
||||
iNumThreadsScheduled = pCtx->iActiveThreadsNum;
|
||||
iNumThreadsRunning = iNumThreadsScheduled;
|
||||
// to fire slice coding threads
|
||||
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
|
||||
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
|
||||
&pCtx->pSliceThreading->pThreadMasterEvent[0],
|
||||
pFbi, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
|
||||
if (iRet) {
|
||||
WelsLog (pLogCtx, WELS_LOG_ERROR,
|
||||
"[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!",
|
||||
iRet, pSvcParam->iCountThreadsNum, iSliceCount, pParam->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
|
||||
return ENC_RETURN_UNEXPECTED;
|
||||
}
|
||||
|
||||
iIndexOfSliceToBeCoded = iNumThreadsRunning;
|
||||
while (1) {
|
||||
if (iIndexOfSliceToBeCoded >= iSliceCount && iNumThreadsRunning <= 0)
|
||||
break;
|
||||
WELS_THREAD_ERROR_CODE lwait = 0;
|
||||
int32_t iEventId = -1;
|
||||
|
||||
lwait = WelsMultipleEventsWaitSingleBlocking (iNumThreadsScheduled,
|
||||
&pCtx->pSliceThreading->pSliceCodedEvent[0],
|
||||
&pCtx->pSliceThreading->pSliceCodedMasterEvent);
|
||||
iEventId = (int32_t) (lwait - WELS_THREAD_ERROR_WAIT_OBJECT_0);
|
||||
if (iEventId >= 0 && iEventId < iNumThreadsScheduled) {
|
||||
if (iIndexOfSliceToBeCoded < iSliceCount) {
|
||||
// pick up succeeding slice for threading
|
||||
// thread_id equal to iEventId per implementation here
|
||||
pCtx->pSliceThreading->pThreadPEncCtx[iEventId].iSliceIndex = iIndexOfSliceToBeCoded;
|
||||
SetOneSliceBsBufferUnderMultithread (pCtx, iEventId, iIndexOfSliceToBeCoded);
|
||||
WelsEventSignal (&pCtx->pSliceThreading->pReadySliceCodingEvent[iEventId]);
|
||||
WelsEventSignal (&pCtx->pSliceThreading->pThreadMasterEvent[iEventId]);
|
||||
++ iIndexOfSliceToBeCoded;
|
||||
} else { // no other slices left for coding
|
||||
-- iNumThreadsRunning;
|
||||
}
|
||||
}
|
||||
}//while(1)
|
||||
|
||||
// all slices are finished coding here
|
||||
// append exclusive slice 0 bs to pFrameBs
|
||||
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
|
||||
}
|
||||
|
||||
} else {
|
||||
pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
|
||||
pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER;
|
||||
pLayerBsInfo->uiSpatialId = pCtx->uiDependencyId;
|
||||
pLayerBsInfo->uiTemporalId = pCtx->uiTemporalId;
|
||||
pLayerBsInfo->uiQualityId = 0;
|
||||
pLayerBsInfo->iNalCount = 0;
|
||||
pCtx->pSliceBs[0].pBs = pLayerBsInfo->pBsBuf;
|
||||
|
||||
pCtx->pTaskManage->ExecuteTasks();
|
||||
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
|
||||
}
|
||||
pCtx->pTaskManage->ExecuteTasks();
|
||||
iLayerSize = AppendSliceToFrameBs (pCtx, pLayerBsInfo, iSliceCount);
|
||||
}
|
||||
// THREAD_FULLY_FIRE_MODE && SM_DYN_SLICE
|
||||
else if ((SM_DYN_SLICE == pParam->sSliceCfg.uiSliceMode) && (pSvcParam->iMultipleThreadIdc > 1)) {
|
||||
|
@ -374,7 +374,8 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
||||
pSmt->pSliceComplexRatio[iIdx] = NULL;
|
||||
}
|
||||
|
||||
if ( pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pMso->uiSliceMode == SM_RASTER_SLICE || pMso->uiSliceMode == SM_ROWMB_SLICE) {
|
||||
if ( pMso->uiSliceMode == SM_FIXEDSLCNUM_SLICE || pMso->uiSliceMode == SM_RASTER_SLICE
|
||||
|| pMso->uiSliceMode == SM_ROWMB_SLICE || pMso->uiSliceMode == SM_AUTO_SLICE) {
|
||||
bWillUseTaskManage = true;
|
||||
}
|
||||
++ iIdx;
|
||||
@ -441,7 +442,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara
|
||||
MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
|
||||
//previous conflict ends
|
||||
|
||||
|
||||
iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum,
|
||||
iMaxSliceBufferSize,
|
||||
iCountBsLen,
|
||||
@ -884,6 +884,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
|
||||
|
||||
iReturn = WelsCodeOneSlice (pEncPEncCtx, iSliceIdx, eNalType);
|
||||
|
@ -37,7 +37,6 @@
|
||||
*
|
||||
*************************************************************************************
|
||||
*/
|
||||
|
||||
#include "wels_task_base.h"
|
||||
|
||||
namespace WelsEnc {
|
||||
|
@ -99,6 +99,10 @@ WelsErrorType CWelsSliceEncodingTask::InitTask() {
|
||||
WelsMutexLock (&m_pCtx->pSliceThreading->mutexThreadBsBufferUsage);
|
||||
m_iThreadIdx = QueryEmptyThread (m_pCtx->pSliceThreading->bThreadBsBufferUsage);
|
||||
WelsMutexUnlock (&m_pCtx->pSliceThreading->mutexThreadBsBufferUsage);
|
||||
|
||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
||||
"[MT] CWelsSliceEncodingTask()InitTask for m_iSliceIdx %d, lock thread %d",
|
||||
m_iSliceIdx, m_iThreadIdx);
|
||||
if (m_iThreadIdx < 0) {
|
||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_WARNING,
|
||||
"[MT] CWelsSliceEncodingTask InitTask(), Cannot find available thread for m_iSliceIdx = %d", m_iSliceIdx);
|
||||
@ -123,6 +127,10 @@ void CWelsSliceEncodingTask::FinishTask() {
|
||||
WelsMutexLock (&m_pCtx->pSliceThreading->mutexThreadBsBufferUsage);
|
||||
m_pCtx->pSliceThreading->bThreadBsBufferUsage[m_iThreadIdx] = false;
|
||||
WelsMutexUnlock (&m_pCtx->pSliceThreading->mutexThreadBsBufferUsage);
|
||||
|
||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
||||
"[MT] CWelsSliceEncodingTask()FinishTask for m_iSliceIdx %d, unlock thread %d",
|
||||
m_iSliceIdx, m_iThreadIdx);
|
||||
}
|
||||
|
||||
WelsErrorType CWelsSliceEncodingTask::ExecuteTask() {
|
||||
@ -199,6 +207,10 @@ WelsErrorType CWelsLoadBalancingSlicingEncodingTask::InitTask() {
|
||||
}
|
||||
|
||||
m_iSliceStart = WelsTime();
|
||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
||||
"[MT] CWelsLoadBalancingSlicingEncodingTask()InitTask for m_iSliceIdx %d at %" PRId64,
|
||||
m_iSliceIdx, m_iSliceStart);
|
||||
|
||||
return ENC_RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
@ -207,7 +219,7 @@ void CWelsLoadBalancingSlicingEncodingTask::FinishTask() {
|
||||
|
||||
m_pCtx->pSliceThreading->pSliceConsumeTime[m_uiDependencyId][m_iSliceIdx] = (uint32_t) (WelsTime() - m_iSliceStart);
|
||||
WelsLog (&m_pCtx->sLogCtx, WELS_LOG_DEBUG,
|
||||
"[MT] CodingSliceThreadProc(), coding_idx %d, um_iSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d",
|
||||
"[MT] CWelsLoadBalancingSlicingEncodingTask()FinishTask, coding_idx %d, um_iSliceIdx %d, pSliceConsumeTime %d, iSliceSize %d, pFirstMbInSlice %d, count_num_mb_in_slice %d",
|
||||
m_pCtx->iCodingIndex,
|
||||
m_iSliceIdx,
|
||||
m_pCtx->pSliceThreading->pSliceConsumeTime[m_uiDependencyId][m_iSliceIdx],
|
||||
|
@ -59,6 +59,7 @@ IWelsTaskManage* IWelsTaskManage::CreateTaskManage (sWelsEncCtx* pCtx, bool bN
|
||||
if (NULL == pCtx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IWelsTaskManage* pTaskManage;
|
||||
if (bNeedLock) {
|
||||
pTaskManage = WELS_NEW_OP (CWelsTaskManageParallel(), CWelsTaskManageParallel);
|
||||
|
Loading…
x
Reference in New Issue
Block a user