blob: 034f2e95178dfc5da7f7b8aa31452f41e0542025 [file] [log] [blame]
nisse559af382017-03-21 13:41:121/*
2 * Copyright (c) 2017 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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_
12#define MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_
nisse559af382017-03-21 13:41:1213
14#include <memory>
15#include <vector>
16
Niels Möllerdecc0762019-04-17 12:14:3217#include "api/transport/field_trial_based_config.h"
Per Kjellander52f7ae72019-09-10 17:28:0618#include "api/transport/network_control.h"
Sebastian Jansson4ad51d82019-06-11 09:24:4019#include "modules/include/module.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "modules/remote_bitrate_estimator/remote_estimator_proxy.h"
Markus Handell9c962502020-07-07 20:03:2621#include "rtc_base/synchronization/mutex.h"
nisse559af382017-03-21 13:41:1222
23namespace webrtc {
24class RemoteBitrateEstimator;
25class RemoteBitrateObserver;
26
27// This class represents the congestion control state for receive
28// streams. For send side bandwidth estimation, this is simply
29// relaying for each received RTP packet back to the sender. While for
30// receive side bandwidth estimation, we do the estimation locally and
31// send our results back to the sender.
32class ReceiveSideCongestionController : public CallStatsObserver,
33 public Module {
34 public:
Sebastian Janssonaa01f272019-01-30 10:28:5935 ReceiveSideCongestionController(Clock* clock, PacketRouter* packet_router);
Per Kjellander52f7ae72019-09-10 17:28:0636 ReceiveSideCongestionController(
37 Clock* clock,
38 PacketRouter* packet_router,
39 NetworkStateEstimator* network_state_estimator);
nisse559af382017-03-21 13:41:1240
Mirko Bonadei8fdcac32018-08-28 14:30:1841 ~ReceiveSideCongestionController() override {}
nisse559af382017-03-21 13:41:1242
43 virtual void OnReceivedPacket(int64_t arrival_time_ms,
44 size_t payload_size,
45 const RTPHeader& header);
46
Johannes Kronf59666b2019-04-08 10:57:0647 void SetSendPeriodicFeedback(bool send_periodic_feedback);
nisse559af382017-03-21 13:41:1248 // TODO(nisse): Delete these methods, design a more specific interface.
49 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(bool send_side_bwe);
50 virtual const RemoteBitrateEstimator* GetRemoteBitrateEstimator(
51 bool send_side_bwe) const;
52
nisse559af382017-03-21 13:41:1253 // Implements CallStatsObserver.
54 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
55
56 // This is send bitrate, used to control the rate of feedback messages.
57 void OnBitrateChanged(int bitrate_bps);
58
59 // Implements Module.
60 int64_t TimeUntilNextProcess() override;
61 void Process() override;
62
63 private:
64 class WrappingBitrateEstimator : public RemoteBitrateEstimator {
65 public:
Sebastian Janssonaa01f272019-01-30 10:28:5966 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock);
nisse559af382017-03-21 13:41:1267
Niels Möllerde953292020-09-29 07:46:2168 WrappingBitrateEstimator() = delete;
69 WrappingBitrateEstimator(const WrappingBitrateEstimator&) = delete;
70 WrappingBitrateEstimator& operator=(const WrappingBitrateEstimator&) =
71 delete;
72
Mirko Bonadei8fdcac32018-08-28 14:30:1873 ~WrappingBitrateEstimator() override;
nisse559af382017-03-21 13:41:1274
75 void IncomingPacket(int64_t arrival_time_ms,
76 size_t payload_size,
77 const RTPHeader& header) override;
78
79 void Process() override;
80
81 int64_t TimeUntilNextProcess() override;
82
83 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
84
85 void RemoveStream(unsigned int ssrc) override;
86
87 bool LatestEstimate(std::vector<unsigned int>* ssrcs,
88 unsigned int* bitrate_bps) const override;
89
90 void SetMinBitrate(int min_bitrate_bps) override;
91
92 private:
93 void PickEstimatorFromHeader(const RTPHeader& header)
Markus Handell9c962502020-07-07 20:03:2694 RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
95 void PickEstimator() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
nisse559af382017-03-21 13:41:1296 RemoteBitrateObserver* observer_;
Sebastian Janssonaa01f272019-01-30 10:28:5997 Clock* const clock_;
Markus Handell9c962502020-07-07 20:03:2698 mutable Mutex mutex_;
nisse559af382017-03-21 13:41:1299 std::unique_ptr<RemoteBitrateEstimator> rbe_;
100 bool using_absolute_send_time_;
101 uint32_t packets_since_absolute_send_time_;
102 int min_bitrate_bps_;
nisse559af382017-03-21 13:41:12103 };
104
Niels Möllerdecc0762019-04-17 12:14:32105 const FieldTrialBasedConfig field_trial_config_;
nisse559af382017-03-21 13:41:12106 WrappingBitrateEstimator remote_bitrate_estimator_;
107 RemoteEstimatorProxy remote_estimator_proxy_;
108};
109
110} // namespace webrtc
111
Mirko Bonadei92ea95e2017-09-15 04:47:31112#endif // MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_