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

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

Issue 1122393004: Add support for switching the audio output device for HTMLMediaElements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes to MediaPlayers so that they invoke callbacks in the correct threads. First complete implem… Created 5 years, 7 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/webmediaplayer_ms.cc
diff --git a/content/renderer/media/webmediaplayer_ms.cc b/content/renderer/media/webmediaplayer_ms.cc
index de6f33b71eb086da1b77295b66ca801bb7251fae..4086d6eff7cc67c59fe5cb2d4e0ab6f9ff3b6b08 100644
--- a/content/renderer/media/webmediaplayer_ms.cc
+++ b/content/renderer/media/webmediaplayer_ms.cc
@@ -5,6 +5,7 @@
#include "content/renderer/media/webmediaplayer_ms.h"
#include <limits>
+#include <string>
#include "base/bind.h"
#include "base/callback.h"
@@ -29,6 +30,7 @@
#include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebSize.h"
+#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebView.h"
@@ -104,6 +106,7 @@ WebMediaPlayerMS::WebMediaPlayerMS(
ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
buffered_(static_cast<size_t>(0)),
volume_(1.0f),
+ main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
client_(client),
delegate_(delegate),
paused_(true),
@@ -122,7 +125,7 @@ WebMediaPlayerMS::WebMediaPlayerMS(
WebMediaPlayerMS::~WebMediaPlayerMS() {
DVLOG(1) << "WebMediaPlayerMS::dtor";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
SetVideoFrameProviderClient(NULL);
GetClient()->setWebLayer(NULL);
@@ -144,7 +147,7 @@ void WebMediaPlayerMS::load(LoadType load_type,
const blink::WebURL& url,
CORSMode cors_mode) {
DVLOG(1) << "WebMediaPlayerMS::load";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
// TODO(acolwell): Change this to DCHECK_EQ(load_type,
// LoadTypeMediaStream) once Blink-side changes land.
@@ -187,7 +190,7 @@ void WebMediaPlayerMS::load(LoadType load_type,
void WebMediaPlayerMS::play() {
DVLOG(1) << "WebMediaPlayerMS::play";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
if (paused_) {
if (video_frame_provider_.get())
@@ -207,7 +210,7 @@ void WebMediaPlayerMS::play() {
void WebMediaPlayerMS::pause() {
DVLOG(1) << "WebMediaPlayerMS::pause";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
if (video_frame_provider_.get())
video_frame_provider_->Pause();
@@ -239,42 +242,91 @@ void WebMediaPlayerMS::pause() {
}
bool WebMediaPlayerMS::supportsSave() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return false;
}
void WebMediaPlayerMS::seek(double seconds) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
}
void WebMediaPlayerMS::setRate(double rate) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
}
void WebMediaPlayerMS::setVolume(double volume) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(1) << "WebMediaPlayerMS::setVolume(volume=" << volume << ")";
volume_ = volume;
if (audio_renderer_.get())
audio_renderer_->SetVolume(volume_);
}
+void WebMediaPlayerMS::setAudioOutputDevice(
+ const blink::WebSetAudioOutputDeviceRequest& request) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ std::string device_id_str(request.deviceID().utf8());
+ GURL security_origin(request.securityOrigin().toString().utf8());
+ DVLOG(1) << __FUNCTION__ << device_id_str << ", "
+ << security_origin << ")";
+
+ blink::WebSetAudioOutputDeviceRequest* request_copy =
+ new blink::WebSetAudioOutputDeviceRequest(request);
+ if (audio_renderer_.get()) {
+ audio_renderer_->SwitchOutputDevice(
+ device_id_str,
+ security_origin,
+ base::Bind(&WebMediaPlayerMS::PrepareFinishSetAudioOutputRequest,
+ base::Unretained(this),
+ main_task_runner_,
+ request_copy));
+
+ } else {
+ request.finish(-1);
+ }
+}
+
+void WebMediaPlayerMS::FinishSetAudioOutputRequest(
+ blink::WebSetAudioOutputDeviceRequest *request,
+ int result) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ DVLOG(1) << __PRETTY_FUNCTION__;
+ request->finish(result);
+ delete request;
+}
+
+void WebMediaPlayerMS::PrepareFinishSetAudioOutputRequest(
+ WebMediaPlayerMS* media_player,
+ const scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ blink::WebSetAudioOutputDeviceRequest *request,
+ int result) {
+ DCHECK(!task_runner->BelongsToCurrentThread());
+ DVLOG(1) << __PRETTY_FUNCTION__;
+ // TODO(guidou): Change base::Unretained to a weak pointer
+ media_player->main_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&WebMediaPlayerMS::FinishSetAudioOutputRequest,
+ base::Unretained(media_player),
+ request,
+ result));
+}
+
+
void WebMediaPlayerMS::setPreload(WebMediaPlayer::Preload preload) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
}
bool WebMediaPlayerMS::hasVideo() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return (video_frame_provider_.get() != NULL);
}
bool WebMediaPlayerMS::hasAudio() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return (audio_renderer_.get() != NULL);
}
blink::WebSize WebMediaPlayerMS::naturalSize() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
gfx::Size size;
if (current_frame_.get())
@@ -284,22 +336,22 @@ blink::WebSize WebMediaPlayerMS::naturalSize() const {
}
bool WebMediaPlayerMS::paused() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return paused_;
}
bool WebMediaPlayerMS::seeking() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return false;
}
double WebMediaPlayerMS::duration() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return std::numeric_limits<double>::infinity();
}
double WebMediaPlayerMS::currentTime() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
if (current_time_.ToInternalValue() != 0) {
return current_time_.InSecondsF();
} else if (audio_renderer_.get()) {
@@ -309,29 +361,29 @@ double WebMediaPlayerMS::currentTime() const {
}
WebMediaPlayer::NetworkState WebMediaPlayerMS::networkState() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(1) << "WebMediaPlayerMS::networkState, state:" << network_state_;
return network_state_;
}
WebMediaPlayer::ReadyState WebMediaPlayerMS::readyState() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(1) << "WebMediaPlayerMS::readyState, state:" << ready_state_;
return ready_state_;
}
blink::WebTimeRanges WebMediaPlayerMS::buffered() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return buffered_;
}
blink::WebTimeRanges WebMediaPlayerMS::seekable() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return blink::WebTimeRanges();
}
bool WebMediaPlayerMS::didLoadingProgress() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return true;
}
@@ -340,7 +392,7 @@ void WebMediaPlayerMS::paint(blink::WebCanvas* canvas,
unsigned char alpha,
SkXfermode::Mode mode) {
DVLOG(3) << "WebMediaPlayerMS::paint";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
media::Context3D context_3d;
if (current_frame_.get() &&
@@ -365,12 +417,12 @@ void WebMediaPlayerMS::paint(blink::WebCanvas* canvas,
}
bool WebMediaPlayerMS::hasSingleSecurityOrigin() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return true;
}
bool WebMediaPlayerMS::didPassCORSAccessCheck() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
return true;
}
@@ -379,25 +431,25 @@ double WebMediaPlayerMS::mediaTimeForTimeValue(double timeValue) const {
}
unsigned WebMediaPlayerMS::decodedFrameCount() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(1) << "WebMediaPlayerMS::decodedFrameCount, " << total_frame_count_;
return total_frame_count_;
}
unsigned WebMediaPlayerMS::droppedFrameCount() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DVLOG(1) << "WebMediaPlayerMS::droppedFrameCount, " << dropped_frame_count_;
return dropped_frame_count_;
}
unsigned WebMediaPlayerMS::audioDecodedByteCount() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
NOTIMPLEMENTED();
return 0;
}
unsigned WebMediaPlayerMS::videoDecodedByteCount() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
NOTIMPLEMENTED();
return 0;
}
@@ -423,7 +475,7 @@ bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture(
bool premultiply_alpha,
bool flip_y) {
TRACE_EVENT0("media", "WebMediaPlayerMS:copyVideoTextureToPlatformTexture");
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
scoped_refptr<media::VideoFrame> video_frame;
{
@@ -484,7 +536,7 @@ void WebMediaPlayerMS::PutCurrentFrame() {
void WebMediaPlayerMS::OnFrameAvailable(
const scoped_refptr<media::VideoFrame>& frame) {
DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
++total_frame_count_;
if (!received_first_frame_) {
received_first_frame_ = true;
@@ -529,33 +581,33 @@ void WebMediaPlayerMS::OnFrameAvailable(
void WebMediaPlayerMS::RepaintInternal() {
DVLOG(1) << "WebMediaPlayerMS::RepaintInternal";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
GetClient()->repaint();
}
void WebMediaPlayerMS::OnSourceError() {
DVLOG(1) << "WebMediaPlayerMS::OnSourceError";
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
SetNetworkState(WebMediaPlayer::NetworkStateFormatError);
RepaintInternal();
}
void WebMediaPlayerMS::SetNetworkState(WebMediaPlayer::NetworkState state) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
network_state_ = state;
// Always notify to ensure client has the latest value.
GetClient()->networkStateChanged();
}
void WebMediaPlayerMS::SetReadyState(WebMediaPlayer::ReadyState state) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
ready_state_ = state;
// Always notify to ensure client has the latest value.
GetClient()->readyStateChanged();
}
blink::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
DCHECK(client_);
return client_;
}

Powered by Google App Engine
This is Rietveld 408576698