Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/renderer/media/media_stream_audio_level_calculator.cc

Issue 661693003: Avoid reporting 0 as input level when AudioProcessing zero out the audio data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed the unittests Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/media_stream_audio_level_calculator.h" 5 #include "content/renderer/media/media_stream_audio_level_calculator.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 22 matching lines...) Expand all
33 : counter_(0), 33 : counter_(0),
34 max_amplitude_(0), 34 max_amplitude_(0),
35 level_(0) { 35 level_(0) {
36 } 36 }
37 37
38 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() { 38 MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() {
39 } 39 }
40 40
41 int MediaStreamAudioLevelCalculator::Calculate(const int16* audio_data, 41 int MediaStreamAudioLevelCalculator::Calculate(const int16* audio_data,
42 int number_of_channels, 42 int number_of_channels,
43 int number_of_frames) { 43 int number_of_frames,
44 bool has_energy) {
44 DCHECK(thread_checker_.CalledOnValidThread()); 45 DCHECK(thread_checker_.CalledOnValidThread());
45 // |level_| is updated every 10 callbacks. For the case where callback comes 46 // |level_| is updated every 10 callbacks. For the case where callback comes
46 // every 10ms, |level_| will be updated approximately every 100ms. 47 // every 10ms, |level_| will be updated approximately every 100ms.
47 static const int kUpdateFrequency = 10; 48 static const int kUpdateFrequency = 10;
48 49
49 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames); 50 int max = MaxAmplitude(audio_data, number_of_channels * number_of_frames);
50 max_amplitude_ = std::max(max_amplitude_, max); 51 max_amplitude_ = std::max(max_amplitude_, max);
51 52
52 if (counter_++ == kUpdateFrequency) { 53 if (counter_++ == kUpdateFrequency) {
53 level_ = max_amplitude_; 54 level_ = (max_amplitude_ == 0 ? has_energy : max_amplitude_);
54 55
55 // Decay the absolute maximum amplitude by 1/4. 56 // Decay the absolute maximum amplitude by 1/4.
56 max_amplitude_ >>= 2; 57 max_amplitude_ >>= 2;
57 58
58 // Reset the counter. 59 // Reset the counter.
59 counter_ = 0; 60 counter_ = 0;
60 } 61 }
61 62
62 return level_; 63 return level_;
63 } 64 }
64 65
65 } // namespace content 66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698