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