summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator_interface.cc
blob: 571bbff71ad6577a54c41aa4b3b9fd8dd64b04a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator_interface.h"

#include <algorithm>
#include <memory>

#include "api/field_trials_view.h"
#include "api/units/time_delta.h"
#include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator.h"
#include "modules/congestion_controller/goog_cc/robust_throughput_estimator.h"
#include "rtc_base/experiments/struct_parameters_parser.h"
#include "rtc_base/logging.h"

namespace webrtc {

constexpr char RobustThroughputEstimatorSettings::kKey[];

RobustThroughputEstimatorSettings::RobustThroughputEstimatorSettings(
    const FieldTrialsView* key_value_config) {
  Parser()->Parse(
      key_value_config->Lookup(RobustThroughputEstimatorSettings::kKey));
  if (window_packets < 10 || 1000 < window_packets) {
    RTC_LOG(LS_WARNING) << "Window size must be between 10 and 1000 packets";
    window_packets = 20;
  }
  if (max_window_packets < 10 || 1000 < max_window_packets) {
    RTC_LOG(LS_WARNING)
        << "Max window size must be between 10 and 1000 packets";
    max_window_packets = 500;
  }
  max_window_packets = std::max(max_window_packets, window_packets);

  if (required_packets < 10 || 1000 < required_packets) {
    RTC_LOG(LS_WARNING) << "Required number of initial packets must be between "
                           "10 and 1000 packets";
    required_packets = 10;
  }
  required_packets = std::min(required_packets, window_packets);

  if (min_window_duration < TimeDelta::Millis(100) ||
      TimeDelta::Millis(3000) < min_window_duration) {
    RTC_LOG(LS_WARNING) << "Window duration must be between 100 and 3000 ms";
    min_window_duration = TimeDelta::Millis(750);
  }
  if (max_window_duration < TimeDelta::Seconds(1) ||
      TimeDelta::Seconds(15) < max_window_duration) {
    RTC_LOG(LS_WARNING) << "Max window duration must be between 1 and 15 s";
    max_window_duration = TimeDelta::Seconds(5);
  }
  min_window_duration = std::min(min_window_duration, max_window_duration);

  if (unacked_weight < 0.0 || 1.0 < unacked_weight) {
    RTC_LOG(LS_WARNING)
        << "Weight for prior unacked size must be between 0 and 1.";
    unacked_weight = 1.0;
  }
}

std::unique_ptr<StructParametersParser>
RobustThroughputEstimatorSettings::Parser() {
  return StructParametersParser::Create(
      "enabled", &enabled,                          //
      "window_packets", &window_packets,            //
      "max_window_packets", &max_window_packets,    //
      "window_duration", &min_window_duration,      //
      "max_window_duration", &max_window_duration,  //
      "required_packets", &required_packets,        //
      "unacked_weight", &unacked_weight);
}

AcknowledgedBitrateEstimatorInterface::
    ~AcknowledgedBitrateEstimatorInterface() {}

std::unique_ptr<AcknowledgedBitrateEstimatorInterface>
AcknowledgedBitrateEstimatorInterface::Create(
    const FieldTrialsView* key_value_config) {
  RobustThroughputEstimatorSettings simplified_estimator_settings(
      key_value_config);
  if (simplified_estimator_settings.enabled) {
    return std::make_unique<RobustThroughputEstimator>(
        simplified_estimator_settings);
  }
  return std::make_unique<AcknowledgedBitrateEstimator>(key_value_config);
}

}  // namespace webrtc