shithub: openh264

Download patch

ref: eb357b51f275b1611ae624ec4aa4c6fa4a21e894
parent: dae4dbf377dea8ba7f69771202fb0867a48e6450
author: ruil2 <[email protected]>
date: Mon May 12 09:09:01 EDT 2014

fix bitrate setting and add bitrate validation

--- a/codec/console/enc/src/welsenc.cpp
+++ b/codec/console/enc/src/welsenc.cpp
@@ -371,7 +371,7 @@
       sParam.iRCMode = (RC_MODES) atoi (argv[i++]);
 
     else if (!strcmp (pCmd, "-tarb") && (i < argc))
-      sParam.iTargetBitrate = atoi (argv[i++]);
+      sParam.iTargetBitrate = 1000*atoi (argv[i++]);
 
     else if (!strcmp (pCmd, "-ltarb") && (i + 1 < argc)) {
       int iLayer = atoi (argv[i++]);
@@ -513,7 +513,7 @@
       g_LevelSetting = atoi (argv[n++]);
 
     else if (!strcmp (pCommand, "-tarb") && (n < argc))
-      pSvcParam.iTargetBitrate = atoi (argv[n++]);
+      pSvcParam.iTargetBitrate = 1000*atoi (argv[n++]);
 
     else if (!strcmp (pCommand, "-numl") && (n < argc)) {
       pSvcParam.iSpatialLayerNum = atoi (argv[n++]);
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -112,6 +112,19 @@
     pCfg->fMaxFrameRate	= fMaxFrameRate;
   }
 
+  //bitrate setting validation
+  if (pCfg->iRCMode != RC_OFF_MODE){
+    int32_t  iTotalBitrate = 0;
+    for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
+      SDLayerParam* fDlp = &pCfg->sDependencyLayers[i];
+      iTotalBitrate += fDlp->iSpatialBitrate;
+    }
+    if(iTotalBitrate > pCfg->iTargetBitrate){
+      WelsLog(NULL, WELS_LOG_ERROR,"Invalid setttings in bitrate. the sum of each layer bitrate(%) is larger than total bitrate setting(%d)\n",
+              iTotalBitrate,pCfg->iTargetBitrate);
+    }
+  }
+
   return ENC_RETURN_SUCCESS;
 }