Index: content/renderer/media/android/webmediaplayer_android.cc |
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc |
index 35e898e9bac8dba0ea903ec4571ad4eec8ade2cc..90687b14ab978c71d9430d6c613586f3f594d6af 100644 |
--- a/content/renderer/media/android/webmediaplayer_android.cc |
+++ b/content/renderer/media/android/webmediaplayer_android.cc |
@@ -133,15 +133,14 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
network_state_(WebMediaPlayer::NetworkStateEmpty), |
ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
texture_id_(0), |
- stream_id_(0), |
is_playing_(false), |
needs_establish_peer_(true), |
- stream_texture_proxy_initialized_(false), |
has_size_info_(false), |
stream_texture_factory_(factory), |
needs_external_surface_(false), |
has_valid_metadata_(false), |
video_frame_provider_client_(NULL), |
+ stream_id_(0), |
pending_playback_(false), |
player_type_(MEDIA_PLAYER_TYPE_URL), |
is_remote_(false), |
@@ -155,6 +154,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
DCHECK(cdm_manager_); |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
+ stream_texture_factory_->AddObserver(this); |
player_id_ = player_manager_->RegisterMediaPlayer(this); |
@@ -182,12 +182,15 @@ WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
player_manager_->UnregisterMediaPlayer(player_id_); |
} |
- if (stream_id_) { |
- GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
- gl->DeleteTextures(1, &texture_id_); |
- texture_id_ = 0; |
- texture_mailbox_ = gpu::Mailbox(); |
- stream_id_ = 0; |
+ { |
+ base::AutoLock lock(client_lock_); |
+ if (stream_id_) { |
+ GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
+ gl->DeleteTextures(1, &texture_id_); |
+ texture_id_ = 0; |
+ texture_mailbox_ = gpu::Mailbox(); |
+ stream_id_ = 0; |
+ } |
} |
{ |
@@ -197,6 +200,8 @@ WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
if (player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && delegate_) |
delegate_->PlayerGone(this); |
+ |
+ stream_texture_factory_->RemoveObserver(this); |
} |
void WebMediaPlayerAndroid::load(LoadType load_type, |
@@ -832,10 +837,19 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { |
needs_external_surface_ = true; |
if (!paused() && !player_manager_->IsInFullscreen(frame_)) |
player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); |
- } else if (stream_texture_proxy_ && !stream_id_) { |
- // Do deferred stream texture creation finally. |
- DoCreateStreamTexture(); |
- SetNeedsEstablishPeer(true); |
+ } else { |
+ bool has_proxy = false; |
+ bool has_stream_id = false; |
+ { |
+ base::AutoLock lock(client_lock_); |
+ has_proxy = !!stream_texture_proxy_.get(); |
+ has_stream_id = !!stream_id_; |
+ } |
+ if (has_proxy && !has_stream_id) { |
+ // Do deferred stream texture creation finally. |
+ DoCreateStreamTexture(); |
+ SetNeedsEstablishPeer(true); |
+ } |
} |
#endif // defined(VIDEO_HOLE) |
natural_size_.width = width; |
@@ -854,8 +868,11 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) { |
// For hidden video element (with style "display:none"), ensure the texture |
// size is set. |
if (!is_remote_ && cached_stream_texture_size_ != natural_size_) { |
- stream_texture_factory_->SetStreamTextureSize( |
- stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); |
+ { |
+ base::AutoLock lock(client_lock_); |
+ stream_texture_factory_->SetStreamTextureSize( |
+ stream_id_, gfx::Size(natural_size_.width, natural_size_.height)); |
+ } |
cached_stream_texture_size_ = natural_size_; |
} |
@@ -1210,23 +1227,15 @@ void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
cc::VideoFrameProvider::Client* client) { |
- // This is called from both the main renderer thread and the compositor |
- // thread (when the main thread is blocked). |
- if (video_frame_provider_client_) |
+ base::AutoLock lock(client_lock_); |
qinmin
2014/09/13 23:49:44
In video_frame_provider_client_impl.cc, it mention
boliu
2014/09/14 00:12:30
Daniel's pseudo code threw me off. Yeah I don't th
|
+ if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
video_frame_provider_client_->StopUsingProvider(); |
video_frame_provider_client_ = client; |
// Set the callback target when a frame is produced. |
if (stream_texture_proxy_) { |
- stream_texture_proxy_->SetClient(client); |
- // If client exists, the compositor thread calls it. At that time, |
- // stream_id_, needs_external_surface_, is_remote_ can be accessed because |
- // the main thread is blocked. |
- if (client && !stream_texture_proxy_initialized_ && stream_id_ && |
- !needs_external_surface_ && !is_remote_) { |
- stream_texture_proxy_->BindToCurrentThread(stream_id_); |
- stream_texture_proxy_initialized_ = true; |
- } |
+ stream_texture_proxy_->Bind( |
+ stream_id_, client, base::MessageLoopProxy::current()); |
} |
} |
@@ -1251,28 +1260,56 @@ void WebMediaPlayerAndroid::PutCurrentFrame( |
const scoped_refptr<media::VideoFrame>& frame) { |
} |
+void WebMediaPlayerAndroid::ResetStreamTextureProxy() { |
+ DCHECK(main_thread_checker_.CalledOnValidThread()); |
+ |
+ { |
+ base::AutoLock lock(client_lock_); |
+ if (stream_id_) { |
+ GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
+ gl->DeleteTextures(1, &texture_id_); |
+ texture_id_ = 0; |
+ texture_mailbox_ = gpu::Mailbox(); |
+ stream_id_ = 0; |
+ } |
+ stream_texture_proxy_.reset(); |
+ } |
+ needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && |
+ !player_manager_->IsInFullscreen(frame_) && |
+ (hasVideo() || IsHLSStream()); |
+ |
+ TryCreateStreamTextureProxyIfNeeded(); |
+ if (needs_establish_peer_ && is_playing_) |
+ EstablishSurfaceTexturePeer(); |
+} |
+ |
void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
- // Already created. |
- if (stream_texture_proxy_) |
- return; |
+ { |
+ // Already created. |
+ base::AutoLock lock(client_lock_); |
+ if (stream_texture_proxy_) |
+ return; |
+ } |
// No factory to create proxy. |
if (!stream_texture_factory_) |
return; |
+ base::AutoLock lock(client_lock_); |
stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
- if (needs_establish_peer_ && stream_texture_proxy_) { |
- DoCreateStreamTexture(); |
- ReallocateVideoFrame(); |
+ if (needs_establish_peer_ && stream_texture_proxy_ && |
+ video_frame_provider_client_) { |
+ stream_texture_proxy_->Bind( |
+ stream_id_, |
+ video_frame_provider_client_, |
+ RenderThreadImpl::current()->compositor_message_loop_proxy()); |
} |
- |
- if (stream_texture_proxy_ && video_frame_provider_client_) |
- stream_texture_proxy_->SetClient(video_frame_provider_client_); |
} |
void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
+ base::AutoLock lock(client_lock_); |
if (!stream_texture_proxy_) |
return; |
@@ -1290,6 +1327,7 @@ void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
} |
void WebMediaPlayerAndroid::DoCreateStreamTexture() { |
+ base::AutoLock lock(client_lock_); |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
DCHECK(!stream_id_); |
DCHECK(!texture_id_); |