shithub: openh264

Download patch

ref: 597adfd98c58eabba7f343378423b35802f35a26
parent: b0c6ea9385f16075f49c99f39ec2a122ae3cdfbb
parent: 3d3884641c69bf52630a677a23ef1059a6834be4
author: sijchen <sijchen@cisco.com>
date: Tue Nov 3 04:05:55 EST 2015

Merge pull request #2207 from sijchen/thp53

[Encoder] remove unneeded codes and add some logs (basing on PR2206)

--- a/codec/common/src/WelsTaskThread.cpp
+++ b/codec/common/src/WelsTaskThread.cpp
@@ -37,9 +37,6 @@
  *
  *************************************************************************************
  */
-
-
-
 #include "WelsTaskThread.h"
 
 namespace WelsCommon {
--- a/codec/common/src/WelsThreadPool.cpp
+++ b/codec/common/src/WelsThreadPool.cpp
@@ -37,8 +37,6 @@
  *
  *************************************************************************************
  */
-
-
 #include "typedefs.h"
 #include "WelsThreadPool.h"
 
@@ -167,7 +165,6 @@
   AddTaskToWaitedList (pTask);
 
   SignalThread();
-
   return WELS_THREAD_ERROR_OK;
 }
 
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -4007,6 +4007,7 @@
       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,
@@ -4020,108 +4021,17 @@
                    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: 3e0ee69
+        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)) {
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -374,7 +374,8 @@
       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 @@
   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,
@@ -883,6 +883,7 @@
               WelsUnloadNalForSlice (pSliceBs);
             }
           }
+
 
           WelsLoadNalForSlice (pSliceBs, eNalType, eNalRefIdc);
 
--- a/codec/encoder/core/src/wels_task_base.cpp
+++ b/codec/encoder/core/src/wels_task_base.cpp
@@ -37,7 +37,6 @@
  *
  *************************************************************************************
  */
-
 #include "wels_task_base.h"
 
 namespace WelsEnc {
--- a/codec/encoder/core/src/wels_task_encoder.cpp
+++ b/codec/encoder/core/src/wels_task_encoder.cpp
@@ -99,6 +99,10 @@
   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 @@
   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 @@
   }
 
   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 @@
 
   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],
--- a/codec/encoder/core/src/wels_task_management.cpp
+++ b/codec/encoder/core/src/wels_task_management.cpp
@@ -59,6 +59,7 @@
   if (NULL == pCtx) {
     return NULL;
   }
+
   IWelsTaskManage* pTaskManage;
   if (bNeedLock) {
     pTaskManage = WELS_NEW_OP (CWelsTaskManageParallel(), CWelsTaskManageParallel);