remb_throttler.h (2161B)
1 /* 2 * Copyright (c) 2021 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 #ifndef MODULES_CONGESTION_CONTROLLER_REMB_THROTTLER_H_ 11 #define MODULES_CONGESTION_CONTROLLER_REMB_THROTTLER_H_ 12 13 #include <cstdint> 14 #include <functional> 15 #include <vector> 16 17 #include "api/units/data_rate.h" 18 #include "api/units/timestamp.h" 19 #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" 20 #include "rtc_base/synchronization/mutex.h" 21 #include "rtc_base/thread_annotations.h" 22 #include "system_wrappers/include/clock.h" 23 24 namespace webrtc { 25 26 // RembThrottler is a helper class used for throttling RTCP REMB messages. 27 // Throttles small changes to the received BWE within 200ms. 28 class RembThrottler : public RemoteBitrateObserver { 29 public: 30 using RembSender = 31 std::function<void(int64_t bitrate_bps, std::vector<uint32_t> ssrcs)>; 32 RembThrottler(RembSender remb_sender, Clock* clock); 33 34 // Ensures the remote party is notified of the receive bitrate no larger than 35 // `bitrate` using RTCP REMB. 36 void SetMaxDesiredReceiveBitrate(DataRate bitrate); 37 38 // Implements RemoteBitrateObserver; 39 // Called every time there is a new bitrate estimate for a receive channel 40 // group. This call will trigger a new RTCP REMB packet if the bitrate 41 // estimate has decreased or if no RTCP REMB packet has been sent for 42 // a certain time interval. 43 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, 44 uint32_t bitrate_bps) override; 45 46 private: 47 const RembSender remb_sender_; 48 Clock* const clock_; 49 mutable Mutex mutex_; 50 Timestamp last_remb_time_ RTC_GUARDED_BY(mutex_); 51 DataRate last_send_remb_bitrate_ RTC_GUARDED_BY(mutex_); 52 DataRate max_remb_bitrate_ RTC_GUARDED_BY(mutex_); 53 }; 54 55 } // namespace webrtc 56 #endif // MODULES_CONGESTION_CONTROLLER_REMB_THROTTLER_H_