summaryrefslogtreecommitdiffstats
path: root/content/renderer/media
diff options
context:
space:
mode:
authorboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-12 00:16:39 +0000
committerboliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-12 00:16:39 +0000
commit0f7cb9dfca0054cd119f2e2e4055e551a206c224 (patch)
tree5fd5744b91abfbc14963a0f2086dd9fd206f6927 /content/renderer/media
parent0f6c7394cf22ac3a11ac946d92e0d22790af2ec0 (diff)
downloadchromium_src-0f7cb9dfca0054cd119f2e2e4055e551a206c224.zip
chromium_src-0f7cb9dfca0054cd119f2e2e4055e551a206c224.tar.gz
chromium_src-0f7cb9dfca0054cd119f2e2e4055e551a206c224.tar.bz2
[Android] Retry create StreamTextureProxy on play
In android webview, StreamTextureProxy cannot be created until the page has entered hardware accelerated mode. This can usually be racy between when the WebMediaPlayerAndroid is first create. In this patch, retry to create the StreamTextureProxy in play, to help reduce the possiblility of this race. Internal bug b/11158022 BUG= NOTRY=true Review URL: https://codereview.chromium.org/26315010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/media')
-rw-r--r--content/renderer/media/android/stream_texture_factory_android_synchronous_impl.cc9
-rw-r--r--content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h10
-rw-r--r--content/renderer/media/android/webmediaplayer_android.cc56
-rw-r--r--content/renderer/media/android/webmediaplayer_android.h3
4 files changed, 53 insertions, 25 deletions
diff --git a/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.cc b/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.cc
index 575bfa6..c109428 100644
--- a/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.cc
+++ b/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.cc
@@ -117,14 +117,19 @@ void StreamTextureProxyImpl::OnFrameAvailable() {
} // namespace
StreamTextureFactorySynchronousImpl::StreamTextureFactorySynchronousImpl(
- ContextProvider* context_provider,
+ const CreateContextProviderCallback& try_create_callback,
int view_id)
- : context_provider_(context_provider), view_id_(view_id) {}
+ : create_context_provider_callback_(try_create_callback),
+ context_provider_(create_context_provider_callback_.Run()),
+ view_id_(view_id) {}
StreamTextureFactorySynchronousImpl::~StreamTextureFactorySynchronousImpl() {}
StreamTextureProxy* StreamTextureFactorySynchronousImpl::CreateProxy() {
if (!context_provider_)
+ context_provider_ = create_context_provider_callback_.Run();
+
+ if (!context_provider_)
return NULL;
return new StreamTextureProxyImpl(context_provider_);
}
diff --git a/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h b/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h
index 8b6ab6f..19d1016 100644
--- a/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h
+++ b/content/renderer/media/android/stream_texture_factory_android_synchronous_impl.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_SYNCHRONOUS_IMPL_H_
#define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_SYNCHRONOUS_IMPL_H_
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "content/renderer/media/android/stream_texture_factory_android.h"
@@ -33,8 +34,12 @@ class StreamTextureFactorySynchronousImpl : public StreamTextureFactory {
virtual ~ContextProvider() {}
};
- StreamTextureFactorySynchronousImpl(ContextProvider* context_provider,
- int view_id);
+ typedef base::Callback<scoped_refptr<ContextProvider>(void)>
+ CreateContextProviderCallback;
+
+ StreamTextureFactorySynchronousImpl(
+ const CreateContextProviderCallback& try_create_callback,
+ int view_id);
virtual ~StreamTextureFactorySynchronousImpl();
virtual StreamTextureProxy* CreateProxy() OVERRIDE;
@@ -49,6 +54,7 @@ class StreamTextureFactorySynchronousImpl : public StreamTextureFactory {
const gfx::Size& size) OVERRIDE;
private:
+ CreateContextProviderCallback create_context_provider_callback_;
scoped_refptr<ContextProvider> context_provider_;
int view_id_;
diff --git a/content/renderer/media/android/webmediaplayer_android.cc b/content/renderer/media/android/webmediaplayer_android.cc
index 9463f88..91e2763 100644
--- a/content/renderer/media/android/webmediaplayer_android.cc
+++ b/content/renderer/media/android/webmediaplayer_android.cc
@@ -126,17 +126,7 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid(
needs_establish_peer_ = false;
current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1));
#endif
- if (stream_texture_factory_) {
- stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
- if (needs_establish_peer_ && stream_texture_proxy_) {
- stream_id_ = stream_texture_factory_->CreateStreamTexture(
- kGLTextureExternalOES,
- &texture_id_,
- &texture_mailbox_,
- &texture_mailbox_sync_point_);
- ReallocateVideoFrame();
- }
- }
+ TryCreateStreamTextureProxyIfNeeded();
if (WebKit::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled()) {
// TODO(xhwang): Report an error when there is encrypted stream but EME is
@@ -318,6 +308,8 @@ void WebMediaPlayerAndroid::play() {
if (audio_renderer_ && paused())
audio_renderer_->Play();
#endif
+
+ TryCreateStreamTextureProxyIfNeeded();
if (hasVideo() && needs_establish_peer_)
EstablishSurfaceTexturePeer();
@@ -719,11 +711,7 @@ void WebMediaPlayerAndroid::OnVideoSizeChanged(int width, int height) {
proxy_->RequestExternalSurface(player_id_, last_computed_rect_);
} else if (stream_texture_factory_ && !stream_id_) {
// Do deferred stream texture creation finally.
- stream_id_ = stream_texture_factory_->CreateStreamTexture(
- kGLTextureExternalOES,
- &texture_id_,
- &texture_mailbox_,
- &texture_mailbox_sync_point_);
+ DoCreateStreamTexture();
if (paused()) {
SetNeedsEstablishPeer(true);
} else {
@@ -924,6 +912,25 @@ void WebMediaPlayerAndroid::PutCurrentFrame(
const scoped_refptr<media::VideoFrame>& frame) {
}
+void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() {
+ // Already created.
+ if (stream_texture_proxy_)
+ return;
+
+ // No factory to create proxy.
+ if (!stream_texture_factory_)
+ return;
+
+ stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
+ if (needs_establish_peer_ && stream_texture_proxy_) {
+ DoCreateStreamTexture();
+ ReallocateVideoFrame();
+ }
+
+ if (stream_texture_proxy_ && video_frame_provider_client_)
+ stream_texture_proxy_->SetClient(video_frame_provider_client_);
+}
+
void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
if (!stream_texture_proxy_)
return;
@@ -936,11 +943,7 @@ void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
texture_id_ = 0;
texture_mailbox_ = gpu::Mailbox();
texture_mailbox_sync_point_ = 0;
- stream_id_ = stream_texture_factory_->CreateStreamTexture(
- kGLTextureExternalOES,
- &texture_id_,
- &texture_mailbox_,
- &texture_mailbox_sync_point_);
+ DoCreateStreamTexture();
ReallocateVideoFrame();
stream_texture_proxy_initialized_ = false;
}
@@ -949,6 +952,17 @@ void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() {
needs_establish_peer_ = false;
}
+void WebMediaPlayerAndroid::DoCreateStreamTexture() {
+ DCHECK(!stream_id_);
+ DCHECK(!texture_id_);
+ DCHECK(!texture_mailbox_sync_point_);
+ stream_id_ = stream_texture_factory_->CreateStreamTexture(
+ kGLTextureExternalOES,
+ &texture_id_,
+ &texture_mailbox_,
+ &texture_mailbox_sync_point_);
+}
+
void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) {
needs_establish_peer_ = needs_establish_peer;
}
diff --git a/content/renderer/media/android/webmediaplayer_android.h b/content/renderer/media/android/webmediaplayer_android.h
index 636d3c2..994eda9 100644
--- a/content/renderer/media/android/webmediaplayer_android.h
+++ b/content/renderer/media/android/webmediaplayer_android.h
@@ -238,6 +238,9 @@ class WebMediaPlayerAndroid
// Helper methods for posting task for setting states and update WebKit.
void UpdateNetworkState(WebKit::WebMediaPlayer::NetworkState state);
void UpdateReadyState(WebKit::WebMediaPlayer::ReadyState state);
+ void TryCreateStreamTextureProxyIfNeeded();
+ void DoCreateStreamTexture();
+
// Helper method to reestablish the surface texture peer for android
// media player.