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