blob: a1951edba90438fc111e953f8f83c72de97064fd [file] [log] [blame]
henrik.lundin92a7a182017-03-07 01:58:55 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VOICE_ENGINE_AUDIO_LEVEL_H_
12#define VOICE_ENGINE_AUDIO_LEVEL_H_
henrik.lundin92a7a182017-03-07 01:58:55 -080013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/criticalsection.h"
15#include "rtc_base/thread_annotations.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020016#include "typedefs.h" // NOLINT(build/include)
henrik.lundin92a7a182017-03-07 01:58:55 -080017
18namespace webrtc {
19
20class AudioFrame;
21namespace voe {
22
23class 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();
zstein3c451862017-07-20 09:57:42 -070033 // 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.lundin92a7a182017-03-07 01:58:55 -080037
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.
zstein3c451862017-07-20 09:57:42 -070041 void ComputeLevel(const AudioFrame& audioFrame, double duration);
henrik.lundin92a7a182017-03-07 01:58:55 -080042
43 private:
44 enum { kUpdateFrequency = 10 };
45
46 rtc::CriticalSection crit_sect_;
47
danilchapa37de392017-09-09 04:17:22 -070048 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_);
zstein3c451862017-07-20 09:57:42 -070052
danilchapa37de392017-09-09 04:17:22 -070053 double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0;
54 double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0;
henrik.lundin92a7a182017-03-07 01:58:55 -080055};
56
57} // namespace voe
58} // namespace webrtc
59
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#endif // VOICE_ENGINE_AUDIO_LEVEL_H_