shithub: openh264

Download patch

ref: b3922b1d3aaccaff7ff1b3cbe15dc7035a09c18a
parent: 429ccb38a8614530c93f6931db6d4b3f2543892e
parent: 128546b99229a0dc3d42052c8f1e45a9b0b83116
author: sijchen <sijchen@cisco.com>
date: Wed Nov 12 15:44:24 EST 2014

Merge pull request #1519 from ruil2/max_nal_size

    add maxnalsize control for gmp wrapper

--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3668,13 +3668,12 @@
   pCtx->eLastNalPriority	= eNalRefIdc;
   pFbi->iLayerNum			= iLayerNum;
   pFbi->iSubSeqId = GetSubSequenceId (pCtx, eFrameType);
+
   WelsLog (pLogCtx, WELS_LOG_DEBUG, "WelsEncoderEncodeExt() OutputInfo iLayerNum = %d,iSubSeqId = %d", iLayerNum,
            pFbi->iSubSeqId);
   for (int32_t i = 0; i < iLayerNum; i++)
     WelsLog (pLogCtx, WELS_LOG_DEBUG, "WelsEncoderEncodeExt() OutputInfo iLayerId = %d,iNalType = %d,iNalCount = %d", i,
              pFbi->sLayerInfo[i].uiLayerType, pFbi->sLayerInfo[i].iNalCount);
-
-
   WelsEmms();
 
   pFbi->eFrameType = eFrameType;
--- a/module/gmp-openh264.cpp
+++ b/module/gmp-openh264.cpp
@@ -210,9 +210,9 @@
       Error (GMPGenericErr);
       return;
     }
-
-    SEncParamBase param;
+    SEncParamExt param;
     memset (&param, 0, sizeof (param));
+    encoder_->GetDefaultParams (&param);
 
     GMPLOG (GL_INFO, "Initializing encoder at "
             << codecSettings.mWidth
@@ -219,35 +219,50 @@
             << "x"
             << codecSettings.mHeight
             << "@"
-            << static_cast<int> (codecSettings.mMaxFramerate)
-            << "max payload size="
-            << maxPayloadSize);
+            << static_cast<int> (codecSettings.mMaxFramerate));
 
     // Translate parameters.
     param.iUsageType = CAMERA_VIDEO_REAL_TIME;
     param.iPicWidth = codecSettings.mWidth;
     param.iPicHeight = codecSettings.mHeight;
+    param.iRCMode = RC_BITRATE_MODE;
     param.iTargetBitrate = codecSettings.mStartBitrate * 1000;
+    param.iMaxBitrate = codecSettings.mMaxBitrate * 1000;
     GMPLOG (GL_INFO, "Initializing Bit Rate at: Start: "
             << codecSettings.mStartBitrate
             << "; Min: "
             << codecSettings.mMinBitrate
             << "; Max: "
-            << codecSettings.mMaxBitrate);
-    param.iRCMode = RC_BITRATE_MODE;
+            << codecSettings.mMaxBitrate
+            << "; Max payload size:"
+            << maxPayloadSize);
 
+    param.uiMaxNalSize = maxPayloadSize;
+
     // TODO(ekr@rtfm.com). Scary conversion from unsigned char to float below.
     param.fMaxFrameRate = static_cast<float> (codecSettings.mMaxFramerate);
 
-    rv = encoder_->Initialize (&param);
+    // Set up layers. Currently we have one layer.
+    SSpatialLayerConfig* layer = &param.sSpatialLayers[0];
+
+    layer->iVideoWidth = codecSettings.mWidth;
+    layer->iVideoHeight = codecSettings.mHeight;
+    layer->fFrameRate = param.fMaxFrameRate;
+    layer->iSpatialBitrate = param.iTargetBitrate;
+    layer->iMaxSpatialBitrate = param.iMaxBitrate;
+
+    //for controlling the NAL size (normally for packetization-mode=0)
+    if (maxPayloadSize != 0) {
+      layer->sSliceCfg.uiSliceMode = SM_DYN_SLICE;
+      layer->sSliceCfg.sSliceArgument.uiSliceSizeConstraint = maxPayloadSize;
+    }
+    rv = encoder_->InitializeExt (&param);
     if (rv) {
       GMPLOG (GL_ERROR, "Couldn't initialize encoder");
       Error (GMPGenericErr);
       return;
     }
-
     max_payload_size_ = maxPayloadSize;
-
     GMPLOG (GL_INFO, "Initialized encoder");
   }
 
@@ -382,7 +397,7 @@
     src.pData[3] = nullptr;
     src.iPicWidth = inputImage->Width();
     src.iPicHeight = inputImage->Height();
-    src.uiTimeStamp = inputImage->Timestamp()/1000; //encoder needs millisecond
+    src.uiTimeStamp = inputImage->Timestamp() / 1000; //encoder needs millisecond
     const SSourcePicture* pics = &src;
 
     int result = encoder_->EncodeFrame (pics, &encoded);
@@ -628,7 +643,7 @@
                             dState,
                             renderTimeMs));
     if (dState) {
-      Error(GMPGenericErr);
+      Error (GMPGenericErr);
     }
   }