henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VOICE_ENGINE_AUDIO_LEVEL_H_ |
| 12 | #define VOICE_ENGINE_AUDIO_LEVEL_H_ |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/criticalsection.h" |
| 15 | #include "rtc_base/thread_annotations.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 16 | #include "typedefs.h" // NOLINT(build/include) |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | class AudioFrame; |
| 21 | namespace voe { |
| 22 | |
| 23 | class AudioLevel { |
| 24 | public: |
| 25 | AudioLevel(); |
| 26 | ~AudioLevel(); |
| 27 | |
| 28 | // Called on "API thread(s)" from APIs like VoEBase::CreateChannel(), |
| 29 | // VoEBase::StopSend(), VoEVolumeControl::GetSpeechOutputLevel(). |
| 30 | int8_t Level() const; |
| 31 | int16_t LevelFullRange() const; |
| 32 | void Clear(); |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 33 | // See the description for "totalAudioEnergy" in the WebRTC stats spec |
| 34 | // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy) |
| 35 | double TotalEnergy() const; |
| 36 | double TotalDuration() const; |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 37 | |
| 38 | // Called on a native capture audio thread (platform dependent) from the |
| 39 | // AudioTransport::RecordedDataIsAvailable() callback. |
| 40 | // In Chrome, this method is called on the AudioInputDevice thread. |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 41 | void ComputeLevel(const AudioFrame& audioFrame, double duration); |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 42 | |
| 43 | private: |
| 44 | enum { kUpdateFrequency = 10 }; |
| 45 | |
| 46 | rtc::CriticalSection crit_sect_; |
| 47 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 48 | int16_t abs_max_ RTC_GUARDED_BY(crit_sect_); |
| 49 | int16_t count_ RTC_GUARDED_BY(crit_sect_); |
| 50 | int8_t current_level_ RTC_GUARDED_BY(crit_sect_); |
| 51 | int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_); |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 52 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 53 | double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0; |
| 54 | double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0; |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace voe |
| 58 | } // namespace webrtc |
| 59 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 60 | #endif // VOICE_ENGINE_AUDIO_LEVEL_H_ |