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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <string> | 10 #include <string> |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 is_cdm_attached_(false), | 200 is_cdm_attached_(false), |
201 #if defined(OS_ANDROID) // WMPI_CAST | 201 #if defined(OS_ANDROID) // WMPI_CAST |
202 cast_impl_(this, client_, params.context_3d_cb()), | 202 cast_impl_(this, client_, params.context_3d_cb()), |
203 #endif | 203 #endif |
204 volume_(1.0), | 204 volume_(1.0), |
205 volume_multiplier_(1.0), | 205 volume_multiplier_(1.0), |
206 renderer_factory_(std::move(renderer_factory)), | 206 renderer_factory_(std::move(renderer_factory)), |
207 surface_manager_(params.surface_manager()), | 207 surface_manager_(params.surface_manager()), |
208 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 208 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
209 suppress_destruction_errors_(false), | 209 suppress_destruction_errors_(false), |
210 can_suspend_state_(CanSuspendState::UNKNOWN) { | 210 can_suspend_state_(CanSuspendState::UNKNOWN), |
211 is_media_remoting_(false), | |
212 is_remote_sink_available_(false), | |
213 is_encrypted_content_(false), | |
214 is_remote_cdm_cb_(params.is_remote_cdm_cb()) { | |
211 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 215 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
212 DCHECK(renderer_factory_); | 216 DCHECK(renderer_factory_); |
213 DCHECK(client_); | 217 DCHECK(client_); |
214 | 218 |
215 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 219 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
216 switches::kForceVideoOverlays); | 220 switches::kForceVideoOverlays); |
217 | 221 |
218 if (delegate_) | 222 if (delegate_) |
219 delegate_id_ = delegate_->AddObserver(this); | 223 delegate_id_ = delegate_->AddObserver(this); |
220 | 224 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
304 surface_created_cb_.Cancel(); | 308 surface_created_cb_.Cancel(); |
305 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; | 309 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; |
306 | 310 |
307 if (decoder_requires_restart_for_overlay_) | 311 if (decoder_requires_restart_for_overlay_) |
308 ScheduleRestart(); | 312 ScheduleRestart(); |
309 } | 313 } |
310 | 314 |
311 void WebMediaPlayerImpl::enteredFullscreen() { | 315 void WebMediaPlayerImpl::enteredFullscreen() { |
312 if (!force_video_overlays_) | 316 if (!force_video_overlays_) |
313 EnableOverlay(); | 317 EnableOverlay(); |
318 videoEnteredFullscreen(); | |
314 } | 319 } |
315 | 320 |
316 void WebMediaPlayerImpl::exitedFullscreen() { | 321 void WebMediaPlayerImpl::exitedFullscreen() { |
317 if (!force_video_overlays_) | 322 if (!force_video_overlays_) |
318 DisableOverlay(); | 323 DisableOverlay(); |
324 videoExitedFullscreen(); | |
319 } | 325 } |
320 | 326 |
321 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 327 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
322 const blink::WebURL& url, | 328 const blink::WebURL& url, |
323 CORSMode cors_mode) { | 329 CORSMode cors_mode) { |
324 DVLOG(1) << __FUNCTION__; | 330 DVLOG(1) << __FUNCTION__; |
325 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 331 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
326 | 332 |
327 GURL gurl(url); | 333 GURL gurl(url); |
328 ReportMetrics(load_type, gurl, frame_->getSecurityOrigin()); | 334 ReportMetrics(load_type, gurl, frame_->getSecurityOrigin()); |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 } | 863 } |
858 | 864 |
859 void WebMediaPlayerImpl::OnEncryptedMediaInitData( | 865 void WebMediaPlayerImpl::OnEncryptedMediaInitData( |
860 EmeInitDataType init_data_type, | 866 EmeInitDataType init_data_type, |
861 const std::vector<uint8_t>& init_data) { | 867 const std::vector<uint8_t>& init_data) { |
862 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); | 868 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); |
863 | 869 |
864 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 | 870 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 |
865 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 871 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
866 | 872 |
873 is_encrypted_content_ = true; | |
874 // Check whether we can switch to remoting for encrypted video. Once switching | |
875 // happens, it is not able to switch back to local media renderer without | |
876 // refreshing the page. | |
877 if (is_remote_sink_available_ && !is_media_remoting_ && | |
878 !is_remote_cdm_cb_.is_null() && is_remote_cdm_cb_.Run()) { | |
879 is_media_remoting_ = true; | |
880 SwitchMediaRenderer(); | |
881 } | |
882 | |
867 encrypted_client_->encrypted( | 883 encrypted_client_->encrypted( |
868 ConvertToWebInitDataType(init_data_type), init_data.data(), | 884 ConvertToWebInitDataType(init_data_type), init_data.data(), |
869 base::saturated_cast<unsigned int>(init_data.size())); | 885 base::saturated_cast<unsigned int>(init_data.size())); |
870 } | 886 } |
871 | 887 |
872 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( | 888 void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated( |
873 std::unique_ptr<MediaTracks> tracks) { | 889 std::unique_ptr<MediaTracks> tracks) { |
874 // For MSE/chunk_demuxer case the media track updates are handled by | 890 // For MSE/chunk_demuxer case the media track updates are handled by |
875 // WebSourceBufferImpl. | 891 // WebSourceBufferImpl. |
876 DCHECK(demuxer_.get()); | 892 DCHECK(demuxer_.get()); |
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1718 // Remote players will be suspended and locally paused. | 1734 // Remote players will be suspended and locally paused. |
1719 if (isRemote()) | 1735 if (isRemote()) |
1720 return; | 1736 return; |
1721 #endif | 1737 #endif |
1722 | 1738 |
1723 // Idle timeout chosen arbitrarily. | 1739 // Idle timeout chosen arbitrarily. |
1724 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 1740 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
1725 this, &WebMediaPlayerImpl::OnPause); | 1741 this, &WebMediaPlayerImpl::OnPause); |
1726 } | 1742 } |
1727 | 1743 |
1744 void WebMediaPlayerImpl::videoEnteredFullscreen() { | |
1745 if (is_encrypted_content_ || is_media_remoting_ || !is_remote_sink_available_) | |
1746 return; | |
1747 | |
1748 is_media_remoting_ = true; | |
1749 SwitchMediaRenderer(); | |
1750 } | |
1751 | |
1752 void WebMediaPlayerImpl::videoExitedFullscreen() { | |
1753 if (is_encrypted_content_ || !is_media_remoting_) | |
1754 return; | |
1755 | |
1756 is_media_remoting_ = false; | |
1757 SwitchMediaRenderer(); | |
1758 } | |
1759 | |
1760 void WebMediaPlayerImpl::OnSinkAvailable() { | |
liberato (no reviews please)
2016/08/29 16:49:12
would it be clearer if these things were pulled ou
xjz
2016/09/09 23:13:06
Yes. Done.
| |
1761 is_remote_sink_available_ = true; | |
1762 } | |
1763 | |
1764 void WebMediaPlayerImpl::OnSinkGone() { | |
1765 is_remote_sink_available_ = false; | |
1766 if (is_media_remoting_) { | |
1767 is_media_remoting_ = false; | |
1768 if (!is_encrypted_content_) { | |
1769 SwitchMediaRenderer(); | |
1770 } else { | |
1771 // TODO(xjz): Need to tell the user to refresh the page. | |
1772 } | |
1773 } | |
1774 } | |
1775 | |
1776 // Switch media renderer between local playing back and remoting media renderer | |
liberato (no reviews please)
2016/08/29 16:49:12
please move this to the .h (good comment, by the w
xjz
2016/09/09 23:13:06
Done.
| |
1777 // according to |is_media_remoting_|. | |
1778 // Note: Always set |is_media_remoting_| accordingly before calling this method. | |
1779 void WebMediaPlayerImpl::SwitchMediaRenderer() { | |
liberato (no reviews please)
2016/08/29 16:49:12
maybe take the new value of is_media_remoting_ as
xjz
2016/09/09 23:13:06
Done.
| |
1780 VLOG(2) << "Switch to: " << (is_media_remoting_ ? "Remoting" : "Local"); | |
1781 pipeline_controller_.Suspend(); | |
1782 pipeline_controller_.Resume(); | |
liberato (no reviews please)
2016/08/29 16:49:12
how does this switch to remote playback?
is there
xjz
2016/09/09 23:13:06
Yes. The implementation will be in the upcoming CL
| |
1783 } | |
1784 | |
1728 } // namespace media | 1785 } // namespace media |
OLD | NEW |