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 |
11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ |
12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ |
13 | 13 |
14 #include <string.h> // size_t | 14 #include <string.h> // size_t |
15 | 15 |
16 #include <list> | 16 #include <list> |
17 | 17 |
18 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 class DelayPeakDetector { | 23 class DelayPeakDetector { |
23 public: | 24 public: |
24 DelayPeakDetector(); | 25 DelayPeakDetector(const TickTimer* tick_timer); |
25 virtual ~DelayPeakDetector(); | 26 virtual ~DelayPeakDetector(); |
26 virtual void Reset(); | 27 virtual void Reset(); |
27 | 28 |
28 // Notifies the DelayPeakDetector of how much audio data is carried in each | 29 // Notifies the DelayPeakDetector of how much audio data is carried in each |
29 // packet. | 30 // packet. |
30 virtual void SetPacketAudioLength(int length_ms); | 31 virtual void SetPacketAudioLength(int length_ms); |
31 | 32 |
32 // Returns true if peak-mode is active. That is, delay peaks were observed | 33 // Returns true if peak-mode is active. That is, delay peaks were observed |
33 // recently. | 34 // recently. |
34 virtual bool peak_found(); | 35 virtual bool peak_found(); |
35 | 36 |
36 // Calculates and returns the maximum delay peak height. Returns -1 if no | 37 // 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 // delay peaks have been observed recently. The unit is number of packets. |
38 virtual int MaxPeakHeight() const; | 39 virtual int MaxPeakHeight() const; |
39 | 40 |
40 // Calculates and returns the maximum delay peak distance in ms. | 41 // Calculates and returns the maximum delay peak distance in ms (strictly |
41 // Returns -1 if no delay peaks have been observed recently. | 42 // larger than 0), or 0 if no delay peaks have been observed recently. |
42 virtual int MaxPeakPeriod() const; | 43 virtual uint64_t MaxPeakPeriod() const; |
43 | 44 |
44 // Updates the DelayPeakDetector with a new inter-arrival time (in packets) | 45 // 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 // 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 // or not). Returns true if peak-mode is active, false if not. |
47 virtual bool Update(int inter_arrival_time, int target_level); | 48 virtual bool Update(int inter_arrival_time, int target_level); |
48 | 49 |
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: | 50 private: |
55 static const size_t kMaxNumPeaks = 8; | 51 static const size_t kMaxNumPeaks = 8; |
56 static const size_t kMinPeaksToTrigger = 2; | 52 static const size_t kMinPeaksToTrigger = 2; |
57 static const int kPeakHeightMs = 78; | 53 static const int kPeakHeightMs = 78; |
58 static const int kMaxPeakPeriodMs = 10000; | 54 static const int kMaxPeakPeriodMs = 10000; |
59 | 55 |
60 typedef struct { | 56 typedef struct { |
61 int period_ms; | 57 uint64_t period_ms; |
62 int peak_height_packets; | 58 int peak_height_packets; |
63 } Peak; | 59 } Peak; |
64 | 60 |
65 bool CheckPeakConditions(); | 61 bool CheckPeakConditions(); |
66 | 62 |
67 std::list<Peak> peak_history_; | 63 std::list<Peak> peak_history_; |
68 bool peak_found_; | 64 bool peak_found_; |
69 int peak_detection_threshold_; | 65 int peak_detection_threshold_; |
70 int peak_period_counter_ms_; | 66 const TickTimer* tick_timer_; |
| 67 std::unique_ptr<TickTimer::Stopwatch> peak_period_stopwatch_; |
71 | 68 |
72 RTC_DISALLOW_COPY_AND_ASSIGN(DelayPeakDetector); | 69 RTC_DISALLOW_COPY_AND_ASSIGN(DelayPeakDetector); |
73 }; | 70 }; |
74 | 71 |
75 } // namespace webrtc | 72 } // namespace webrtc |
76 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ | 73 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_DELAY_PEAK_DETECTOR_H_ |
OLD | NEW |