Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / media_stream_audio_level_calculator.h
blobe7d25cc5d548add19f02afa9b35796f20e0ca7ca
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_LEVEL_CALCULATOR_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_LEVEL_CALCULATOR_H_
8 #include "base/threading/thread_checker.h"
10 namespace media {
11 class AudioBus;
14 namespace content {
16 // This class is used by the WebRtcLocalAudioTrack to calculate the level of
17 // the audio signal. And the audio level will be eventually used by the volume
18 // animation UI.
19 // The algorithm used by this class is the same as how it is done in
20 // third_party/webrtc/voice_engine/level_indicator.cc.
21 class MediaStreamAudioLevelCalculator {
22 public:
23 MediaStreamAudioLevelCalculator();
24 ~MediaStreamAudioLevelCalculator();
26 // Calculates the signal level of the audio data, returning the absolute value
27 // of the amplitude of the signal.
28 float Calculate(const media::AudioBus& audio_bus);
30 private:
31 // Used to DCHECK that the constructor and Calculate() are always called on
32 // the same audio thread. Note that the destructor will be called on a
33 // different thread, which can be either the main render thread or a new
34 // audio thread where WebRtcLocalAudioTrack::OnSetFormat() is called.
35 base::ThreadChecker thread_checker_;
37 int counter_;
38 float max_amplitude_;
39 float level_;
42 } // namespace content
44 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_LEVEL_CALCULATOR_H_