OLD | NEW |
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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 namespace content { | 148 namespace content { |
149 | 149 |
150 WebMediaPlayerAndroid::WebMediaPlayerAndroid( | 150 WebMediaPlayerAndroid::WebMediaPlayerAndroid( |
151 blink::WebFrame* frame, | 151 blink::WebFrame* frame, |
152 blink::WebMediaPlayerClient* client, | 152 blink::WebMediaPlayerClient* client, |
153 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 153 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
154 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 154 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
155 RendererMediaPlayerManager* player_manager, | 155 RendererMediaPlayerManager* player_manager, |
156 media::CdmFactory* cdm_factory, | 156 media::CdmFactory* cdm_factory, |
| 157 media::MediaPermission* media_permission, |
| 158 blink::WebContentDecryptionModule* initial_cdm, |
157 scoped_refptr<StreamTextureFactory> factory, | 159 scoped_refptr<StreamTextureFactory> factory, |
158 const media::WebMediaPlayerParams& params) | 160 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 161 media::MediaLog* media_log) |
159 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 162 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), |
160 frame_(frame), | 163 frame_(frame), |
161 client_(client), | 164 client_(client), |
162 encrypted_client_(encrypted_client), | 165 encrypted_client_(encrypted_client), |
163 delegate_(delegate), | 166 delegate_(delegate), |
164 defer_load_cb_(params.defer_load_cb()), | |
165 buffered_(static_cast<size_t>(1)), | 167 buffered_(static_cast<size_t>(1)), |
166 media_task_runner_(params.media_task_runner()), | 168 media_task_runner_(task_runner), |
167 ignore_metadata_duration_change_(false), | 169 ignore_metadata_duration_change_(false), |
168 pending_seek_(false), | 170 pending_seek_(false), |
169 seeking_(false), | 171 seeking_(false), |
170 did_loading_progress_(false), | 172 did_loading_progress_(false), |
171 player_manager_(player_manager), | 173 player_manager_(player_manager), |
172 cdm_factory_(cdm_factory), | 174 cdm_factory_(cdm_factory), |
173 media_permission_(params.media_permission()), | 175 media_permission_(media_permission), |
174 network_state_(WebMediaPlayer::NetworkStateEmpty), | 176 network_state_(WebMediaPlayer::NetworkStateEmpty), |
175 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 177 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
176 texture_id_(0), | 178 texture_id_(0), |
177 stream_id_(0), | 179 stream_id_(0), |
178 is_player_initialized_(false), | 180 is_player_initialized_(false), |
179 is_playing_(false), | 181 is_playing_(false), |
180 needs_establish_peer_(true), | 182 needs_establish_peer_(true), |
181 has_size_info_(false), | 183 has_size_info_(false), |
182 // Threaded compositing isn't enabled universally yet. | 184 // Compositor thread does not exist in layout tests. |
183 compositor_task_runner_( | 185 compositor_loop_( |
184 params.compositor_task_runner() | 186 RenderThreadImpl::current()->compositor_task_runner().get() |
185 ? params.compositor_task_runner() | 187 ? RenderThreadImpl::current()->compositor_task_runner() |
186 : base::ThreadTaskRunnerHandle::Get()), | 188 : base::ThreadTaskRunnerHandle::Get()), |
187 stream_texture_factory_(factory), | 189 stream_texture_factory_(factory), |
188 needs_external_surface_(false), | 190 needs_external_surface_(false), |
189 is_fullscreen_(false), | 191 is_fullscreen_(false), |
190 video_frame_provider_client_(NULL), | 192 video_frame_provider_client_(NULL), |
191 player_type_(MEDIA_PLAYER_TYPE_URL), | 193 player_type_(MEDIA_PLAYER_TYPE_URL), |
192 is_remote_(false), | 194 is_remote_(false), |
193 media_log_(params.media_log()), | 195 media_log_(media_log), |
194 init_data_type_(media::EmeInitDataType::UNKNOWN), | 196 init_data_type_(media::EmeInitDataType::UNKNOWN), |
195 cdm_context_(NULL), | 197 cdm_context_(NULL), |
196 allow_stored_credentials_(false), | 198 allow_stored_credentials_(false), |
197 is_local_resource_(false), | 199 is_local_resource_(false), |
198 interpolator_(&default_tick_clock_), | 200 interpolator_(&default_tick_clock_), |
199 weak_factory_(this) { | 201 weak_factory_(this) { |
200 DCHECK(player_manager_); | 202 DCHECK(player_manager_); |
201 DCHECK(cdm_factory_); | 203 DCHECK(cdm_factory_); |
202 | 204 |
203 DCHECK(main_thread_checker_.CalledOnValidThread()); | 205 DCHECK(main_thread_checker_.CalledOnValidThread()); |
(...skipping 10 matching lines...) Expand all Loading... |
214 if (force_use_overlay_embedded_video_ || | 216 if (force_use_overlay_embedded_video_ || |
215 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { | 217 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { |
216 // Defer stream texture creation until we are sure it's necessary. | 218 // Defer stream texture creation until we are sure it's necessary. |
217 needs_establish_peer_ = false; | 219 needs_establish_peer_ = false; |
218 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); | 220 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); |
219 } | 221 } |
220 #endif // defined(VIDEO_HOLE) | 222 #endif // defined(VIDEO_HOLE) |
221 TryCreateStreamTextureProxyIfNeeded(); | 223 TryCreateStreamTextureProxyIfNeeded(); |
222 interpolator_.SetUpperBound(base::TimeDelta()); | 224 interpolator_.SetUpperBound(base::TimeDelta()); |
223 | 225 |
224 if (params.initial_cdm()) { | 226 if (initial_cdm) { |
225 cdm_context_ = media::ToWebContentDecryptionModuleImpl(params.initial_cdm()) | 227 cdm_context_ = |
226 ->GetCdmContext(); | 228 media::ToWebContentDecryptionModuleImpl(initial_cdm)->GetCdmContext(); |
227 } | 229 } |
228 } | 230 } |
229 | 231 |
230 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { | 232 WebMediaPlayerAndroid::~WebMediaPlayerAndroid() { |
231 DCHECK(main_thread_checker_.CalledOnValidThread()); | 233 DCHECK(main_thread_checker_.CalledOnValidThread()); |
232 SetVideoFrameProviderClient(NULL); | 234 SetVideoFrameProviderClient(NULL); |
233 client_->setWebLayer(NULL); | 235 client_->setWebLayer(NULL); |
234 | 236 |
235 if (is_player_initialized_) | 237 if (is_player_initialized_) |
236 player_manager_->DestroyPlayer(player_id_); | 238 player_manager_->DestroyPlayer(player_id_); |
(...skipping 27 matching lines...) Expand all Loading... |
264 base::WaitableEvent waiter(false, false); | 266 base::WaitableEvent waiter(false, false); |
265 media_source_delegate_->Stop( | 267 media_source_delegate_->Stop( |
266 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); | 268 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); |
267 waiter.Wait(); | 269 waiter.Wait(); |
268 } | 270 } |
269 } | 271 } |
270 | 272 |
271 void WebMediaPlayerAndroid::load(LoadType load_type, | 273 void WebMediaPlayerAndroid::load(LoadType load_type, |
272 const blink::WebURL& url, | 274 const blink::WebURL& url, |
273 CORSMode cors_mode) { | 275 CORSMode cors_mode) { |
274 if (!defer_load_cb_.is_null()) { | |
275 defer_load_cb_.Run(base::Bind(&WebMediaPlayerAndroid::DoLoad, | |
276 weak_factory_.GetWeakPtr(), load_type, url, | |
277 cors_mode)); | |
278 return; | |
279 } | |
280 DoLoad(load_type, url, cors_mode); | |
281 } | |
282 | |
283 void WebMediaPlayerAndroid::DoLoad(LoadType load_type, | |
284 const blink::WebURL& url, | |
285 CORSMode cors_mode) { | |
286 DCHECK(main_thread_checker_.CalledOnValidThread()); | 276 DCHECK(main_thread_checker_.CalledOnValidThread()); |
287 | 277 |
288 media::ReportMetrics(load_type, GURL(url), | 278 media::ReportMetrics(load_type, GURL(url), |
289 GURL(frame_->document().securityOrigin().toString())); | 279 GURL(frame_->document().securityOrigin().toString())); |
290 | 280 |
291 switch (load_type) { | 281 switch (load_type) { |
292 case LoadTypeURL: | 282 case LoadTypeURL: |
293 player_type_ = MEDIA_PLAYER_TYPE_URL; | 283 player_type_ = MEDIA_PLAYER_TYPE_URL; |
294 break; | 284 break; |
295 | 285 |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 } | 1251 } |
1262 } | 1252 } |
1263 | 1253 |
1264 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1254 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
1265 cc::VideoFrameProvider::Client* client) { | 1255 cc::VideoFrameProvider::Client* client) { |
1266 // This is called from both the main renderer thread and the compositor | 1256 // This is called from both the main renderer thread and the compositor |
1267 // thread (when the main thread is blocked). | 1257 // thread (when the main thread is blocked). |
1268 | 1258 |
1269 // Set the callback target when a frame is produced. Need to do this before | 1259 // Set the callback target when a frame is produced. Need to do this before |
1270 // StopUsingProvider to ensure we really stop using the client. | 1260 // StopUsingProvider to ensure we really stop using the client. |
1271 if (stream_texture_proxy_) { | 1261 if (stream_texture_proxy_) |
1272 stream_texture_proxy_->BindToLoop(stream_id_, client, | 1262 stream_texture_proxy_->BindToLoop(stream_id_, client, compositor_loop_); |
1273 compositor_task_runner_); | |
1274 } | |
1275 | 1263 |
1276 if (video_frame_provider_client_ && video_frame_provider_client_ != client) | 1264 if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
1277 video_frame_provider_client_->StopUsingProvider(); | 1265 video_frame_provider_client_->StopUsingProvider(); |
1278 video_frame_provider_client_ = client; | 1266 video_frame_provider_client_ = client; |
1279 } | 1267 } |
1280 | 1268 |
1281 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1269 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
1282 scoped_refptr<media::VideoFrame>& video_frame) { | 1270 scoped_refptr<media::VideoFrame>& video_frame) { |
1283 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1271 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1284 base::AutoLock auto_lock(current_frame_lock_); | 1272 base::AutoLock auto_lock(current_frame_lock_); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 // Not needed for hole punching. | 1338 // Not needed for hole punching. |
1351 if (!needs_establish_peer_) | 1339 if (!needs_establish_peer_) |
1352 return; | 1340 return; |
1353 | 1341 |
1354 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1342 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
1355 if (stream_texture_proxy_) { | 1343 if (stream_texture_proxy_) { |
1356 DoCreateStreamTexture(); | 1344 DoCreateStreamTexture(); |
1357 ReallocateVideoFrame(); | 1345 ReallocateVideoFrame(); |
1358 if (video_frame_provider_client_) { | 1346 if (video_frame_provider_client_) { |
1359 stream_texture_proxy_->BindToLoop( | 1347 stream_texture_proxy_->BindToLoop( |
1360 stream_id_, video_frame_provider_client_, compositor_task_runner_); | 1348 stream_id_, video_frame_provider_client_, compositor_loop_); |
1361 } | 1349 } |
1362 } | 1350 } |
1363 } | 1351 } |
1364 | 1352 |
1365 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1353 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
1366 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1354 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1367 if (!stream_texture_proxy_) | 1355 if (!stream_texture_proxy_) |
1368 return; | 1356 return; |
1369 | 1357 |
1370 if (stream_texture_factory_.get() && stream_id_) | 1358 if (stream_texture_factory_.get() && stream_id_) |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 | 1888 |
1901 bool is_hls = IsHLSStream(); | 1889 bool is_hls = IsHLSStream(); |
1902 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); | 1890 UMA_HISTOGRAM_BOOLEAN("Media.Android.IsHttpLiveStreamingMedia", is_hls); |
1903 if (is_hls) { | 1891 if (is_hls) { |
1904 media::RecordOriginOfHLSPlayback( | 1892 media::RecordOriginOfHLSPlayback( |
1905 GURL(frame_->document().securityOrigin().toString())); | 1893 GURL(frame_->document().securityOrigin().toString())); |
1906 } | 1894 } |
1907 } | 1895 } |
1908 | 1896 |
1909 } // namespace content | 1897 } // namespace content |
OLD | NEW |