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

Unified Diff: media/base/audio_renderer_mixer.cc

Issue 2067863003: Mixing audio with different latency requirements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android test fix Created 4 years, 6 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
« no previous file with comments | « media/base/audio_renderer_mixer.h ('k') | media/base/audio_renderer_mixer_input.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_renderer_mixer.cc
diff --git a/media/base/audio_renderer_mixer.cc b/media/base/audio_renderer_mixer.cc
index 008fcce793320af352ff80ab17ff51c8ea17cff3..93d8c751472d81cc4c65ac31bb46cba49fc3d501 100644
--- a/media/base/audio_renderer_mixer.cc
+++ b/media/base/audio_renderer_mixer.cc
@@ -10,20 +10,55 @@
#include "base/bind_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
namespace media {
enum { kPauseDelaySeconds = 10 };
+// Tracks the maximum value of a counter and logs it into a UMA histogram upon
+// each increase of the maximum. NOT thread-safe, make sure it is used under
+// lock.
+class AudioRendererMixer::UMAMaxValueTracker {
+ public:
+ UMAMaxValueTracker(const UmaLogCallback& log_callback)
+ : log_callback_(log_callback), count_(0), max_count_(0) {}
+
+ ~UMAMaxValueTracker() {}
+
+ // Increments the counter, updates the maximum.
+ void Increment() {
+ ++count_;
+ if (max_count_ < count_) {
+ max_count_ = count_;
+ log_callback_.Run(max_count_);
+ }
+ }
+
+ // Decrements the counter.
+ void Decrement() {
+ DCHECK_GE(count_, 0);
+ --count_;
+ }
+
+ private:
+ const UmaLogCallback log_callback_;
+ int count_;
+ int max_count_;
+ DISALLOW_COPY_AND_ASSIGN(UMAMaxValueTracker);
+};
+
AudioRendererMixer::AudioRendererMixer(const AudioParameters& output_params,
- scoped_refptr<AudioRendererSink> sink)
+ scoped_refptr<AudioRendererSink> sink,
+ const UmaLogCallback& log_callback)
: output_params_(output_params),
audio_sink_(std::move(sink)),
master_converter_(output_params, output_params, true),
pause_delay_(base::TimeDelta::FromSeconds(kPauseDelaySeconds)),
last_play_time_(base::TimeTicks::Now()),
// Initialize |playing_| to true since Start() results in an auto-play.
- playing_(true) {
+ playing_(true),
+ input_count_tracker_(new UMAMaxValueTracker(log_callback)) {
DCHECK(audio_sink_);
audio_sink_->Initialize(output_params, this);
audio_sink_->Start();
@@ -70,6 +105,8 @@ void AudioRendererMixer::AddMixerInput(const AudioParameters& input_params,
}
converter->second->AddInput(input);
}
+
+ input_count_tracker_->Increment();
}
void AudioRendererMixer::RemoveMixerInput(
@@ -91,6 +128,8 @@ void AudioRendererMixer::RemoveMixerInput(
converters_.erase(converter);
}
}
+
+ input_count_tracker_->Decrement();
}
void AudioRendererMixer::AddErrorCallback(const base::Closure& error_cb) {
« no previous file with comments | « media/base/audio_renderer_mixer.h ('k') | media/base/audio_renderer_mixer_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698