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