LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/modules/audio_processing - level_estimator_impl.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 31 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 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             : 
      11             : #include "webrtc/modules/audio_processing/level_estimator_impl.h"
      12             : 
      13             : #include "webrtc/base/array_view.h"
      14             : #include "webrtc/modules/audio_processing/audio_buffer.h"
      15             : #include "webrtc/modules/audio_processing/rms_level.h"
      16             : #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
      17             : 
      18             : namespace webrtc {
      19             : 
      20           0 : LevelEstimatorImpl::LevelEstimatorImpl(rtc::CriticalSection* crit)
      21           0 :     : crit_(crit), rms_(new RmsLevel()) {
      22           0 :   RTC_DCHECK(crit);
      23           0 : }
      24             : 
      25           0 : LevelEstimatorImpl::~LevelEstimatorImpl() {}
      26             : 
      27           0 : void LevelEstimatorImpl::Initialize() {
      28           0 :   rtc::CritScope cs(crit_);
      29           0 :   rms_->Reset();
      30           0 : }
      31             : 
      32           0 : void LevelEstimatorImpl::ProcessStream(AudioBuffer* audio) {
      33           0 :   RTC_DCHECK(audio);
      34           0 :   rtc::CritScope cs(crit_);
      35           0 :   if (!enabled_) {
      36           0 :     return;
      37             :   }
      38             : 
      39           0 :   for (size_t i = 0; i < audio->num_channels(); i++) {
      40           0 :     rms_->Analyze(rtc::ArrayView<const int16_t>(audio->channels_const()[i],
      41           0 :                                                 audio->num_frames()));
      42             :   }
      43             : }
      44             : 
      45           0 : int LevelEstimatorImpl::Enable(bool enable) {
      46           0 :   rtc::CritScope cs(crit_);
      47           0 :   if (enable && !enabled_) {
      48           0 :     rms_->Reset();
      49             :   }
      50           0 :   enabled_ = enable;
      51           0 :   return AudioProcessing::kNoError;
      52             : }
      53             : 
      54           0 : bool LevelEstimatorImpl::is_enabled() const {
      55           0 :   rtc::CritScope cs(crit_);
      56           0 :   return enabled_;
      57             : }
      58             : 
      59           0 : int LevelEstimatorImpl::RMS() {
      60           0 :   rtc::CritScope cs(crit_);
      61           0 :   if (!enabled_) {
      62           0 :     return AudioProcessing::kNotEnabledError;
      63             :   }
      64             : 
      65           0 :   return rms_->Average();
      66             : }
      67             : }  // namespace webrtc

Generated by: LCOV version 1.13