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 <stddef.h> 9 #include <stdint.h> 10 11 12 namespace remoting { 13 14 // Helper used in audio capturers to detect and drop silent audio packets. 15 class AudioSilenceDetector { 16 public: 17 // |threshold| is used to specify maximum absolute sample value that should 18 // still be considered as silence. 19 explicit AudioSilenceDetector(int threshold); 20 ~AudioSilenceDetector(); 21 22 void Reset(int sampling_rate, int channels); 23 24 // Must be called for each new chunk of data. Return true the given packet 25 // is silence should be dropped. 26 bool IsSilence(const int16_t* samples, size_t frames); 27 28 // The count of channels received from last Reset(). 29 int channels() const; 30 31 private: 32 // Maximum absolute sample value that should still be considered as silence. 33 int threshold_; 34 35 // Silence period threshold in samples. Silence intervals shorter than this 36 // value are still encoded and sent to the client, so that we don't disrupt 37 // playback by dropping them. 38 int silence_length_max_; 39 40 // Lengths of the current silence period in samples. 41 int silence_length_; 42 43 // The count of channels. 44 int channels_; 45 }; 46 47 } // namespace remoting 48 49 #endif // REMOTING_HOST_AUDIO_SILENCE_DETECTOR_H_ 50