Factorize bandwidth bitrate driver bitrate functions

parent d372749b
......@@ -308,43 +308,33 @@ static int bandwidth_change_ptime(MSAudioBitrateDriver *obj, int percent){
return apply_ptime(obj,obj->min_ptime + (max_ptime - obj->min_ptime) * percent / 100.f);
}
static int bandwidth_dec_video_bitrate(MSBandwidthBitrateDriver *obj, const MSRateControlAction *action){
int new_br;
ms_filter_call_method(obj->venc,MS_FILTER_GET_BITRATE,&obj->cur_bitrate);
new_br=((float)obj->cur_bitrate)*(100.0-(float)action->value)/100.0;
if (new_br<min_video_bitrate){
ms_message("MSBandwidthBitrateDriver: reaching low bound.");
new_br=min_video_bitrate;
}
ms_message("MSBandwidthBitrateDriver: targeting %i bps for video encoder.",new_br);
ms_filter_call_method(obj->venc,MS_FILTER_SET_BITRATE,&new_br);
obj->cur_bitrate=new_br;
rtp_session_set_target_upload_bandwidth(obj->vsession, obj->cur_bitrate);
return new_br==min_video_bitrate ? -1 : 0;
}
static int bandwidth_inc_video_bitrate(MSBandwidthBitrateDriver *obj, const MSRateControlAction *action){
static int bandwidth_change_video_bitrate(MSBandwidthBitrateDriver *obj, const MSRateControlAction *action){
int newbr;
int oldbr;
int ret=0;
bool_t decrease = (action->type == MSRateControlActionDecreaseBitrate);
int bound= (decrease) ? min_video_bitrate : obj->nom_bitrate;
ms_filter_call_method(obj->venc,MS_FILTER_GET_BITRATE,&obj->cur_bitrate);
if (obj->cur_bitrate==0){
ms_message("MSBandwidthBitrateDriver: current bitrate was not known.");
return -1; /*current bitrate was not known*/
}
newbr= (float)obj->cur_bitrate*(100.0+(float)action->value)/100.0;
if (newbr>obj->nom_bitrate){
if (obj->cur_bitrate==obj->nom_bitrate){
ms_message("MSBandwidthBitrateDriver: bitrate already at maximum level.");
newbr= (float)obj->cur_bitrate*(100.0+(decrease?-1:1)*(float)action->value)/100.0;
if ((decrease&&newbr<bound) || (!decrease&&newbr>bound)){
if (obj->cur_bitrate==bound){
ms_message("MSBandwidthBitrateDriver: bitrate already reached %s limit %d b/s.", (decrease)?"min":"max",bound);
return -1;
}
newbr=obj->nom_bitrate;
newbr=bound;
}
ms_message("MSBandwidthBitrateDriver: increasing bitrate from %i to %i bps for video encoder.",obj->cur_bitrate,newbr);
oldbr=obj->cur_bitrate;
obj->cur_bitrate=newbr;
rtp_session_set_target_upload_bandwidth(obj->vsession, obj->cur_bitrate);
ms_filter_call_method(obj->venc,MS_FILTER_SET_BITRATE,&obj->cur_bitrate);
ms_filter_call_method(obj->venc,MS_FILTER_GET_BITRATE,&newbr);
ms_message("MSBandwidthBitrateDriver: changing bitrate from %i to %i bps for video encoder.",oldbr,newbr);
return ret;
}
......@@ -365,7 +355,7 @@ static int bandwidth_driver_execute_action(MSBitrateDriver *objbase, const MSRat
switch(action->type){
case MSRateControlActionDecreaseBitrate:
if (obj->venc){
ret=bandwidth_dec_video_bitrate(obj,action);
ret=bandwidth_change_video_bitrate(obj,action);
}
if (ret!=0 && obj->audio_driver){
ret=ms_bitrate_driver_execute_action(obj->audio_driver,action);
......@@ -380,7 +370,7 @@ static int bandwidth_driver_execute_action(MSBitrateDriver *objbase, const MSRat
break;
case MSRateControlActionIncreaseQuality:
if (obj->venc){
ret=bandwidth_inc_video_bitrate(obj,action);
ret=bandwidth_change_video_bitrate(obj,action);
}
if (ret!=0 && obj->audio_driver){
ret=ms_bitrate_driver_execute_action(obj->audio_driver,action);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment