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" | |
19 | 20 |
20 static const uint32 kGLTextureExternalOES = 0x8D65; | 21 static const uint32 kGLTextureExternalOES = 0x8D65; |
21 | 22 |
22 using WebKit::WebMediaPlayer; | 23 using WebKit::WebMediaPlayer; |
23 using WebKit::WebMediaSource; | 24 using WebKit::WebMediaSource; |
24 using WebKit::WebSize; | 25 using WebKit::WebSize; |
25 using WebKit::WebTimeRanges; | 26 using WebKit::WebTimeRanges; |
26 using WebKit::WebURL; | 27 using WebKit::WebURL; |
27 using WebKit::WebVideoFrame; | |
28 using media::MediaPlayerBridge; | 28 using media::MediaPlayerBridge; |
29 using media::VideoFrame; | 29 using media::VideoFrame; |
30 | 30 |
31 namespace webkit_media { | 31 namespace webkit_media { |
32 | 32 |
33 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 33 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
34 WebKit::WebMediaPlayerClient* client, | 34 WebKit::WebMediaPlayerClient* client, |
35 WebMediaPlayerManagerAndroid* manager, | 35 WebMediaPlayerManagerAndroid* manager, |
36 StreamTextureFactory* factory) | 36 StreamTextureFactory* factory) |
37 : client_(client), | 37 : client_(client), |
38 buffered_(1u), | 38 buffered_(1u), |
39 main_loop_(MessageLoop::current()), | 39 main_loop_(MessageLoop::current()), |
40 pending_seek_(0), | 40 pending_seek_(0), |
41 seeking_(false), | 41 seeking_(false), |
42 did_loading_progress_(false), | 42 did_loading_progress_(false), |
43 manager_(manager), | 43 manager_(manager), |
44 network_state_(WebMediaPlayer::NetworkStateEmpty), | 44 network_state_(WebMediaPlayer::NetworkStateEmpty), |
45 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 45 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
46 is_playing_(false), | 46 is_playing_(false), |
47 needs_establish_peer_(true), | 47 needs_establish_peer_(true), |
48 has_size_info_(false), | 48 has_size_info_(false), |
49 stream_texture_factory_(factory), | 49 stream_texture_factory_(factory), |
50 needs_external_surface_(false) { | 50 needs_external_surface_(false), |
51 video_frame_provider_client_(NULL) { | |
51 main_loop_->AddDestructionObserver(this); | 52 main_loop_->AddDestructionObserver(this); |
52 if (manager_) | 53 if (manager_) |
53 player_id_ = manager_->RegisterMediaPlayer(this); | 54 player_id_ = manager_->RegisterMediaPlayer(this); |
54 | 55 |
55 if (CommandLine::ForCurrentProcess()->HasSwitch( | 56 if (CommandLine::ForCurrentProcess()->HasSwitch( |
56 switches::kUseExternalVideoSurface)) { | 57 switches::kUseExternalVideoSurface)) { |
57 needs_external_surface_ = true; | 58 needs_external_surface_ = true; |
58 SetNeedsEstablishPeer(false); | 59 SetNeedsEstablishPeer(false); |
59 ReallocateVideoFrame(); | 60 ReallocateVideoFrame(); |
60 } else if (stream_texture_factory_.get()) { | 61 } else if (stream_texture_factory_.get()) { |
61 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 62 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
62 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 63 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
63 ReallocateVideoFrame(); | 64 ReallocateVideoFrame(); |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 68 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
69 SetVideoFrameProviderClient(NULL); | |
70 client_->setWebLayer(NULL); | |
71 | |
68 if (stream_id_) | 72 if (stream_id_) |
69 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 73 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
70 | 74 |
71 if (manager_) | 75 if (manager_) |
72 manager_->UnregisterMediaPlayer(player_id_); | 76 manager_->UnregisterMediaPlayer(player_id_); |
73 | 77 |
74 if (main_loop_) | 78 if (main_loop_) |
75 main_loop_->RemoveDestructionObserver(this); | 79 main_loop_->RemoveDestructionObserver(this); |
76 } | 80 } |
77 | 81 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 return 0; | 285 return 0; |
282 } | 286 } |
283 | 287 |
284 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { | 288 void WebMediaPlayerAndroid::OnMediaPrepared(base::TimeDelta duration) { |
285 if (url_.SchemeIs("file")) | 289 if (url_.SchemeIs("file")) |
286 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 290 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
287 | 291 |
288 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { | 292 if (ready_state_ != WebMediaPlayer::ReadyStateHaveEnoughData) { |
289 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 293 UpdateReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
290 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 294 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
291 } else { | 295 } |
292 // If the status is already set to ReadyStateHaveEnoughData, set it again | 296 |
293 // to make sure that Videolayerchromium will get created. | 297 if (hasVideo() && !video_weblayer_ && client->needsWebLayer()) { |
294 UpdateReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 298 video_weblayer_.reset( |
299 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); | |
300 client_->setWebLayer(video_weblayer_.get()); | |
295 } | 301 } |
296 | 302 |
297 // 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 |
298 // duration. | 304 // duration. |
299 if (duration_ != duration) { | 305 if (duration_ != duration) { |
300 duration_ = duration; | 306 duration_ = duration; |
301 client_->durationChanged(); | 307 client_->durationChanged(); |
302 } | 308 } |
303 } | 309 } |
304 | 310 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 } | 406 } |
401 | 407 |
402 void WebMediaPlayerAndroid::Detach() { | 408 void WebMediaPlayerAndroid::Detach() { |
403 Destroy(); | 409 Destroy(); |
404 | 410 |
405 if (stream_id_) { | 411 if (stream_id_) { |
406 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 412 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
407 stream_id_ = 0; | 413 stream_id_ = 0; |
408 } | 414 } |
409 | 415 |
410 web_video_frame_.reset(); | 416 current_frame_ = NULL; |
411 | 417 |
412 manager_ = NULL; | 418 manager_ = NULL; |
413 } | 419 } |
414 | 420 |
415 void WebMediaPlayerAndroid::ReallocateVideoFrame() { | 421 void WebMediaPlayerAndroid::ReallocateVideoFrame() { |
416 if (needs_external_surface_) { | 422 if (needs_external_surface_) { |
417 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. | 423 // VideoFrame::CreateHoleFrame is only defined under GOOGLE_TV. |
418 #if defined(GOOGLE_TV) | 424 #if defined(GOOGLE_TV) |
419 if (!natural_size_.isEmpty()) { | 425 if (!natural_size_.isEmpty()) { |
420 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::CreateHoleFrame( | 426 current__frame_ = VideoFrame::CreateHoleFrame( |
scherkus (not reviewing)
2013/03/21 20:38:59
typo (extra _)
| |
421 natural_size_))); | 427 natural_size_))); |
422 } | 428 } |
423 #else | 429 #else |
424 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; | 430 NOTIMPLEMENTED() << "Hole punching not supported outside of Google TV"; |
425 #endif | 431 #endif |
426 } else if (texture_id_) { | 432 } else if (texture_id_) { |
427 web_video_frame_.reset(new WebVideoFrameImpl(VideoFrame::WrapNativeTexture( | 433 current_frame_ = VideoFrame::WrapNativeTexture( |
428 texture_id_, kGLTextureExternalOES, natural_size_, | 434 texture_id_, kGLTextureExternalOES, natural_size_, |
429 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), | 435 gfx::Rect(natural_size_), natural_size_, base::TimeDelta(), |
430 VideoFrame::ReadPixelsCB(), | 436 VideoFrame::ReadPixelsCB(), |
431 base::Closure()))); | 437 base::Closure()); |
432 } | 438 } |
433 } | 439 } |
434 | 440 |
435 WebVideoFrame* WebMediaPlayerAndroid::getCurrentFrame() { | 441 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
436 if (stream_texture_proxy_.get() && !stream_texture_proxy_->IsInitialized() | 442 cc::VideoFrameProvider::Client* client) { |
443 // This is called from both the main renderer thread and the compositor | |
444 // thread (when the main thread is blocked). | |
445 if (video_frame_provider_client_) | |
446 video_frame_provider_client_->StopUsingProvider(); | |
447 video_frame_provider_client_ = client; | |
448 | |
449 // Set the callback target when a frame is produced. | |
450 if (stream_texture_proxy_) | |
451 stream_texture_proxy_->SetClient(client); | |
452 } | |
453 | |
454 scoped_refptr<media::VideoFrame> WebMediaPlayerAndroid::GetCurrentFrame() { | |
455 if (stream_texture_proxy_ && !stream_texture_proxy_->IsInitialized() | |
437 && stream_id_ && !needs_external_surface_) { | 456 && stream_id_ && !needs_external_surface_) { |
scherkus (not reviewing)
2013/03/21 20:38:59
leading && should be on previous line
| |
438 gfx::Size natural_size = web_video_frame_->video_frame->natural_size(); | 457 gfx::Size natural_size = current_frame_->natural_size(); |
439 stream_texture_proxy_->Initialize( | 458 stream_texture_proxy_->Initialize( |
440 stream_id_, natural_size.width(), natural_size.height()); | 459 stream_id_, natural_size.width(), natural_size.height()); |
441 } | 460 } |
442 | 461 return current_frame_; |
443 return web_video_frame_.get(); | |
444 } | 462 } |
445 | 463 |
446 void WebMediaPlayerAndroid::putCurrentFrame( | 464 void WebMediaPlayerAndroid::PutCurrentFrame( |
447 WebVideoFrame* web_video_frame) { | 465 const scoped_refptr<media::VideoFrame>& frame) { |
448 } | |
449 | |
450 void WebMediaPlayerAndroid::setStreamTextureClient( | |
451 WebKit::WebStreamTextureClient* client) { | |
452 if (stream_texture_proxy_.get()) | |
453 stream_texture_proxy_->SetClient(client); | |
454 } | 466 } |
455 | 467 |
456 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 468 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
457 if (stream_texture_factory_.get() && stream_id_) | 469 if (stream_texture_factory_.get() && stream_id_) |
458 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); | 470 stream_texture_factory_->EstablishPeer(stream_id_, player_id_); |
459 needs_establish_peer_ = false; | 471 needs_establish_peer_ = false; |
460 } | 472 } |
461 | 473 |
462 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { | 474 void WebMediaPlayerAndroid::SetNeedsEstablishPeer(bool needs_establish_peer) { |
463 needs_establish_peer_ = needs_establish_peer; | 475 needs_establish_peer_ = needs_establish_peer; |
464 } | 476 } |
465 | 477 |
466 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { | 478 void WebMediaPlayerAndroid::UpdatePlayingState(bool is_playing) { |
467 is_playing_ = is_playing; | 479 is_playing_ = is_playing; |
468 } | 480 } |
469 | 481 |
470 } // namespace webkit_media | 482 } // namespace webkit_media |
OLD | NEW |