utility_function.cc (3494B)
1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/congestion_controller/pcc/utility_function.h" 12 13 #include <algorithm> 14 #include <cmath> 15 16 #include "api/units/data_rate.h" 17 #include "modules/congestion_controller/pcc/monitor_interval.h" 18 #include "rtc_base/checks.h" 19 20 namespace webrtc { 21 namespace pcc { 22 23 VivaceUtilityFunction::VivaceUtilityFunction( 24 double delay_gradient_coefficient, 25 double loss_coefficient, 26 double throughput_coefficient, 27 double throughput_power, 28 double delay_gradient_threshold, 29 double delay_gradient_negative_bound) 30 : delay_gradient_coefficient_(delay_gradient_coefficient), 31 loss_coefficient_(loss_coefficient), 32 throughput_power_(throughput_power), 33 throughput_coefficient_(throughput_coefficient), 34 delay_gradient_threshold_(delay_gradient_threshold), 35 delay_gradient_negative_bound_(delay_gradient_negative_bound) { 36 RTC_DCHECK_GE(delay_gradient_negative_bound_, 0); 37 } 38 39 double VivaceUtilityFunction::Compute( 40 const PccMonitorInterval& monitor_interval) const { 41 RTC_DCHECK(monitor_interval.IsFeedbackCollectionDone()); 42 double bitrate = monitor_interval.GetTargetSendingRate().bps(); 43 double loss_rate = monitor_interval.GetLossRate(); 44 double rtt_gradient = 45 monitor_interval.ComputeDelayGradient(delay_gradient_threshold_); 46 rtt_gradient = std::max(rtt_gradient, -delay_gradient_negative_bound_); 47 return (throughput_coefficient_ * std::pow(bitrate, throughput_power_)) - 48 (delay_gradient_coefficient_ * bitrate * rtt_gradient) - 49 (loss_coefficient_ * bitrate * loss_rate); 50 } 51 52 VivaceUtilityFunction::~VivaceUtilityFunction() = default; 53 54 ModifiedVivaceUtilityFunction::ModifiedVivaceUtilityFunction( 55 double delay_gradient_coefficient, 56 double loss_coefficient, 57 double throughput_coefficient, 58 double throughput_power, 59 double delay_gradient_threshold, 60 double delay_gradient_negative_bound) 61 : delay_gradient_coefficient_(delay_gradient_coefficient), 62 loss_coefficient_(loss_coefficient), 63 throughput_power_(throughput_power), 64 throughput_coefficient_(throughput_coefficient), 65 delay_gradient_threshold_(delay_gradient_threshold), 66 delay_gradient_negative_bound_(delay_gradient_negative_bound) { 67 RTC_DCHECK_GE(delay_gradient_negative_bound_, 0); 68 } 69 70 double ModifiedVivaceUtilityFunction::Compute( 71 const PccMonitorInterval& monitor_interval) const { 72 RTC_DCHECK(monitor_interval.IsFeedbackCollectionDone()); 73 double bitrate = monitor_interval.GetTargetSendingRate().bps(); 74 double loss_rate = monitor_interval.GetLossRate(); 75 double rtt_gradient = 76 monitor_interval.ComputeDelayGradient(delay_gradient_threshold_); 77 rtt_gradient = std::max(rtt_gradient, -delay_gradient_negative_bound_); 78 return (throughput_coefficient_ * std::pow(bitrate, throughput_power_) * 79 bitrate) - 80 (delay_gradient_coefficient_ * bitrate * bitrate * rtt_gradient) - 81 (loss_coefficient_ * bitrate * bitrate * loss_rate); 82 } 83 84 ModifiedVivaceUtilityFunction::~ModifiedVivaceUtilityFunction() = default; 85 86 } // namespace pcc 87 } // namespace webrtc