1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ 13 14 #include <string.h> // size_t 15 16 #include <list> 17 18 #include "webrtc/base/constructormagic.h" 19 20 namespace webrtc { 21 22 class DelayPeakDetector { 23 public: 24 DelayPeakDetector(); 25 virtual ~DelayPeakDetector() {} 26 virtual void Reset(); 27 28 // Notifies the DelayPeakDetector of how much audio data is carried in each 29 // packet. 30 virtual void SetPacketAudioLength(int length_ms); 31 32 // Returns true if peak-mode is active. That is, delay peaks were observed 33 // recently. 34 virtual bool peak_found() { return peak_found_; } 35 36 // Calculates and returns the maximum delay peak height. Returns -1 if no 37 // delay peaks have been observed recently. The unit is number of packets. 38 virtual int MaxPeakHeight() const; 39 40 // Calculates and returns the maximum delay peak distance in ms. 41 // Returns -1 if no delay peaks have been observed recently. 42 virtual int MaxPeakPeriod() const; 43 44 // Updates the DelayPeakDetector with a new inter-arrival time (in packets) 45 // and the current target buffer level (needed to decide if a peak is observed 46 // or not). Returns true if peak-mode is active, false if not. 47 virtual bool Update(int inter_arrival_time, int target_level); 48 49 // Increments the |peak_period_counter_ms_| with |inc_ms|. Only increments 50 // the counter if it is non-negative. A negative denotes that no peak has 51 // been observed. 52 virtual void IncrementCounter(int inc_ms); 53 54 private: 55 static const size_t kMaxNumPeaks = 8; 56 static const size_t kMinPeaksToTrigger = 2; 57 static const int kPeakHeightMs = 78; 58 static const int kMaxPeakPeriodMs = 10000; 59 60 typedef struct { 61 int period_ms; 62 int peak_height_packets; 63 } Peak; 64 65 bool CheckPeakConditions(); 66 67 std::list<Peak> peak_history_; 68 bool peak_found_; 69 int peak_detection_threshold_; 70 int peak_period_counter_ms_; 71 72 DISALLOW_COPY_AND_ASSIGN(DelayPeakDetector); 73 }; 74 75 } // namespace webrtc 76 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ 77