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 531311a00682af072f3e9288815bdcf91523670f..ef7038c70196dc06fa89da1eb537f20df812e842 100644 |
--- a/content/renderer/media/android/webmediaplayer_android.cc |
+++ b/content/renderer/media/android/webmediaplayer_android.cc |
@@ -154,6 +154,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
DCHECK(cdm_manager_); |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
+ stream_texture_factory_->AddObserver(this); |
player_id_ = player_manager_->RegisterMediaPlayer(this); |
@@ -195,6 +196,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, |
@@ -1195,7 +1198,7 @@ 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_) |
+ if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
video_frame_provider_client_->StopUsingProvider(); |
video_frame_provider_client_ = client; |
@@ -1234,6 +1237,27 @@ void WebMediaPlayerAndroid::PutCurrentFrame( |
const scoped_refptr<media::VideoFrame>& frame) { |
} |
+void WebMediaPlayerAndroid::ResetStreamTextureProxy() { |
+ DCHECK(main_thread_checker_.CalledOnValidThread()); |
+ |
+ 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()); |
+ stream_texture_proxy_initialized_ = false; |
+ |
+ TryCreateStreamTextureProxyIfNeeded(); |
+ if (needs_establish_peer_ && is_playing_) |
+ EstablishSurfaceTexturePeer(); |
+} |
+ |
void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
// Already created. |
@@ -1248,10 +1272,23 @@ void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
if (needs_establish_peer_ && stream_texture_proxy_) { |
DoCreateStreamTexture(); |
ReallocateVideoFrame(); |
+ |
+ base::WaitableEvent completion(true, false); |
boliu
2014/09/12 20:22:47
what if I add a "if (video_frame_provider_client_)
|
+ RenderThreadImpl::current()->compositor_message_loop_proxy()->PostTask( |
+ FROM_HERE, |
+ base::Bind( |
+ &WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread, |
+ base::Unretained(this), |
+ &completion)); |
+ completion.Wait(); |
} |
+} |
- if (stream_texture_proxy_ && video_frame_provider_client_) |
- stream_texture_proxy_->SetClient(video_frame_provider_client_); |
+void WebMediaPlayerAndroid::BindStreamTextureProxyOnCompositorThread( |
+ base::WaitableEvent* completion) { |
+ if (video_frame_provider_client_) |
+ SetVideoFrameProviderClient(video_frame_provider_client_); |
+ completion->Signal(); |
} |
void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |