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 "rtc_base/checks.h"
18
19 namespace webrtc {
20 namespace pcc {
21
VivaceUtilityFunction(double delay_gradient_coefficient,double loss_coefficient,double throughput_coefficient,double throughput_power,double delay_gradient_threshold,double delay_gradient_negative_bound)22 VivaceUtilityFunction::VivaceUtilityFunction(
23 double delay_gradient_coefficient,
24 double loss_coefficient,
25 double throughput_coefficient,
26 double throughput_power,
27 double delay_gradient_threshold,
28 double delay_gradient_negative_bound)
29 : delay_gradient_coefficient_(delay_gradient_coefficient),
30 loss_coefficient_(loss_coefficient),
31 throughput_power_(throughput_power),
32 throughput_coefficient_(throughput_coefficient),
33 delay_gradient_threshold_(delay_gradient_threshold),
34 delay_gradient_negative_bound_(delay_gradient_negative_bound) {
35 RTC_DCHECK_GE(delay_gradient_negative_bound_, 0);
36 }
37
Compute(const PccMonitorInterval & monitor_interval) const38 double VivaceUtilityFunction::Compute(
39 const PccMonitorInterval& monitor_interval) const {
40 RTC_DCHECK(monitor_interval.IsFeedbackCollectionDone());
41 double bitrate = monitor_interval.GetTargetSendingRate().bps();
42 double loss_rate = monitor_interval.GetLossRate();
43 double rtt_gradient =
44 monitor_interval.ComputeDelayGradient(delay_gradient_threshold_);
45 rtt_gradient = std::max(rtt_gradient, -delay_gradient_negative_bound_);
46 return (throughput_coefficient_ * std::pow(bitrate, throughput_power_)) -
47 (delay_gradient_coefficient_ * bitrate * rtt_gradient) -
48 (loss_coefficient_ * bitrate * loss_rate);
49 }
50
51 VivaceUtilityFunction::~VivaceUtilityFunction() = default;
52
ModifiedVivaceUtilityFunction(double delay_gradient_coefficient,double loss_coefficient,double throughput_coefficient,double throughput_power,double delay_gradient_threshold,double delay_gradient_negative_bound)53 ModifiedVivaceUtilityFunction::ModifiedVivaceUtilityFunction(
54 double delay_gradient_coefficient,
55 double loss_coefficient,
56 double throughput_coefficient,
57 double throughput_power,
58 double delay_gradient_threshold,
59 double delay_gradient_negative_bound)
60 : delay_gradient_coefficient_(delay_gradient_coefficient),
61 loss_coefficient_(loss_coefficient),
62 throughput_power_(throughput_power),
63 throughput_coefficient_(throughput_coefficient),
64 delay_gradient_threshold_(delay_gradient_threshold),
65 delay_gradient_negative_bound_(delay_gradient_negative_bound) {
66 RTC_DCHECK_GE(delay_gradient_negative_bound_, 0);
67 }
68
Compute(const PccMonitorInterval & monitor_interval) const69 double ModifiedVivaceUtilityFunction::Compute(
70 const PccMonitorInterval& monitor_interval) const {
71 RTC_DCHECK(monitor_interval.IsFeedbackCollectionDone());
72 double bitrate = monitor_interval.GetTargetSendingRate().bps();
73 double loss_rate = monitor_interval.GetLossRate();
74 double rtt_gradient =
75 monitor_interval.ComputeDelayGradient(delay_gradient_threshold_);
76 rtt_gradient = std::max(rtt_gradient, -delay_gradient_negative_bound_);
77 return (throughput_coefficient_ * std::pow(bitrate, throughput_power_) *
78 bitrate) -
79 (delay_gradient_coefficient_ * bitrate * bitrate * rtt_gradient) -
80 (loss_coefficient_ * bitrate * bitrate * loss_rate);
81 }
82
83 ModifiedVivaceUtilityFunction::~ModifiedVivaceUtilityFunction() = default;
84
85 } // namespace pcc
86 } // namespace webrtc
87