Index: webkit/media/android/webmediaplayer_android.cc |
diff --git a/webkit/media/android/webmediaplayer_android.cc b/webkit/media/android/webmediaplayer_android.cc |
index 5a1350234bdc5f60c3f96a8eff29f9412c36e885..feb0b907ec02c1f83b6fd672a53699d1092476fc 100644 |
--- a/webkit/media/android/webmediaplayer_android.cc |
+++ b/webkit/media/android/webmediaplayer_android.cc |
@@ -4,9 +4,11 @@ |
#include "webkit/media/android/webmediaplayer_android.h" |
+#include "base/command_line.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "media/base/android/media_player_bridge.h" |
+#include "media/base/media_switches.h" |
#include "media/base/video_frame.h" |
#include "net/base/mime_util.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.h" |
@@ -43,11 +45,16 @@ WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
is_playing_(false), |
needs_establish_peer_(true), |
has_size_info_(false), |
- stream_texture_factory_(factory) { |
+ stream_texture_factory_(factory), |
+ needs_external_surface_(false) { |
main_loop_->AddDestructionObserver(this); |
if (manager_) |
player_id_ = manager_->RegisterMediaPlayer(this); |
+ if (CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kUseExternalVideoSurface)) { |
+ SetNeedsExternalSurface(true); |
+ } |
if (stream_texture_factory_.get()) { |
stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
@@ -80,6 +87,10 @@ void WebMediaPlayerAndroid::cancelLoad() { |
} |
void WebMediaPlayerAndroid::play() { |
+ if (hasVideo() && needs_external_surface_) { |
+ DCHECK(!needs_establish_peer_); |
+ RequestExternalSurface(); |
+ } |
if (hasVideo() && needs_establish_peer_) |
EstablishSurfaceTexturePeer(); |
@@ -380,7 +391,16 @@ void WebMediaPlayerAndroid::Detach() { |
} |
void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
- if (texture_id_) { |
+ if (needs_external_surface_) { |
+ // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. |
+#if defined(GOOGLE_TV) |
+ if (!natural_size_.isEmpty()) |
+ video_frame_.reset(new WebVideoFrameImpl(VideoFrame::CreateHoleFrame( |
+ natural_size_))); |
+#else |
+ NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; |
+#endif |
+ } else if (texture_id_) { |
video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( |
texture_id_, kGLTextureExternalOES, natural_size_, |
gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
@@ -391,7 +411,7 @@ void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { |
if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() |
- && stream_id_) { |
+ && stream_id_ && !needs_external_surface_) { |
stream_texture_proxy_->Initialize( |
stream_id_, video_frame_->width(), video_frame_->height()); |
} |
@@ -423,4 +443,11 @@ void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
is_playing_ = is_playing; |
} |
+void WebMediaPlayerAndroid::SetNeedsExternalSurface( |
+ bool needs_external_surface) { |
+ needs_external_surface_ = needs_external_surface; |
+ SetNeedsEstablishPeer(!needs_external_surface); |
+ ReallocateVideoFrame(); |
+} |
+ |
} // namespace webkit_media |