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"
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
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
{
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
);
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_
;
39 } // namespace content
41 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_LEVEL_CALCULATOR_H_