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/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "cc/layers/video_layer.h" | 10 #include "cc/layers/video_layer.h" |
11 #include "media/base/android/media_player_bridge.h" | 11 #include "media/base/android/media_player_bridge.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "net/base/mime_util.h" | 13 #include "net/base/mime_util.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" |
15 #include "webkit/compositor_bindings/web_layer_impl.h" | 15 #include "webkit/compositor_bindings/web_layer_impl.h" |
16 #include "webkit/media/android/stream_texture_factory_android.h" | 16 #include "webkit/media/android/stream_texture_factory_android.h" |
17 #include "webkit/media/android/webmediaplayer_manager_android.h" | 17 #include "webkit/media/android/webmediaplayer_manager_android.h" |
18 #include "webkit/media/media_switches.h" | 18 #include "webkit/media/media_switches.h" |
19 #include "webkit/media/webmediaplayer_util.h" | 19 #include "webkit/media/webmediaplayer_util.h" |
20 #include "webkit/media/webvideoframe_impl.h" | |
21 | 20 |
22 static const uint32 kGLTextureExternalOES = 0x8D65; | 21 static const uint32 kGLTextureExternalOES = 0x8D65; |
23 | 22 |
24 using WebKit::WebMediaPlayer; | 23 using WebKit::WebMediaPlayer; |
25 using WebKit::WebMediaSource; | 24 using WebKit::WebMediaSource; |
26 using WebKit::WebSize; | 25 using WebKit::WebSize; |
27 using WebKit::WebTimeRanges; | 26 using WebKit::WebTimeRanges; |
28 using WebKit::WebURL; | 27 using WebKit::WebURL; |
29 using WebKit::WebVideoFrame; | |
30 using media::MediaPlayerBridge; | 28 using media::MediaPlayerBridge; |
31 using media::VideoFrame; | 29 using media::VideoFrame; |
32 | 30 |
33 namespace webkit_media { | 31 namespace webkit_media { |
34 | 32 |
35 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 33 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
36 WebKit::WebMediaPlayerClient* client, | 34 WebKit::WebMediaPlayerClient* client, |
37 WebMediaPlayerManagerAndroid* manager, | 35 WebMediaPlayerManagerAndroid* manager, |
38 StreamTextureFactory* factory) | 36 StreamTextureFactory* factory) |
39 : client_(client), | 37 : client_(client), |
(...skipping 21 matching lines...) Expand all Loading... |
61 SetNeedsEstablishPeer(false); | 59 SetNeedsEstablishPeer(false); |
62 ReallocateVideoFrame(); | 60 ReallocateVideoFrame(); |
63 } else if (stream_texture_factory_.get()) { | 61 } else if (stream_texture_factory_.get()) { |
64 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 62 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
65 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 63 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
66 ReallocateVideoFrame(); | 64 ReallocateVideoFrame(); |
67 } | 65 } |
68 } | 66 } |
69 | 67 |
70 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 68 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
71 #ifdef REMOVE_WEBVIDEOFRAME | |
72 SetVideoFrameProviderClient(NULL); | 69 SetVideoFrameProviderClient(NULL); |
73 client_->setWebLayer(NULL); | 70 client_->setWebLayer(NULL); |
74 #endif | |
75 | 71 |
76 if (stream_id_) | 72 if (stream_id_) |
77 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 73 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
78 | 74 |
79 if (manager_) | 75 if (manager_) |
80 manager_->UnregisterMediaPlayer(player_id_); | 76 manager_->UnregisterMediaPlayer(player_id_); |
81 | 77 |
82 if (main_loop_) | 78 if (main_loop_) |
83 main_loop_->RemoveDestructionObserver(this); | 79 main_loop_->RemoveDestructionObserver(this); |
84 } | 80 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 return 0; | 285 return 0; |
290 } | 286 } |
291 | 287 |
292 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { | 288 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { |
293 if (url_.SchemeIs("file")) | 289 if (url_.SchemeIs("file")) |
294 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 290 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
295 | 291 |
296 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 292 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
297 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 293 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
298 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 294 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
299 #ifndef REMOVE_WEBVIDEOFRAME | |
300 } else { | |
301 // If the status is already set to ReadyStateHaveEnoughData, set it again | |
302 // to make sure that Videolayerchromium will get created. | |
303 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | |
304 #endif | |
305 } | 295 } |
306 | 296 |
307 #ifdef REMOVE_WEBVIDEOFRAME | |
308 if (hasVideo() && !video_weblayer_ && client_->needsWebLayerForVideo()) { | 297 if (hasVideo() && !video_weblayer_ && client_->needsWebLayerForVideo()) { |
309 video_weblayer_.reset( | 298 video_weblayer_.reset( |
310 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); | 299 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
311 client_->setWebLayer(video_weblayer_.get()); | 300 client_->setWebLayer(video_weblayer_.get()); |
312 } | 301 } |
313 #endif | |
314 | 302 |
315 // In we have skipped loading, we have to update webkit about the new | 303 // In we have skipped loading, we have to update webkit about the new |
316 // duration. | 304 // duration. |
317 if (duration_ != duration) { | 305 if (duration_ != duration) { |
318 duration_ = duration; | 306 duration_ = duration; |
319 client_->durationChanged(); | 307 client_->durationChanged(); |
320 } | 308 } |
321 } | 309 } |
322 | 310 |
323 void WebMediaPlayerAndroid::OnPlaybackComplete() { | 311 void WebMediaPlayerAndroid::OnPlaybackComplete() { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 #endif | 429 #endif |
442 } else if (texture_id_) { | 430 } else if (texture_id_) { |
443 current_frame_ = VideoFrame::WrapNativeTexture( | 431 current_frame_ = VideoFrame::WrapNativeTexture( |
444 texture_id_, kGLTextureExternalOES, natural_size_, | 432 texture_id_, kGLTextureExternalOES, natural_size_, |
445 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), | 433 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
446 VideoFrame::ReadPixelsCB(), | 434 VideoFrame::ReadPixelsCB(), |
447 base::Closure()); | 435 base::Closure()); |
448 } | 436 } |
449 } | 437 } |
450 | 438 |
451 #ifndef REMOVE_WEBVIDEOFRAME | |
452 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | |
453 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() && | |
454 stream_id_ && !needs_external_surface_) { | |
455 gfx::Size natural_size = current_frame_->natural_size(); | |
456 stream_texture_proxy_->Initialize( | |
457 stream_id_, natural_size.width(), natural_size.height()); | |
458 } | |
459 | |
460 return new WebVideoFrameImpl(current_frame_); | |
461 } | |
462 | |
463 void WebMediaPlayerAndroid::putCurrentFrame( | |
464 WebVideoFrame* web_video_frame) { | |
465 delete web_video_frame; | |
466 } | |
467 | |
468 void WebMediaPlayerAndroid::setStreamTextureClient( | |
469 WebKit::WebStreamTextureClient* client) { | |
470 if (stream_texture_proxy_.get()) | |
471 stream_texture_proxy_->SetClient(client); | |
472 } | |
473 #else | |
474 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 439 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
475 cc::VideoFrameProvider::Client* client) { | 440 cc::VideoFrameProvider::Client* client) { |
476 // This is called from both the main renderer thread and the compositor | 441 // This is called from both the main renderer thread and the compositor |
477 // thread (when the main thread is blocked). | 442 // thread (when the main thread is blocked). |
478 if (video_frame_provider_client_) | 443 if (video_frame_provider_client_) |
479 video_frame_provider_client_->StopUsingProvider(); | 444 video_frame_provider_client_->StopUsingProvider(); |
480 video_frame_provider_client_ = client; | 445 video_frame_provider_client_ = client; |
481 | 446 |
482 // Set the callback target when a frame is produced. | 447 // Set the callback target when a frame is produced. |
483 if (stream_texture_proxy_) | 448 if (stream_texture_proxy_) |
484 stream_texture_proxy_->SetClient(client); | 449 stream_texture_proxy_->SetClient(client); |
485 } | 450 } |
486 | 451 |
487 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | 452 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
488 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() && | 453 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() && |
489 stream_id_ && !needs_external_surface_) { | 454 stream_id_ && !needs_external_surface_) { |
490 gfx::Size natural_size = current_frame_->natural_size(); | 455 gfx::Size natural_size = current_frame_->natural_size(); |
491 stream_texture_proxy_->Initialize( | 456 stream_texture_proxy_->Initialize( |
492 stream_id_, natural_size.width(), natural_size.height()); | 457 stream_id_, natural_size.width(), natural_size.height()); |
493 } | 458 } |
494 return current_frame_; | 459 return current_frame_; |
495 } | 460 } |
496 | 461 |
497 void WebMediaPlayerAndroid::PutCurrentFrame( | 462 void WebMediaPlayerAndroid::PutCurrentFrame( |
498 const scoped_refptr<media::VideoFrame>& frame) { | 463 const scoped_refptr<media::VideoFrame>& frame) { |
499 } | 464 } |
500 #endif | |
501 | 465 |
502 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 466 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
503 if (stream_texture_factory_.get() && stream_id_) | 467 if (stream_texture_factory_.get() && stream_id_) |
504 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 468 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
505 needs_establish_peer_ = false; | 469 needs_establish_peer_ = false; |
506 } | 470 } |
507 | 471 |
508 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 472 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
509 needs_establish_peer_ = needs_establish_peer; | 473 needs_establish_peer_ = needs_establish_peer; |
510 } | 474 } |
511 | 475 |
512 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 476 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
513 is_playing_ = is_playing; | 477 is_playing_ = is_playing; |
514 } | 478 } |
515 | 479 |
516 } // namespace webkit_media | 480 } // namespace webkit_media |
OLD | NEW |