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

Unified Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 1580493004: Plumb audio focus support for spitzer clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delegate_hookup
Patch Set: Fix crash, plumb. Created 4 years, 11 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/browser/renderer_host/media/audio_renderer_host.cc
diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc
index 49e395bd0edd694d600d280b7a72eb9568c1c043..0bc6af5b9d7044b36a144403d4bfb2b41a8a44ca 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host.cc
@@ -21,6 +21,7 @@
#include "content/browser/media/audio_stream_monitor.h"
#include "content/browser/media/capture/audio_mirroring_manager.h"
#include "content/browser/media/media_internals.h"
+#include "content/browser/media/media_web_contents_observer.h"
#include "content/browser/renderer_host/media/audio_input_device_manager.h"
#include "content/browser/renderer_host/media/audio_sync_reader.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
@@ -182,6 +183,8 @@ class AudioRendererHost::AudioEntry
bool playing() const { return playing_; }
void set_playing(bool playing) { playing_ = playing; }
+ void update_last_pause_time() { last_pause_time_ = base::TimeTicks::Now(); }
+ base::TimeTicks last_pause_time() { return last_pause_time_; }
private:
// media::AudioOutputController::EventHandler implementation.
@@ -206,6 +209,8 @@ class AudioRendererHost::AudioEntry
const scoped_refptr<media::AudioOutputController> controller_;
bool playing_;
+
+ base::TimeTicks last_pause_time_;
};
AudioRendererHost::AudioEntry::AudioEntry(
@@ -637,6 +642,30 @@ void AudioRendererHost::OnPlayStream(int stream_id) {
return;
}
+ if (entry->controller()->GetAudioParameters().effects() &
+ media::AudioParameters::FOCUSABLE) {
+ MediaWebContentsObserver::HasAudioFocus(
+ render_process_id_, entry->render_frame_id(),
+ base::Bind(&AudioRendererHost::OnFocusAvailable, this, stream_id,
+ base::TimeTicks::Now()));
+ } else {
+ entry->controller()->Play();
+ audio_log_->OnStarted(stream_id);
+ }
+}
+
+void AudioRendererHost::OnFocusAvailable(int stream_id,
+ base::TimeTicks play_time) {
+ // Abort the playback if:
+ // - The entry has been destroyed while focus was requested.
+ // - A subsequent pause has come through.
+ //
+ // A focus request never fails via this path. If it's denied a pause request
+ // will be issues directly to the player.
+ AudioEntry* entry = LookupById(stream_id);
+ if (!entry || play_time < entry->last_pause_time())
+ return;
+
entry->controller()->Play();
audio_log_->OnStarted(stream_id);
}
@@ -650,6 +679,7 @@ void AudioRendererHost::OnPauseStream(int stream_id) {
return;
}
+ entry->update_last_pause_time();
entry->controller()->Pause();
audio_log_->OnStopped(stream_id);
}

Powered by Google App Engine
This is Rietveld 408576698