| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_ABS_SEN
D_TIME_H_ | 11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| 12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_ABS_SEN
D_TIME_H_ | 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| 13 | 13 |
| 14 #include <list> | 14 #include <list> |
| 15 #include <map> | 15 #include <map> |
| 16 #include <memory> | 16 #include <memory> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/constructormagic.h" | 20 #include "webrtc/base/constructormagic.h" |
| 21 #include "webrtc/base/criticalsection.h" | 21 #include "webrtc/base/criticalsection.h" |
| 22 #include "webrtc/base/rate_statistics.h" | 22 #include "webrtc/base/rate_statistics.h" |
| 23 #include "webrtc/base/thread_checker.h" | 23 #include "webrtc/base/thread_checker.h" |
| 24 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" | 24 #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
| 25 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 25 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
| 26 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
| 27 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" | 27 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
| 28 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" | 28 #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
| 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 struct Probe { | 33 class DelayBasedBwe : public RemoteBitrateEstimator { |
| 34 Probe(int64_t send_time_ms, int64_t recv_time_ms, size_t payload_size) | |
| 35 : send_time_ms(send_time_ms), | |
| 36 recv_time_ms(recv_time_ms), | |
| 37 payload_size(payload_size) {} | |
| 38 int64_t send_time_ms; | |
| 39 int64_t recv_time_ms; | |
| 40 size_t payload_size; | |
| 41 }; | |
| 42 | |
| 43 struct Cluster { | |
| 44 Cluster() | |
| 45 : send_mean_ms(0.0f), | |
| 46 recv_mean_ms(0.0f), | |
| 47 mean_size(0), | |
| 48 count(0), | |
| 49 num_above_min_delta(0) {} | |
| 50 | |
| 51 int GetSendBitrateBps() const { | |
| 52 RTC_CHECK_GT(send_mean_ms, 0.0f); | |
| 53 return mean_size * 8 * 1000 / send_mean_ms; | |
| 54 } | |
| 55 | |
| 56 int GetRecvBitrateBps() const { | |
| 57 RTC_CHECK_GT(recv_mean_ms, 0.0f); | |
| 58 return mean_size * 8 * 1000 / recv_mean_ms; | |
| 59 } | |
| 60 | |
| 61 float send_mean_ms; | |
| 62 float recv_mean_ms; | |
| 63 // TODO(holmer): Add some variance metric as well? | |
| 64 size_t mean_size; | |
| 65 int count; | |
| 66 int num_above_min_delta; | |
| 67 }; | |
| 68 | |
| 69 class RemoteBitrateEstimatorAbsSendTime : public RemoteBitrateEstimator { | |
| 70 public: | 34 public: |
| 71 explicit RemoteBitrateEstimatorAbsSendTime(RemoteBitrateObserver* observer); | 35 explicit DelayBasedBwe(RemoteBitrateObserver* observer); |
| 72 virtual ~RemoteBitrateEstimatorAbsSendTime() {} | 36 virtual ~DelayBasedBwe() {} |
| 73 | 37 |
| 74 void IncomingPacketFeedbackVector( | 38 void IncomingPacketFeedbackVector( |
| 75 const std::vector<PacketInfo>& packet_feedback_vector) override; | 39 const std::vector<PacketInfo>& packet_feedback_vector) override; |
| 76 | 40 |
| 77 void IncomingPacket(int64_t arrival_time_ms, | 41 void IncomingPacket(int64_t arrival_time_ms, |
| 78 size_t payload_size, | 42 size_t payload_size, |
| 79 const RTPHeader& header, | 43 const RTPHeader& header, |
| 80 bool was_paced) override; | 44 bool was_paced) override; |
| 45 |
| 46 void IncomingPacket(int64_t arrival_time_ms, |
| 47 size_t payload_size, |
| 48 const RTPHeader& header, |
| 49 bool was_paced, |
| 50 int probe_cluster_id); |
| 51 |
| 81 // This class relies on Process() being called periodically (at least once | 52 // This class relies on Process() being called periodically (at least once |
| 82 // every other second) for streams to be timed out properly. Therefore it | 53 // every other second) for streams to be timed out properly. Therefore it |
| 83 // shouldn't be detached from the ProcessThread except if it's about to be | 54 // shouldn't be detached from the ProcessThread except if it's about to be |
| 84 // deleted. | 55 // deleted. |
| 85 void Process() override; | 56 void Process() override; |
| 86 int64_t TimeUntilNextProcess() override; | 57 int64_t TimeUntilNextProcess() override; |
| 87 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; | 58 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 88 void RemoveStream(uint32_t ssrc) override; | 59 void RemoveStream(uint32_t ssrc) override; |
| 89 bool LatestEstimate(std::vector<uint32_t>* ssrcs, | 60 bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 90 uint32_t* bitrate_bps) const override; | 61 uint32_t* bitrate_bps) const override; |
| 91 void SetMinBitrate(int min_bitrate_bps) override; | 62 void SetMinBitrate(int min_bitrate_bps) override; |
| 92 | 63 |
| 93 private: | 64 private: |
| 65 struct Probe { |
| 66 Probe(int64_t send_time_ms, |
| 67 int64_t recv_time_ms, |
| 68 size_t payload_size, |
| 69 int cluster_id) |
| 70 : send_time_ms(send_time_ms), |
| 71 recv_time_ms(recv_time_ms), |
| 72 payload_size(payload_size), |
| 73 cluster_id(cluster_id) {} |
| 74 int64_t send_time_ms; |
| 75 int64_t recv_time_ms; |
| 76 size_t payload_size; |
| 77 int cluster_id; |
| 78 }; |
| 79 |
| 80 struct Cluster { |
| 81 Cluster() |
| 82 : send_mean_ms(0.0f), |
| 83 recv_mean_ms(0.0f), |
| 84 mean_size(0), |
| 85 count(0), |
| 86 num_above_min_delta(0) {} |
| 87 |
| 88 int GetSendBitrateBps() const { |
| 89 RTC_CHECK_GT(send_mean_ms, 0.0f); |
| 90 return mean_size * 8 * 1000 / send_mean_ms; |
| 91 } |
| 92 |
| 93 int GetRecvBitrateBps() const { |
| 94 RTC_CHECK_GT(recv_mean_ms, 0.0f); |
| 95 return mean_size * 8 * 1000 / recv_mean_ms; |
| 96 } |
| 97 |
| 98 float send_mean_ms; |
| 99 float recv_mean_ms; |
| 100 // TODO(holmer): Add some variance metric as well? |
| 101 size_t mean_size; |
| 102 int count; |
| 103 int num_above_min_delta; |
| 104 }; |
| 105 |
| 94 typedef std::map<uint32_t, int64_t> Ssrcs; | 106 typedef std::map<uint32_t, int64_t> Ssrcs; |
| 95 enum class ProbeResult { kBitrateUpdated, kNoUpdate }; | 107 enum class ProbeResult { kBitrateUpdated, kNoUpdate }; |
| 96 | 108 |
| 97 static bool IsWithinClusterBounds(int send_delta_ms, | |
| 98 const Cluster& cluster_aggregate); | |
| 99 | |
| 100 static void AddCluster(std::list<Cluster>* clusters, Cluster* cluster); | 109 static void AddCluster(std::list<Cluster>* clusters, Cluster* cluster); |
| 101 | 110 |
| 102 void IncomingPacketInfo(int64_t arrival_time_ms, | 111 void IncomingPacketInfo(int64_t arrival_time_ms, |
| 103 uint32_t send_time_24bits, | 112 uint32_t send_time_24bits, |
| 104 size_t payload_size, | 113 size_t payload_size, |
| 105 uint32_t ssrc, | 114 uint32_t ssrc, |
| 106 bool was_paced); | 115 bool was_paced, |
| 116 int probe_cluster_id); |
| 107 | 117 |
| 108 void ComputeClusters(std::list<Cluster>* clusters) const; | 118 void ComputeClusters(std::list<Cluster>* clusters) const; |
| 109 | 119 |
| 110 std::list<Cluster>::const_iterator FindBestProbe( | 120 std::list<Cluster>::const_iterator FindBestProbe( |
| 111 const std::list<Cluster>& clusters) const; | 121 const std::list<Cluster>& clusters) const; |
| 112 | 122 |
| 113 // Returns true if a probe which changed the estimate was detected. | 123 // Returns true if a probe which changed the estimate was detected. |
| 114 ProbeResult ProcessClusters(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(&crit_); | 124 ProbeResult ProcessClusters(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(&crit_); |
| 115 | 125 |
| 116 bool IsBitrateImproving(int probe_bitrate_bps) const | 126 bool IsBitrateImproving(int probe_bitrate_bps) const |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 std::vector<int64_t> recent_update_time_ms_; | 138 std::vector<int64_t> recent_update_time_ms_; |
| 129 std::list<Probe> probes_; | 139 std::list<Probe> probes_; |
| 130 size_t total_probes_received_; | 140 size_t total_probes_received_; |
| 131 int64_t first_packet_time_ms_; | 141 int64_t first_packet_time_ms_; |
| 132 int64_t last_update_ms_; | 142 int64_t last_update_ms_; |
| 133 | 143 |
| 134 rtc::CriticalSection crit_; | 144 rtc::CriticalSection crit_; |
| 135 Ssrcs ssrcs_ GUARDED_BY(&crit_); | 145 Ssrcs ssrcs_ GUARDED_BY(&crit_); |
| 136 AimdRateControl remote_rate_ GUARDED_BY(&crit_); | 146 AimdRateControl remote_rate_ GUARDED_BY(&crit_); |
| 137 | 147 |
| 138 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorAbsSendTime); | 148 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
| 139 }; | 149 }; |
| 140 | 150 |
| 141 } // namespace webrtc | 151 } // namespace webrtc |
| 142 | 152 |
| 143 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_ABS_
SEND_TIME_H_ | 153 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| OLD | NEW |