Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1244 } | 1244 } |
| 1245 } | 1245 } |
| 1246 | 1246 |
| 1247 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( | 1247 void WebMediaPlayerAndroid::SetVideoFrameProviderClient( |
| 1248 cc::VideoFrameProvider::Client* client) { | 1248 cc::VideoFrameProvider::Client* client) { |
| 1249 // This is called from both the main renderer thread and the compositor | 1249 // This is called from both the main renderer thread and the compositor |
| 1250 // thread (when the main thread is blocked). | 1250 // thread (when the main thread is blocked). |
| 1251 | 1251 |
| 1252 // Set the callback target when a frame is produced. Need to do this before | 1252 // Set the callback target when a frame is produced. Need to do this before |
| 1253 // StopUsingProvider to ensure we really stop using the client. | 1253 // StopUsingProvider to ensure we really stop using the client. |
| 1254 if (stream_texture_proxy_) { | 1254 if (stream_texture_proxy_) { |
|
watk
2016/07/29 19:03:16
For consistency we don't use braces for single lin
tguilbert
2016/08/01 22:05:57
Done.
| |
| 1255 stream_texture_proxy_->BindToLoop(stream_id_, client, | 1255 UpdateStreamTextureProxyCallback(client); |
| 1256 compositor_task_runner_); | |
| 1257 } | 1256 } |
| 1258 | 1257 |
| 1259 if (video_frame_provider_client_ && video_frame_provider_client_ != client) | 1258 if (video_frame_provider_client_ && video_frame_provider_client_ != client) |
| 1260 video_frame_provider_client_->StopUsingProvider(); | 1259 video_frame_provider_client_->StopUsingProvider(); |
| 1261 video_frame_provider_client_ = client; | 1260 video_frame_provider_client_ = client; |
|
watk
2016/07/29 19:03:16
I'm not sure how this was ever thread safe, if thi
tguilbert
2016/08/01 22:05:57
My guess is that it is being used in a safe way, w
| |
| 1262 } | 1261 } |
| 1263 | 1262 |
| 1264 void WebMediaPlayerAndroid::SetCurrentFrameInternal( | 1263 void WebMediaPlayerAndroid::SetCurrentFrameInternal( |
| 1265 scoped_refptr<media::VideoFrame>& video_frame) { | 1264 scoped_refptr<media::VideoFrame>& video_frame) { |
| 1266 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1265 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1267 base::AutoLock auto_lock(current_frame_lock_); | 1266 base::AutoLock auto_lock(current_frame_lock_); |
| 1268 current_frame_ = video_frame; | 1267 current_frame_ = video_frame; |
| 1269 } | 1268 } |
| 1270 | 1269 |
| 1271 bool WebMediaPlayerAndroid::UpdateCurrentFrame(base::TimeTicks deadline_min, | 1270 bool WebMediaPlayerAndroid::UpdateCurrentFrame(base::TimeTicks deadline_min, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1303 texture_id_ = 0; | 1302 texture_id_ = 0; |
| 1304 texture_mailbox_ = gpu::Mailbox(); | 1303 texture_mailbox_ = gpu::Mailbox(); |
| 1305 stream_id_ = 0; | 1304 stream_id_ = 0; |
| 1306 } | 1305 } |
| 1307 stream_texture_proxy_.reset(); | 1306 stream_texture_proxy_.reset(); |
| 1308 needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && | 1307 needs_establish_peer_ = !needs_external_surface_ && !is_remote_ && |
| 1309 !is_fullscreen_ && | 1308 !is_fullscreen_ && |
| 1310 (hasVideo() || IsHLSStream()); | 1309 (hasVideo() || IsHLSStream()); |
| 1311 } | 1310 } |
| 1312 | 1311 |
| 1312 void WebMediaPlayerAndroid::UpdateStreamTextureProxyCallback( | |
| 1313 cc::VideoFrameProvider::Client* client) { | |
| 1314 base::Closure frame_received_cb = base::Closure(); | |
|
watk
2016/07/29 19:03:16
You can remove the "= base::Closure();"
tguilbert
2016/08/01 22:05:57
Done.
| |
| 1315 | |
| 1316 if (client) { | |
| 1317 // Unretained is safe here because: | |
| 1318 // - |client| will remain alive, until we call |client_|->setWebLayer(NULL) | |
| 1319 // in the destructor. | |
| 1320 // - We call SetVideoFrameProviderClient(NULL) before calling | |
| 1321 // |client_|->setWebLayer(NULL) in the destructor. | |
| 1322 // - The Closure is protected by a lock in StreamTextureProxy. | |
|
watk
2016/07/29 19:03:16
I would say the proof can be stated slightly more
tguilbert
2016/08/01 22:05:57
Nicely said. Thank you!
| |
| 1323 frame_received_cb = | |
| 1324 base::Bind(&cc::VideoFrameProvider::Client::DidReceiveFrame, | |
| 1325 base::Unretained(client)); | |
| 1326 } | |
| 1327 | |
| 1328 stream_texture_proxy_->BindToLoop(stream_id_, frame_received_cb, | |
|
watk
2016/07/29 19:03:16
Same question as above. Is it thread safe to be ac
tguilbert
2016/08/01 22:05:57
I have not gone through the mental exercise of pro
watk
2016/08/01 22:30:03
sgtm with leaving as is
| |
| 1329 compositor_task_runner_); | |
| 1330 } | |
| 1331 | |
| 1313 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { | 1332 void WebMediaPlayerAndroid::TryCreateStreamTextureProxyIfNeeded() { |
| 1314 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1333 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1315 // Already created. | 1334 // Already created. |
| 1316 if (stream_texture_proxy_) | 1335 if (stream_texture_proxy_) |
| 1317 return; | 1336 return; |
| 1318 | 1337 |
| 1319 // No factory to create proxy. | 1338 // No factory to create proxy. |
| 1320 if (!stream_texture_factory_.get()) | 1339 if (!stream_texture_factory_.get()) |
| 1321 return; | 1340 return; |
| 1322 | 1341 |
| 1323 // Not needed for hole punching. | 1342 // Not needed for hole punching. |
| 1324 if (!needs_establish_peer_) | 1343 if (!needs_establish_peer_) |
| 1325 return; | 1344 return; |
| 1326 | 1345 |
| 1327 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); | 1346 stream_texture_proxy_.reset(stream_texture_factory_->CreateProxy()); |
| 1328 if (stream_texture_proxy_) { | 1347 if (stream_texture_proxy_) { |
| 1329 DoCreateStreamTexture(); | 1348 DoCreateStreamTexture(); |
| 1330 ReallocateVideoFrame(); | 1349 ReallocateVideoFrame(); |
| 1331 if (video_frame_provider_client_) { | 1350 if (video_frame_provider_client_) { |
|
watk
2016/07/29 19:03:16
no braces
tguilbert
2016/08/01 22:05:57
Done.
| |
| 1332 stream_texture_proxy_->BindToLoop( | 1351 UpdateStreamTextureProxyCallback(video_frame_provider_client_); |
| 1333 stream_id_, video_frame_provider_client_, compositor_task_runner_); | |
| 1334 } | 1352 } |
| 1335 } | 1353 } |
| 1336 } | 1354 } |
| 1337 | 1355 |
| 1338 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { | 1356 void WebMediaPlayerAndroid::EstablishSurfaceTexturePeer() { |
| 1339 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1357 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1340 if (!stream_texture_proxy_) | 1358 if (!stream_texture_proxy_) |
| 1341 return; | 1359 return; |
| 1342 | 1360 |
| 1343 if (stream_texture_factory_.get() && stream_id_) | 1361 if (stream_texture_factory_.get() && stream_id_) |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1662 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1680 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1663 } else if (is_hls_url == is_hls) { | 1681 } else if (is_hls_url == is_hls) { |
| 1664 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1682 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1665 } | 1683 } |
| 1666 UMA_HISTOGRAM_ENUMERATION( | 1684 UMA_HISTOGRAM_ENUMERATION( |
| 1667 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1685 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1668 result, PREDICTION_RESULT_MAX); | 1686 result, PREDICTION_RESULT_MAX); |
| 1669 } | 1687 } |
| 1670 | 1688 |
| 1671 } // namespace content | 1689 } // namespace content |
| OLD | NEW |