1 /* 2 * Copyright (c) 2015 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_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_SINGLE_STREAM_H_ 12 #define MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_SINGLE_STREAM_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <map> 18 #include <vector> 19 20 #include "api/transport/field_trial_based_config.h" 21 #include "api/units/data_rate.h" 22 #include "api/units/time_delta.h" 23 #include "api/units/timestamp.h" 24 #include "modules/remote_bitrate_estimator/aimd_rate_control.h" 25 #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" 26 #include "rtc_base/rate_statistics.h" 27 #include "rtc_base/synchronization/mutex.h" 28 #include "rtc_base/thread_annotations.h" 29 30 namespace webrtc { 31 32 class Clock; 33 struct RTPHeader; 34 35 class RemoteBitrateEstimatorSingleStream : public RemoteBitrateEstimator { 36 public: 37 RemoteBitrateEstimatorSingleStream(RemoteBitrateObserver* observer, 38 Clock* clock); 39 40 RemoteBitrateEstimatorSingleStream() = delete; 41 RemoteBitrateEstimatorSingleStream( 42 const RemoteBitrateEstimatorSingleStream&) = delete; 43 RemoteBitrateEstimatorSingleStream& operator=( 44 const RemoteBitrateEstimatorSingleStream&) = delete; 45 46 ~RemoteBitrateEstimatorSingleStream() override; 47 48 void IncomingPacket(int64_t arrival_time_ms, 49 size_t payload_size, 50 const RTPHeader& header) override; 51 TimeDelta Process() override; 52 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; 53 void RemoveStream(uint32_t ssrc) override; 54 DataRate LatestEstimate() const override; 55 56 private: 57 struct Detector; 58 59 typedef std::map<uint32_t, Detector*> SsrcOveruseEstimatorMap; 60 61 // Triggers a new estimate calculation. 62 void UpdateEstimate(int64_t time_now) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); 63 64 void GetSsrcs(std::vector<uint32_t>* ssrcs) const 65 RTC_SHARED_LOCKS_REQUIRED(mutex_); 66 67 Clock* const clock_; 68 const FieldTrialBasedConfig field_trials_; 69 SsrcOveruseEstimatorMap overuse_detectors_ RTC_GUARDED_BY(mutex_); 70 RateStatistics incoming_bitrate_ RTC_GUARDED_BY(mutex_); 71 uint32_t last_valid_incoming_bitrate_ RTC_GUARDED_BY(mutex_); 72 AimdRateControl remote_rate_ RTC_GUARDED_BY(mutex_); 73 RemoteBitrateObserver* const observer_ RTC_GUARDED_BY(mutex_); 74 mutable Mutex mutex_; 75 int64_t last_process_time_; 76 int64_t process_interval_ms_ RTC_GUARDED_BY(mutex_); 77 bool uma_recorded_; 78 }; 79 80 } // namespace webrtc 81 82 #endif // MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_SINGLE_STREAM_H_ 83