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 | |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 11 | #ifndef AUDIO_AUDIO_LEVEL_H_ |
| 12 | #define AUDIO_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" |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
| 19 | class AudioFrame; |
| 20 | namespace voe { |
| 21 | |
| 22 | class AudioLevel { |
| 23 | public: |
| 24 | AudioLevel(); |
| 25 | ~AudioLevel(); |
| 26 | |
| 27 | // Called on "API thread(s)" from APIs like VoEBase::CreateChannel(), |
Niels Möller | f120cba | 2018-01-30 09:33:03 +0100 | [diff] [blame] | 28 | // VoEBase::StopSend() |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 29 | int16_t LevelFullRange() const; |
| 30 | void Clear(); |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 31 | // See the description for "totalAudioEnergy" in the WebRTC stats spec |
| 32 | // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy) |
| 33 | double TotalEnergy() const; |
| 34 | double TotalDuration() const; |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 35 | |
| 36 | // Called on a native capture audio thread (platform dependent) from the |
| 37 | // AudioTransport::RecordedDataIsAvailable() callback. |
| 38 | // In Chrome, this method is called on the AudioInputDevice thread. |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 39 | void ComputeLevel(const AudioFrame& audioFrame, double duration); |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | enum { kUpdateFrequency = 10 }; |
| 43 | |
| 44 | rtc::CriticalSection crit_sect_; |
| 45 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 46 | int16_t abs_max_ RTC_GUARDED_BY(crit_sect_); |
| 47 | int16_t count_ RTC_GUARDED_BY(crit_sect_); |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 48 | int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_); |
zstein | 3c45186 | 2017-07-20 09:57:42 -0700 | [diff] [blame] | 49 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 50 | double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0; |
| 51 | double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0; |
henrik.lundin | 92a7a18 | 2017-03-07 01:58:55 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace voe |
| 55 | } // namespace webrtc |
| 56 | |
Fredrik Solenberg | a8b7c7f | 2018-01-17 11:18:31 +0100 | [diff] [blame] | 57 | #endif // AUDIO_AUDIO_LEVEL_H_ |