OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 int RemoteBitrateEstimatorAbsSendTime::Id() const { | 95 int RemoteBitrateEstimatorAbsSendTime::Id() const { |
96 return static_cast<int>(reinterpret_cast<uint64_t>(this)); | 96 return static_cast<int>(reinterpret_cast<uint64_t>(this)); |
97 } | 97 } |
98 | 98 |
99 RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime( | 99 RemoteBitrateEstimatorAbsSendTime::RemoteBitrateEstimatorAbsSendTime( |
100 RemoteBitrateObserver* observer, | 100 RemoteBitrateObserver* observer, |
101 Clock* clock) | 101 Clock* clock) |
102 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 102 : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
103 observer_(observer), | 103 observer_(observer), |
104 clock_(clock), | 104 clock_(clock), |
105 ssrcs_(), | |
106 inter_arrival_(), | |
107 estimator_(OverUseDetectorOptions()), | |
108 detector_(OverUseDetectorOptions()), | |
109 incoming_bitrate_(kBitrateWindowMs, 8000), | 105 incoming_bitrate_(kBitrateWindowMs, 8000), |
110 last_process_time_(-1), | 106 last_process_time_(-1), |
111 process_interval_ms_(kProcessIntervalMs), | 107 process_interval_ms_(kProcessIntervalMs), |
112 total_propagation_delta_ms_(0), | 108 total_propagation_delta_ms_(0), |
113 total_probes_received_(0), | 109 total_probes_received_(0), |
114 first_packet_time_ms_(-1) { | 110 first_packet_time_ms_(-1) { |
115 assert(observer_); | 111 assert(observer_); |
116 assert(clock_); | 112 assert(clock_); |
117 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; | 113 LOG(LS_INFO) << "RemoteBitrateEstimatorAbsSendTime: Instantiating."; |
118 } | 114 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // here. | 260 // here. |
265 ssrcs_[ssrc] = now_ms; | 261 ssrcs_[ssrc] = now_ms; |
266 incoming_bitrate_.Update(payload_size, now_ms); | 262 incoming_bitrate_.Update(payload_size, now_ms); |
267 const BandwidthUsage prior_state = detector_.State(); | 263 const BandwidthUsage prior_state = detector_.State(); |
268 | 264 |
269 if (first_packet_time_ms_ == -1) | 265 if (first_packet_time_ms_ == -1) |
270 first_packet_time_ms_ = clock_->TimeInMilliseconds(); | 266 first_packet_time_ms_ = clock_->TimeInMilliseconds(); |
271 | 267 |
272 uint32_t ts_delta = 0; | 268 uint32_t ts_delta = 0; |
273 int64_t t_delta = 0; | 269 int64_t t_delta = 0; |
274 int size_delta = 0; | |
275 // For now only try to detect probes while we don't have a valid estimate, and | 270 // For now only try to detect probes while we don't have a valid estimate, and |
276 // make sure the packet was paced. We currently assume that only packets | 271 // make sure the packet was paced. We currently assume that only packets |
277 // larger than 200 bytes are paced by the sender. | 272 // larger than 200 bytes are paced by the sender. |
278 was_paced = was_paced && payload_size > PacedSender::kMinProbePacketSize; | 273 was_paced = was_paced && payload_size > PacedSender::kMinProbePacketSize; |
279 if (was_paced && | 274 if (was_paced && |
280 (!remote_rate_.ValidEstimate() || | 275 (!remote_rate_.ValidEstimate() || |
281 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { | 276 now_ms - first_packet_time_ms_ < kInitialProbingIntervalMs)) { |
282 // TODO(holmer): Use a map instead to get correct order? | 277 // TODO(holmer): Use a map instead to get correct order? |
283 if (total_probes_received_ < kMaxProbePackets) { | 278 if (total_probes_received_ < kMaxProbePackets) { |
284 int send_delta_ms = -1; | 279 int send_delta_ms = -1; |
285 int recv_delta_ms = -1; | 280 int recv_delta_ms = -1; |
286 if (!probes_.empty()) { | 281 if (!probes_.empty()) { |
287 send_delta_ms = send_time_ms - probes_.back().send_time_ms; | 282 send_delta_ms = send_time_ms - probes_.back().send_time_ms; |
288 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; | 283 recv_delta_ms = arrival_time_ms - probes_.back().recv_time_ms; |
289 } | 284 } |
290 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms | 285 LOG(LS_INFO) << "Probe packet received: send time=" << send_time_ms |
291 << " ms, recv time=" << arrival_time_ms | 286 << " ms, recv time=" << arrival_time_ms |
292 << " ms, send delta=" << send_delta_ms | 287 << " ms, send delta=" << send_delta_ms |
293 << " ms, recv delta=" << recv_delta_ms << " ms."; | 288 << " ms, recv delta=" << recv_delta_ms << " ms."; |
294 } | 289 } |
295 probes_.push_back(Probe(send_time_ms, arrival_time_ms, payload_size)); | 290 probes_.push_back(Probe(send_time_ms, arrival_time_ms, payload_size)); |
296 ++total_probes_received_; | 291 ++total_probes_received_; |
297 ProcessClusters(now_ms); | 292 ProcessClusters(now_ms); |
298 } | 293 } |
299 if (!inter_arrival_.get()) { | 294 if (!inter_arrival_.get()) { |
300 inter_arrival_.reset( | 295 inter_arrival_.reset( |
301 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 296 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
302 kTimestampToMs, true)); | 297 kTimestampToMs, true)); |
303 } | 298 } |
304 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, payload_size, | 299 if (inter_arrival_->ComputeDeltas(timestamp, arrival_time_ms, &ts_delta, |
305 &ts_delta, &t_delta, &size_delta)) { | 300 &t_delta)) { |
306 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 301 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
307 estimator_.Update(t_delta, ts_delta_ms, size_delta, detector_.State()); | 302 estimator_.Update(t_delta, ts_delta_ms, detector_.State()); |
308 detector_.Detect(estimator_.offset(), ts_delta_ms, | 303 detector_.Detect(estimator_.offset(), ts_delta_ms, |
309 estimator_.num_of_deltas(), arrival_time_ms); | 304 estimator_.num_of_deltas(), arrival_time_ms); |
310 UpdateStats(static_cast<int>(t_delta - ts_delta_ms), now_ms); | 305 UpdateStats(static_cast<int>(t_delta - ts_delta_ms), now_ms); |
311 } | 306 } |
312 if (detector_.State() == kBwOverusing) { | 307 if (detector_.State() == kBwOverusing) { |
313 uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); | 308 uint32_t incoming_bitrate_bps = incoming_bitrate_.Rate(now_ms); |
314 if (prior_state != kBwOverusing || | 309 if (prior_state != kBwOverusing || |
315 remote_rate_.TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { | 310 remote_rate_.TimeToReduceFurther(now_ms, incoming_bitrate_bps)) { |
316 // The first overuse should immediately trigger a new estimate. | 311 // The first overuse should immediately trigger a new estimate. |
317 // We also have to update the estimate immediately if we are overusing | 312 // We also have to update the estimate immediately if we are overusing |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 | 434 |
440 total_propagation_delta_ms_ = | 435 total_propagation_delta_ms_ = |
441 std::max(total_propagation_delta_ms_ + propagation_delta_ms, 0); | 436 std::max(total_propagation_delta_ms_ + propagation_delta_ms, 0); |
442 } | 437 } |
443 | 438 |
444 void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) { | 439 void RemoteBitrateEstimatorAbsSendTime::SetMinBitrate(int min_bitrate_bps) { |
445 CriticalSectionScoped cs(crit_sect_.get()); | 440 CriticalSectionScoped cs(crit_sect_.get()); |
446 remote_rate_.SetMinBitrate(min_bitrate_bps); | 441 remote_rate_.SetMinBitrate(min_bitrate_bps); |
447 } | 442 } |
448 } // namespace webrtc | 443 } // namespace webrtc |
OLD | NEW |