blob: 3bbe5fdd20185c9ae1af3e0dd35593766390a34c [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(),
Niels Möllerf120cba2018-01-30 09:33:03 +010028 // VoEBase::StopSend()
henrik.lundin92a7a182017-03-07 01:58:55 -080029 int16_t LevelFullRange() const;
30 void Clear();
zstein3c451862017-07-20 09:57:42 -070031 // 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.lundin92a7a182017-03-07 01:58:55 -080035
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.
zstein3c451862017-07-20 09:57:42 -070039 void ComputeLevel(const AudioFrame& audioFrame, double duration);
henrik.lundin92a7a182017-03-07 01:58:55 -080040
41 private:
42 enum { kUpdateFrequency = 10 };
43
44 rtc::CriticalSection crit_sect_;
45
danilchapa37de392017-09-09 04:17:22 -070046 int16_t abs_max_ RTC_GUARDED_BY(crit_sect_);
47 int16_t count_ RTC_GUARDED_BY(crit_sect_);
danilchapa37de392017-09-09 04:17:22 -070048 int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_);
zstein3c451862017-07-20 09:57:42 -070049
danilchapa37de392017-09-09 04:17:22 -070050 double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0;
51 double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0;
henrik.lundin92a7a182017-03-07 01:58:55 -080052};
53
54} // namespace voe
55} // namespace webrtc
56
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010057#endif // AUDIO_AUDIO_LEVEL_H_