| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/media/android/webmediaplayer_android.h" | 5 #include "webkit/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "media/base/android/media_player_bridge.h" | 10 #include "media/base/android/media_player_bridge.h" |
| 10 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
| 11 #include "net/base/mime_util.h" | 12 #include "net/base/mime_util.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" |
| 13 #include "webkit/media/android/stream_texture_factory_android.h" | 14 #include "webkit/media/android/stream_texture_factory_android.h" |
| 14 #include "webkit/media/android/webmediaplayer_manager_android.h" | 15 #include "webkit/media/android/webmediaplayer_manager_android.h" |
| 16 #include "webkit/media/media_switches.h" |
| 15 #include "webkit/media/webmediaplayer_util.h" | 17 #include "webkit/media/webmediaplayer_util.h" |
| 16 #include "webkit/media/webvideoframe_impl.h" | 18 #include "webkit/media/webvideoframe_impl.h" |
| 17 | 19 |
| 18 static const uint32 kGLTextureExternalOES = 0x8D65; | 20 static const uint32 kGLTextureExternalOES = 0x8D65; |
| 19 | 21 |
| 20 using WebKit::WebMediaPlayer; | 22 using WebKit::WebMediaPlayer; |
| 21 using WebKit::WebMediaSource; | 23 using WebKit::WebMediaSource; |
| 22 using WebKit::WebSize; | 24 using WebKit::WebSize; |
| 23 using WebKit::WebTimeRanges; | 25 using WebKit::WebTimeRanges; |
| 24 using WebKit::WebURL; | 26 using WebKit::WebURL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 main_loop_(MessageLoop::current()), | 39 main_loop_(MessageLoop::current()), |
| 38 pending_seek_(0), | 40 pending_seek_(0), |
| 39 seeking_(false), | 41 seeking_(false), |
| 40 did_loading_progress_(false), | 42 did_loading_progress_(false), |
| 41 manager_(manager), | 43 manager_(manager), |
| 42 network_state_(WebMediaPlayer::NetworkStateEmpty), | 44 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 43 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 45 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 44 is_playing_(false), | 46 is_playing_(false), |
| 45 needs_establish_peer_(true), | 47 needs_establish_peer_(true), |
| 46 has_size_info_(false), | 48 has_size_info_(false), |
| 47 stream_texture_factory_(factory) { | 49 stream_texture_factory_(factory), |
| 50 needs_external_surface_(false) { |
| 48 main_loop_->AddDestructionObserver(this); | 51 main_loop_->AddDestructionObserver(this); |
| 49 if (manager_) | 52 if (manager_) |
| 50 player_id_ = manager_->RegisterMediaPlayer(this); | 53 player_id_ = manager_->RegisterMediaPlayer(this); |
| 51 | 54 |
| 52 if (stream_texture_factory_.get()) { | 55 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 switches::kUseExternalVideoSurface)) { |
| 57 needs_external_surface_ = true; |
| 58 SetNeedsEstablishPeer(false); |
| 59 ReallocateVideoFrame(); |
| 60 } else if (stream_texture_factory_.get()) { |
| 53 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 61 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 54 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 62 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
| 55 ReallocateVideoFrame(); | 63 ReallocateVideoFrame(); |
| 56 } | 64 } |
| 57 } | 65 } |
| 58 | 66 |
| 59 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 67 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 60 if (stream_id_) | 68 if (stream_id_) |
| 61 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 69 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
| 62 | 70 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 80 WebMediaSource* media_source, | 88 WebMediaSource* media_source, |
| 81 CORSMode cors_mode) { | 89 CORSMode cors_mode) { |
| 82 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
| 83 } | 91 } |
| 84 | 92 |
| 85 void WebMediaPlayerAndroid::cancelLoad() { | 93 void WebMediaPlayerAndroid::cancelLoad() { |
| 86 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
| 87 } | 95 } |
| 88 | 96 |
| 89 void WebMediaPlayerAndroid::play() { | 97 void WebMediaPlayerAndroid::play() { |
| 98 if (hasVideo() && needs_external_surface_) { |
| 99 DCHECK(!needs_establish_peer_); |
| 100 RequestExternalSurface(); |
| 101 } |
| 90 if (hasVideo() && needs_establish_peer_) | 102 if (hasVideo() && needs_establish_peer_) |
| 91 EstablishSurfaceTexturePeer(); | 103 EstablishSurfaceTexturePeer(); |
| 92 | 104 |
| 93 PlayInternal(); | 105 PlayInternal(); |
| 94 is_playing_ = true; | 106 is_playing_ = true; |
| 95 } | 107 } |
| 96 | 108 |
| 97 void WebMediaPlayerAndroid::pause() { | 109 void WebMediaPlayerAndroid::pause() { |
| 98 PauseInternal(); | 110 PauseInternal(); |
| 99 is_playing_ = false; | 111 is_playing_ = false; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 406 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
| 395 stream_id_ = 0; | 407 stream_id_ = 0; |
| 396 } | 408 } |
| 397 | 409 |
| 398 web_video_frame_.reset(); | 410 web_video_frame_.reset(); |
| 399 | 411 |
| 400 manager_ = NULL; | 412 manager_ = NULL; |
| 401 } | 413 } |
| 402 | 414 |
| 403 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 415 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
| 404 if (texture_id_) { | 416 if (needs_external_surface_) { |
| 417 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. |
| 418 #if defined(GOOGLE_TV) |
| 419 if (!natural_size_.isEmpty()) { |
| 420 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::CreateHoleFrame( |
| 421 natural_size_))); |
| 422 } |
| 423 #else |
| 424 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; |
| 425 #endif |
| 426 } else if (texture_id_) { |
| 405 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( | 427 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( |
| 406 texture_id_, kGLTextureExternalOES, natural_size_, | 428 texture_id_, kGLTextureExternalOES, natural_size_, |
| 407 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), | 429 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
| 408 VideoFrame::ReadPixelsCB(), | 430 VideoFrame::ReadPixelsCB(), |
| 409 base::Closure()))); | 431 base::Closure()))); |
| 410 } | 432 } |
| 411 } | 433 } |
| 412 | 434 |
| 413 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | 435 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { |
| 414 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() | 436 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() |
| 415 && stream_id_) { | 437 && stream_id_ && !needs_external_surface_) { |
| 416 gfx::Size natural_size = web_video_frame_->video_frame->natural_size(); | 438 gfx::Size natural_size = web_video_frame_->video_frame->natural_size(); |
| 417 stream_texture_proxy_->Initialize( | 439 stream_texture_proxy_->Initialize( |
| 418 stream_id_, natural_size.width(), natural_size.height()); | 440 stream_id_, natural_size.width(), natural_size.height()); |
| 419 } | 441 } |
| 420 | 442 |
| 421 return web_video_frame_.get(); | 443 return web_video_frame_.get(); |
| 422 } | 444 } |
| 423 | 445 |
| 424 void WebMediaPlayerAndroid::putCurrentFrame( | 446 void WebMediaPlayerAndroid::putCurrentFrame( |
| 425 WebVideoFrame* web_video_frame) { | 447 WebVideoFrame* web_video_frame) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 439 | 461 |
| 440 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 462 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
| 441 needs_establish_peer_ = needs_establish_peer; | 463 needs_establish_peer_ = needs_establish_peer; |
| 442 } | 464 } |
| 443 | 465 |
| 444 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 466 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
| 445 is_playing_ = is_playing; | 467 is_playing_ = is_playing; |
| 446 } | 468 } |
| 447 | 469 |
| 448 } // namespace webkit_media | 470 } // namespace webkit_media |
| OLD | NEW |