blob: 883641ac79bbab08961e2c4852f1020a8d23c7b3 [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
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010011#ifndef AUDIO_AUDIO_LEVEL_H_
12#define AUDIO_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"
henrik.lundin92a7a182017-03-07 01:58:55 -080016
17namespace webrtc {
18
19class AudioFrame;
20namespace voe {
21
22class AudioLevel {
23 public:
24 AudioLevel();
25 ~AudioLevel();
26
27 // Called on "API thread(s)" from APIs like VoEBase::CreateChannel(),
28 // VoEBase::StopSend(), VoEVolumeControl::GetSpeechOutputLevel().
29 int8_t Level() const;
30 int16_t LevelFullRange() const;
31 void Clear();
zstein3c451862017-07-20 09:57:42 -070032 // See the description for "totalAudioEnergy" in the WebRTC stats spec
33 // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy)
34 double TotalEnergy() const;
35 double TotalDuration() const;
henrik.lundin92a7a182017-03-07 01:58:55 -080036
37 // Called on a native capture audio thread (platform dependent) from the
38 // AudioTransport::RecordedDataIsAvailable() callback.
39 // In Chrome, this method is called on the AudioInputDevice thread.
zstein3c451862017-07-20 09:57:42 -070040 void ComputeLevel(const AudioFrame& audioFrame, double duration);
henrik.lundin92a7a182017-03-07 01:58:55 -080041
42 private:
43 enum { kUpdateFrequency = 10 };
44
45 rtc::CriticalSection crit_sect_;
46
danilchapa37de392017-09-09 04:17:22 -070047 int16_t abs_max_ RTC_GUARDED_BY(crit_sect_);
48 int16_t count_ RTC_GUARDED_BY(crit_sect_);
49 int8_t current_level_ RTC_GUARDED_BY(crit_sect_);
50 int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_);
zstein3c451862017-07-20 09:57:42 -070051
danilchapa37de392017-09-09 04:17:22 -070052 double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0;
53 double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0;
henrik.lundin92a7a182017-03-07 01:58:55 -080054};
55
56} // namespace voe
57} // namespace webrtc
58
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010059#endif // AUDIO_AUDIO_LEVEL_H_