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