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/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "cc/layers/video_layer.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" |
| 14 #include "webkit/compositor_bindings/web_layer_impl.h" |
13 #include "webkit/media/android/stream_texture_factory_android.h" | 15 #include "webkit/media/android/stream_texture_factory_android.h" |
14 #include "webkit/media/android/webmediaplayer_manager_android.h" | 16 #include "webkit/media/android/webmediaplayer_manager_android.h" |
15 #include "webkit/media/webmediaplayer_util.h" | 17 #include "webkit/media/webmediaplayer_util.h" |
16 #include "webkit/media/webvideoframe_impl.h" | |
17 | 18 |
18 static const uint32 kGLTextureExternalOES = 0x8D65; | 19 static const uint32 kGLTextureExternalOES = 0x8D65; |
19 | 20 |
20 using WebKit::WebMediaPlayer; | 21 using WebKit::WebMediaPlayer; |
21 using WebKit::WebMediaSource; | 22 using WebKit::WebMediaSource; |
22 using WebKit::WebSize; | 23 using WebKit::WebSize; |
23 using WebKit::WebTimeRanges; | 24 using WebKit::WebTimeRanges; |
24 using WebKit::WebURL; | 25 using WebKit::WebURL; |
25 using WebKit::WebVideoFrame; | |
26 using media::MediaPlayerBridge; | 26 using media::MediaPlayerBridge; |
27 using media::VideoFrame; | 27 using media::VideoFrame; |
28 | 28 |
29 namespace webkit_media { | 29 namespace webkit_media { |
30 | 30 |
31 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 31 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
32 WebKit::WebMediaPlayerClient* client, | 32 WebKit::WebMediaPlayerClient* client, |
33 WebMediaPlayerManagerAndroid* manager, | 33 WebMediaPlayerManagerAndroid* manager, |
34 StreamTextureFactory* factory) | 34 StreamTextureFactory* factory) |
35 : client_(client), | 35 : client_(client), |
36 buffered_(1u), | 36 buffered_(1u), |
37 main_loop_(MessageLoop::current()), | 37 main_loop_(MessageLoop::current()), |
38 pending_seek_(0), | 38 pending_seek_(0), |
39 seeking_(false), | 39 seeking_(false), |
40 did_loading_progress_(false), | 40 did_loading_progress_(false), |
41 manager_(manager), | 41 manager_(manager), |
42 network_state_(WebMediaPlayer::NetworkStateEmpty), | 42 network_state_(WebMediaPlayer::NetworkStateEmpty), |
43 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 43 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
44 is_playing_(false), | 44 is_playing_(false), |
45 needs_establish_peer_(true), | 45 needs_establish_peer_(true), |
46 has_size_info_(false), | 46 has_size_info_(false), |
47 stream_texture_factory_(factory) { | 47 stream_texture_factory_(factory), |
| 48 video_frame_provider_client_(NULL) { |
48 main_loop_->AddDestructionObserver(this); | 49 main_loop_->AddDestructionObserver(this); |
49 if (manager_) | 50 if (manager_) |
50 player_id_ = manager_->RegisterMediaPlayer(this); | 51 player_id_ = manager_->RegisterMediaPlayer(this); |
51 | 52 |
52 if (stream_texture_factory_.get()) { | 53 if (stream_texture_factory_.get()) { |
53 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 54 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
54 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 55 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
55 ReallocateVideoFrame(); | 56 ReallocateVideoFrame(); |
56 } | 57 } |
57 } | 58 } |
58 | 59 |
59 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 60 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 61 SetVideoFrameProviderClient(NULL); |
| 62 client_->setWebLayer(NULL); |
| 63 |
60 if (stream_id_) | 64 if (stream_id_) |
61 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 65 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
62 | 66 |
63 if (manager_) | 67 if (manager_) |
64 manager_->UnregisterMediaPlayer(player_id_); | 68 manager_->UnregisterMediaPlayer(player_id_); |
65 | 69 |
66 if (main_loop_) | 70 if (main_loop_) |
67 main_loop_->RemoveDestructionObserver(this); | 71 main_loop_->RemoveDestructionObserver(this); |
68 } | 72 } |
69 | 73 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return 0; | 273 return 0; |
270 } | 274 } |
271 | 275 |
272 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { | 276 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { |
273 if (url_.SchemeIs("file")) | 277 if (url_.SchemeIs("file")) |
274 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 278 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
275 | 279 |
276 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 280 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
277 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 281 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
278 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 282 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
279 } else { | 283 } |
280 // If the status is already set to ReadyStateHaveEnoughData, set it again | 284 |
281 // to make sure that Videolayerchromium will get created. | 285 if (hasVideo() && !video_weblayer_) { |
282 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 286 video_weblayer_.reset( |
| 287 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 288 client_->setWebLayer(video_weblayer_.get()); |
283 } | 289 } |
284 | 290 |
285 // In we have skipped loading, we have to update webkit about the new | 291 // In we have skipped loading, we have to update webkit about the new |
286 // duration. | 292 // duration. |
287 if (duration_ != duration) { | 293 if (duration_ != duration) { |
288 duration_ = duration; | 294 duration_ = duration; |
289 client_->durationChanged(); | 295 client_->durationChanged(); |
290 } | 296 } |
291 } | 297 } |
292 | 298 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 } | 394 } |
389 | 395 |
390 void WebMediaPlayerAndroid::Detach() { | 396 void WebMediaPlayerAndroid::Detach() { |
391 Destroy(); | 397 Destroy(); |
392 | 398 |
393 if (stream_id_) { | 399 if (stream_id_) { |
394 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 400 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
395 stream_id_ = 0; | 401 stream_id_ = 0; |
396 } | 402 } |
397 | 403 |
398 web_video_frame_.reset(); | 404 current_frame_ = NULL; |
399 | 405 |
400 manager_ = NULL; | 406 manager_ = NULL; |
401 } | 407 } |
402 | 408 |
403 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 409 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
404 if (texture_id_) { | 410 if (texture_id_) { |
405 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( | 411 current_frame_ = VideoFrame::WrapNativeTexture( |
406 texture_id_, kGLTextureExternalOES, natural_size_, | 412 texture_id_, kGLTextureExternalOES, natural_size_, |
407 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), | 413 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
408 VideoFrame::ReadPixelsCB(), | 414 VideoFrame::ReadPixelsCB(), |
409 base::Closure()))); | 415 base::Closure()); |
410 } | 416 } |
411 } | 417 } |
412 | 418 |
413 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | 419 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
414 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() | 420 cc::VideoFrameProvider::Client* client) { |
| 421 // This is called from both the main renderer thread and the compositor |
| 422 // thread (when the main thread is blocked). |
| 423 if (video_frame_provider_client_) |
| 424 video_frame_provider_client_->StopUsingProvider(); |
| 425 video_frame_provider_client_ = client; |
| 426 |
| 427 // Set the callback target when a frame is produced. |
| 428 if (stream_texture_proxy_) |
| 429 stream_texture_proxy_->SetClient(client); |
| 430 } |
| 431 |
| 432 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
| 433 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() |
415 && stream_id_) { | 434 && stream_id_) { |
416 gfx::Size natural_size = web_video_frame_->video_frame->natural_size(); | 435 gfx::Size natural_size = current_frame_->natural_size(); |
417 stream_texture_proxy_->Initialize( | 436 stream_texture_proxy_->Initialize( |
418 stream_id_, natural_size.width(), natural_size.height()); | 437 stream_id_, natural_size.width(), natural_size.height()); |
419 } | 438 } |
420 | 439 return current_frame_; |
421 return web_video_frame_.get(); | |
422 } | 440 } |
423 | 441 |
424 void WebMediaPlayerAndroid::putCurrentFrame( | 442 void WebMediaPlayerAndroid::PutCurrentFrame( |
425 WebVideoFrame* web_video_frame) { | 443 const scoped_refptr<media::VideoFrame>& frame) { |
426 } | |
427 | |
428 void WebMediaPlayerAndroid::setStreamTextureClient( | |
429 WebKit::WebStreamTextureClient* client) { | |
430 if (stream_texture_proxy_.get()) | |
431 stream_texture_proxy_->SetClient(client); | |
432 } | 444 } |
433 | 445 |
434 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 446 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
435 if (stream_texture_factory_.get() && stream_id_) | 447 if (stream_texture_factory_.get() && stream_id_) |
436 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 448 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
437 needs_establish_peer_ = false; | 449 needs_establish_peer_ = false; |
438 } | 450 } |
439 | 451 |
440 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 452 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
441 needs_establish_peer_ = needs_establish_peer; | 453 needs_establish_peer_ = needs_establish_peer; |
442 } | 454 } |
443 | 455 |
444 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 456 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
445 is_playing_ = is_playing; | 457 is_playing_ = is_playing; |
446 } | 458 } |
447 | 459 |
448 } // namespace webkit_media | 460 } // namespace webkit_media |
OLD | NEW |