nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_ |
| 12 | #define MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_ |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 17 | #include "api/transport/field_trial_based_config.h" |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 18 | #include "api/transport/network_control.h" |
Sebastian Jansson | 4ad51d8 | 2019-06-11 09:24:40 | [diff] [blame] | 19 | #include "modules/include/module.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
Markus Handell | 9c96250 | 2020-07-07 20:03:26 | [diff] [blame] | 21 | #include "rtc_base/synchronization/mutex.h" |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | class RemoteBitrateEstimator; |
| 25 | class 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. |
| 32 | class ReceiveSideCongestionController : public CallStatsObserver, |
| 33 | public Module { |
| 34 | public: |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 35 | ReceiveSideCongestionController(Clock* clock, PacketRouter* packet_router); |
Per Kjellander | 52f7ae7 | 2019-09-10 17:28:06 | [diff] [blame] | 36 | ReceiveSideCongestionController( |
| 37 | Clock* clock, |
| 38 | PacketRouter* packet_router, |
| 39 | NetworkStateEstimator* network_state_estimator); |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 40 | |
Mirko Bonadei | 8fdcac3 | 2018-08-28 14:30:18 | [diff] [blame] | 41 | ~ReceiveSideCongestionController() override {} |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 42 | |
| 43 | virtual void OnReceivedPacket(int64_t arrival_time_ms, |
| 44 | size_t payload_size, |
| 45 | const RTPHeader& header); |
| 46 | |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame] | 47 | void SetSendPeriodicFeedback(bool send_periodic_feedback); |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 48 | // 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 | |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 53 | // 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 Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 66 | WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock); |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 67 | |
Niels Möller | de95329 | 2020-09-29 07:46:21 | [diff] [blame] | 68 | WrappingBitrateEstimator() = delete; |
| 69 | WrappingBitrateEstimator(const WrappingBitrateEstimator&) = delete; |
| 70 | WrappingBitrateEstimator& operator=(const WrappingBitrateEstimator&) = |
| 71 | delete; |
| 72 | |
Mirko Bonadei | 8fdcac3 | 2018-08-28 14:30:18 | [diff] [blame] | 73 | ~WrappingBitrateEstimator() override; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 74 | |
| 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 Handell | 9c96250 | 2020-07-07 20:03:26 | [diff] [blame] | 94 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 95 | void PickEstimator() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 96 | RemoteBitrateObserver* observer_; |
Sebastian Jansson | aa01f27 | 2019-01-30 10:28:59 | [diff] [blame] | 97 | Clock* const clock_; |
Markus Handell | 9c96250 | 2020-07-07 20:03:26 | [diff] [blame] | 98 | mutable Mutex mutex_; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 99 | std::unique_ptr<RemoteBitrateEstimator> rbe_; |
| 100 | bool using_absolute_send_time_; |
| 101 | uint32_t packets_since_absolute_send_time_; |
| 102 | int min_bitrate_bps_; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 103 | }; |
| 104 | |
Niels Möller | decc076 | 2019-04-17 12:14:32 | [diff] [blame] | 105 | const FieldTrialBasedConfig field_trial_config_; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 106 | WrappingBitrateEstimator remote_bitrate_estimator_; |
| 107 | RemoteEstimatorProxy remote_estimator_proxy_; |
| 108 | }; |
| 109 | |
| 110 | } // namespace webrtc |
| 111 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 112 | #endif // MODULES_CONGESTION_CONTROLLER_INCLUDE_RECEIVE_SIDE_CONGESTION_CONTROLLER_H_ |