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

Unified Diff: media/audio/audio_output_controller.cc

Issue 22339024: Crash fix: Remove MessageLoop from AudioPowerMonitor and instead use MessageLoopProxy in AudioOutpu… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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: media/audio/audio_output_controller.cc
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc
index 4005047f428c2390aebc084cfb3b0d07a2529ef7..8b12c9e4be83130faded2e174463d673037427cc 100644
--- a/media/audio/audio_output_controller.cc
+++ b/media/audio/audio_output_controller.cc
@@ -11,7 +11,6 @@
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
-#include "media/audio/audio_power_monitor.h"
#include "media/audio/audio_util.h"
#include "media/audio/shared_memory_util.h"
#include "media/base/scoped_histogram_timer.h"
@@ -49,7 +48,10 @@ AudioOutputController::AudioOutputController(AudioManager* audio_manager,
num_allowed_io_(0),
sync_reader_(sync_reader),
message_loop_(audio_manager->GetMessageLoop()),
- number_polling_attempts_left_(0) {
+ number_polling_attempts_left_(0),
+ power_monitor_(
+ params.sample_rate(),
+ TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMillis)) {
DCHECK(audio_manager);
DCHECK(handler_);
DCHECK(sync_reader_);
@@ -156,17 +158,13 @@ void AudioOutputController::DoPlay() {
state_ = kPlaying;
- // Start monitoring power levels and send an initial notification that we're
- // starting in silence.
- handler_->OnPowerMeasured(AudioPowerMonitor::zero_power(), false);
- power_monitor_callback_.Reset(
- base::Bind(&EventHandler::OnPowerMeasured, base::Unretained(handler_)));
- power_monitor_.reset(new AudioPowerMonitor(
- params_.sample_rate(),
- TimeDelta::FromMilliseconds(kPowerMeasurementTimeConstantMillis),
- TimeDelta::FromSeconds(1) / kPowerMeasurementsPerSecond,
- base::MessageLoop::current(),
- power_monitor_callback_.callback()));
+ power_monitor_.Reset();
+ power_poll_callback_.Reset(
+ base::Bind(&AudioOutputController::ReportPowerMeasurementPeriodically,
+ this));
+ // Run the callback to send an initial notification that we're starting in
+ // silence, and to schedule periodic callbacks.
+ power_poll_callback_.callback().Run();
// We start the AudioOutputStream lazily.
AllowEntryToOnMoreIOData();
@@ -175,6 +173,15 @@ void AudioOutputController::DoPlay() {
handler_->OnPlaying();
}
+void AudioOutputController::ReportPowerMeasurementPeriodically() {
+ DCHECK(message_loop_->BelongsToCurrentThread());
+ handler_->OnPowerMeasured(power_monitor_.ReadCurrentPower(),
+ power_monitor_.TestForClippingAndClear());
+ message_loop_->PostDelayedTask(
+ FROM_HERE, power_poll_callback_.callback(),
+ TimeDelta::FromSeconds(1) / kPowerMeasurementsPerSecond);
+}
+
void AudioOutputController::StopStream() {
DCHECK(message_loop_->BelongsToCurrentThread());
@@ -182,11 +189,7 @@ void AudioOutputController::StopStream() {
stream_->Stop();
DisallowEntryToOnMoreIOData();
- // Stop monitoring power levels. By canceling power_monitor_callback_, any
- // tasks posted to |message_loop_| by AudioPowerMonitor during the
- // stream_->Stop() call above will not run.
- power_monitor_.reset();
- power_monitor_callback_.Cancel();
+ power_poll_callback_.Cancel();
state_ = kPaused;
}
@@ -279,7 +282,7 @@ int AudioOutputController::OnMoreIOData(AudioBus* source,
sync_reader_->UpdatePendingBytes(
buffers_state.total_bytes() + frames * params_.GetBytesPerFrame());
- power_monitor_->Scan(*dest, frames);
+ power_monitor_.Scan(*dest, frames);
AllowEntryToOnMoreIOData();
return frames;

Powered by Google App Engine
This is Rietveld 408576698