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

Unified Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 532993002: work-in-progress patch to fix context lost black video (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more threading fix Created 6 years, 3 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/android/webmediaplayer_android.cc
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc
index 35e898e9bac8dba0ea903ec4571ad4eec8ade2cc..b13338269b9fcb17953e96ef98d12928f3ca562a 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -136,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),
@@ -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);
@@ -197,6 +197,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,
@@ -1212,21 +1214,14 @@ 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;
// 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;
- }
+ if (stream_texture_proxy_ && client) {
no sievers 2014/09/15 19:00:40 need to handle client == NULL also
boliu 2014/09/15 20:41:53 Done.
+ stream_texture_proxy_->BindToLoop(
+ stream_id_, client, base::MessageLoopProxy::current());
no sievers 2014/09/15 19:00:40 Call BindToLoop() before StopUsingProvider()
boliu 2014/09/15 20:41:53 Done. Realized can't call MLP::current() here
}
}
@@ -1251,6 +1246,26 @@ 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());
+
+ TryCreateStreamTextureProxyIfNeeded();
+ if (needs_establish_peer_ && is_playing_)
+ EstablishSurfaceTexturePeer();
+}
+
void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
DCHECK(main_thread_checker_.CalledOnValidThread());
// Already created.
@@ -1261,14 +1276,18 @@ void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
if (!stream_texture_factory_)
return;
+ // Not needed for hole punching.
+ if (!needs_establish_peer_)
+ return;
+
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_->BindToLoop(
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698