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 total_probes_received_(0), | |
89 first_packet_time_ms_(-1), | |
90 last_update_ms_(-1), | |
91 ssrcs_() { | |
92 RTC_DCHECK(observer_); | |
93 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | |
94 network_thread_.DetachFromThread(); | |
95 } | 69 } |
96 | 70 |
97 void RemoteBitrateEstimatorAbsSendTime::ComputeClusters( | 71 DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer) |
98 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 // XXX(philipel): 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 { |
99 Cluster current; | 88 Cluster current; |
100 int64_t prev_send_time = -1; | 89 int64_t prev_send_time = -1; |
101 int64_t prev_recv_time = -1; | 90 int64_t prev_recv_time = -1; |
| 91 int last_probe_cluster_id = -1; |
102 for (std::list<Probe>::const_iterator it = probes_.begin(); | 92 for (std::list<Probe>::const_iterator it = probes_.begin(); |
103 it != probes_.end(); | 93 it != probes_.end(); ++it) { |
104 ++it) { | 94 if (last_probe_cluster_id == -1) |
| 95 last_probe_cluster_id = it->cluster_id; |
105 if (prev_send_time >= 0) { | 96 if (prev_send_time >= 0) { |
106 int send_delta_ms = it->send_time_ms - prev_send_time; | 97 int send_delta_ms = it->send_time_ms - prev_send_time; |
107 int recv_delta_ms = it->recv_time_ms - prev_recv_time; | 98 int recv_delta_ms = it->recv_time_ms - prev_recv_time; |
108 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { | 99 if (send_delta_ms >= 1 && recv_delta_ms >= 1) { |
109 ++current.num_above_min_delta; | 100 ++current.num_above_min_delta; |
110 } | 101 } |
111 if (!IsWithinClusterBounds(send_delta_ms, current)) { | 102 if (it->cluster_id != last_probe_cluster_id) { |
112 if (current.count >= kMinClusterSize) | 103 if (current.count >= kMinClusterSize) |
113 AddCluster(clusters, ¤t); | 104 AddCluster(clusters, ¤t); |
114 current = Cluster(); | 105 current = Cluster(); |
115 } | 106 } |
116 current.send_mean_ms += send_delta_ms; | 107 current.send_mean_ms += send_delta_ms; |
117 current.recv_mean_ms += recv_delta_ms; | 108 current.recv_mean_ms += recv_delta_ms; |
118 current.mean_size += it->payload_size; | 109 current.mean_size += it->payload_size; |
119 ++current.count; | 110 ++current.count; |
| 111 last_probe_cluster_id = it->cluster_id; |
120 } | 112 } |
121 prev_send_time = it->send_time_ms; | 113 prev_send_time = it->send_time_ms; |
122 prev_recv_time = it->recv_time_ms; | 114 prev_recv_time = it->recv_time_ms; |
123 } | 115 } |
124 if (current.count >= kMinClusterSize) | 116 if (current.count >= kMinClusterSize) |
125 AddCluster(clusters, ¤t); | 117 AddCluster(clusters, ¤t); |
126 } | 118 } |
127 | 119 |
128 std::list<Cluster>::const_iterator | 120 std::list<DelayBasedBwe::Cluster>::const_iterator DelayBasedBwe::FindBestProbe( |
129 RemoteBitrateEstimatorAbsSendTime::FindBestProbe( | |
130 const std::list<Cluster>& clusters) const { | 121 const std::list<Cluster>& clusters) const { |
131 int highest_probe_bitrate_bps = 0; | 122 int highest_probe_bitrate_bps = 0; |
132 std::list<Cluster>::const_iterator best_it = clusters.end(); | 123 std::list<Cluster>::const_iterator best_it = clusters.end(); |
133 for (std::list<Cluster>::const_iterator it = clusters.begin(); | 124 for (std::list<Cluster>::const_iterator it = clusters.begin(); |
134 it != clusters.end(); | 125 it != clusters.end(); ++it) { |
135 ++it) { | |
136 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) | 126 if (it->send_mean_ms == 0 || it->recv_mean_ms == 0) |
137 continue; | 127 continue; |
138 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; |
139 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; |
140 if (it->num_above_min_delta > it->count / 2 && | 130 if (it->num_above_min_delta > it->count / 2 && |
141 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && | 131 (it->recv_mean_ms - it->send_mean_ms <= 2.0f && |
142 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { | 132 it->send_mean_ms - it->recv_mean_ms <= 5.0f)) { |
143 int probe_bitrate_bps = | 133 int probe_bitrate_bps = |
144 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); | 134 std::min(it->GetSendBitrateBps(), it->GetRecvBitrateBps()); |
145 if (probe_bitrate_bps > highest_probe_bitrate_bps) { | 135 if (probe_bitrate_bps > highest_probe_bitrate_bps) { |
146 highest_probe_bitrate_bps = probe_bitrate_bps; | 136 highest_probe_bitrate_bps = probe_bitrate_bps; |
147 best_it = it; | 137 best_it = it; |
148 } | 138 } |
149 } else { | 139 } else { |
150 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps | 140 LOG(LS_INFO) << "Probe failed, sent at " << send_bitrate_bps |
151 << " bps, received at " << recv_bitrate_bps | 141 << " bps, received at " << recv_bitrate_bps |
152 << " bps. Mean send delta: " << it->send_mean_ms | 142 << " bps. Mean send delta: " << it->send_mean_ms |
153 << " ms, mean recv delta: " << it->recv_mean_ms | 143 << " ms, mean recv delta: " << it->recv_mean_ms |
154 << " ms, num probes: " << it->count; | 144 << " ms, num probes: " << it->count; |
155 break; | 145 break; |
156 } | 146 } |
157 } | 147 } |
158 return best_it; | 148 return best_it; |
159 } | 149 } |
160 | 150 |
161 RemoteBitrateEstimatorAbsSendTime::ProbeResult | 151 DelayBasedBwe::ProbeResult DelayBasedBwe::ProcessClusters(int64_t now_ms) { |
162 RemoteBitrateEstimatorAbsSendTime::ProcessClusters(int64_t now_ms) { | |
163 std::list<Cluster> clusters; | 152 std::list<Cluster> clusters; |
164 ComputeClusters(&clusters); | 153 ComputeClusters(&clusters); |
165 if (clusters.empty()) { | 154 if (clusters.empty()) { |
166 // 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, |
167 // we will remove the oldest one. | 156 // we will remove the oldest one. |
168 if (probes_.size() >= kMaxProbePackets) | 157 if (probes_.size() >= kMaxProbePackets) |
169 probes_.pop_front(); | 158 probes_.pop_front(); |
170 return ProbeResult::kNoUpdate; | 159 return ProbeResult::kNoUpdate; |
171 } | 160 } |
172 | 161 |
(...skipping 15 matching lines...) Expand all Loading... |
188 } | 177 } |
189 } | 178 } |
190 | 179 |
191 // 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 |
192 // of probes. | 181 // of probes. |
193 if (clusters.size() >= kExpectedNumberOfProbes) | 182 if (clusters.size() >= kExpectedNumberOfProbes) |
194 probes_.clear(); | 183 probes_.clear(); |
195 return ProbeResult::kNoUpdate; | 184 return ProbeResult::kNoUpdate; |
196 } | 185 } |
197 | 186 |
198 bool RemoteBitrateEstimatorAbsSendTime::IsBitrateImproving( | 187 bool DelayBasedBwe::IsBitrateImproving(int new_bitrate_bps) const { |
199 int new_bitrate_bps) const { | |
200 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; | 188 bool initial_probe = !remote_rate_.ValidEstimate() && new_bitrate_bps > 0; |
201 bool bitrate_above_estimate = | 189 bool bitrate_above_estimate = |
202 remote_rate_.ValidEstimate() && | 190 remote_rate_.ValidEstimate() && |
203 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); | 191 new_bitrate_bps > static_cast<int>(remote_rate_.LatestEstimate()); |
204 return initial_probe || bitrate_above_estimate; | 192 return initial_probe || bitrate_above_estimate; |
205 } | 193 } |
206 | 194 |
207 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketFeedbackVector( | 195 void DelayBasedBwe::IncomingPacketFeedbackVector( |
208 const std::vector<PacketInfo>& packet_feedback_vector) { | 196 const std::vector<PacketInfo>& packet_feedback_vector) { |
209 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 197 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
210 for (const auto& packet_info : packet_feedback_vector) { | 198 for (const auto& packet_info : packet_feedback_vector) { |
211 IncomingPacketInfo(packet_info.arrival_time_ms, | 199 IncomingPacketInfo(packet_info.arrival_time_ms, |
212 ConvertMsTo24Bits(packet_info.send_time_ms), | 200 ConvertMsTo24Bits(packet_info.send_time_ms), |
213 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); |
214 } | 203 } |
215 } | 204 } |
216 | 205 |
217 void RemoteBitrateEstimatorAbsSendTime::IncomingPacket(int64_t arrival_time_ms, | 206 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms, |
218 size_t payload_size, | 207 size_t payload_size, |
219 const RTPHeader& header, | 208 const RTPHeader& header, |
220 bool was_paced) { | 209 bool was_paced) { |
221 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 210 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
222 if (!header.extension.hasAbsoluteSendTime) { | 211 if (!header.extension.hasAbsoluteSendTime) { |
223 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTimeImpl: Incoming packet " | 212 // XXX(philipel): The BitrateEstimatorTest relies on this EXACT log line. |
| 213 LOG(LS_WARNING) << "RemoteBitrateEstimatorAbsSendTime: Incoming packet " |
224 "is missing absolute send time extension!"; | 214 "is missing absolute send time extension!"; |
225 return; | 215 return; |
226 } | 216 } |
227 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, | 217 IncomingPacketInfo(arrival_time_ms, header.extension.absoluteSendTime, |
228 payload_size, header.ssrc, was_paced); | 218 payload_size, header.ssrc, was_paced, |
| 219 PacketInfo::kNotAProbe); |
229 } | 220 } |
230 | 221 |
231 void RemoteBitrateEstimatorAbsSendTime::IncomingPacketInfo( | 222 void DelayBasedBwe::IncomingPacket(int64_t arrival_time_ms, |
232 int64_t arrival_time_ms, | 223 size_t payload_size, |
233 uint32_t send_time_24bits, | 224 const RTPHeader& header, |
234 size_t payload_size, | 225 bool was_paced, |
235 uint32_t ssrc, | 226 int probe_cluster_id) { |
236 bool was_paced) { | 227 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 228 if (!header.extension.hasAbsoluteSendTime) { |
| 229 // XXX(philipel): 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) { |
237 assert(send_time_24bits < (1ul << 24)); | 244 assert(send_time_24bits < (1ul << 24)); |
238 // 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, |
239 // so wrapping works properly. | 246 // so wrapping works properly. |
240 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; | 247 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
241 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; | 248 int64_t send_time_ms = static_cast<int64_t>(timestamp) * kTimestampToMs; |
242 | 249 |
243 int64_t now_ms = arrival_time_ms; | 250 int64_t now_ms = arrival_time_ms; |
244 // 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 |
245 // here. | 252 // here. |
246 incoming_bitrate_.Update(payload_size, now_ms); | 253 incoming_bitrate_.Update(payload_size, now_ms); |
247 | 254 |
248 if (first_packet_time_ms_ == -1) | 255 if (first_packet_time_ms_ == -1) |
249 first_packet_time_ms_ = arrival_time_ms; | 256 first_packet_time_ms_ = arrival_time_ms; |
250 | 257 |
251 uint32_t ts_delta = 0; | 258 uint32_t ts_delta = 0; |
252 int64_t t_delta = 0; | 259 int64_t t_delta = 0; |
253 int size_delta = 0; | 260 int size_delta = 0; |
254 // For now only try to detect probes while we don't have a valid estimate, and | 261 |
255 // make sure the packet was paced. We currently assume that only packets | |
256 // larger than 200 bytes are paced by the sender. | |
257 was_paced = was_paced && payload_size > PacedSender::kMinProbePacketSize; | |
258 bool update_estimate = false; | 262 bool update_estimate = false; |
259 uint32_t target_bitrate_bps = 0; | 263 uint32_t target_bitrate_bps = 0; |
260 std::vector<uint32_t> ssrcs; | 264 std::vector<uint32_t> ssrcs; |
261 { | 265 { |
262 rtc::CritScope lock(&crit_); | 266 rtc::CritScope lock(&crit_); |
263 | 267 |
264 TimeoutStreams(now_ms); | 268 TimeoutStreams(now_ms); |
265 RTC_DCHECK(inter_arrival_.get()); | 269 RTC_DCHECK(inter_arrival_.get()); |
266 RTC_DCHECK(estimator_.get()); | 270 RTC_DCHECK(estimator_.get()); |
267 ssrcs_[ssrc] = now_ms; | 271 ssrcs_[ssrc] = now_ms; |
268 | 272 |
269 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 && |
270 (!remote_rate_.ValidEstimate() || | 278 (!remote_rate_.ValidEstimate() || |
271 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { | 279 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { |
272 // TODO(holmer): Use a map instead to get correct order? | 280 // TODO(holmer): Use a map instead to get correct order? |
273 if (total_probes_received_ < kMaxProbePackets) { | 281 if (total_probes_received_ < kMaxProbePackets) { |
274 int send_delta_ms = -1; | 282 int send_delta_ms = -1; |
275 int recv_delta_ms = -1; | 283 int recv_delta_ms = -1; |
276 if (!probes_.empty()) { | 284 if (!probes_.empty()) { |
277 send_delta_ms = send_time_ms - probes_.back().send_time_ms; | 285 send_delta_ms = send_time_ms - probes_.back().send_time_ms; |
278 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; | 286 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; |
279 } | 287 } |
280 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms | 288 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms |
281 << " ms, recv time=" << arrival_time_ms | 289 << " ms, recv time=" << arrival_time_ms |
282 << " ms, send delta=" << send_delta_ms | 290 << " ms, send delta=" << send_delta_ms |
283 << " ms, recv delta=" << recv_delta_ms << " ms."; | 291 << " ms, recv delta=" << recv_delta_ms << " ms."; |
284 } | 292 } |
285 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)); |
286 ++total_probes_received_; | 295 ++total_probes_received_; |
287 // 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 |
288 // effect by calling the OnReceiveBitrateChanged callback. | 297 // effect by calling the OnReceiveBitrateChanged callback. |
289 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) | 298 if (ProcessClusters(now_ms) == ProbeResult::kBitrateUpdated) |
290 update_estimate = true; | 299 update_estimate = true; |
291 } | 300 } |
292 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, | 301 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, |
293 &ts_delta, &t_delta, &size_delta)) { | 302 &ts_delta, &t_delta, &size_delta)) { |
294 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 303 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
295 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); | 304 estimator_->Update(t_delta, ts_delta_ms, size_delta, detector_.State()); |
(...skipping 26 matching lines...) Expand all Loading... |
322 update_estimate = remote_rate_.ValidEstimate(); | 331 update_estimate = remote_rate_.ValidEstimate(); |
323 ssrcs = Keys(ssrcs_); | 332 ssrcs = Keys(ssrcs_); |
324 } | 333 } |
325 } | 334 } |
326 if (update_estimate) { | 335 if (update_estimate) { |
327 last_update_ms_ = now_ms; | 336 last_update_ms_ = now_ms; |
328 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); | 337 observer_->OnReceiveBitrateChanged(ssrcs, target_bitrate_bps); |
329 } | 338 } |
330 } | 339 } |
331 | 340 |
332 void RemoteBitrateEstimatorAbsSendTime::Process() {} | 341 void DelayBasedBwe::Process() {} |
333 | 342 |
334 int64_t RemoteBitrateEstimatorAbsSendTime::TimeUntilNextProcess() { | 343 int64_t DelayBasedBwe::TimeUntilNextProcess() { |
335 const int64_t kDisabledModuleTime = 1000; | 344 const int64_t kDisabledModuleTime = 1000; |
336 return kDisabledModuleTime; | 345 return kDisabledModuleTime; |
337 } | 346 } |
338 | 347 |
339 void RemoteBitrateEstimatorAbsSendTime::TimeoutStreams(int64_t now_ms) { | 348 void DelayBasedBwe::TimeoutStreams(int64_t now_ms) { |
340 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { | 349 for (Ssrcs::iterator it = ssrcs_.begin(); it != ssrcs_.end();) { |
341 if ((now_ms - it->second) > kStreamTimeOutMs) { | 350 if ((now_ms - it->second) > kStreamTimeOutMs) { |
342 ssrcs_.erase(it++); | 351 ssrcs_.erase(it++); |
343 } else { | 352 } else { |
344 ++it; | 353 ++it; |
345 } | 354 } |
346 } | 355 } |
347 if (ssrcs_.empty()) { | 356 if (ssrcs_.empty()) { |
348 // We can't update the estimate if we don't have any active streams. | 357 // We can't update the estimate if we don't have any active streams. |
349 inter_arrival_.reset( | 358 inter_arrival_.reset( |
350 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 359 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
351 kTimestampToMs, true)); | 360 kTimestampToMs, true)); |
352 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | 361 estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
353 // We deliberately don't reset the first_packet_time_ms_ here for now since | 362 // We deliberately don't reset the first_packet_time_ms_ here for now since |
354 // we only probe for bandwidth in the beginning of a call right now. | 363 // we only probe for bandwidth in the beginning of a call right now. |
355 } | 364 } |
356 } | 365 } |
357 | 366 |
358 void RemoteBitrateEstimatorAbsSendTime::OnRttUpdate(int64_t avg_rtt_ms, | 367 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
359 int64_t max_rtt_ms) { | |
360 rtc::CritScope lock(&crit_); | 368 rtc::CritScope lock(&crit_); |
361 remote_rate_.SetRtt(avg_rtt_ms); | 369 remote_rate_.SetRtt(avg_rtt_ms); |
362 } | 370 } |
363 | 371 |
364 void RemoteBitrateEstimatorAbsSendTime::RemoveStream(uint32_t ssrc) { | 372 void DelayBasedBwe::RemoveStream(uint32_t ssrc) { |
365 rtc::CritScope lock(&crit_); | 373 rtc::CritScope lock(&crit_); |
366 ssrcs_.erase(ssrc); | 374 ssrcs_.erase(ssrc); |
367 } | 375 } |
368 | 376 |
369 bool RemoteBitrateEstimatorAbsSendTime::LatestEstimate( | 377 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
370 std::vector<uint32_t>* ssrcs, | 378 uint32_t* bitrate_bps) const { |
371 uint32_t* bitrate_bps) const { | |
372 // Currently accessed from both the process thread (see | 379 // Currently accessed from both the process thread (see |
373 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 380 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
374 // Call::GetStats()). Should in the future only be accessed from a single | 381 // Call::GetStats()). Should in the future only be accessed from a single |
375 // thread. | 382 // thread. |
376 RTC_DCHECK(ssrcs); | 383 RTC_DCHECK(ssrcs); |
377 RTC_DCHECK(bitrate_bps); | 384 RTC_DCHECK(bitrate_bps); |
378 rtc::CritScope lock(&crit_); | 385 rtc::CritScope lock(&crit_); |
379 if (!remote_rate_.ValidEstimate()) { | 386 if (!remote_rate_.ValidEstimate()) { |
380 return false; | 387 return false; |
381 } | 388 } |
382 *ssrcs = Keys(ssrcs_); | 389 *ssrcs = Keys(ssrcs_); |
383 if (ssrcs_.empty()) { | 390 if (ssrcs_.empty()) { |
384 *bitrate_bps = 0; | 391 *bitrate_bps = 0; |
385 } else { | 392 } else { |
386 *bitrate_bps = remote_rate_.LatestEstimate(); | 393 *bitrate_bps = remote_rate_.LatestEstimate(); |
387 } | 394 } |
388 return true; | 395 return true; |
389 } | 396 } |
390 | 397 |
391 void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) { | 398 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
392 // Called from both the configuration thread and the network thread. Shouldn't | 399 // Called from both the configuration thread and the network thread. Shouldn't |
393 // be called from the network thread in the future. | 400 // be called from the network thread in the future. |
394 rtc::CritScope lock(&crit_); | 401 rtc::CritScope lock(&crit_); |
395 remote_rate_.SetMinBitrate(min_bitrate_bps); | 402 remote_rate_.SetMinBitrate(min_bitrate_bps); |
396 } | 403 } |
397 } // namespace webrtc | 404 } // namespace webrtc |
OLD | NEW |