1 /*
2 * Copyright (c) 2019 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/goog_cc/acknowledged_bitrate_estimator_interface.h"
12
13 #include <algorithm>
14
15 #include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
16 #include "modules/congestion_controller/goog_cc/robust_throughput_estimator.h"
17 #include "rtc_base/logging.h"
18
19 namespace webrtc {
20
21 constexpr char RobustThroughputEstimatorSettings::kKey[];
22
RobustThroughputEstimatorSettings(const WebRtcKeyValueConfig * key_value_config)23 RobustThroughputEstimatorSettings::RobustThroughputEstimatorSettings(
24 const WebRtcKeyValueConfig* key_value_config) {
25 Parser()->Parse(
26 key_value_config->Lookup(RobustThroughputEstimatorSettings::kKey));
27 if (min_packets < 10 || kMaxPackets < min_packets) {
28 RTC_LOG(LS_WARNING) << "Window size must be between 10 and " << kMaxPackets
29 << " packets";
30 min_packets = 20;
31 }
32 if (initial_packets < 10 || kMaxPackets < initial_packets) {
33 RTC_LOG(LS_WARNING) << "Initial size must be between 10 and " << kMaxPackets
34 << " packets";
35 initial_packets = 20;
36 }
37 initial_packets = std::min(initial_packets, min_packets);
38 if (window_duration < TimeDelta::Millis(100) ||
39 TimeDelta::Millis(2000) < window_duration) {
40 RTC_LOG(LS_WARNING) << "Window duration must be between 100 and 2000 ms";
41 window_duration = TimeDelta::Millis(500);
42 }
43 if (unacked_weight < 0.0 || 1.0 < unacked_weight) {
44 RTC_LOG(LS_WARNING)
45 << "Weight for prior unacked size must be between 0 and 1.";
46 unacked_weight = 1.0;
47 }
48 }
49
50 std::unique_ptr<StructParametersParser>
Parser()51 RobustThroughputEstimatorSettings::Parser() {
52 return StructParametersParser::Create("enabled", &enabled, //
53 "reduce_bias", &reduce_bias, //
54 "assume_shared_link", //
55 &assume_shared_link, //
56 "min_packets", &min_packets, //
57 "window_duration", &window_duration, //
58 "initial_packets", &initial_packets, //
59 "unacked_weight", &unacked_weight);
60 }
61
62 AcknowledgedBitrateEstimatorInterface::
~AcknowledgedBitrateEstimatorInterface()63 ~AcknowledgedBitrateEstimatorInterface() {}
64
65 std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
Create(const WebRtcKeyValueConfig * key_value_config)66 AcknowledgedBitrateEstimatorInterface::Create(
67 const WebRtcKeyValueConfig* key_value_config) {
68 RobustThroughputEstimatorSettings simplified_estimator_settings(
69 key_value_config);
70 if (simplified_estimator_settings.enabled) {
71 return std::make_unique<RobustThroughputEstimator>(
72 simplified_estimator_settings);
73 }
74 return std::make_unique<AcknowledgedBitrateEstimator>(key_value_config);
75 }
76
77 } // namespace webrtc
78