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 "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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 160 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
| 161 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 161 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
| 162 | 162 |
| 163 WebMediaPlayerImpl::WebMediaPlayerImpl( | 163 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 164 blink::WebLocalFrame* frame, | 164 blink::WebLocalFrame* frame, |
| 165 blink::WebMediaPlayerClient* client, | 165 blink::WebMediaPlayerClient* client, |
| 166 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 166 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 167 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 167 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 168 std::unique_ptr<RendererFactory> renderer_factory, | 168 std::unique_ptr<RendererFactory> renderer_factory, |
| 169 linked_ptr<UrlIndex> url_index, | 169 linked_ptr<UrlIndex> url_index, |
| 170 MediaPlayerObserver* observer, | |
| 170 const WebMediaPlayerParams& params) | 171 const WebMediaPlayerParams& params) |
|
xhwang
2016/10/01 07:12:15
Since the |observer| is optional, can you put it i
xjz
2016/10/03 22:31:08
Done.
| |
| 171 : frame_(frame), | 172 : frame_(frame), |
| 172 delegate_state_(DelegateState::GONE), | 173 delegate_state_(DelegateState::GONE), |
| 173 is_idle_(false), | 174 is_idle_(false), |
| 174 must_suspend_(false), | 175 must_suspend_(false), |
| 175 network_state_(WebMediaPlayer::NetworkStateEmpty), | 176 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 176 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 177 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 177 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 178 highest_ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 178 preload_(MultibufferDataSource::AUTO), | 179 preload_(MultibufferDataSource::AUTO), |
| 179 buffering_strategy_(MultibufferDataSource::BUFFERING_STRATEGY_NORMAL), | 180 buffering_strategy_(MultibufferDataSource::BUFFERING_STRATEGY_NORMAL), |
| 180 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 181 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 cast_impl_(this, client_, params.context_3d_cb()), | 221 cast_impl_(this, client_, params.context_3d_cb()), |
| 221 #endif | 222 #endif |
| 222 volume_(1.0), | 223 volume_(1.0), |
| 223 volume_multiplier_(1.0), | 224 volume_multiplier_(1.0), |
| 224 renderer_factory_(std::move(renderer_factory)), | 225 renderer_factory_(std::move(renderer_factory)), |
| 225 surface_manager_(params.surface_manager()), | 226 surface_manager_(params.surface_manager()), |
| 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 227 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 227 suppress_destruction_errors_(false), | 228 suppress_destruction_errors_(false), |
| 228 can_suspend_state_(CanSuspendState::UNKNOWN), | 229 can_suspend_state_(CanSuspendState::UNKNOWN), |
| 229 is_encrypted_(false), | 230 is_encrypted_(false), |
| 230 underflow_count_(0) { | 231 underflow_count_(0), |
| 232 observer_(observer) { | |
| 231 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 233 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 232 DCHECK(renderer_factory_); | 234 DCHECK(renderer_factory_); |
| 233 DCHECK(client_); | 235 DCHECK(client_); |
| 234 | 236 |
| 235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 237 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 switches::kForceVideoOverlays); | 238 switches::kForceVideoOverlays); |
| 237 | 239 |
| 238 disable_fullscreen_video_overlays_ = | 240 disable_fullscreen_video_overlays_ = |
| 239 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); | 241 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); |
| 240 | 242 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 surface_created_cb_.Cancel(); | 332 surface_created_cb_.Cancel(); |
| 331 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; | 333 overlay_surface_id_ = SurfaceManager::kNoSurfaceID; |
| 332 | 334 |
| 333 if (decoder_requires_restart_for_overlay_) | 335 if (decoder_requires_restart_for_overlay_) |
| 334 ScheduleRestart(); | 336 ScheduleRestart(); |
| 335 } | 337 } |
| 336 | 338 |
| 337 void WebMediaPlayerImpl::enteredFullscreen() { | 339 void WebMediaPlayerImpl::enteredFullscreen() { |
| 338 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) | 340 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) |
| 339 EnableOverlay(); | 341 EnableOverlay(); |
| 342 if (observer_) | |
| 343 observer_->OnEnteredFullscreen(); | |
| 340 } | 344 } |
| 341 | 345 |
| 342 void WebMediaPlayerImpl::exitedFullscreen() { | 346 void WebMediaPlayerImpl::exitedFullscreen() { |
| 343 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) | 347 if (!force_video_overlays_ && !disable_fullscreen_video_overlays_) |
| 344 DisableOverlay(); | 348 DisableOverlay(); |
| 349 if (observer_) | |
| 350 observer_->OnExitedFullscreen(); | |
| 345 } | 351 } |
| 346 | 352 |
| 347 void WebMediaPlayerImpl::DoLoad(LoadType load_type, | 353 void WebMediaPlayerImpl::DoLoad(LoadType load_type, |
| 348 const blink::WebURL& url, | 354 const blink::WebURL& url, |
| 349 CORSMode cors_mode) { | 355 CORSMode cors_mode) { |
| 350 DVLOG(1) << __func__; | 356 DVLOG(1) << __func__; |
| 351 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 357 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 352 | 358 |
| 353 GURL gurl(url); | 359 GURL gurl(url); |
| 354 ReportMetrics(load_type, gurl, frame_->getSecurityOrigin()); | 360 ReportMetrics(load_type, gurl, frame_->getSecurityOrigin()); |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 946 } | 952 } |
| 947 } | 953 } |
| 948 | 954 |
| 949 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, | 955 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
| 950 CdmContext* cdm_context) { | 956 CdmContext* cdm_context) { |
| 951 if (!cdm_context) { | 957 if (!cdm_context) { |
| 952 cdm_attached_cb.Run(false); | 958 cdm_attached_cb.Run(false); |
| 953 return; | 959 return; |
| 954 } | 960 } |
| 955 | 961 |
| 962 if (observer_) | |
| 963 observer_->OnSetCdm(cdm_context); | |
| 964 | |
| 956 // If CDM initialization succeeded, tell the pipeline about it. | 965 // If CDM initialization succeeded, tell the pipeline about it. |
| 957 pipeline_.SetCdm(cdm_context, cdm_attached_cb); | 966 pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
| 958 } | 967 } |
| 959 | 968 |
| 960 void WebMediaPlayerImpl::OnCdmAttached(bool success) { | 969 void WebMediaPlayerImpl::OnCdmAttached(bool success) { |
| 961 if (success) { | 970 if (success) { |
| 962 set_cdm_result_->complete(); | 971 set_cdm_result_->complete(); |
| 963 set_cdm_result_.reset(); | 972 set_cdm_result_.reset(); |
| 964 is_cdm_attached_ = true; | 973 is_cdm_attached_ = true; |
| 965 return; | 974 return; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 | 1091 |
| 1083 if (overlay_enabled_ && surface_manager_) | 1092 if (overlay_enabled_ && surface_manager_) |
| 1084 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); | 1093 surface_manager_->NaturalSizeChanged(pipeline_metadata_.natural_size); |
| 1085 | 1094 |
| 1086 DCHECK(!video_weblayer_); | 1095 DCHECK(!video_weblayer_); |
| 1087 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( | 1096 video_weblayer_.reset(new cc_blink::WebLayerImpl(cc::VideoLayer::Create( |
| 1088 compositor_, pipeline_metadata_.video_rotation))); | 1097 compositor_, pipeline_metadata_.video_rotation))); |
| 1089 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1098 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1090 video_weblayer_->SetContentsOpaqueIsFixed(true); | 1099 video_weblayer_->SetContentsOpaqueIsFixed(true); |
| 1091 client_->setWebLayer(video_weblayer_.get()); | 1100 client_->setWebLayer(video_weblayer_.get()); |
| 1101 if (observer_) { | |
| 1102 observer_->OnDecoderConfigChanged( | |
| 1103 pipeline_metadata_.audio_decoder_config, | |
| 1104 pipeline_metadata_.video_decoder_config); | |
|
xhwang
2016/10/01 07:12:15
So if there's no video, then we don't call OnDecod
xjz
2016/10/03 22:31:08
Changed to pass the PipelineMetadata. And will be
| |
| 1105 } | |
| 1092 } | 1106 } |
| 1093 | 1107 |
| 1094 CreateWatchTimeReporter(); | 1108 CreateWatchTimeReporter(); |
| 1095 UpdatePlayState(); | 1109 UpdatePlayState(); |
| 1096 } | 1110 } |
| 1097 | 1111 |
| 1098 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { | 1112 void WebMediaPlayerImpl::OnBufferingStateChange(BufferingState state) { |
| 1099 DVLOG(1) << __func__ << "(" << state << ")"; | 1113 DVLOG(1) << __func__ << "(" << state << ")"; |
| 1100 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1114 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1101 | 1115 |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1814 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, | 1828 hasAudio(), hasVideo(), !!chunk_demuxer_, is_encrypted_, media_log_, |
| 1815 pipeline_metadata_.natural_size, | 1829 pipeline_metadata_.natural_size, |
| 1816 base::Bind(&GetCurrentTimeInternal, this))); | 1830 base::Bind(&GetCurrentTimeInternal, this))); |
| 1817 watch_time_reporter_->OnVolumeChange(volume_); | 1831 watch_time_reporter_->OnVolumeChange(volume_); |
| 1818 if (delegate_ && delegate_->IsHidden()) | 1832 if (delegate_ && delegate_->IsHidden()) |
| 1819 watch_time_reporter_->OnHidden(); | 1833 watch_time_reporter_->OnHidden(); |
| 1820 else | 1834 else |
| 1821 watch_time_reporter_->OnShown(); | 1835 watch_time_reporter_->OnShown(); |
| 1822 } | 1836 } |
| 1823 | 1837 |
| 1838 void WebMediaPlayerImpl::ancestorEnteredFullscreen() { | |
| 1839 if (observer_) | |
| 1840 observer_->OnEnteredFullscreen(); | |
| 1841 } | |
| 1842 | |
| 1843 void WebMediaPlayerImpl::ancestorExitedFullscreen() { | |
| 1844 if (observer_) | |
| 1845 observer_->OnExitedFullscreen(); | |
| 1846 } | |
| 1847 | |
| 1824 } // namespace media | 1848 } // namespace media |
| OLD | NEW |