shithub: openh264

Download patch

ref: 6a8f6c9b8e88cfbccc6a24bbdac518b4fc6e605b
parent: f6c37b009664288d066e8c9efd4adf10e4b7a6d0
author: Karina <ruil2@cisco.com>
date: Wed May 3 06:32:08 EDT 2017

use cavlc if profile is baseline(following profile set)

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -132,10 +132,6 @@
                uiProfileIdc);
       pLayerInfo->uiProfileIdc = PRO_BASELINE;
     }
-    if (pParam->iEntropyCodingModeFlag && pLayerInfo->uiProfileIdc == PRO_BASELINE) {
-      pLayerInfo->uiProfileIdc = PRO_MAIN;
-      WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to main profile because cabac is enabled", iLayer);
-    }
   } else {
     if (iLayer == SPATIAL_LAYER_0) {
       if ((uiProfileIdc != PRO_BASELINE) && (uiProfileIdc != PRO_MAIN) && (uiProfileIdc != PRO_HIGH)) {
@@ -143,10 +139,6 @@
                  uiProfileIdc);
         pLayerInfo->uiProfileIdc = PRO_BASELINE;
       }
-      if (pParam->iEntropyCodingModeFlag && (pLayerInfo->uiProfileIdc == PRO_BASELINE)) {
-        pLayerInfo->uiProfileIdc = PRO_MAIN;
-        WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to main profile because cabac is enabled", iLayer);
-      }
     } else {
       if ((uiProfileIdc != PRO_SCALABLE_BASELINE) && (uiProfileIdc != PRO_SCALABLE_HIGH)) {
         pLayerInfo->uiProfileIdc = PRO_SCALABLE_BASELINE;
@@ -153,10 +145,6 @@
         WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) doesn't support profile(%d), change to scalable baseline profile",
                  iLayer, uiProfileIdc);
       }
-      if (pParam->iEntropyCodingModeFlag && (pLayerInfo->uiProfileIdc == PRO_SCALABLE_BASELINE)) {
-        pLayerInfo->uiProfileIdc = PRO_SCALABLE_HIGH;
-        WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) change to scalable hight profile because cabac is enabled", iLayer);
-      }
     }
   }
 }
@@ -645,7 +633,15 @@
     break;
     }
   }
-
+  for (i = 0; i < pCodingParam->iSpatialLayerNum; ++ i) {
+    SSpatialLayerConfig* pLayerInfo = &pCodingParam->sSpatialLayers[i];
+    if ((pLayerInfo->uiProfileIdc == PRO_BASELINE) || (pLayerInfo->uiProfileIdc == PRO_SCALABLE_BASELINE)) {
+      if (pCodingParam->iEntropyCodingModeFlag != 0) {
+        pCodingParam->iEntropyCodingModeFlag = 0;
+        WelsLog (pLogCtx, WELS_LOG_WARNING, "layerId(%d) Profile is baseline, Change CABAC to CAVLC",i);
+      }
+    }
+  }
   return ParamValidation (pLogCtx, pCodingParam);
 }
 
@@ -728,7 +724,7 @@
  * \return  0 - successful; otherwise failed
  */
 int32_t AcquireLayersNals (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pParam, int32_t* pCountLayers,
-    int32_t* pCountNals) {
+                           int32_t* pCountNals) {
   int32_t iCountNumLayers       = 0;
   int32_t iCountNumNals         = 0;
   int32_t iNumDependencyLayers  = 0;
@@ -2415,7 +2411,7 @@
   else if (iPartitionNum > AVERSLICENUM_CONSTRAINT)
     iPartitionNum = AVERSLICENUM_CONSTRAINT; // AVERSLICENUM_CONSTRAINT might be variable, however not fixed by MACRO
   iCountMbNumPerPartition /= iPartitionNum;
-  if(iCountMbNumPerPartition == 0 || iCountMbNumPerPartition == 1) {
+  if (iCountMbNumPerPartition == 0 || iCountMbNumPerPartition == 1) {
     iCountMbNumPerPartition = kiMbNumInFrame;
     iPartitionNum           = 1;
   }
@@ -2444,7 +2440,7 @@
     ++ i;
   }
 
-  while(i<MAX_THREADS_NUM) {
+  while (i < MAX_THREADS_NUM) {
     pCurDq->FirstMbIdxOfPartition[i]     = 0;
     pCurDq->EndMbIdxOfPartition[i]       = 0;
     pCurDq->LastCodedMbIdxOfPartition[i] = 0;
@@ -2489,7 +2485,7 @@
     //MINPACKETSIZE_CONSTRAINT
     //suppose 16 byte per mb at average
     uiMiniPacketSize = (uint32_t) (uiFrmByte / pSliceCtx->iMaxSliceNumConstraint);
-    if (pSliceCtx->uiSliceSizeConstraint < uiMiniPacketSize ) {
+    if (pSliceCtx->uiSliceSizeConstraint < uiMiniPacketSize) {
       WelsLog (& (pCtx->sLogCtx),
                WELS_LOG_WARNING,
                "Set-SliceConstraint(%d) too small for current resolution (MB# %d) under QP/BR!",
@@ -3655,7 +3651,7 @@
 
       WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);
       assert (0 == (int) pCurSlice->iSliceIdx);
-      pCtx->iEncoderError   = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, 0);
+      pCtx->iEncoderError   = SetSliceBoundaryInfo (pCtx->pCurDqLayer, pCurSlice, 0);
       WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
 
       pCtx->iEncoderError   = WelsCodeOneSlice (pCtx, pCurSlice, eNalType);
@@ -3748,10 +3744,10 @@
           ++ iIdx;
         }
 
-        int32_t iRet = InitAllSlicesInThread(pCtx);
+        int32_t iRet = InitAllSlicesInThread (pCtx);
         if (iRet) {
           WelsLog (pLogCtx, WELS_LOG_ERROR,
-                  "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!",
+                   "WelsEncoderEncodeExt(), multi-slice (mode %d) InitAllSlicesInThread() error!",
                    pParam->sSliceArgument.uiSliceMode);
           return ENC_RETURN_UNEXPECTED;
         }
@@ -3796,7 +3792,7 @@
 
           pCurSlice = &pCtx->pCurDqLayer->sSliceBufferInfo[0].pSliceBuffer[iSliceIdx];
           assert (iSliceIdx == pCurSlice->iSliceIdx);
-          pCtx->iEncoderError   = SetSliceBoundaryInfo(pCtx->pCurDqLayer, pCurSlice, iSliceIdx);
+          pCtx->iEncoderError   = SetSliceBoundaryInfo (pCtx->pCurDqLayer, pCurSlice, iSliceIdx);
 
           pCtx->iEncoderError = WelsCodeOneSlice (pCtx, pCurSlice, eNalType);
           WELS_VERIFY_RETURN_IFNEQ (pCtx->iEncoderError, ENC_RETURN_SUCCESS)
@@ -4426,7 +4422,7 @@
   int32_t iRet = 0;
 
   iRet = FrameBsRealloc (pCtx, pFrameBsInfo, pLayerBsInfo, pCtx->pCurDqLayer->iMaxSliceNum);
-  if(ENC_RETURN_SUCCESS != iRet) {
+  if (ENC_RETURN_SUCCESS != iRet) {
     return iRet;
   }
 
@@ -4470,7 +4466,8 @@
     int32_t iPayloadSize    = 0;
     SSlice* pCurSlice = NULL;
 
-    if (iSliceIdx >= (pCurLayer->sSliceBufferInfo[uSlcBuffIdx].iMaxSliceNum - kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[]
+    if (iSliceIdx >= (pCurLayer->sSliceBufferInfo[uSlcBuffIdx].iMaxSliceNum -
+                      kiSliceIdxStep)) { // insufficient memory in pSliceInLayer[]
       if (pCtx->iActiveThreadsNum == 1) {
         //only single thread support re-alloc now
         if (DynSliceRealloc (pCtx, pFrameBSInfo, pLayerBsInfo)) {
--- a/test/api/BaseEncoderTest.cpp
+++ b/test/api/BaseEncoderTest.cpp
@@ -20,7 +20,6 @@
     param.iPicWidth      = pEncParamExt->iPicWidth;
     param.iPicHeight     = pEncParamExt->iPicHeight;
     param.iTargetBitrate = 5000000;
-
     return encoder->Initialize (&param);
   } else {
     SEncParamExt param;
@@ -36,7 +35,8 @@
     param.bIsLosslessLink  = pEncParamExt->bIsLosslessLink;
     param.bEnableLongTermReference = pEncParamExt->bEnableLongTermReference;
     param.iEntropyCodingModeFlag   = pEncParamExt->iEntropyCodingModeFlag ? 1 : 0;
-    if (eSliceMode != SM_SINGLE_SLICE && eSliceMode != SM_SIZELIMITED_SLICE) //SM_SIZELIMITED_SLICE don't support multi-thread now
+    if (eSliceMode != SM_SINGLE_SLICE
+        && eSliceMode != SM_SIZELIMITED_SLICE) //SM_SIZELIMITED_SLICE don't support multi-thread now
       param.iMultipleThreadIdc = 2;
 
     for (int i = 0; i < param.iSpatialLayerNum; i++) {
@@ -57,9 +57,11 @@
         param.iMultipleThreadIdc = 4;
         param.bUseLoadBalancing = false;
       }
+      if (param.iEntropyCodingModeFlag) {
+        param.sSpatialLayers[i].uiProfileIdc = PRO_MAIN;
+      }
     }
     param.iTargetBitrate *= param.iSpatialLayerNum;
-
     return encoder->InitializeExt (&param);
   }
 }
--- a/test/api/encode_options_test.cpp
+++ b/test/api/encode_options_test.cpp
@@ -1973,10 +1973,7 @@
   if ((iEncProfileIdc != PRO_BASELINE) && (iEncProfileIdc != PRO_MAIN) && (iEncProfileIdc != PRO_HIGH)) {
     iEncProfileIdc = PRO_BASELINE;
   }
-  if ((iEncProfileIdc == PRO_BASELINE) && (sParam.iEntropyCodingModeFlag == 1))
-    iEncProfileIdc = PRO_MAIN;
 
-
   ASSERT_TRUE (iDecProfileIdc == iEncProfileIdc) << "enc_profile = " << iEncProfileIdc << "  dec_profile = " <<
       iDecProfileIdc;
 
@@ -2036,9 +2033,6 @@
   if ((iEncProfileIdc != PRO_BASELINE) && (iEncProfileIdc != PRO_MAIN) && (iEncProfileIdc != PRO_HIGH)) {
     iEncProfileIdc = PRO_BASELINE;
   }
-  if ((iEncProfileIdc == PRO_BASELINE) && (sParam.iEntropyCodingModeFlag == 1))
-    iEncProfileIdc = PRO_MAIN;
-
 
   ASSERT_TRUE (iDecProfileIdc == iEncProfileIdc) << "enc_profile = " << iEncProfileIdc << "  dec_profile = " <<
       iDecProfileIdc;