OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 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 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s
end_time.h" | 11 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
12 | 12 |
13 #include <math.h> | 13 #include <math.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
19 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/thread_annotations.h" | 20 #include "webrtc/base/thread_annotations.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat
or.h" |
23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
24 #include "webrtc/typedefs.h" | 24 #include "webrtc/typedefs.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace { |
27 | |
28 enum { | 27 enum { |
29 kTimestampGroupLengthMs = 5, | 28 kTimestampGroupLengthMs = 5, |
30 kAbsSendTimeFraction = 18, | 29 kAbsSendTimeFraction = 18, |
31 kAbsSendTimeInterArrivalUpshift = 8, | 30 kAbsSendTimeInterArrivalUpshift = 8, |
32 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, | 31 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, |
33 kInitialProbingIntervalMs = 2000, | 32 kInitialProbingIntervalMs = 2000, |
34 kMinClusterSize = 4, | 33 kMinClusterSize = 4, |
35 kMaxProbePackets = 15, | 34 kMaxProbePackets = 15, |
36 kExpectedNumberOfProbes = 3 | 35 kExpectedNumberOfProbes = 3 |
37 }; | 36 }; |
38 | 37 |
39 static const double kTimestampToMs = 1000.0 / | 38 static const double kTimestampToMs = |
40 static_cast<double>(1 << kInterArrivalShift); | 39 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
41 | 40 |
42 template<typename K, typename V> | 41 template <typename K, typename V> |
43 std::vector<K> Keys(const std::map<K, V>& map) { | 42 std::vector<K> Keys(const std::map<K, V>& map) { |
44 std::vector<K> keys; | 43 std::vector<K> keys; |
45 keys.reserve(map.size()); | 44 keys.reserve(map.size()); |
46 for (typename std::map<K, V>::const_iterator it = map.begin(); | 45 for (typename std::map<K, V>::const_iterator it = map.begin(); |
47 it != map.end(); ++it) { | 46 it != map.end(); ++it) { |
48 keys.push_back(it->first); | 47 keys.push_back(it->first); |
49 } | 48 } |
50 return keys; | 49 return keys; |
51 } | 50 } |
52 | 51 |
53 uint32_t ConvertMsTo24Bits(int64_t time_ms) { | 52 uint32_t ConvertMsTo24Bits(int64_t time_ms) { |
54 uint32_t time_24_bits = | 53 uint32_t time_24_bits = |
55 static_cast<uint32_t>( | 54 static_cast<uint32_t>( |
56 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / | 55 ((static_cast<uint64_t>(time_ms) << kAbsSendTimeFraction) + 500) / |
57 1000) & | 56 1000) & |
58 0x00FFFFFF; | 57 0x00FFFFFF; |
59 return time_24_bits; | 58 return time_24_bits; |
60 } | 59 } |
| 60 } // namespace |
61 | 61 |
62 bool RemoteBitrateEstimatorAbsSendTime::IsWithinClusterBounds( | 62 namespace webrtc { |
63 int send_delta_ms, | |
64 const Cluster& cluster_aggregate) { | |
65 if (cluster_aggregate.count == 0) | |
66 return true; | |
67 float cluster_mean = cluster_aggregate.send_mean_ms / | |
68 static_cast<float>(cluster_aggregate.count); | |
69 return fabs(static_cast<float>(send_delta_ms) - cluster_mean) < 2.5f; | |
70 } | |
71 | 63 |
72 void RemoteBitrateEstimatorAbsSendTime::AddCluster( | 64 void DelayBasedBwe::AddCluster(std::list<Cluster>* clusters, Cluster* cluster) { |
73 std::list<Cluster>* clusters, | 65 cluster->send_mean_ms /= static_cast<float>(cluster->count); |
74 Cluster* cluster) { | 66 cluster->recv_mean_ms /= static_cast<float>(cluster->count); |
75 cluster->send_mean_ms /= static_cast<float>(cluster->count); | 67 cluster->mean_size /= cluster->count; |
76 cluster->recv_mean_ms /= static_cast<float>(cluster->count); | 68 clusters->push_back(*cluster); |
77 cluster->mean_size /= cluster->count; | |
78 clusters->push_back(*cluster); | |
79 } | |
80 | |
81 RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime( | |
82 RemoteBitrateObserver* observer) | |
83 : observer_(observer), | |
84 inter_arrival_(), | |
85 estimator_(), | |
86 detector_(OverUseDetectorOptions()), | |
87 incoming_bitrate_(kBitrateWindowMs, 8000), | |
88 incoming_bitrate_initialized_(false), | |
89 total_probes_received_(0), | |
90 first_packet_time_ms_(-1), | |
91 last_update_ms_(-1), | |
92 ssrcs_() { | |
93 RTC_DCHECK(observer_); | |
94 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | |
95 network_thread_.DetachFromThread(); | |
96 } | 69 } |
97 | 70 |
98 void RemoteBitrateEstimatorAbsSendTime::ComputeClusters( | 71 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer) |
99 std::list<Cluster>* clusters) const { | 72 : observer_(observer), |
| 73 inter_arrival_(), |
| 74 estimator_(), |
| 75 detector_(OverUseDetectorOptions()), |
| 76 incoming_bitrate_(kBitrateWindowMs, 8000), |
| 77 total_probes_received_(0), |
| 78 first_packet_time_ms_(-1), |
| 79 last_update_ms_(-1), |
| 80 ssrcs_() { |
| 81 RTC_DCHECK(observer_); |
| 82 // NOTE! The BitrateEstimatorTest relies on this EXACT log line. |
| 83 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; |
| 84 network_thread_.DetachFromThread(); |
| 85 } |
| 86 |
| 87 void DelayBasedBwe::ComputeClusters(std::list<Cluster>* clusters) const { |
100 Cluster current; | 88 Cluster current; |
101 int64_t prev_send_time = -1; | 89 int64_t prev_send_time = -1; |
102 int64_t prev_recv_time = -1; | 90 int64_t prev_recv_time = -1; |
| 91 int last_probe_cluster_id = -1; |
103 for (std::list<Probe>::const_iterator it = probes_.begin(); | 92 for (std::list<Probe>::const_iterator it = probes_.begin(); |
104 it != probes_.end(); | 93 it != probes_.end(); ++it) { |
105 ++it) { | 94 if (last_probe_cluster_id == -1) |
| 95 last_probe_cluster_id = it->cluster_id; |
106 if (prev_send_time >= 0) { | 96 if (prev_send_time >= 0) { |
107 int send_delta_ms = it->send_time_ms - prev_send_time; | 97 int send_delta_ms = it->send_time_ms - prev_send_time; |
108 int recv_delta_ms = it->recv_time_ms - prev_recv_time; | 98 int recv_delta_ms = it->recv_time_ms - prev_recv_time; |
109 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { | 99 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { |
110 ++current.num_above_min_delta; | 100 ++current.num_above_min_delta; |
111 } | 101 } |
112 if (!IsWithinClusterBounds(send_delta_ms, current)) { | 102 if (it->cluster_id != last_probe_cluster_id) { |
113 if (current.count >= kMinClusterSize) | 103 if (current.count >= kMinClusterSize) |
114 AddCluster(clusters, ¤t); | 104 AddCluster(clusters, ¤t); |
115 current = Cluster(); | 105 current = Cluster(); |
116 } | 106 } |
117 current.send_mean_ms += send_delta_ms; | 107 current.send_mean_ms += send_delta_ms; |
118 current.recv_mean_ms += recv_delta_ms; | 108 current.recv_mean_ms += recv_delta_ms; |
119 current.mean_size += it->payload_size; | 109 current.mean_size += it->payload_size; |
120 ++current.count; | 110 ++current.count; |
| 111 last_probe_cluster_id = it->cluster_id; |
121 } | 112 } |
122 prev_send_time = it->send_time_ms; | 113 prev_send_time = it->send_time_ms; |
123 prev_recv_time = it->recv_time_ms; | 114 prev_recv_time = it->recv_time_ms; |
124 } | 115 } |
125 if (current.count >= kMinClusterSize) | 116 if (current.count >= kMinClusterSize) |
126 AddCluster(clusters, ¤t); | 117 AddCluster(clusters, ¤t); |
127 } | 118 } |
128 | 119 |
129 std::list<Cluster>::const_iterator | 120 std::list<DelayBasedBwe::Cluster>::const_iterator DelayBasedBwe::FindBestProbe( |
130 RemoteBitrateEstimatorAbsSendTime::FindBestProbe( | |
131 const std::list<Cluster>& clusters) const { | 121 const std::list<Cluster>& clusters) const { |
132 int highest_probe_bitrate_bps = 0; | 122 int highest_probe_bitrate_bps = 0; |
133 std::list<Cluster>::const_iterator best_it = clusters.end(); | 123 std::list<Cluster>::const_iterator best_it = clusters.end(); |
134 for (std::list<Cluster>::const_iterator it = clusters.begin(); | 124 for (std::list<Cluster>::const_iterator it = clusters.begin(); |
135 it != clusters.end(); | 125 it != clusters.end(); ++it) { |
136 ++it) { | |
137 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) | 126 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) |
138 continue; | 127 continue; |
139 int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms; | 128 int send_bitrate_bps = it->mean_size * 8 * 1000 / it->send_mean_ms; |
140 int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms; | 129 int recv_bitrate_bps = it->mean_size * 8 * 1000 / it->recv_mean_ms; |
141 if (it->num_above_min_delta > it->count / 2 && | 130 if (it->num_above_min_delta > it->count / 2 && |
142 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && | 131 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && |
143 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { | 132 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { |
144 int probe_bitrate_bps = | 133 int probe_bitrate_bps = |
145 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); | 134 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); |
146 if (probe_bitrate_bps > highest_probe_bitrate_bps) { | 135 if (probe_bitrate_bps > highest_probe_bitrate_bps) { |
147 highest_probe_bitrate_bps = probe_bitrate_bps; | 136 highest_probe_bitrate_bps = probe_bitrate_bps; |
148 best_it = it; | 137 best_it = it; |
149 } | 138 } |
150 } else { | 139 } else { |
151 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps | 140 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps |
152 << " bps, received at " << recv_bitrate_bps | 141 << " bps, received at " << recv_bitrate_bps |
153 << " bps. Mean send delta: " << it->send_mean_ms | 142 << " bps. Mean send delta: " << it->send_mean_ms |
154 << " ms, mean recv delta: " << it->recv_mean_ms | 143 << " ms, mean recv delta: " << it->recv_mean_ms |
155 << " ms, num probes: " << it->count; | 144 << " ms, num probes: " << it->count; |
156 break; | 145 break; |
157 } | 146 } |
158 } | 147 } |
159 return best_it; | 148 return best_it; |
160 } | 149 } |
161 | 150 |
162 RemoteBitrateEstimatorAbsSendTime::ProbeResult | 151 DelayBasedBwe::ProbeResult DelayBasedBwe::ProcessClusters(int64_t now_ms) { |
163 RemoteBitrateEstimatorAbsSendTime::ProcessClusters(int64_t now_ms) { | |
164 std::list<Cluster> clusters; | 152 std::list<Cluster> clusters; |
165 ComputeClusters(&clusters); | 153 ComputeClusters(&clusters); |
166 if (clusters.empty()) { | 154 if (clusters.empty()) { |
167 // If we reach the max number of probe packets and still have no clusters, | 155 // If we reach the max number of probe packets and still have no clusters, |
168 // we will remove the oldest one. | 156 // we will remove the oldest one. |
169 if (probes_.size() >= kMaxProbePackets) | 157 if (probes_.size() >= kMaxProbePackets) |
170 probes_.pop_front(); | 158 probes_.pop_front(); |
171 return ProbeResult::kNoUpdate; | 159 return ProbeResult::kNoUpdate; |
172 } | 160 } |
173 | 161 |
(...skipping 15 matching lines...) Expand all Loading... |
189 } | 177 } |
190 } | 178 } |
191 | 179 |
192 // Not probing and received non-probe packet, or finished with current set | 180 // Not probing and received non-probe packet, or finished with current set |
193 // of probes. | 181 // of probes. |
194 if (clusters.size() >= kExpectedNumberOfProbes) | 182 if (clusters.size() >= kExpectedNumberOfProbes) |
195 probes_.clear(); | 183 probes_.clear(); |
196 return ProbeResult::kNoUpdate; | 184 return ProbeResult::kNoUpdate; |
197 } | 185 } |
198 | 186 |
199 bool RemoteBitrateEstimatorAbsSendTime::IsBitrateImproving( | 187 bool DelayBasedBwe::IsBitrateImproving(int new_bitrate_bps) const { |
200 int new_bitrate_bps) const { | |
201 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; | 188 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; |
202 bool bitrate_above_estimate = | 189 bool bitrate_above_estimate = |
203 remote_rate_.ValidEstimate() && | 190 remote_rate_.ValidEstimate() && |
204 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); | 191 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); |
205 return initial_probe || bitrate_above_estimate; | 192 return initial_probe || bitrate_above_estimate; |
206 } | 193 } |
207 | 194 |
208 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketFeedbackVector( | 195 void DelayBasedBwe::IncomingPacketFeedbackVector( |
209 const std::vector<PacketInfo>& packet_feedback_vector) { | 196 const std::vector<PacketInfo>& packet_feedback_vector) { |
210 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 197 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
211 for (const auto& packet_info : packet_feedback_vector) { | 198 for (const auto& packet_info : packet_feedback_vector) { |
212 IncomingPacketInfo(packet_info.arrival_time_ms, | 199 IncomingPacketInfo(packet_info.arrival_time_ms, |
213 ConvertMsTo24Bits(packet_info.send_time_ms), | 200 ConvertMsTo24Bits(packet_info.send_time_ms), |
214 packet_info.payload_size, 0, packet_info.was_paced); | 201 packet_info.payload_size, 0, packet_info.was_paced, |
| 202 packet_info.probe_cluster_id); |
215 } | 203 } |
216 } | 204 } |
217 | 205 |
218 void RemoteBitrateEstimatorAbsSendTime::IncomingPacket(int64_t arrival_time_ms, | 206 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms, |
219 size_t payload_size, | 207 size_t payload_size, |
220 const RTPHeader& header, | 208 const RTPHeader& header, |
221 bool was_paced) { | 209 bool was_paced) { |
222 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 210 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
223 if (!header.extension.hasAbsoluteSendTime) { | 211 if (!header.extension.hasAbsoluteSendTime) { |
224 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTimeImpl: Incoming packet " | 212 // NOTE! The BitrateEstimatorTest relies on this EXACT log line. |
| 213 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet " |
225 "is missing absolute send time extension!"; | 214 "is missing absolute send time extension!"; |
226 return; | 215 return; |
227 } | 216 } |
228 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, | 217 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, |
229 payload_size, header.ssrc, was_paced); | 218 payload_size, header.ssrc, was_paced, |
| 219 PacketInfo::kNotAProbe); |
230 } | 220 } |
231 | 221 |
232 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( | 222 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms, |
233 int64_t arrival_time_ms, | 223 size_t payload_size, |
234 uint32_t send_time_24bits, | 224 const RTPHeader& header, |
235 size_t payload_size, | 225 bool was_paced, |
236 uint32_t ssrc, | 226 int probe_cluster_id) { |
237 bool was_paced) { | 227 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 228 if (!header.extension.hasAbsoluteSendTime) { |
| 229 // NOTE! The BitrateEstimatorTest relies on this EXACT log line. |
| 230 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet " |
| 231 "is missing absolute send time extension!"; |
| 232 return; |
| 233 } |
| 234 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, |
| 235 payload_size, header.ssrc, was_paced, probe_cluster_id); |
| 236 } |
| 237 |
| 238 void DelayBasedBwe::IncomingPacketInfo(int64_t arrival_time_ms, |
| 239 uint32_t send_time_24bits, |
| 240 size_t payload_size, |
| 241 uint32_t ssrc, |
| 242 bool was_paced, |
| 243 int probe_cluster_id) { |
238 assert(send_time_24bits < (1ul << 24)); | 244 assert(send_time_24bits < (1ul << 24)); |
239 // Shift up send time to use the full 32 bits that inter_arrival works with, | 245 // Shift up send time to use the full 32 bits that inter_arrival works with, |
240 // so wrapping works properly. | 246 // so wrapping works properly. |
241 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; | 247 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
242 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; | 248 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; |
243 | 249 |
244 int64_t now_ms = arrival_time_ms; | 250 int64_t now_ms = arrival_time_ms; |
245 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from | 251 // TODO(holmer): SSRCs are only needed for REMB, should be broken out from |
246 // here. | 252 // here. |
247 | |
248 // Check if incoming bitrate estimate is valid, and if it needs to be reset. | |
249 rtc::Optional<uint32_t> incoming_bitrate = incoming_bitrate_.Rate(now_ms); | |
250 if (incoming_bitrate) { | |
251 incoming_bitrate_initialized_ = true; | |
252 } else if (incoming_bitrate_initialized_) { | |
253 // Incoming bitrate had a previous valid value, but now not enough data | |
254 // point are left within the current window. Reset incoming bitrate | |
255 // estimator so that the window size will only contain new data points. | |
256 incoming_bitrate_.Reset(); | |
257 incoming_bitrate_initialized_ = false; | |
258 } | |
259 incoming_bitrate_.Update(payload_size, now_ms); | 253 incoming_bitrate_.Update(payload_size, now_ms); |
260 | 254 |
261 if (first_packet_time_ms_ == -1) | 255 if (first_packet_time_ms_ == -1) |
262 first_packet_time_ms_ = arrival_time_ms; | 256 first_packet_time_ms_ = arrival_time_ms; |
263 | 257 |
264 uint32_t ts_delta = 0; | 258 uint32_t ts_delta = 0; |
265 int64_t t_delta = 0; | 259 int64_t t_delta = 0; |
266 int size_delta = 0; | 260 int size_delta = 0; |
267 // For now only try to detect probes while we don't have a valid estimate, and | 261 |
268 // make sure the packet was paced. We currently assume that only packets | |
269 // larger than 200 bytes are paced by the sender. | |
270 was_paced = was_paced && payload_size > PacedSender::kMinProbePacketSize; | |
271 bool update_estimate = false; | 262 bool update_estimate = false; |
272 uint32_t target_bitrate_bps = 0; | 263 uint32_t target_bitrate_bps = 0; |
273 std::vector<uint32_t> ssrcs; | 264 std::vector<uint32_t> ssrcs; |
274 { | 265 { |
275 rtc::CritScope lock(&crit_); | 266 rtc::CritScope lock(&crit_); |
276 | 267 |
277 TimeoutStreams(now_ms); | 268 TimeoutStreams(now_ms); |
278 RTC_DCHECK(inter_arrival_.get()); | 269 RTC_DCHECK(inter_arrival_.get()); |
279 RTC_DCHECK(estimator_.get()); | 270 RTC_DCHECK(estimator_.get()); |
280 ssrcs_[ssrc] = now_ms; | 271 ssrcs_[ssrc] = now_ms; |
281 | 272 |
282 if (was_paced && | 273 // For now only try to detect probes while we don't have a valid estimate, |
| 274 // and make sure the packet was paced. We currently assume that only packets |
| 275 // larger than 200 bytes are paced by the sender. |
| 276 if (probe_cluster_id != PacketInfo::kNotAProbe && |
| 277 payload_size > PacedSender::kMinProbePacketSize && |
283 (!remote_rate_.ValidEstimate() || | 278 (!remote_rate_.ValidEstimate() || |
284 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { | 279 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { |
285 // TODO(holmer): Use a map instead to get correct order? | 280 // TODO(holmer): Use a map instead to get correct order? |
286 if (total_probes_received_ < kMaxProbePackets) { | 281 if (total_probes_received_ < kMaxProbePackets) { |
287 int send_delta_ms = -1; | 282 int send_delta_ms = -1; |
288 int recv_delta_ms = -1; | 283 int recv_delta_ms = -1; |
289 if (!probes_.empty()) { | 284 if (!probes_.empty()) { |
290 send_delta_ms = send_time_ms - probes_.back().send_time_ms; | 285 send_delta_ms = send_time_ms - probes_.back().send_time_ms; |
291 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; | 286 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; |
292 } | 287 } |
293 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms | 288 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms |
294 << " ms, recv time=" << arrival_time_ms | 289 << " ms, recv time=" << arrival_time_ms |
295 << " ms, send delta=" << send_delta_ms | 290 << " ms, send delta=" << send_delta_ms |
296 << " ms, recv delta=" << recv_delta_ms << " ms."; | 291 << " ms, recv delta=" << recv_delta_ms << " ms."; |
297 } | 292 } |
298 probes_.push_back(Probe(send_time_ms, arrival_time_ms, payload_size)); | 293 probes_.push_back( |
| 294 Probe(send_time_ms, arrival_time_ms, payload_size, probe_cluster_id)); |
299 ++total_probes_received_; | 295 ++total_probes_received_; |
300 // Make sure that a probe which updated the bitrate immediately has an | 296 // Make sure that a probe which updated the bitrate immediately has an |
301 // effect by calling the OnReceiveBitrateChanged callback. | 297 // effect by calling the OnReceiveBitrateChanged callback. |
302 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) | 298 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) |
303 update_estimate = true; | 299 update_estimate = true; |
304 } | 300 } |
305 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, | 301 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, |
306 &ts_delta, &t_delta, &size_delta)) { | 302 &ts_delta, &t_delta, &size_delta)) { |
307 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 303 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
308 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); | 304 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); |
(...skipping 28 matching lines...) Expand all Loading... |
337 update_estimate = remote_rate_.ValidEstimate(); | 333 update_estimate = remote_rate_.ValidEstimate(); |
338 ssrcs = Keys(ssrcs_); | 334 ssrcs = Keys(ssrcs_); |
339 } | 335 } |
340 } | 336 } |
341 if (update_estimate) { | 337 if (update_estimate) { |
342 last_update_ms_ = now_ms; | 338 last_update_ms_ = now_ms; |
343 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); | 339 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); |
344 } | 340 } |
345 } | 341 } |
346 | 342 |
347 void RemoteBitrateEstimatorAbsSendTime::Process() {} | 343 void DelayBasedBwe::Process() {} |
348 | 344 |
349 int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess() { | 345 int64_t DelayBasedBwe::TimeUntilNextProcess() { |
350 const int64_t kDisabledModuleTime = 1000; | 346 const int64_t kDisabledModuleTime = 1000; |
351 return kDisabledModuleTime; | 347 return kDisabledModuleTime; |
352 } | 348 } |
353 | 349 |
354 void RemoteBitrateEstimatorAbsSendTime::TimeoutStreams(int64_t now_ms) { | 350 void DelayBasedBwe::TimeoutStreams(int64_t now_ms) { |
355 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { | 351 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { |
356 if ((now_ms - it->second) > kStreamTimeOutMs) { | 352 if ((now_ms - it->second) > kStreamTimeOutMs) { |
357 ssrcs_.erase(it++); | 353 ssrcs_.erase(it++); |
358 } else { | 354 } else { |
359 ++it; | 355 ++it; |
360 } | 356 } |
361 } | 357 } |
362 if (ssrcs_.empty()) { | 358 if (ssrcs_.empty()) { |
363 // We can't update the estimate if we don't have any active streams. | 359 // We can't update the estimate if we don't have any active streams. |
364 inter_arrival_.reset( | 360 inter_arrival_.reset( |
365 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 361 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
366 kTimestampToMs, true)); | 362 kTimestampToMs, true)); |
367 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | 363 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
368 // We deliberately don't reset the first_packet_time_ms_ here for now since | 364 // We deliberately don't reset the first_packet_time_ms_ here for now since |
369 // we only probe for bandwidth in the beginning of a call right now. | 365 // we only probe for bandwidth in the beginning of a call right now. |
370 } | 366 } |
371 } | 367 } |
372 | 368 |
373 void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avg_rtt_ms, | 369 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
374 int64_t max_rtt_ms) { | |
375 rtc::CritScope lock(&crit_); | 370 rtc::CritScope lock(&crit_); |
376 remote_rate_.SetRtt(avg_rtt_ms); | 371 remote_rate_.SetRtt(avg_rtt_ms); |
377 } | 372 } |
378 | 373 |
379 void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) { | 374 void DelayBasedBwe::RemoveStream(uint32_t ssrc) { |
380 rtc::CritScope lock(&crit_); | 375 rtc::CritScope lock(&crit_); |
381 ssrcs_.erase(ssrc); | 376 ssrcs_.erase(ssrc); |
382 } | 377 } |
383 | 378 |
384 bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate( | 379 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
385 std::vector<uint32_t>* ssrcs, | 380 uint32_t* bitrate_bps) const { |
386 uint32_t* bitrate_bps) const { | |
387 // Currently accessed from both the process thread (see | 381 // Currently accessed from both the process thread (see |
388 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 382 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
389 // Call::GetStats()). Should in the future only be accessed from a single | 383 // Call::GetStats()). Should in the future only be accessed from a single |
390 // thread. | 384 // thread. |
391 RTC_DCHECK(ssrcs); | 385 RTC_DCHECK(ssrcs); |
392 RTC_DCHECK(bitrate_bps); | 386 RTC_DCHECK(bitrate_bps); |
393 rtc::CritScope lock(&crit_); | 387 rtc::CritScope lock(&crit_); |
394 if (!remote_rate_.ValidEstimate()) { | 388 if (!remote_rate_.ValidEstimate()) { |
395 return false; | 389 return false; |
396 } | 390 } |
397 *ssrcs = Keys(ssrcs_); | 391 *ssrcs = Keys(ssrcs_); |
398 if (ssrcs_.empty()) { | 392 if (ssrcs_.empty()) { |
399 *bitrate_bps = 0; | 393 *bitrate_bps = 0; |
400 } else { | 394 } else { |
401 *bitrate_bps = remote_rate_.LatestEstimate(); | 395 *bitrate_bps = remote_rate_.LatestEstimate(); |
402 } | 396 } |
403 return true; | 397 return true; |
404 } | 398 } |
405 | 399 |
406 void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) { | 400 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
407 // Called from both the configuration thread and the network thread. Shouldn't | 401 // Called from both the configuration thread and the network thread. Shouldn't |
408 // be called from the network thread in the future. | 402 // be called from the network thread in the future. |
409 rtc::CritScope lock(&crit_); | 403 rtc::CritScope lock(&crit_); |
410 remote_rate_.SetMinBitrate(min_bitrate_bps); | 404 remote_rate_.SetMinBitrate(min_bitrate_bps); |
411 } | 405 } |
412 } // namespace webrtc | 406 } // namespace webrtc |
OLD | NEW |