ref: ac1630f435e42421fced379e20d5c1965a998960
parent: f0728ed365b178c828428bd32043a3289e91c3a1
parent: a20c503d14c6d4df5c0d8e36da52981faa6d846f
author: dongzha <dongzha@cisco.com>
date: Mon Jun 23 10:50:52 EDT 2014
Merge pull request #999 from ruil2/format_update add max nal size setting in gmp wrapper
--- a/module/gmp-openh264.cpp
+++ b/module/gmp-openh264.cpp
@@ -204,40 +204,95 @@
if (rv) {
return GMPVideoGenericErr;
}
+ if (maxPayloadSize <= 0) {
+ SEncParamBase param;
+ memset (¶m, 0, sizeof (param));
- SEncParamBase param;
- memset (¶m, 0, sizeof (param));
+ GMPLOG (GL_INFO, "Initializing encoder at "
+ << codecSettings.mWidth
+ << "x"
+ << codecSettings.mHeight
+ << "@"
+ << static_cast<int> (codecSettings.mMaxFramerate)
+ << "max payload size="
+ << maxPayloadSize);
- GMPLOG (GL_INFO, "Initializing encoder at "
- << codecSettings.mWidth
- << "x"
- << codecSettings.mHeight
- << "@"
- << static_cast<int> (codecSettings.mMaxFramerate)
- << "max payload size="
- << maxPayloadSize);
+ // Translate parameters.
+ param.iUsageType = CAMERA_VIDEO_REAL_TIME;
+ param.iPicWidth = codecSettings.mWidth;
+ param.iPicHeight = codecSettings.mHeight;
+ param.iTargetBitrate = codecSettings.mStartBitrate * 1000;
+ GMPLOG (GL_INFO, "Initializing Bit Rate at: Start: "
+ << codecSettings.mStartBitrate
+ << "; Min: "
+ << codecSettings.mMinBitrate
+ << "; Max: "
+ << codecSettings.mMaxBitrate);
- // Translate parameters.
- param.iUsageType = CAMERA_VIDEO_REAL_TIME;
- param.iPicWidth = codecSettings.mWidth;
- param.iPicHeight = codecSettings.mHeight;
- param.iTargetBitrate = codecSettings.mStartBitrate * 1000;
- GMPLOG (GL_INFO, "Initializing Bit Rate at: Start: "
- << codecSettings.mStartBitrate
- << "; Min: "
- << codecSettings.mMinBitrate
- << "; Max: "
- << codecSettings.mMaxBitrate);
- param.iRCMode = RC_BITRATE_MODE;
+ param.iRCMode = RC_BITRATE_MODE;
- // TODO(ekr@rtfm.com). Scary conversion from unsigned char to float below.
- param.fMaxFrameRate = static_cast<float> (codecSettings.mMaxFramerate);
- param.iInputCsp = videoFormatI420;
+ // TODO(ekr@rtfm.com). Scary conversion from unsigned char to float below.
+ param.fMaxFrameRate = static_cast<float> (codecSettings.mMaxFramerate);
+ param.iInputCsp = videoFormatI420;
- rv = encoder_->Initialize (¶m);
- if (rv) {
- GMPLOG (GL_ERROR, "Couldn't initialize encoder");
- return GMPVideoGenericErr;
+ rv = encoder_->Initialize (¶m);
+ if (rv) {
+ GMPLOG (GL_ERROR, "Couldn't initialize encoder");
+ return GMPVideoGenericErr;
+ }
+ } else {
+ SEncParamExt param;
+ memset (¶m, 0, sizeof (param));
+ encoder_->GetDefaultParams (¶m);
+
+ GMPLOG (GL_INFO, "Initializing encoder at "
+ << codecSettings.mWidth
+ << "x"
+ << codecSettings.mHeight
+ << "@"
+ << static_cast<int> (codecSettings.mMaxFramerate)
+ << "max payload size="
+ << maxPayloadSize);
+
+ // Translate parameters.
+ param.iUsageType = CAMERA_VIDEO_REAL_TIME;
+ param.iInputCsp = videoFormatI420;
+ 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);
+ //for controlling the NAL size (normally for packetization-mode=0)
+ param.uiMaxNalSize = maxPayloadSize;
+
+ // TODO(ekr@rtfm.com). Scary conversion from unsigned char to float below.
+ param.fMaxFrameRate = static_cast<float> (codecSettings.mMaxFramerate);
+
+ // Set up layers. Currently we have one layer.
+ SSpatialLayerConfig* layer = ¶m.sSpatialLayers[0];
+
+ layer->iVideoWidth = codecSettings.mWidth;
+ layer->iVideoHeight = codecSettings.mHeight;
+ layer->fFrameRate = param.fMaxFrameRate;
+ layer->iSpatialBitrate = param.iTargetBitrate;
+ layer->iMaxSpatialBitrate = param.iMaxBitrate;
+
+ // Based on guidance from Cisco.
+ layer->sSliceCfg.uiSliceMode = SM_DYN_SLICE;
+ layer->sSliceCfg.sSliceArgument.uiSliceSizeConstraint = maxPayloadSize;
+
+ rv = encoder_->InitializeExt (¶m);
+ if (rv) {
+ GMPLOG (GL_ERROR, "Couldn't initialize encoder");
+ return GMPVideoGenericErr;
+ }
+
}
max_payload_size_ = maxPayloadSize;