Chromium Code Reviews| 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 67aa9b097a3ed7e1755f7f42697bd01a9ab5a5a3..d8449f5b92f7e2cfd99e53966638c61f2d4c39c7 100644 |
| --- a/content/renderer/media/android/webmediaplayer_android.cc |
| +++ b/content/renderer/media/android/webmediaplayer_android.cc |
| @@ -122,6 +122,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| client_(client), |
| delegate_(delegate), |
| buffered_(static_cast<size_t>(1)), |
| + stream_texture_proxy_initialized_(false), |
| media_task_runner_(task_runner), |
| ignore_metadata_duration_change_(false), |
| pending_seek_(false), |
| @@ -135,7 +136,6 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| 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), |
| @@ -153,6 +153,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
| DCHECK(cdm_manager_); |
| DCHECK(main_thread_checker_.CalledOnValidThread()); |
| + stream_texture_factory_->AddObserver(this); |
| player_id_ = player_manager_->RegisterMediaPlayer(this); |
| @@ -194,6 +195,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, |
| @@ -322,6 +325,44 @@ void WebMediaPlayerAndroid::play() { |
| UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
| } |
| +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(); |
| + SetNeedsEstablishPeer(true); |
| + |
| + TryCreateStreamTextureProxyIfNeeded(); |
| + if (hasVideo() && needs_establish_peer_ && |
| + !player_manager_->IsInFullscreen(frame_)) { |
| + EstablishSurfaceTexturePeer(); |
| + } |
| + |
| + { |
| + base::AutoLock auto_lock(current_frame_lock_); |
| + if (!stream_texture_proxy_initialized_) |
| + return; |
| + |
| + stream_texture_proxy_initialized_ = false; |
| + DCHECK(client_bound_loop_.get()); |
| + client_bound_loop_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebMediaPlayerAndroid::UpdateFrameOnClientThread, |
| + weak_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +void WebMediaPlayerAndroid::UpdateFrameOnClientThread() { |
| + if (video_frame_provider_client_) |
| + video_frame_provider_client_->DidReceiveFrame(); |
| +} |
| + |
| void WebMediaPlayerAndroid::pause() { |
| DCHECK(main_thread_checker_.CalledOnValidThread()); |
| Pause(true); |
| @@ -1217,9 +1258,17 @@ void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
| scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
| scoped_refptr<VideoFrame> video_frame; |
| + bool proxy_initialized = true; |
| { |
| base::AutoLock auto_lock(current_frame_lock_); |
| video_frame = current_frame_; |
| + proxy_initialized = stream_texture_proxy_initialized_; |
| + } |
| + |
| + if (!proxy_initialized) { |
| + SetVideoFrameProviderClient(video_frame_provider_client_); |
|
boliu
2014/09/08 15:31:10
Back in m37 days, we used to call BindToThread her
|
| + base::AutoLock auto_lock(current_frame_lock_); |
| + stream_texture_proxy_initialized_ = true; |
| } |
| return video_frame; |