Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: webkit/renderer/media/android/webmediaplayer_android.cc

Issue 14247018: Implement WebRTC in Chrome for TV (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/media/android/webmediaplayer_android.h" 5 #include "webkit/renderer/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 11 matching lines...) Expand all
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaSource.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
26 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" 26 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
27 #include "webkit/renderer/media/android/webmediaplayer_manager_android.h" 27 #include "webkit/renderer/media/android/webmediaplayer_manager_android.h"
28 #include "webkit/renderer/media/android/webmediaplayer_proxy_android.h" 28 #include "webkit/renderer/media/android/webmediaplayer_proxy_android.h"
29 #include "webkit/renderer/media/crypto/key_systems.h" 29 #include "webkit/renderer/media/crypto/key_systems.h"
30 #include "webkit/renderer/media/webmediaplayer_util.h" 30 #include "webkit/renderer/media/webmediaplayer_util.h"
31 31
32 #if defined(GOOGLE_TV)
33 #include "webkit/renderer/media/media_stream_audio_renderer.h"
34 #include "webkit/renderer/media/media_stream_client.h"
35 #endif
36
32 static const uint32 kGLTextureExternalOES = 0x8D65; 37 static const uint32 kGLTextureExternalOES = 0x8D65;
33 38
34 using WebKit::WebMediaPlayer; 39 using WebKit::WebMediaPlayer;
35 using WebKit::WebMediaSource; 40 using WebKit::WebMediaSource;
36 using WebKit::WebSize; 41 using WebKit::WebSize;
37 using WebKit::WebString; 42 using WebKit::WebString;
38 using WebKit::WebTimeRanges; 43 using WebKit::WebTimeRanges;
39 using WebKit::WebURL; 44 using WebKit::WebURL;
40 using media::MediaPlayerAndroid; 45 using media::MediaPlayerAndroid;
41 using media::VideoFrame; 46 using media::VideoFrame;
(...skipping 24 matching lines...) Expand all
66 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), 71 ready_state_(WebMediaPlayer::ReadyStateHaveNothing),
67 is_playing_(false), 72 is_playing_(false),
68 needs_establish_peer_(true), 73 needs_establish_peer_(true),
69 stream_texture_proxy_initialized_(false), 74 stream_texture_proxy_initialized_(false),
70 has_size_info_(false), 75 has_size_info_(false),
71 stream_texture_factory_(factory), 76 stream_texture_factory_(factory),
72 needs_external_surface_(false), 77 needs_external_surface_(false),
73 video_frame_provider_client_(NULL), 78 video_frame_provider_client_(NULL),
74 proxy_(proxy), 79 proxy_(proxy),
75 current_time_(0), 80 current_time_(0),
76 media_log_(media_log) { 81 media_log_(media_log),
82 media_stream_client_(NULL) {
77 main_loop_->AddDestructionObserver(this); 83 main_loop_->AddDestructionObserver(this);
78 if (manager_) 84 if (manager_)
79 player_id_ = manager_->RegisterMediaPlayer(this); 85 player_id_ = manager_->RegisterMediaPlayer(this);
80 86
81 if (stream_texture_factory_) { 87 if (stream_texture_factory_) {
82 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); 88 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy());
83 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_); 89 stream_id_ = stream_texture_factory_->CreateStreamTexture(&texture_id_);
84 ReallocateVideoFrame(); 90 ReallocateVideoFrame();
85 } 91 }
86 92
87 #if defined(GOOGLE_TV) 93 #if defined(GOOGLE_TV)
88 if (WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) { 94 if (WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) {
89 // |decryptor_| is owned, so Unretained() is safe here. 95 // |decryptor_| is owned, so Unretained() is safe here.
90 decryptor_.reset(new ProxyDecryptor( 96 decryptor_.reset(new ProxyDecryptor(
91 client, 97 client,
92 frame, 98 frame,
93 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, base::Unretained(this)), 99 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, base::Unretained(this)),
94 base::Bind(&WebMediaPlayerAndroid::OnKeyError, base::Unretained(this)), 100 base::Bind(&WebMediaPlayerAndroid::OnKeyError, base::Unretained(this)),
95 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, 101 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage,
96 base::Unretained(this)), 102 base::Unretained(this)),
97 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, base::Unretained(this)))); 103 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, base::Unretained(this))));
98 } 104 }
105
106 demuxer_ = NULL;
99 #endif // defined(GOOGLE_TV) 107 #endif // defined(GOOGLE_TV)
100 } 108 }
101 109
102 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { 110 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() {
103 SetVideoFrameProviderClient(NULL); 111 SetVideoFrameProviderClient(NULL);
104 client_->setWebLayer(NULL); 112 client_->setWebLayer(NULL);
105 113
106 if (proxy_) 114 if (proxy_)
107 proxy_->DestroyPlayer(player_id_); 115 proxy_->DestroyPlayer(player_id_);
108 116
109 if (stream_id_) 117 if (stream_id_)
110 stream_texture_factory_->DestroyStreamTexture(texture_id_); 118 stream_texture_factory_->DestroyStreamTexture(texture_id_);
111 119
112 if (manager_) 120 if (manager_)
113 manager_->UnregisterMediaPlayer(player_id_); 121 manager_->UnregisterMediaPlayer(player_id_);
114 122
115 if (main_loop_) 123 if (main_loop_)
116 main_loop_->RemoveDestructionObserver(this); 124 main_loop_->RemoveDestructionObserver(this);
125 #if defined(GOOGLE_TV)
126 if (demuxer_ && !destroy_demuxer_cb_.is_null()) {
127 media_source_delegate_.reset();
128 destroy_demuxer_cb_.Run();
129 }
130 #endif
117 } 131 }
118 132
119 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) { 133 void WebMediaPlayerAndroid::load(const WebURL& url, CORSMode cors_mode) {
120 load(url, NULL, cors_mode); 134 load(url, NULL, cors_mode);
121 } 135 }
122 136
123 void WebMediaPlayerAndroid::load(const WebURL& url, 137 void WebMediaPlayerAndroid::load(const WebURL& url,
124 WebMediaSource* media_source, 138 WebMediaSource* media_source,
125 CORSMode cors_mode) { 139 CORSMode cors_mode) {
126 if (cors_mode != CORSModeUnspecified) 140 if (cors_mode != CORSModeUnspecified)
127 NOTIMPLEMENTED() << "No CORS support"; 141 NOTIMPLEMENTED() << "No CORS support";
128 142
129 if (media_source) { 143 MediaPlayerAndroid::SourceType source_type =
144 MediaPlayerAndroid::SOURCE_TYPE_URL;
145
146 if (media_source)
147 source_type = MediaPlayerAndroid::SOURCE_TYPE_MSE;
148 #if defined(GOOGLE_TV)
149 if (media_stream_client_) {
150 DCHECK(!media_source);
151 source_type = MediaPlayerAndroid::SOURCE_TYPE_STREAM;
152 }
153 #endif
154
155 if (source_type != MediaPlayerAndroid::SOURCE_TYPE_URL) {
130 media_source_delegate_.reset( 156 media_source_delegate_.reset(
131 new MediaSourceDelegate(proxy_, player_id_, media_log_)); 157 new MediaSourceDelegate(proxy_, player_id_, media_log_));
132 // |media_source_delegate_| is owned, so Unretained() is safe here. 158 // |media_source_delegate_| is owned, so Unretained() is safe here.
133 media_source_delegate_->Initialize( 159 if (source_type == MediaPlayerAndroid::SOURCE_TYPE_MSE) {
134 media_source, 160 media_source_delegate_->InitializeMediaSource(
135 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, base::Unretained(this)), 161 media_source,
136 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, 162 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, base::Unretained(this)),
137 base::Unretained(this))); 163 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState,
164 base::Unretained(this)));
165 }
166 #if defined(GOOGLE_TV)
167 if (source_type == MediaPlayerAndroid::SOURCE_TYPE_STREAM) {
168 media_source_delegate_->InitializeMediaStream(
169 demuxer_,
170 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState,
171 base::Unretained(this)));
172 }
173 #endif
138 } 174 }
139 175
176 InitializeMediaPlayer(url, source_type);
177 }
178
179 void WebMediaPlayerAndroid::InitializeMediaPlayer(
180 const WebURL& url,
181 MediaPlayerAndroid::SourceType source_type) {
140 url_ = url; 182 url_ = url;
141 GURL first_party_url = frame_->document().firstPartyForCookies(); 183 GURL first_party_url = frame_->document().firstPartyForCookies();
142 if (proxy_) { 184 if (proxy_) {
143 proxy_->Initialize(player_id_, url_, media_source != NULL, first_party_url); 185 proxy_->Initialize(player_id_, url, source_type, first_party_url);
144 if (manager_->IsInFullscreen(frame_)) 186 if (manager_->IsInFullscreen(frame_))
145 proxy_->EnterFullscreen(player_id_); 187 proxy_->EnterFullscreen(player_id_);
146 } 188 }
147 189
148 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); 190 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
149 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); 191 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing);
150 } 192 }
151 193
152 void WebMediaPlayerAndroid::cancelLoad() { 194 void WebMediaPlayerAndroid::cancelLoad() {
153 NOTIMPLEMENTED(); 195 NOTIMPLEMENTED();
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 const GURL default_url_gurl(default_url); 954 const GURL default_url_gurl(default_url);
913 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) 955 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
914 << "Invalid URL in default_url: " << default_url; 956 << "Invalid URL in default_url: " << default_url;
915 957
916 client_->keyMessage(WebString::fromUTF8(key_system), 958 client_->keyMessage(WebString::fromUTF8(key_system),
917 WebString::fromUTF8(session_id), 959 WebString::fromUTF8(session_id),
918 reinterpret_cast<const uint8*>(message.data()), 960 reinterpret_cast<const uint8*>(message.data()),
919 message.size(), 961 message.size(),
920 default_url_gurl); 962 default_url_gurl);
921 } 963 }
964
965 bool WebMediaPlayerAndroid::InjectMediaStream(
966 MediaStreamClient* media_stream_client,
967 media::Demuxer* demuxer,
968 const base::Closure& destroy_demuxer_cb) {
969 DCHECK(!demuxer);
970 media_stream_client_ = media_stream_client;
971 demuxer_ = demuxer;
972 destroy_demuxer_cb_ = destroy_demuxer_cb;
973 return true;
974 }
922 #endif // defined(GOOGLE_TV) 975 #endif // defined(GOOGLE_TV)
923 976
924 void WebMediaPlayerAndroid::OnNeedKey(const std::string& key_system, 977 void WebMediaPlayerAndroid::OnNeedKey(const std::string& key_system,
925 const std::string& session_id, 978 const std::string& session_id,
926 const std::string& type, 979 const std::string& type,
927 scoped_ptr<uint8[]> init_data, 980 scoped_ptr<uint8[]> init_data,
928 int init_data_size) { 981 int init_data_size) {
929 // Do not fire NeedKey event if encrypted media is not enabled. 982 // Do not fire NeedKey event if encrypted media is not enabled.
930 if (!decryptor_) 983 if (!decryptor_)
931 return; 984 return;
(...skipping 28 matching lines...) Expand all
960 void WebMediaPlayerAndroid::exitFullscreen() { 1013 void WebMediaPlayerAndroid::exitFullscreen() {
961 if (proxy_) 1014 if (proxy_)
962 proxy_->ExitFullscreen(player_id_); 1015 proxy_->ExitFullscreen(player_id_);
963 } 1016 }
964 1017
965 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 1018 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
966 return manager_->CanEnterFullscreen(frame_); 1019 return manager_->CanEnterFullscreen(frame_);
967 } 1020 }
968 1021
969 } // namespace webkit_media 1022 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/renderer/media/android/webmediaplayer_android.h ('k') | webkit/renderer/media/android/webmediaplayer_proxy_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698