chrome.bluetoothSocket: clean-up Listen functions
[chromium-blink-merge.git] / content / renderer / media / media_stream_audio_level_calculator.h
blob41c9c34f7be1b2f803941ca2429417ddc8eb4fdc
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 content {
12 // This class is used by the WebRtcLocalAudioTrack to calculate the level of
13 // the audio signal. And the audio level will be eventually used by the volume
14 // animation UI.
15 // The algorithm used by this class is the same as how it is done in
16 // third_party/webrtc/voice_engine/level_indicator.cc.
17 class MediaStreamAudioLevelCalculator {
18 public:
19 MediaStreamAudioLevelCalculator();
20 ~MediaStreamAudioLevelCalculator();
22 // Calculates the signal level of the audio data.
23 // Returns the absolute value of the amplitude of the signal.
24 int Calculate(const int16* audio_data, int number_of_channels,
25 int number_of_frames);
27 private:
28 // Used to DCHECK that the constructor and Calculate() are always called on
29 // the same audio thread. Note that the destructor will be called on a
30 // different thread, which can be either the main render thread or a new
31 // audio thread where WebRtcLocalAudioTrack::OnSetFormat() is called.
32 base::ThreadChecker thread_checker_;
34 int counter_;
35 int max_amplitude_;
36 int level_;
39 } // namespace content
41 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_LEVEL_CALCULATOR_H_