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 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_ACKNOWLEDGED_BITRATE_ESTIMATOR_INTERFACE_H_
12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_ACKNOWLEDGED_BITRATE_ESTIMATOR_INTERFACE_H_
13 
14 #include <stddef.h>
15 
16 #include <memory>
17 #include <vector>
18 
19 #include "absl/types/optional.h"
20 #include "api/field_trials_view.h"
21 #include "api/transport/network_types.h"
22 #include "api/units/data_rate.h"
23 #include "api/units/time_delta.h"
24 #include "api/units/timestamp.h"
25 #include "rtc_base/experiments/struct_parameters_parser.h"
26 
27 namespace webrtc {
28 
29 struct RobustThroughputEstimatorSettings {
30   static constexpr char kKey[] = "WebRTC-Bwe-RobustThroughputEstimatorSettings";
31 
32   RobustThroughputEstimatorSettings() = delete;
33   explicit RobustThroughputEstimatorSettings(
34       const FieldTrialsView* key_value_config);
35 
36   bool enabled = false;  // Set to true to use RobustThroughputEstimator.
37 
38   // The estimator keeps the smallest window containing at least
39   // `window_packets` and at least the packets received during the last
40   // `min_window_duration` milliseconds.
41   // (This means that it may store more than `window_packets` at high bitrates,
42   // and a longer duration than `min_window_duration` at low bitrates.)
43   // However, if will never store more than kMaxPackets (for performance
44   // reasons), and never longer than max_window_duration (to avoid very old
45   // packets influencing the estimate for example when sending is paused).
46   unsigned window_packets = 20;
47   unsigned max_window_packets = 500;
48   TimeDelta min_window_duration = TimeDelta::Seconds(1);
49   TimeDelta max_window_duration = TimeDelta::Seconds(5);
50 
51   // The estimator window requires at least `required_packets` packets
52   // to produce an estimate.
53   unsigned required_packets = 10;
54 
55   // If audio packets aren't included in allocation (i.e. the
56   // estimated available bandwidth is divided only among the video
57   // streams), then `unacked_weight` should be set to 0.
58   // If audio packets are included in allocation, but not in bandwidth
59   // estimation (i.e. they don't have transport-wide sequence numbers,
60   // but we nevertheless divide the estimated available bandwidth among
61   // both audio and video streams), then `unacked_weight` should be set to 1.
62   // If all packets have transport-wide sequence numbers, then the value
63   // of `unacked_weight` doesn't matter.
64   double unacked_weight = 1.0;
65 
66   std::unique_ptr<StructParametersParser> Parser();
67 };
68 
69 class AcknowledgedBitrateEstimatorInterface {
70  public:
71   static std::unique_ptr<AcknowledgedBitrateEstimatorInterface> Create(
72       const FieldTrialsView* key_value_config);
73   virtual ~AcknowledgedBitrateEstimatorInterface();
74 
75   virtual void IncomingPacketFeedbackVector(
76       const std::vector<PacketResult>& packet_feedback_vector) = 0;
77   virtual absl::optional<DataRate> bitrate() const = 0;
78   virtual absl::optional<DataRate> PeekRate() const = 0;
79   virtual void SetAlr(bool in_alr) = 0;
80   virtual void SetAlrEndedTime(Timestamp alr_ended_time) = 0;
81 };
82 
83 }  // namespace webrtc
84 
85 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_ACKNOWLEDGED_BITRATE_ESTIMATOR_INTERFACE_H_
86