| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 24 #include "webkit/media/android/webmediaplayer_manager_android.h" | 24 #include "webkit/media/android/webmediaplayer_manager_android.h" |
| 25 #include "webkit/media/android/webmediaplayer_proxy_android.h" | 25 #include "webkit/media/android/webmediaplayer_proxy_android.h" |
| 26 #include "webkit/media/webmediaplayer_util.h" | 26 #include "webkit/media/webmediaplayer_util.h" |
| 27 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" | 27 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" |
| 28 | 28 |
| 29 #if defined(GOOGLE_TV) | 29 #if defined(GOOGLE_TV) |
| 30 #include "webkit/media/android/media_source_delegate.h" | 30 #include "webkit/media/android/media_source_delegate.h" |
| 31 #include "webkit/media/media_stream_audio_renderer.h" |
| 32 #include "webkit/media/media_stream_client.h" |
| 31 #endif | 33 #endif |
| 32 | 34 |
| 33 static const uint32 kGLTextureExternalOES = 0x8D65; | 35 static const uint32 kGLTextureExternalOES = 0x8D65; |
| 34 | 36 |
| 35 using WebKit::WebMediaPlayer; | 37 using WebKit::WebMediaPlayer; |
| 36 using WebKit::WebMediaSource; | 38 using WebKit::WebMediaSource; |
| 37 using WebKit::WebSize; | 39 using WebKit::WebSize; |
| 38 using WebKit::WebString; | 40 using WebKit::WebString; |
| 39 using WebKit::WebTimeRanges; | 41 using WebKit::WebTimeRanges; |
| 40 using WebKit::WebURL; | 42 using WebKit::WebURL; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 network_state_(WebMediaPlayer::NetworkStateEmpty), | 63 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 62 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 64 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 63 is_playing_(false), | 65 is_playing_(false), |
| 64 needs_establish_peer_(true), | 66 needs_establish_peer_(true), |
| 65 has_size_info_(false), | 67 has_size_info_(false), |
| 66 stream_texture_factory_(factory), | 68 stream_texture_factory_(factory), |
| 67 needs_external_surface_(false), | 69 needs_external_surface_(false), |
| 68 video_frame_provider_client_(NULL), | 70 video_frame_provider_client_(NULL), |
| 69 proxy_(proxy), | 71 proxy_(proxy), |
| 70 current_time_(0), | 72 current_time_(0), |
| 71 media_log_(media_log) { | 73 media_log_(media_log), |
| 74 media_stream_client_(NULL) { |
| 72 main_loop_->AddDestructionObserver(this); | 75 main_loop_->AddDestructionObserver(this); |
| 73 if (manager_) | 76 if (manager_) |
| 74 player_id_ = manager_->RegisterMediaPlayer(this); | 77 player_id_ = manager_->RegisterMediaPlayer(this); |
| 75 | 78 |
| 76 if (stream_texture_factory_) { | 79 if (stream_texture_factory_) { |
| 77 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 80 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 78 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); | 81 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); |
| 79 ReallocateVideoFrame(); | 82 ReallocateVideoFrame(); |
| 80 } | 83 } |
| 84 #if defined(GOOGLE_TV) |
| 85 demuxer_ = NULL; |
| 86 #endif |
| 81 } | 87 } |
| 82 | 88 |
| 83 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 89 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
| 84 SetVideoFrameProviderClient(NULL); | 90 SetVideoFrameProviderClient(NULL); |
| 85 client_->setWebLayer(NULL); | 91 client_->setWebLayer(NULL); |
| 86 | 92 |
| 87 if (proxy_) | 93 if (proxy_) |
| 88 proxy_->DestroyPlayer(player_id_); | 94 proxy_->DestroyPlayer(player_id_); |
| 89 | 95 |
| 90 if (stream_id_) | 96 if (stream_id_) |
| 91 stream_texture_factory_->DestroyStreamTexture(texture_id_); | 97 stream_texture_factory_->DestroyStreamTexture(texture_id_); |
| 92 | 98 |
| 93 if (manager_) | 99 if (manager_) |
| 94 manager_->UnregisterMediaPlayer(player_id_); | 100 manager_->UnregisterMediaPlayer(player_id_); |
| 95 | 101 |
| 96 if (main_loop_) | 102 if (main_loop_) |
| 97 main_loop_->RemoveDestructionObserver(this); | 103 main_loop_->RemoveDestructionObserver(this); |
| 104 #if defined(GOOGLE_TV) |
| 105 if (demuxer_ && !destroy_demuxer_cb_.is_null()) { |
| 106 media_source_delegate_.reset(); |
| 107 destroy_demuxer_cb_.Run(); |
| 108 } |
| 109 #endif |
| 98 } | 110 } |
| 99 | 111 |
| 100 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { | 112 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { |
| 101 load(url, NULL, cors_mode); | 113 load(url, NULL, cors_mode); |
| 102 } | 114 } |
| 103 | 115 |
| 104 void WebMediaPlayerAndroid::load(const WebURL& url, | 116 void WebMediaPlayerAndroid::load(const WebURL& url, |
| 105 WebMediaSource* media_source, | 117 WebMediaSource* media_source, |
| 106 CORSMode cors_mode) { | 118 CORSMode cors_mode) { |
| 107 if (cors_mode != CORSModeUnspecified) | 119 if (cors_mode != CORSModeUnspecified) |
| 108 NOTIMPLEMENTED() << "No CORS support"; | 120 NOTIMPLEMENTED() << "No CORS support"; |
| 109 | 121 |
| 110 scoped_ptr<WebKit::WebMediaSource> scoped_media_source(media_source); | 122 MediaPlayerAndroid::SourceType source_type = |
| 123 MediaPlayerAndroid::SOURCE_TYPE_URL; |
| 124 |
| 125 if (media_source) |
| 126 source_type = MediaPlayerAndroid::SOURCE_TYPE_MSE; |
| 111 #if defined(GOOGLE_TV) | 127 #if defined(GOOGLE_TV) |
| 112 if (media_source) { | 128 if (media_stream_client_) { |
| 113 media_source_delegate_.reset( | 129 DCHECK(!media_source); |
| 114 new MediaSourceDelegate( | 130 source_type = MediaPlayerAndroid::SOURCE_TYPE_STREAM; |
| 115 frame_, client_, proxy_, player_id_, media_log_)); | 131 } |
| 132 |
| 133 if (source_type != MediaPlayerAndroid::SOURCE_TYPE_URL) { |
| 116 // |media_source_delegate_| is owned, so Unretained() is safe here. | 134 // |media_source_delegate_| is owned, so Unretained() is safe here. |
| 117 media_source_delegate_->Initialize( | 135 media_source_delegate_.reset(new MediaSourceDelegate( |
| 118 scoped_media_source.Pass(), | 136 proxy_, |
| 137 player_id_, |
| 119 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, | 138 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, |
| 120 base::Unretained(this))); | 139 base::Unretained(this)))); |
| 140 if (source_type == MediaPlayerAndroid::SOURCE_TYPE_MSE) { |
| 141 media_source_delegate_->InitializeMediaSource( |
| 142 frame_, client_, media_source, media_log_); |
| 143 } else if (source_type == MediaPlayerAndroid::SOURCE_TYPE_STREAM) { |
| 144 media_source_delegate_->InitializeMediaStream(demuxer_); |
| 145 } |
| 121 } | 146 } |
| 122 #endif | 147 #endif |
| 123 | 148 |
| 149 InitializeMediaPlayer(url, source_type); |
| 150 } |
| 151 |
| 152 void WebMediaPlayerAndroid::InitializeMediaPlayer( |
| 153 const WebURL& url, |
| 154 MediaPlayerAndroid::SourceType source_type) { |
| 124 url_ = url; | 155 url_ = url; |
| 125 GURL first_party_url = frame_->document().firstPartyForCookies(); | 156 GURL first_party_url = frame_->document().firstPartyForCookies(); |
| 126 if (proxy_) { | 157 if (proxy_) { |
| 127 proxy_->Initialize(player_id_, url_, media_source != NULL, first_party_url); | 158 proxy_->Initialize(player_id_, url, source_type, first_party_url); |
| 128 if (manager_->IsInFullscreen(frame_)) | 159 if (manager_->IsInFullscreen(frame_)) |
| 129 proxy_->EnterFullscreen(player_id_); | 160 proxy_->EnterFullscreen(player_id_); |
| 130 } | 161 } |
| 131 | 162 |
| 132 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 163 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 133 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 164 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 134 } | 165 } |
| 135 | 166 |
| 136 void WebMediaPlayerAndroid::cancelLoad() { | 167 void WebMediaPlayerAndroid::cancelLoad() { |
| 137 NOTIMPLEMENTED(); | 168 NOTIMPLEMENTED(); |
| 138 } | 169 } |
| 139 | 170 |
| 140 void WebMediaPlayerAndroid::play() { | 171 void WebMediaPlayerAndroid::play() { |
| 141 #if defined(GOOGLE_TV) | 172 #if defined(GOOGLE_TV) |
| 142 if (hasVideo() && needs_external_surface_) { | 173 if (hasVideo() && needs_external_surface_) { |
| 143 DCHECK(!needs_establish_peer_); | |
| 144 if (proxy_) | 174 if (proxy_) |
| 145 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 175 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
| 146 } | 176 } |
| 147 #endif | 177 #endif |
| 148 if (hasVideo() && needs_establish_peer_) | 178 if (hasVideo() && needs_establish_peer_) |
| 149 EstablishSurfaceTexturePeer(); | 179 EstablishSurfaceTexturePeer(); |
| 150 | 180 |
| 151 if (paused() && proxy_) | 181 if (paused() && proxy_) |
| 152 proxy_->Start(player_id_); | 182 proxy_->Start(player_id_); |
| 153 is_playing_ = true; | 183 is_playing_ = true; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 #if defined(GOOGLE_TV) | 490 #if defined(GOOGLE_TV) |
| 461 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( | 491 static bool has_switch = CommandLine::ForCurrentProcess()->HasSwitch( |
| 462 switches::kUseExternalVideoSurfaceThresholdInPixels); | 492 switches::kUseExternalVideoSurfaceThresholdInPixels); |
| 463 static int threshold = 0; | 493 static int threshold = 0; |
| 464 static bool parsed_arg = | 494 static bool parsed_arg = |
| 465 has_switch && | 495 has_switch && |
| 466 base::StringToInt( | 496 base::StringToInt( |
| 467 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 497 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 468 switches::kUseExternalVideoSurfaceThresholdInPixels), | 498 switches::kUseExternalVideoSurfaceThresholdInPixels), |
| 469 &threshold); | 499 &threshold); |
| 470 | |
| 471 if ((parsed_arg && threshold <= width * height) || | 500 if ((parsed_arg && threshold <= width * height) || |
| 472 // Use H/W surface for MSE as the content is protected. | 501 // Use H/W surface for MSE as the content is protected. |
| 473 media_source_delegate_) { | 502 media_source_delegate_) { |
| 474 needs_external_surface_ = true; | 503 needs_external_surface_ = true; |
| 475 SetNeedsEstablishPeer(false); | 504 SetNeedsEstablishPeer(false); |
| 476 if (!paused() && proxy_) | 505 if (!paused() && proxy_) |
| 477 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); | 506 proxy_->RequestExternalSurface(player_id_, last_computed_rect_); |
| 478 } | 507 } |
| 479 #endif | 508 #endif |
| 480 | 509 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 | 679 |
| 651 // Return false when the geometry hasn't been changed from the last time. | 680 // Return false when the geometry hasn't been changed from the last time. |
| 652 if (last_computed_rect_ == *rect) | 681 if (last_computed_rect_ == *rect) |
| 653 return false; | 682 return false; |
| 654 | 683 |
| 655 // Store the changed geometry information when it is actually changed. | 684 // Store the changed geometry information when it is actually changed. |
| 656 last_computed_rect_ = *rect; | 685 last_computed_rect_ = *rect; |
| 657 return true; | 686 return true; |
| 658 } | 687 } |
| 659 | 688 |
| 660 WebMediaPlayer::MediaKeyException | 689 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( |
| 661 WebMediaPlayerAndroid::generateKeyRequest(const WebString& key_system, | 690 const WebString& key_system, |
| 662 const unsigned char* init_data, | 691 const unsigned char* init_data, |
| 663 unsigned init_data_length) { | 692 unsigned init_data_length) { |
| 664 if (media_source_delegate_) { | 693 if (media_source_delegate_) { |
| 665 return media_source_delegate_->GenerateKeyRequest( | 694 return media_source_delegate_->GenerateKeyRequest( |
| 666 key_system, init_data, init_data_length); | 695 key_system, init_data, init_data_length); |
| 667 } | 696 } |
| 668 return MediaKeyExceptionKeySystemNotSupported; | 697 return MediaKeyExceptionKeySystemNotSupported; |
| 669 } | 698 } |
| 670 | 699 |
| 671 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | 700 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( |
| 672 const WebString& key_system, | 701 const WebString& key_system, |
| 673 const unsigned char* key, | 702 const unsigned char* key, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 690 return MediaKeyExceptionKeySystemNotSupported; | 719 return MediaKeyExceptionKeySystemNotSupported; |
| 691 } | 720 } |
| 692 | 721 |
| 693 void WebMediaPlayerAndroid::OnReadFromDemuxer( | 722 void WebMediaPlayerAndroid::OnReadFromDemuxer( |
| 694 media::DemuxerStream::Type type, bool seek_done) { | 723 media::DemuxerStream::Type type, bool seek_done) { |
| 695 if (media_source_delegate_) | 724 if (media_source_delegate_) |
| 696 media_source_delegate_->OnReadFromDemuxer(type, seek_done); | 725 media_source_delegate_->OnReadFromDemuxer(type, seek_done); |
| 697 else | 726 else |
| 698 NOTIMPLEMENTED(); | 727 NOTIMPLEMENTED(); |
| 699 } | 728 } |
| 729 |
| 730 bool WebMediaPlayerAndroid::InjectMediaStream( |
| 731 MediaStreamClient* media_stream_client, |
| 732 media::Demuxer* demuxer, |
| 733 const base::Closure& destroy_demuxer_cb) { |
| 734 DCHECK(!demuxer); |
| 735 media_stream_client_ = media_stream_client; |
| 736 demuxer_ = demuxer; |
| 737 destroy_demuxer_cb_ = destroy_demuxer_cb; |
| 738 return true; |
| 739 } |
| 700 #endif | 740 #endif |
| 701 | 741 |
| 702 void WebMediaPlayerAndroid::enterFullscreen() { | 742 void WebMediaPlayerAndroid::enterFullscreen() { |
| 703 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { | 743 if (proxy_ && manager_->CanEnterFullscreen(frame_)) { |
| 704 proxy_->EnterFullscreen(player_id_); | 744 proxy_->EnterFullscreen(player_id_); |
| 705 SetNeedsEstablishPeer(false); | 745 SetNeedsEstablishPeer(false); |
| 706 } | 746 } |
| 707 } | 747 } |
| 708 | 748 |
| 709 void WebMediaPlayerAndroid::exitFullscreen() { | 749 void WebMediaPlayerAndroid::exitFullscreen() { |
| 710 if (proxy_) | 750 if (proxy_) |
| 711 proxy_->ExitFullscreen(player_id_); | 751 proxy_->ExitFullscreen(player_id_); |
| 712 } | 752 } |
| 713 | 753 |
| 714 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 754 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 715 return manager_->CanEnterFullscreen(frame_); | 755 return manager_->CanEnterFullscreen(frame_); |
| 716 } | 756 } |
| 717 | 757 |
| 718 } // namespace webkit_media | 758 } // namespace webkit_media |
| OLD | NEW |