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_BANDWIDTH_ESTIMATOR_H_ |
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_ABS_SEN D_TIME_H_ | 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BANDWIDTH_ESTIMATOR_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 { |
danilchap
2016/06/03 16:25:29
it is easiser to follow code when class name match
philipel
2016/06/08 11:46:38
Renamed files to delay_based_bwe.cc/h.
| |
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; |
81 // This class relies on Process() being called periodically (at least once | 45 // This class relies on Process() being called periodically (at least once |
82 // every other second) for streams to be timed out properly. Therefore it | 46 // 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 | 47 // shouldn't be detached from the ProcessThread except if it's about to be |
84 // deleted. | 48 // deleted. |
85 void Process() override; | 49 void Process() override; |
86 int64_t TimeUntilNextProcess() override; | 50 int64_t TimeUntilNextProcess() override; |
87 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; | 51 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
88 void RemoveStream(uint32_t ssrc) override; | 52 void RemoveStream(uint32_t ssrc) override; |
89 bool LatestEstimate(std::vector<uint32_t>* ssrcs, | 53 bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
90 uint32_t* bitrate_bps) const override; | 54 uint32_t* bitrate_bps) const override; |
91 void SetMinBitrate(int min_bitrate_bps) override; | 55 void SetMinBitrate(int min_bitrate_bps) override; |
92 | 56 |
93 private: | 57 private: |
58 struct Probe { | |
59 Probe(int64_t send_time_ms, | |
60 int64_t recv_time_ms, | |
61 size_t payload_size, | |
62 int probe_cluster_id) | |
63 : send_time_ms(send_time_ms), | |
64 recv_time_ms(recv_time_ms), | |
65 payload_size(payload_size), | |
66 probe_cluster_id(probe_cluster_id) {} | |
67 int64_t send_time_ms; | |
68 int64_t recv_time_ms; | |
69 size_t payload_size; | |
70 int probe_cluster_id; | |
danilchap
2016/06/03 16:25:29
this code (specially this struct) already knows it
philipel
2016/06/08 11:46:38
Done.
| |
71 }; | |
72 | |
73 struct Cluster { | |
danilchap
2016/06/03 16:25:28
Probe can't be easily forward-declared, but Cluste
philipel
2016/06/08 11:46:38
I would keep them grouped rather than to have one
| |
74 Cluster() | |
75 : send_mean_ms(0.0f), | |
76 recv_mean_ms(0.0f), | |
77 mean_size(0), | |
78 count(0), | |
79 num_above_min_delta(0) {} | |
80 | |
81 int GetSendBitrateBps() const { | |
82 RTC_CHECK_GT(send_mean_ms, 0.0f); | |
83 return mean_size * 8 * 1000 / send_mean_ms; | |
84 } | |
85 | |
86 int GetRecvBitrateBps() const { | |
87 RTC_CHECK_GT(recv_mean_ms, 0.0f); | |
88 return mean_size * 8 * 1000 / recv_mean_ms; | |
89 } | |
90 | |
91 float send_mean_ms; | |
92 float recv_mean_ms; | |
93 // TODO(holmer): Add some variance metric as well? | |
94 size_t mean_size; | |
95 int count; | |
96 int num_above_min_delta; | |
97 }; | |
98 | |
94 typedef std::map<uint32_t, int64_t> Ssrcs; | 99 typedef std::map<uint32_t, int64_t> Ssrcs; |
95 enum class ProbeResult { kBitrateUpdated, kNoUpdate }; | 100 enum class ProbeResult { kBitrateUpdated, kNoUpdate }; |
96 | 101 |
97 static bool IsWithinClusterBounds(int send_delta_ms, | |
98 const Cluster& cluster_aggregate); | |
99 | |
100 static void AddCluster(std::list<Cluster>* clusters, Cluster* cluster); | 102 static void AddCluster(std::list<Cluster>* clusters, Cluster* cluster); |
101 | 103 |
102 void IncomingPacketInfo(int64_t arrival_time_ms, | 104 void IncomingPacketInfo(int64_t arrival_time_ms, |
103 uint32_t send_time_24bits, | 105 uint32_t send_time_24bits, |
104 size_t payload_size, | 106 size_t payload_size, |
105 uint32_t ssrc, | 107 uint32_t ssrc, |
106 bool was_paced); | 108 bool was_paced, |
109 int probe_cluster_id); | |
107 | 110 |
108 void ComputeClusters(std::list<Cluster>* clusters) const; | 111 void ComputeClusters(std::list<Cluster>* clusters) const; |
109 | 112 |
110 std::list<Cluster>::const_iterator FindBestProbe( | 113 std::list<Cluster>::const_iterator FindBestProbe( |
111 const std::list<Cluster>& clusters) const; | 114 const std::list<Cluster>& clusters) const; |
112 | 115 |
113 // Returns true if a probe which changed the estimate was detected. | 116 // Returns true if a probe which changed the estimate was detected. |
114 ProbeResult ProcessClusters(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(&crit_); | 117 ProbeResult ProcessClusters(int64_t now_ms) EXCLUSIVE_LOCKS_REQUIRED(&crit_); |
115 | 118 |
116 bool IsBitrateImproving(int probe_bitrate_bps) const | 119 bool IsBitrateImproving(int probe_bitrate_bps) const |
(...skipping 11 matching lines...) Expand all Loading... | |
128 std::vector<int64_t> recent_update_time_ms_; | 131 std::vector<int64_t> recent_update_time_ms_; |
129 std::list<Probe> probes_; | 132 std::list<Probe> probes_; |
130 size_t total_probes_received_; | 133 size_t total_probes_received_; |
131 int64_t first_packet_time_ms_; | 134 int64_t first_packet_time_ms_; |
132 int64_t last_update_ms_; | 135 int64_t last_update_ms_; |
133 | 136 |
134 rtc::CriticalSection crit_; | 137 rtc::CriticalSection crit_; |
135 Ssrcs ssrcs_ GUARDED_BY(&crit_); | 138 Ssrcs ssrcs_ GUARDED_BY(&crit_); |
136 AimdRateControl remote_rate_ GUARDED_BY(&crit_); | 139 AimdRateControl remote_rate_ GUARDED_BY(&crit_); |
137 | 140 |
138 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RemoteBitrateEstimatorAbsSendTime); | 141 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
139 }; | 142 }; |
140 | 143 |
141 } // namespace webrtc | 144 } // namespace webrtc |
142 | 145 |
143 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_ABS_ SEND_TIME_H_ | 146 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BANDWIDTH_ESTIMATOR_ H_ |
OLD | NEW |