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