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 "media/base/android/media_player_bridge.h" | 11 #include "media/base/android/media_player_bridge.h" |
11 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
12 #include "net/base/mime_util.h" | 13 #include "net/base/mime_util.h" |
13 #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" |
14 #include "webkit/media/android/stream_texture_factory_android.h" | 16 #include "webkit/media/android/stream_texture_factory_android.h" |
15 #include "webkit/media/android/webmediaplayer_manager_android.h" | 17 #include "webkit/media/android/webmediaplayer_manager_android.h" |
16 #include "webkit/media/media_switches.h" | 18 #include "webkit/media/media_switches.h" |
17 #include "webkit/media/webmediaplayer_util.h" | 19 #include "webkit/media/webmediaplayer_util.h" |
18 #include "webkit/media/webvideoframe_impl.h" | 20 #include "webkit/media/webvideoframe_impl.h" |
19 | 21 |
20 static const uint32 kGLTextureExternalOES = 0x8D65; | 22 static const uint32 kGLTextureExternalOES = 0x8D65; |
21 | 23 |
22 using WebKit::WebMediaPlayer; | 24 using WebKit::WebMediaPlayer; |
23 using WebKit::WebMediaSource; | 25 using WebKit::WebMediaSource; |
(...skipping 16 matching lines...) Expand all Loading... |
40 pending_seek_(0), | 42 pending_seek_(0), |
41 seeking_(false), | 43 seeking_(false), |
42 did_loading_progress_(false), | 44 did_loading_progress_(false), |
43 manager_(manager), | 45 manager_(manager), |
44 network_state_(WebMediaPlayer::NetworkStateEmpty), | 46 network_state_(WebMediaPlayer::NetworkStateEmpty), |
45 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 47 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
46 is_playing_(false), | 48 is_playing_(false), |
47 needs_establish_peer_(true), | 49 needs_establish_peer_(true), |
48 has_size_info_(false), | 50 has_size_info_(false), |
49 stream_texture_factory_(factory), | 51 stream_texture_factory_(factory), |
50 needs_external_surface_(false) { | 52 needs_external_surface_(false), |
| 53 video_frame_provider_client_(NULL) { |
51 main_loop_->AddDestructionObserver(this); | 54 main_loop_->AddDestructionObserver(this); |
52 if (manager_) | 55 if (manager_) |
53 player_id_ = manager_->RegisterMediaPlayer(this); | 56 player_id_ = manager_->RegisterMediaPlayer(this); |
54 | 57 |
55 if (CommandLine::ForCurrentProcess()->HasSwitch( | 58 if (CommandLine::ForCurrentProcess()->HasSwitch( |
56 switches::kUseExternalVideoSurface)) { | 59 switches::kUseExternalVideoSurface)) { |
57 needs_external_surface_ = true; | 60 needs_external_surface_ = true; |
58 SetNeedsEstablishPeer(false); | 61 SetNeedsEstablishPeer(false); |
59 ReallocateVideoFrame(); | 62 ReallocateVideoFrame(); |
60 } else if (stream_texture_factory_.get()) { | 63 } else if (stream_texture_factory_.get()) { |
61 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 64 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
62 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 65 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
63 ReallocateVideoFrame(); | 66 ReallocateVideoFrame(); |
64 } | 67 } |
65 } | 68 } |
66 | 69 |
67 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 70 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 71 #ifdef REMOVE_WEBVIDEOFRAME |
| 72 SetVideoFrameProviderClient(NULL); |
| 73 client_->setWebLayer(NULL); |
| 74 #endif |
| 75 |
68 if (stream_id_) | 76 if (stream_id_) |
69 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 77 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
70 | 78 |
71 if (manager_) | 79 if (manager_) |
72 manager_->UnregisterMediaPlayer(player_id_); | 80 manager_->UnregisterMediaPlayer(player_id_); |
73 | 81 |
74 if (main_loop_) | 82 if (main_loop_) |
75 main_loop_->RemoveDestructionObserver(this); | 83 main_loop_->RemoveDestructionObserver(this); |
76 } | 84 } |
77 | 85 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return 0; | 289 return 0; |
282 } | 290 } |
283 | 291 |
284 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { | 292 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { |
285 if (url_.SchemeIs("file")) | 293 if (url_.SchemeIs("file")) |
286 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 294 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
287 | 295 |
288 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 296 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
289 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 297 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
290 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 298 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 299 #ifndef REMOVE_WEBVIDEOFRAME |
291 } else { | 300 } else { |
292 // If the status is already set to ReadyStateHaveEnoughData, set it again | 301 // If the status is already set to ReadyStateHaveEnoughData, set it again |
293 // to make sure that Videolayerchromium will get created. | 302 // to make sure that Videolayerchromium will get created. |
294 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 303 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 304 #endif |
295 } | 305 } |
296 | 306 |
| 307 #ifdef REMOVE_WEBVIDEOFRAME |
| 308 if (hasVideo() && !video_weblayer_ && client->needsWebLayerForVideo()) { |
| 309 video_weblayer_.reset( |
| 310 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 311 client_->setWebLayer(video_weblayer_.get()); |
| 312 } |
| 313 #endif |
| 314 |
297 // In we have skipped loading, we have to update webkit about the new | 315 // In we have skipped loading, we have to update webkit about the new |
298 // duration. | 316 // duration. |
299 if (duration_ != duration) { | 317 if (duration_ != duration) { |
300 duration_ = duration; | 318 duration_ = duration; |
301 client_->durationChanged(); | 319 client_->durationChanged(); |
302 } | 320 } |
303 } | 321 } |
304 | 322 |
305 void WebMediaPlayerAndroid::OnPlaybackComplete() { | 323 void WebMediaPlayerAndroid::OnPlaybackComplete() { |
306 // When playback is about to finish, android media player often stops | 324 // When playback is about to finish, android media player often stops |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 418 } |
401 | 419 |
402 void WebMediaPlayerAndroid::Detach() { | 420 void WebMediaPlayerAndroid::Detach() { |
403 Destroy(); | 421 Destroy(); |
404 | 422 |
405 if (stream_id_) { | 423 if (stream_id_) { |
406 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 424 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
407 stream_id_ = 0; | 425 stream_id_ = 0; |
408 } | 426 } |
409 | 427 |
410 web_video_frame_.reset(); | 428 current_frame_ = NULL; |
411 | 429 |
412 manager_ = NULL; | 430 manager_ = NULL; |
413 } | 431 } |
414 | 432 |
415 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 433 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
416 if (needs_external_surface_) { | 434 if (needs_external_surface_) { |
417 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. | 435 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. |
418 #if defined(GOOGLE_TV) | 436 #if defined(GOOGLE_TV) |
419 if (!natural_size_.isEmpty()) { | 437 if (!natural_size_.isEmpty()) |
420 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::CreateHoleFrame( | 438 current_frame_ = VideoFrame::CreateHoleFrame(natural_size_); |
421 natural_size_))); | |
422 } | |
423 #else | 439 #else |
424 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; | 440 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; |
425 #endif | 441 #endif |
426 } else if (texture_id_) { | 442 } else if (texture_id_) { |
427 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( | 443 current_frame_ = VideoFrame::WrapNativeTexture( |
428 texture_id_, kGLTextureExternalOES, natural_size_, | 444 texture_id_, kGLTextureExternalOES, natural_size_, |
429 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), | 445 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
430 VideoFrame::ReadPixelsCB(), | 446 VideoFrame::ReadPixelsCB(), |
431 base::Closure()))); | 447 base::Closure()); |
432 } | 448 } |
433 } | 449 } |
434 | 450 |
| 451 #ifndef REMOVE_WEBVIDEOFRAME |
435 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | 452 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { |
436 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() | 453 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() && |
437 && stream_id_ && !needs_external_surface_) { | 454 stream_id_ && !needs_external_surface_) { |
438 gfx::Size natural_size = web_video_frame_->video_frame->natural_size(); | 455 gfx::Size natural_size = current_frame_->natural_size(); |
439 stream_texture_proxy_->Initialize( | 456 stream_texture_proxy_->Initialize( |
440 stream_id_, natural_size.width(), natural_size.height()); | 457 stream_id_, natural_size.width(), natural_size.height()); |
441 } | 458 } |
442 | 459 |
443 return web_video_frame_.get(); | 460 return new WebVideoFrameImpl(current_frame_); |
444 } | 461 } |
445 | 462 |
446 void WebMediaPlayerAndroid::putCurrentFrame( | 463 void WebMediaPlayerAndroid::putCurrentFrame( |
447 WebVideoFrame* web_video_frame) { | 464 WebVideoFrame* web_video_frame) { |
| 465 delete web_video_frame; |
448 } | 466 } |
449 | 467 |
450 void WebMediaPlayerAndroid::setStreamTextureClient( | 468 void WebMediaPlayerAndroid::setStreamTextureClient( |
451 WebKit::WebStreamTextureClient* client) { | 469 WebKit::WebStreamTextureClient* client) { |
452 if (stream_texture_proxy_.get()) | 470 if (stream_texture_proxy_.get()) |
453 stream_texture_proxy_->SetClient(client); | 471 stream_texture_proxy_->SetClient(client); |
454 } | 472 } |
| 473 #else |
| 474 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
| 475 cc::VideoFrameProvider::Client* client) { |
| 476 // This is called from both the main renderer thread and the compositor |
| 477 // thread (when the main thread is blocked). |
| 478 if (video_frame_provider_client_) |
| 479 video_frame_provider_client_->StopUsingProvider(); |
| 480 video_frame_provider_client_ = client; |
| 481 |
| 482 // Set the callback target when a frame is produced. |
| 483 if (stream_texture_proxy_) |
| 484 stream_texture_proxy_->SetClient(client); |
| 485 } |
| 486 |
| 487 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { |
| 488 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() && |
| 489 stream_id_ && !needs_external_surface_) { |
| 490 gfx::Size natural_size = current_frame_->natural_size(); |
| 491 stream_texture_proxy_->Initialize( |
| 492 stream_id_, natural_size.width(), natural_size.height()); |
| 493 } |
| 494 return current_frame_; |
| 495 } |
| 496 |
| 497 void WebMediaPlayerAndroid::PutCurrentFrame( |
| 498 const scoped_refptr<media::VideoFrame>& frame) { |
| 499 } |
| 500 #endif |
455 | 501 |
456 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 502 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
457 if (stream_texture_factory_.get() && stream_id_) | 503 if (stream_texture_factory_.get() && stream_id_) |
458 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 504 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
459 needs_establish_peer_ = false; | 505 needs_establish_peer_ = false; |
460 } | 506 } |
461 | 507 |
462 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 508 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
463 needs_establish_peer_ = needs_establish_peer; | 509 needs_establish_peer_ = needs_establish_peer; |
464 } | 510 } |
465 | 511 |
466 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 512 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
467 is_playing_ = is_playing; | 513 is_playing_ = is_playing; |
468 } | 514 } |
469 | 515 |
470 } // namespace webkit_media | 516 } // namespace webkit_media |
OLD | NEW |