Skip to content

Commit

Permalink
Merge pull request cisco#4 from sijchen/plugin2_SetRates11
Browse files Browse the repository at this point in the history
add SetRates function and related fix
  • Loading branch information
ekr committed Mar 26, 2014
2 parents dec466b + c4e499d commit aa84bc9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
12 changes: 10 additions & 2 deletions codec/encoder/plus/src/welsEncoderExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,11 @@ int CWelsH264SVCEncoder::GetOption (ENCODER_OPTION eOptionId, void* pOption) {
m_uiCountFrameNum, m_iCspInternal);
#endif//REC_FRAME_COUNT
SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
if((pInfo->iLayer!=SPATIAL_LAYER_ALL)||(pInfo->iLayer!=SPATIAL_LAYER_0)||(pInfo->iLayer!=SPATIAL_LAYER_1)||(pInfo->iLayer!=SPATIAL_LAYER_2)||(pInfo->iLayer!=SPATIAL_LAYER_3))
if((pInfo->iLayer!=SPATIAL_LAYER_ALL)
&&(pInfo->iLayer!=SPATIAL_LAYER_0)
&&(pInfo->iLayer!=SPATIAL_LAYER_1)
&&(pInfo->iLayer!=SPATIAL_LAYER_2)
&&(pInfo->iLayer!=SPATIAL_LAYER_3))
return cmInitParaError;
if(pInfo->iLayer == SPATIAL_LAYER_ALL){
pInfo->iBitrate = m_pEncContext->pSvcParam->iTargetBitrate;
Expand All @@ -1069,7 +1073,11 @@ int CWelsH264SVCEncoder::GetOption (ENCODER_OPTION eOptionId, void* pOption) {
m_uiCountFrameNum, m_iCspInternal);
#endif//REC_FRAME_COUNT
SBitrateInfo*pInfo = (static_cast<SBitrateInfo *>(pOption));
if((pInfo->iLayer!=SPATIAL_LAYER_ALL)||(pInfo->iLayer!=SPATIAL_LAYER_0)||(pInfo->iLayer!=SPATIAL_LAYER_1)||(pInfo->iLayer!=SPATIAL_LAYER_2)||(pInfo->iLayer!=SPATIAL_LAYER_3))
if((pInfo->iLayer!=SPATIAL_LAYER_ALL)
&&(pInfo->iLayer!=SPATIAL_LAYER_0)
&&(pInfo->iLayer!=SPATIAL_LAYER_1)
&&(pInfo->iLayer!=SPATIAL_LAYER_2)
&&(pInfo->iLayer!=SPATIAL_LAYER_3))
return cmInitParaError;
if(pInfo->iLayer == SPATIAL_LAYER_ALL){
pInfo->iBitrate = m_pEncContext->pSvcParam->iMaxBitrate;
Expand Down
71 changes: 68 additions & 3 deletions module/gmp-openh264.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@ class OpenH264VideoEncoder : public GMPVideoEncoder
param.iUsageType = CAMERA_VIDEO_REAL_TIME;
param.iPicWidth = codecSettings.mWidth;
param.iPicHeight = codecSettings.mHeight;
param.iTargetBitrate =
(codecSettings.mStartBitrate + codecSettings.mMaxBitrate) * 500;
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;

Expand Down Expand Up @@ -268,7 +273,7 @@ class OpenH264VideoEncoder : public GMPVideoEncoder

switch (encoded.eOutputFrameType) {
case videoFrameTypeIDR:
encoded_type = kGMPDeltaFrame;
encoded_type = kGMPKeyFrame;
has_frame = true;
break;
case videoFrameTypeI:
Expand Down Expand Up @@ -374,6 +379,66 @@ class OpenH264VideoEncoder : public GMPVideoEncoder

virtual GMPVideoErr SetRates(uint32_t aNewBitRate, uint32_t aFrameRate) override {
printf("%s\n", __PRETTY_FUNCTION__);
GMPLOG(GL_INFO, "[SetRates] Begin with: "
<< aNewBitRate << " , "<< aFrameRate);

//update bitrate if needed
const int32_t newBitRate = aNewBitRate*1000; //kbps->bps
SBitrateInfo existEncoderBitRate;
existEncoderBitRate.iLayer = SPATIAL_LAYER_ALL;
int rv = encoder_->GetOption(ENCODER_OPTION_BITRATE, &existEncoderBitRate);
if (rv!=cmResultSuccess) {
GMPLOG(GL_ERROR, "[SetRates] Error in Getting Bit Rate at Layer:"
<< rv
<< " ; Layer = "
<< existEncoderBitRate.iLayer
<< " ; BR = "
<< existEncoderBitRate.iBitrate);
return GMPVideoGenericErr;
}
if ( rv==cmResultSuccess && existEncoderBitRate.iBitrate!=newBitRate ) {
SBitrateInfo newEncoderBitRate;
newEncoderBitRate.iLayer = SPATIAL_LAYER_ALL;
newEncoderBitRate.iBitrate = newBitRate;
rv = encoder_->SetOption(ENCODER_OPTION_BITRATE, &newEncoderBitRate);
if (rv==cmResultSuccess) {
GMPLOG(GL_INFO, "[SetRates] Update Encoder Bandwidth (AllLayers): ReturnValue: "
<< rv
<< "BitRate(kbps): "
<< aNewBitRate);
} else {
GMPLOG(GL_ERROR, "[SetRates] Error in Setting Bit Rate at Layer:"
<< rv
<< " ; Layer = "
<< newEncoderBitRate.iLayer
<< " ; BR = "
<< newEncoderBitRate.iBitrate);
return GMPVideoGenericErr;
}
}

//update framerate if needed
float existFrameRate = 0;
rv = encoder_->GetOption(ENCODER_OPTION_FRAME_RATE, &existFrameRate);
if (rv!=cmResultSuccess) {
GMPLOG(GL_ERROR, "[SetRates] Error in Getting Frame Rate:"
<< rv << " FrameRate: " << existFrameRate);
return GMPVideoGenericErr;
}
if ( rv==cmResultSuccess &&
( aFrameRate-existFrameRate>0.001f || existFrameRate-aFrameRate>0.001f ) ) {
float newFrameRate = static_cast<float>(aFrameRate);
rv = encoder_->SetOption(ENCODER_OPTION_FRAME_RATE, &newFrameRate);
if (rv==cmResultSuccess) {
GMPLOG(GL_INFO, "[SetRates] Update Encoder Frame Rate: ReturnValue: "
<< rv << " FrameRate: " << aFrameRate);
} else {
GMPLOG(GL_ERROR, "[SetRates] Error in Setting Frame Rate: ReturnValue: "
<< rv << " FrameRate: " << aFrameRate);
return GMPVideoGenericErr;
}
}

return GMPVideoNoErr;
}

Expand Down

0 comments on commit aa84bc9

Please sign in to comment.