| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return max_period_element->period_ms; | 70 return max_period_element->period_ms; |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool DelayPeakDetector::Update(int inter_arrival_time, int target_level) { | 73 bool DelayPeakDetector::Update(int inter_arrival_time, int target_level) { |
| 74 if (inter_arrival_time > target_level + peak_detection_threshold_ || | 74 if (inter_arrival_time > target_level + peak_detection_threshold_ || |
| 75 inter_arrival_time > 2 * target_level) { | 75 inter_arrival_time > 2 * target_level) { |
| 76 // A delay peak is observed. | 76 // A delay peak is observed. |
| 77 if (!peak_period_stopwatch_) { | 77 if (!peak_period_stopwatch_) { |
| 78 // This is the first peak. Reset the period counter. | 78 // This is the first peak. Reset the period counter. |
| 79 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); | 79 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); |
| 80 } else if (peak_period_stopwatch_->ElapsedMs() <= kMaxPeakPeriodMs) { | 80 } else if (peak_period_stopwatch_->ElapsedMs() > 0) { |
| 81 // This is not the first peak, and the period is valid. | 81 if (peak_period_stopwatch_->ElapsedMs() <= kMaxPeakPeriodMs) { |
| 82 // Store peak data in the vector. | 82 // This is not the first peak, and the period is valid. |
| 83 Peak peak_data; | 83 // Store peak data in the vector. |
| 84 peak_data.period_ms = peak_period_stopwatch_->ElapsedMs(); | 84 Peak peak_data; |
| 85 peak_data.peak_height_packets = inter_arrival_time; | 85 peak_data.period_ms = peak_period_stopwatch_->ElapsedMs(); |
| 86 peak_history_.push_back(peak_data); | 86 peak_data.peak_height_packets = inter_arrival_time; |
| 87 while (peak_history_.size() > kMaxNumPeaks) { | 87 peak_history_.push_back(peak_data); |
| 88 // Delete the oldest data point. | 88 while (peak_history_.size() > kMaxNumPeaks) { |
| 89 peak_history_.pop_front(); | 89 // Delete the oldest data point. |
| 90 peak_history_.pop_front(); |
| 91 } |
| 92 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); |
| 93 } else if (peak_period_stopwatch_->ElapsedMs() <= 2 * kMaxPeakPeriodMs) { |
| 94 // Invalid peak due to too long period. Reset period counter and start |
| 95 // looking for next peak. |
| 96 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); |
| 97 } else { |
| 98 // More than 2 times the maximum period has elapsed since the last peak |
| 99 // was registered. It seams that the network conditions have changed. |
| 100 // Reset the peak statistics. |
| 101 Reset(); |
| 90 } | 102 } |
| 91 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); | |
| 92 } else if (peak_period_stopwatch_->ElapsedMs() <= 2 * kMaxPeakPeriodMs) { | |
| 93 // Invalid peak due to too long period. Reset period counter and start | |
| 94 // looking for next peak. | |
| 95 peak_period_stopwatch_ = tick_timer_->GetNewStopwatch(); | |
| 96 } else { | |
| 97 // More than 2 times the maximum period has elapsed since the last peak | |
| 98 // was registered. It seams that the network conditions have changed. | |
| 99 // Reset the peak statistics. | |
| 100 Reset(); | |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 return CheckPeakConditions(); | 105 return CheckPeakConditions(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool DelayPeakDetector::CheckPeakConditions() { | 108 bool DelayPeakDetector::CheckPeakConditions() { |
| 107 size_t s = peak_history_.size(); | 109 size_t s = peak_history_.size(); |
| 108 if (s >= kMinPeaksToTrigger && | 110 if (s >= kMinPeaksToTrigger && |
| 109 peak_period_stopwatch_->ElapsedMs() <= 2 * MaxPeakPeriod()) { | 111 peak_period_stopwatch_->ElapsedMs() <= 2 * MaxPeakPeriod()) { |
| 110 peak_found_ = true; | 112 peak_found_ = true; |
| 111 } else { | 113 } else { |
| 112 peak_found_ = false; | 114 peak_found_ = false; |
| 113 } | 115 } |
| 114 return peak_found_; | 116 return peak_found_; |
| 115 } | 117 } |
| 116 } // namespace webrtc | 118 } // namespace webrtc |
| OLD | NEW |