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

Unified Diff: content/renderer/media/media_stream_audio_level_calculator.cc

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_audio_level_calculator.cc
diff --git a/content/renderer/media/media_stream_audio_level_calculator.cc b/content/renderer/media/media_stream_audio_level_calculator.cc
index ad76a43dd2f6ad14125b5a92506990e1bbc34aaf..a2da00ee64582d4a605f867637d8e1baeda434a8 100644
--- a/content/renderer/media/media_stream_audio_level_calculator.cc
+++ b/content/renderer/media/media_stream_audio_level_calculator.cc
@@ -5,6 +5,7 @@
#include "content/renderer/media/media_stream_audio_level_calculator.h"
#include <cmath>
+#include <limits>
#include "base/logging.h"
#include "base/stl_util.h"
@@ -28,23 +29,37 @@ float MaxAmplitude(const float* audio_data, int length) {
} // namespace
+MediaStreamAudioLevelCalculator::ReportedLevel::ReportedLevel()
+ : level_(0.0f) {}
+
+MediaStreamAudioLevelCalculator::ReportedLevel::~ReportedLevel() {}
+
+float MediaStreamAudioLevelCalculator::ReportedLevel::Get() const {
+ base::AutoLock auto_lock(lock_);
+ return level_;
+}
+
MediaStreamAudioLevelCalculator::MediaStreamAudioLevelCalculator()
: counter_(0),
max_amplitude_(0.0f),
- level_(0.0f) {
+ reported_level_(new ReportedLevel()) {
}
MediaStreamAudioLevelCalculator::~MediaStreamAudioLevelCalculator() {
+ base::AutoLock auto_lock(reported_level_->lock_);
+ reported_level_->level_ = 0.0f;
}
-float MediaStreamAudioLevelCalculator::Calculate(
- const media::AudioBus& audio_bus) {
+void MediaStreamAudioLevelCalculator::Calculate(
+ const media::AudioBus& audio_bus,
+ bool assume_nonzero_energy) {
DCHECK(thread_checker_.CalledOnValidThread());
// |level_| is updated every 10 callbacks. For the case where callback comes
// every 10ms, |level_| will be updated approximately every 100ms.
static const int kUpdateFrequency = 10;
- float max = 0.0f;
+ float max = assume_nonzero_energy ? 1.0f / std::numeric_limits<int16_t>::max()
+ : 0.0f;
for (int i = 0; i < audio_bus.channels(); ++i) {
const float max_this_channel =
MaxAmplitude(audio_bus.channel(i), audio_bus.frames());
@@ -54,7 +69,11 @@ float MediaStreamAudioLevelCalculator::Calculate(
max_amplitude_ = std::max(max_amplitude_, max);
if (counter_++ == kUpdateFrequency) {
- level_ = max_amplitude_;
+ {
+ base::AutoLock auto_lock(reported_level_->lock_);
+ // Clip the reported level to make sure it is in the range [0.0,1.0].
+ reported_level_->level_ = std::min(1.0f, max_amplitude_);
+ }
// Decay the absolute maximum amplitude by 1/4.
max_amplitude_ /= 4.0f;
@@ -62,8 +81,6 @@ float MediaStreamAudioLevelCalculator::Calculate(
// Reset the counter.
counter_ = 0;
}
-
- return level_;
}
} // namespace content
« no previous file with comments | « content/renderer/media/media_stream_audio_level_calculator.h ('k') | content/renderer/media/media_stream_audio_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698