audio_silence_detector.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.
4
5#ifndef REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_
6#define REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_
7
8#include "base/basictypes.h"
9#include "base/logging.h"
10
11namespace remoting {
12
13// Helper used in audio capturers to detect and drop silent audio packets.
14class AudioSilenceDetector {
15 public:
16  // |threshold| is used to specify maximum absolute sample value that should
17  // still be considered as silence.
18  AudioSilenceDetector(int threshold);
19  ~AudioSilenceDetector();
20
21  void Reset(int sampling_rate, int channels);
22
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);
26
27 private:
28  // Maximum absolute sample value that should still be considered as silence.
29  int threshold_;
30
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_;
35
36  // Lengths of the current silence period in samples.
37  int silence_length_;
38};
39
40}  // namespace remoting
41
42#endif  // REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_