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