Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / host / audio_silence_detector.h
blobf02be315e32da25102cfe8c4e85a81f6caa74b94
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_
6 #define REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_
8 #include "base/basictypes.h"
9 #include "base/logging.h"
11 namespace remoting {
13 // Helper used in audio capturers to detect and drop silent audio packets.
14 class AudioSilenceDetector {
15 public:
16 // |threshold| is used to specify maximum absolute sample value that should
17 // still be considered as silence.
18 explicit AudioSilenceDetector(int threshold);
19 ~AudioSilenceDetector();
21 void Reset(int sampling_rate, int channels);
23 // Must be called for each new chunk of data. Return true the given packet
24 // is silence should be dropped.
25 bool IsSilence(const int16* samples, size_t samples_count);
27 private:
28 // Maximum absolute sample value that should still be considered as silence.
29 int threshold_;
31 // Silence period threshold in samples. Silence intervals shorter than this
32 // value are still encoded and sent to the client, so that we don't disrupt
33 // playback by dropping them.
34 int silence_length_max_;
36 // Lengths of the current silence period in samples.
37 int silence_length_;
40 } // namespace remoting
42 #endif // REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_