OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 peak_detector_.Reset(); | 312 peak_detector_.Reset(); |
313 ResetHistogram(); // Resets target levels too. | 313 ResetHistogram(); // Resets target levels too. |
314 iat_factor_ = 0; // Adapt the histogram faster for the first few packets. | 314 iat_factor_ = 0; // Adapt the histogram faster for the first few packets. |
315 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); | 315 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); |
316 max_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); | 316 max_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); |
317 iat_cumulative_sum_ = 0; | 317 iat_cumulative_sum_ = 0; |
318 max_iat_cumulative_sum_ = 0; | 318 max_iat_cumulative_sum_ = 0; |
319 last_pack_cng_or_dtmf_ = 1; | 319 last_pack_cng_or_dtmf_ = 1; |
320 } | 320 } |
321 | 321 |
322 int DelayManager::AverageIAT() const { | 322 double DelayManager::EstimatedClockDriftPpm() const { |
323 int32_t sum_q24 = 0; | 323 double sum = 0.0; |
324 // Using an int for the upper limit of the following for-loop so the | 324 // Calculate the expected value based on the probabilities in |iat_vector_|. |
325 // loop-counter can be int. Otherwise we need a cast where |sum_q24| is | 325 for (size_t i = 0; i < iat_vector_.size(); ++i) { |
326 // updated. | 326 sum += static_cast<double>(iat_vector_[i]) * i; |
327 const int iat_vec_size = static_cast<int>(iat_vector_.size()); | |
328 assert(iat_vector_.size() == 65); // Algorithm is hard-coded for this size. | |
329 for (int i = 0; i < iat_vec_size; ++i) { | |
330 // Shift 6 to fit worst case: 2^30 * 64. | |
331 sum_q24 += (iat_vector_[i] >> 6) * i; | |
332 } | 327 } |
333 // Subtract the nominal inter-arrival time 1 = 2^24 in Q24. | 328 // The probabilities in |iat_vector_| are in Q30. Divide by 1 << 30 to convert |
334 sum_q24 -= (1 << 24); | 329 // to Q0; subtract the nominal inter-arrival time (1) to make a zero |
335 // Multiply with 1000000 / 2^24 = 15625 / 2^18 to get in parts-per-million. | 330 // clockdrift represent as 0; mulitply by 1000000 to produce parts-per-million |
336 // Shift 7 to Q17 first, then multiply with 15625 and shift another 11. | 331 // (ppm). |
337 return ((sum_q24 >> 7) * 15625) >> 11; | 332 return (sum / (1 << 30) - 1) * 1e6; |
338 } | 333 } |
339 | 334 |
340 bool DelayManager::PeakFound() const { | 335 bool DelayManager::PeakFound() const { |
341 return peak_detector_.peak_found(); | 336 return peak_detector_.peak_found(); |
342 } | 337 } |
343 | 338 |
344 void DelayManager::ResetPacketIatCount() { | 339 void DelayManager::ResetPacketIatCount() { |
345 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); | 340 packet_iat_stopwatch_ = tick_timer_->GetNewStopwatch(); |
346 } | 341 } |
347 | 342 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 int DelayManager::base_target_level() const { return base_target_level_; } | 408 int DelayManager::base_target_level() const { return base_target_level_; } |
414 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } | 409 void DelayManager::set_streaming_mode(bool value) { streaming_mode_ = value; } |
415 int DelayManager::last_pack_cng_or_dtmf() const { | 410 int DelayManager::last_pack_cng_or_dtmf() const { |
416 return last_pack_cng_or_dtmf_; | 411 return last_pack_cng_or_dtmf_; |
417 } | 412 } |
418 | 413 |
419 void DelayManager::set_last_pack_cng_or_dtmf(int value) { | 414 void DelayManager::set_last_pack_cng_or_dtmf(int value) { |
420 last_pack_cng_or_dtmf_ = value; | 415 last_pack_cng_or_dtmf_ = value; |
421 } | 416 } |
422 } // namespace webrtc | 417 } // namespace webrtc |
OLD | NEW |