shithub: openh264

Download patch

ref: c5631f65387d2db05127d4d285f61a372115bfe2
parent: b26bcda090f40f834fdeeb68bafdd5772dcbd726
author: Karina <[email protected]>
date: Wed Jul 19 11:52:31 EDT 2017

add logs and init memory

--- a/codec/encoder/core/inc/param_svc.h
+++ b/codec/encoder/core/inc/param_svc.h
@@ -541,7 +541,7 @@
   if (*pParam != NULL) {
     FreeCodingParam (pParam, pMa);
   }
-  SWelsSvcCodingParam* pCodingParam = (SWelsSvcCodingParam*)pMa->WelsMalloc (sizeof (SWelsSvcCodingParam),
+  SWelsSvcCodingParam* pCodingParam = (SWelsSvcCodingParam*)pMa->WelsMallocz (sizeof (SWelsSvcCodingParam),
                                       "SWelsSvcCodingParam");
   if (NULL == pCodingParam)
     return 1;
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -384,8 +384,8 @@
       }
 
     }
-    pCfg->iMinQp = WELS_CLIP3 (pCfg->iMinQp , GOM_MIN_QP_MODE, 51);
-    pCfg->iMaxQp = WELS_CLIP3 (pCfg->iMaxQp , pCfg->iMinQp, 51);
+    pCfg->iMinQp = WELS_CLIP3 (pCfg->iMinQp, GOM_MIN_QP_MODE, 51);
+    pCfg->iMaxQp = WELS_CLIP3 (pCfg->iMaxQp, pCfg->iMinQp, 51);
   }
   // ref-frames validation
   if (((pCfg->iUsageType == CAMERA_VIDEO_REAL_TIME) || (pCfg->iUsageType == SCREEN_CONTENT_REAL_TIME))
@@ -1439,7 +1439,7 @@
       break;
 
     t32 = i | (i << 16);
-    ST32 (t  , t32);
+    ST32 (t, t32);
     ST32 (t + 2, t32);
 
     p = pRowY;
@@ -2357,7 +2357,7 @@
   pCtx->bDeliveryFlag = true;
   *ppCtx = pCtx;
 
-  WelsLog (pLogCtx, WELS_LOG_DEBUG, "WelsInitEncoderExt(), pCtx= 0x%p.", (void*)pCtx);
+  WelsLog (pLogCtx, WELS_LOG_INFO, "WelsInitEncoderExt(), pCtx= 0x%p.", (void*)pCtx);
 
   return 0;
 }
@@ -3360,7 +3360,7 @@
   pFbi->iLayerNum = 0;
   pFbi->iFrameSizeInBytes = 0;
 }
-EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsInfo, int32_t iSpatialNum ,
+EVideoFrameType PrepareEncodeFrame (sWelsEncCtx* pCtx, SLayerBSInfo*& pLayerBsInfo, int32_t iSpatialNum,
                                     int8_t& iCurDid, int32_t& iCurTid,
                                     int32_t& iLayerNum, int32_t& iFrameSize, long long uiTimeStamp) {
   SWelsSvcCodingParam* pSvcParam        = pCtx->pSvcParam;
@@ -3500,7 +3500,7 @@
   pCtx->pCurDqLayer             = pCtx->ppDqLayerList[iCurDid];
   pCtx->pCurDqLayer->pRefLayer  = NULL;
   if (!pSvcParam->bSimulcastAVC) {
-    eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize,
+    eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum, iCurDid, iCurTid, iLayerNum, iFrameSize,
                                      pFbi->uiTimeStamp);
     if (eFrameType == videoFrameTypeSkip) {
       pFbi->eFrameType = videoFrameTypeSkip;
@@ -3526,7 +3526,7 @@
     pCtx->uiDependencyId        =  iCurDid;
 
     if (pSvcParam->bSimulcastAVC) {
-      eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum , iCurDid, iCurTid, iLayerNum, iFrameSize,
+      eFrameType = PrepareEncodeFrame (pCtx, pLayerBsInfo, iSpatialNum, iCurDid, iCurTid, iLayerNum, iFrameSize,
                                        pFbi->uiTimeStamp);
       if (eFrameType == videoFrameTypeSkip) {
         pLayerBsInfo->eFrameType = videoFrameTypeSkip;
@@ -4184,7 +4184,21 @@
   if (pNewParam->iMaxNumRefFrame > pOldParam->iMaxNumRefFrame) {
     bNeedReset = true;
   }
+  if (bNeedReset) {
+    WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+             "WelsEncoderParamAdjust(),bSimulcastAVC(%d,%d),iSpatialLayerNum(%d,%d),iPicWidth(%d,%d),iPicHeight(%d,%d),Rect.iWidth(%d,%d),Rect.iHeight(%d,%d)",
+             pOldParam->bSimulcastAVC, pNewParam->bSimulcastAVC, pOldParam->iSpatialLayerNum, pNewParam->iSpatialLayerNum,
+             pOldParam->iPicWidth, pNewParam->iPicWidth, pOldParam->iPicHeight, pNewParam->iPicHeight,
+             pOldParam->SUsedPicRect.iWidth, pNewParam->SUsedPicRect.iWidth, pOldParam->SUsedPicRect.iHeight,
+             pNewParam->SUsedPicRect.iHeight);
 
+    WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+             "WelsEncoderParamAdjust(),bEnableLongTermReference(%d,%d),iLTRRefNum(%d,%d),iMultipleThreadIdc(%d,%d),bEnableBackgroundDetection(%d,%d),bEnableAdaptiveQuant(%d,%d),eSpsPpsIdStrategy(%d,%d),iMaxNumRefFrame(%d,%d)",
+             pOldParam->bEnableLongTermReference, pNewParam->bEnableLongTermReference, pOldParam->iLTRRefNum, pNewParam->iLTRRefNum,
+             pOldParam->iMultipleThreadIdc, pNewParam->iMultipleThreadIdc, pOldParam->bEnableBackgroundDetection,
+             pNewParam->bEnableBackgroundDetection, pOldParam->bEnableAdaptiveQuant, pNewParam->bEnableAdaptiveQuant,
+             pOldParam->eSpsPpsIdStrategy, pNewParam->eSpsPpsIdStrategy, pNewParam->iMaxNumRefFrame, pOldParam->iMaxNumRefFrame);
+  }
   if (!bNeedReset) { // Check its picture resolutions/quality settings respectively in each dependency layer
     iIndexD = 0;
     assert (pOldParam->iSpatialLayerNum == pNewParam->iSpatialLayerNum);
@@ -4200,6 +4214,11 @@
           kpOldDlp->iActualWidth != kpNewDlp->iActualWidth ||
           kpOldDlp->iActualHeight != kpNewDlp->iActualHeight) {
         bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust(),iIndexD = %d,sSpatialLayers.wxh_old(%d,%d),sSpatialLayers.wxh_new(%d,%d),iActualwxh_old(%d,%d),iActualwxh_new(%d,%d)",
+                 iIndexD, pOldParam->sSpatialLayers[iIndexD].iVideoWidth, pOldParam->sSpatialLayers[iIndexD].iVideoHeight,
+                 pNewParam->sSpatialLayers[iIndexD].iVideoWidth, pNewParam->sSpatialLayers[iIndexD].iVideoHeight, kpOldDlp->iActualWidth,
+                 kpOldDlp->iActualHeight, kpNewDlp->iActualWidth, kpNewDlp->iActualHeight);
         break;
       }
 
@@ -4208,7 +4227,15 @@
           ||
           pOldParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceNum !=
           pNewParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceNum) {
+
         bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust(),iIndexD = %d,uiSliceMode (%d,%d),uiSliceNum(%d,%d)", iIndexD,
+                 pOldParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceMode,
+                 pNewParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceMode,
+                 pOldParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceNum,
+                 pNewParam->sSpatialLayers[iIndexD].sSliceArgument.uiSliceNum);
+
         break;
       }
       if (pOldParam->sSpatialLayers[iIndexD].uiProfileIdc !=
@@ -4217,6 +4244,11 @@
           pOldParam->sSpatialLayers[iIndexD].uiLevelIdc !=
           pNewParam->sSpatialLayers[iIndexD].uiLevelIdc) {
         bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust(),iIndexD = %d,uiProfileIdc(%d,%d),uiLevelIdc(%d,%d)", iIndexD,
+                 pOldParam->sSpatialLayers[iIndexD].uiProfileIdc, pNewParam->sSpatialLayers[iIndexD].uiProfileIdc,
+                 pOldParam->sSpatialLayers[iIndexD].uiLevelIdc, pNewParam->sSpatialLayers[iIndexD].uiLevelIdc);
+
         break;
       }
 
@@ -4229,6 +4261,10 @@
         fT2 = pNewParam->fMaxFrameRate / kpNewDlp->fOutputFrameRate - pOldParam->fMaxFrameRate / kpOldDlp->fOutputFrameRate;
       if (fT1 > EPSN || fT1 < -EPSN || fT2 > EPSN || fT2 < -EPSN) {
         bNeedReset = true;
+        WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
+                 "WelsEncoderParamAdjust() iIndexD = %d,fInputFrameRate(%f,%f),fOutputFrameRate(%f,%f),fMaxFrameRate(%f,%f)", iIndexD,
+                 kpOldDlp->fInputFrameRate, kpNewDlp->fInputFrameRate, kpOldDlp->fOutputFrameRate, kpNewDlp->fOutputFrameRate,
+                 pOldParam->fMaxFrameRate, pNewParam->fMaxFrameRate);
         break;
       }
       ++ iIndexD;
--- a/codec/encoder/core/src/slice_multi_threading.cpp
+++ b/codec/encoder/core/src/slice_multi_threading.cpp
@@ -339,7 +339,7 @@
   int32_t iThreadBufferNum = WELS_MIN ((*ppCtx)->pTaskManage->GetThreadPoolThreadNum(), MAX_THREADS_NUM);
 
   for (iIdx = 0; iIdx < iThreadBufferNum; iIdx++) {
-    pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer");
+    pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMallocz (iCountBsLen, "pSmt->pThreadBsBuffer");
     WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]))
   }
   iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage);
--- a/codec/encoder/core/src/svc_enc_slice_segment.cpp
+++ b/codec/encoder/core/src/svc_enc_slice_segment.cpp
@@ -382,7 +382,7 @@
   }
 
   if (SM_SINGLE_SLICE == uiSliceMode) {
-    pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap");
+    pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMallocz (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap");
 
     WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap)
     pSliceSeg->iSliceNumInFrame = 1;
@@ -398,7 +398,7 @@
         && uiSliceMode != SM_SIZELIMITED_SLICE )
       return 1;
 
-    pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMalloc (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap");
+    pSliceSeg->pOverallMbMap = (uint16_t*)pMa->WelsMallocz (kiCountMbNum * sizeof (uint16_t), "pSliceSeg->pOverallMbMap");
     WELS_VERIFY_RETURN_IF (1, NULL == pSliceSeg->pOverallMbMap)
 
     WelsSetMemMultiplebytes_c(pSliceSeg->pOverallMbMap, 0, kiCountMbNum, sizeof(uint16_t));
--- a/codec/encoder/core/src/svc_encode_slice.cpp
+++ b/codec/encoder/core/src/svc_encode_slice.cpp
@@ -898,7 +898,7 @@
 
   if (bIndependenceBsBuffer) {
     pSlice->pSliceBsa      = &pSlice->sSliceBs.sBsWrite;
-    pSlice->sSliceBs.pBs   = (uint8_t*)pMa->WelsMalloc (iMaxSliceBufferSize, "sSliceBs.pBs");
+    pSlice->sSliceBs.pBs   = (uint8_t*)pMa->WelsMallocz (iMaxSliceBufferSize, "sSliceBs.pBs");
     if (NULL == pSlice->sSliceBs.pBs) {
       return ENC_RETURN_MEMALLOCERR;
     }
--- a/codec/encoder/core/src/svc_motion_estimate.cpp
+++ b/codec/encoder/core/src/svc_motion_estimate.cpp
@@ -651,7 +651,7 @@
                             (kiFrameWidth - kiMarginSize) * sizeof (uint32_t) + kiFrameWidth * 8 * sizeof (uint8_t);
   }
   pFeatureSearchPreparation->pFeatureOfBlock =
-    (uint16_t*)pMa->WelsMalloc (iListOfFeatureOfBlock, "pFeatureOfBlock");
+    (uint16_t*)pMa->WelsMallocz (iListOfFeatureOfBlock, "pFeatureOfBlock");
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == (pFeatureSearchPreparation->pFeatureOfBlock))
 
   pFeatureSearchPreparation->uiFeatureStrategyIndex = kiFeatureStrategyIndex;
@@ -688,19 +688,19 @@
   const int32_t kiListSize  = (0 == kiFeatureStrategyIndex) ? (bIsBlock8x8 ? LIST_SIZE_SUM_8x8 : LIST_SIZE_SUM_16x16) :
                               256;
 
-  pScreenBlockFeatureStorage->pTimesOfFeatureValue = (uint32_t*)pMa->WelsMalloc (kiListSize * sizeof (uint32_t),
+  pScreenBlockFeatureStorage->pTimesOfFeatureValue = (uint32_t*)pMa->WelsMallocz (kiListSize * sizeof (uint32_t),
       "pScreenBlockFeatureStorage->pTimesOfFeatureValue");
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pTimesOfFeatureValue)
 
-  pScreenBlockFeatureStorage->pLocationOfFeature = (uint16_t**)pMa->WelsMalloc (kiListSize * sizeof (uint16_t*),
+  pScreenBlockFeatureStorage->pLocationOfFeature = (uint16_t**)pMa->WelsMallocz (kiListSize * sizeof (uint16_t*),
       "pScreenBlockFeatureStorage->pLocationOfFeature");
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationOfFeature)
 
-  pScreenBlockFeatureStorage->pLocationPointer = (uint16_t*)pMa->WelsMalloc (2 * kiFrameSize * sizeof (uint16_t),
+  pScreenBlockFeatureStorage->pLocationPointer = (uint16_t*)pMa->WelsMallocz (2 * kiFrameSize * sizeof (uint16_t),
       "pScreenBlockFeatureStorage->pLocationPointer");
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pLocationPointer)
   //  uint16_t* pFeatureValuePointerList[WELS_MAX (LIST_SIZE_SUM_16x16, LIST_SIZE_MSE_16x16)] = {0};
-  pScreenBlockFeatureStorage->pFeatureValuePointerList = (uint16_t**)pMa->WelsMalloc (WELS_MAX (LIST_SIZE_SUM_16x16,
+  pScreenBlockFeatureStorage->pFeatureValuePointerList = (uint16_t**)pMa->WelsMallocz (WELS_MAX (LIST_SIZE_SUM_16x16,
       LIST_SIZE_MSE_16x16) * sizeof (uint16_t*),
       "pScreenBlockFeatureStorage->pFeatureValuePointerList");
   WELS_VERIFY_RETURN_IF (ENC_RETURN_MEMALLOCERR, NULL == pScreenBlockFeatureStorage->pFeatureValuePointerList)