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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 99 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
100 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 100 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
101 | 101 |
102 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 102 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
103 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 103 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
104 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 104 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
105 | 105 |
106 WebMediaPlayerImpl::WebMediaPlayerImpl( | 106 WebMediaPlayerImpl::WebMediaPlayerImpl( |
107 blink::WebLocalFrame* frame, | 107 blink::WebLocalFrame* frame, |
108 blink::WebMediaPlayerClient* client, | 108 blink::WebMediaPlayerClient* client, |
| 109 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
109 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 110 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
110 scoped_ptr<RendererFactory> renderer_factory, | 111 scoped_ptr<RendererFactory> renderer_factory, |
111 CdmFactory* cdm_factory, | 112 CdmFactory* cdm_factory, |
112 const WebMediaPlayerParams& params) | 113 const WebMediaPlayerParams& params) |
113 : frame_(frame), | 114 : frame_(frame), |
114 network_state_(WebMediaPlayer::NetworkStateEmpty), | 115 network_state_(WebMediaPlayer::NetworkStateEmpty), |
115 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 116 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
116 preload_(BufferedDataSource::AUTO), | 117 preload_(BufferedDataSource::AUTO), |
117 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 118 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
118 media_task_runner_(params.media_task_runner()), | 119 media_task_runner_(params.media_task_runner()), |
119 media_log_(params.media_log()), | 120 media_log_(params.media_log()), |
120 pipeline_(media_task_runner_, media_log_.get()), | 121 pipeline_(media_task_runner_, media_log_.get()), |
121 load_type_(LoadTypeURL), | 122 load_type_(LoadTypeURL), |
122 opaque_(false), | 123 opaque_(false), |
123 paused_(true), | 124 paused_(true), |
124 seeking_(false), | 125 seeking_(false), |
125 playback_rate_(0.0), | 126 playback_rate_(0.0), |
126 ended_(false), | 127 ended_(false), |
127 pending_seek_(false), | 128 pending_seek_(false), |
128 pending_seek_seconds_(0.0f), | 129 pending_seek_seconds_(0.0f), |
129 should_notify_time_changed_(false), | 130 should_notify_time_changed_(false), |
130 client_(client), | 131 client_(client), |
| 132 encrypted_client_(encrypted_client), |
131 delegate_(delegate), | 133 delegate_(delegate), |
132 defer_load_cb_(params.defer_load_cb()), | 134 defer_load_cb_(params.defer_load_cb()), |
133 context_3d_cb_(params.context_3d_cb()), | 135 context_3d_cb_(params.context_3d_cb()), |
134 supports_save_(true), | 136 supports_save_(true), |
135 chunk_demuxer_(NULL), | 137 chunk_demuxer_(NULL), |
136 // Threaded compositing isn't enabled universally yet. | 138 // Threaded compositing isn't enabled universally yet. |
137 compositor_task_runner_( | 139 compositor_task_runner_( |
138 params.compositor_task_runner() | 140 params.compositor_task_runner() |
139 ? params.compositor_task_runner() | 141 ? params.compositor_task_runner() |
140 : base::MessageLoop::current()->task_runner()), | 142 : base::MessageLoop::current()->task_runner()), |
141 compositor_(new VideoFrameCompositor( | 143 compositor_(new VideoFrameCompositor( |
142 compositor_task_runner_, | 144 compositor_task_runner_, |
143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 145 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
144 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 146 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
145 encrypted_media_support_(cdm_factory, | 147 encrypted_media_support_(cdm_factory, |
146 client, | 148 encrypted_client, |
147 params.media_permission(), | 149 params.media_permission(), |
148 base::Bind(&WebMediaPlayerImpl::SetCdm, | 150 base::Bind(&WebMediaPlayerImpl::SetCdm, |
149 AsWeakPtr(), | 151 AsWeakPtr(), |
150 base::Bind(&IgnoreCdmAttached))), | 152 base::Bind(&IgnoreCdmAttached))), |
151 renderer_factory_(renderer_factory.Pass()) { | 153 renderer_factory_(renderer_factory.Pass()) { |
152 media_log_->AddEvent( | 154 media_log_->AddEvent( |
153 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 155 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
154 | 156 |
155 if (params.initial_cdm()) { | 157 if (params.initial_cdm()) { |
156 SetCdm(base::Bind(&IgnoreCdmAttached), | 158 SetCdm(base::Bind(&IgnoreCdmAttached), |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && | 678 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && |
677 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 679 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
678 return; | 680 return; |
679 } | 681 } |
680 | 682 |
681 // TODO(xhwang): Update this UMA name. | 683 // TODO(xhwang): Update this UMA name. |
682 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 684 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
683 | 685 |
684 encrypted_media_support_.SetInitDataType(init_data_type); | 686 encrypted_media_support_.SetInitDataType(init_data_type); |
685 | 687 |
686 client_->encrypted(ConvertToWebInitDataType(init_data_type), | 688 encrypted_client_->encrypted( |
687 vector_as_array(&init_data), | 689 ConvertToWebInitDataType(init_data_type), vector_as_array(&init_data), |
688 base::saturated_cast<unsigned int>(init_data.size())); | 690 base::saturated_cast<unsigned int>(init_data.size())); |
689 } | 691 } |
690 | 692 |
691 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { | 693 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
692 client_->didBlockPlaybackWaitingForKey(); | 694 encrypted_client_->didBlockPlaybackWaitingForKey(); |
693 | 695 |
694 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 696 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
695 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 697 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
696 // |has_additional_usable_key| = true). http://crbug.com/461903 | 698 // |has_additional_usable_key| = true). http://crbug.com/461903 |
697 client_->didResumePlaybackBlockedForKey(); | 699 encrypted_client_->didResumePlaybackBlockedForKey(); |
698 } | 700 } |
699 | 701 |
700 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, | 702 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
701 CdmContext* cdm_context) { | 703 CdmContext* cdm_context) { |
702 // If CDM initialization succeeded, tell the pipeline about it. | 704 // If CDM initialization succeeded, tell the pipeline about it. |
703 if (cdm_context) | 705 if (cdm_context) |
704 pipeline_.SetCdm(cdm_context, cdm_attached_cb); | 706 pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
705 } | 707 } |
706 | 708 |
707 void WebMediaPlayerImpl::OnCdmAttached( | 709 void WebMediaPlayerImpl::OnCdmAttached( |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 | 1017 |
1016 // pause() may be called after playback has ended and the HTMLMediaElement | 1018 // pause() may be called after playback has ended and the HTMLMediaElement |
1017 // requires that currentTime() == duration() after ending. We want to ensure | 1019 // requires that currentTime() == duration() after ending. We want to ensure |
1018 // |paused_time_| matches currentTime() in this case or a future seek() may | 1020 // |paused_time_| matches currentTime() in this case or a future seek() may |
1019 // incorrectly discard what it thinks is a seek to the existing time. | 1021 // incorrectly discard what it thinks is a seek to the existing time. |
1020 paused_time_ = | 1022 paused_time_ = |
1021 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1023 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1022 } | 1024 } |
1023 | 1025 |
1024 } // namespace media | 1026 } // namespace media |
OLD | NEW |