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 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 109 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
ddorwin
2015/05/26 21:43:07
We've never had to duplicate this constructor befo
Srirama
2015/05/27 14:48:50
I need to setup the path for encrypted_client rela
| |
110 scoped_ptr<RendererFactory> renderer_factory, | 110 scoped_ptr<RendererFactory> renderer_factory, |
111 CdmFactory* cdm_factory, | 111 CdmFactory* cdm_factory, |
112 const WebMediaPlayerParams& params) | 112 const WebMediaPlayerParams& params) |
113 : frame_(frame), | 113 : frame_(frame), |
114 network_state_(WebMediaPlayer::NetworkStateEmpty), | 114 network_state_(WebMediaPlayer::NetworkStateEmpty), |
115 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 115 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
116 preload_(BufferedDataSource::AUTO), | 116 preload_(BufferedDataSource::AUTO), |
117 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 117 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
118 media_task_runner_(params.media_task_runner()), | 118 media_task_runner_(params.media_task_runner()), |
119 media_log_(params.media_log()), | 119 media_log_(params.media_log()), |
(...skipping 17 matching lines...) Expand all Loading... | |
137 compositor_task_runner_( | 137 compositor_task_runner_( |
138 params.compositor_task_runner() | 138 params.compositor_task_runner() |
139 ? params.compositor_task_runner() | 139 ? params.compositor_task_runner() |
140 : base::MessageLoop::current()->task_runner()), | 140 : base::MessageLoop::current()->task_runner()), |
141 compositor_(new VideoFrameCompositor( | 141 compositor_(new VideoFrameCompositor( |
142 compositor_task_runner_, | 142 compositor_task_runner_, |
143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 143 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
144 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 144 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
145 encrypted_media_support_(cdm_factory, | 145 encrypted_media_support_(cdm_factory, |
146 client, | 146 client, |
147 nullptr, | |
147 params.media_permission(), | 148 params.media_permission(), |
148 base::Bind(&WebMediaPlayerImpl::SetCdm, | 149 base::Bind(&WebMediaPlayerImpl::SetCdm, |
149 AsWeakPtr(), | 150 AsWeakPtr(), |
151 base::Bind(&IgnoreCdmAttached))), | |
152 renderer_factory_(renderer_factory.Pass()) { | |
153 media_log_->AddEvent( | |
154 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | |
155 | |
156 if (params.initial_cdm()) { | |
157 SetCdm(base::Bind(&IgnoreCdmAttached), | |
158 ToWebContentDecryptionModuleImpl(params.initial_cdm()) | |
159 ->GetCdmContext()); | |
160 } | |
161 | |
162 // TODO(xhwang): When we use an external Renderer, many methods won't work, | |
163 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 | |
164 | |
165 // Use the null sink if no sink was provided. | |
166 audio_source_provider_ = new WebAudioSourceProviderImpl( | |
167 params.audio_renderer_sink().get() | |
168 ? params.audio_renderer_sink() | |
169 : new NullAudioSink(media_task_runner_)); | |
170 } | |
171 | |
172 WebMediaPlayerImpl::WebMediaPlayerImpl( | |
173 blink::WebLocalFrame* frame, | |
174 blink::WebMediaPlayerClient* client, | |
175 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | |
176 base::WeakPtr<WebMediaPlayerDelegate> delegate, | |
177 scoped_ptr<RendererFactory> renderer_factory, | |
178 CdmFactory* cdm_factory, | |
179 const WebMediaPlayerParams& params) | |
180 : frame_(frame), | |
181 network_state_(WebMediaPlayer::NetworkStateEmpty), | |
182 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | |
183 preload_(BufferedDataSource::AUTO), | |
184 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
185 media_task_runner_(params.media_task_runner()), | |
186 media_log_(params.media_log()), | |
187 pipeline_(media_task_runner_, media_log_.get()), | |
188 load_type_(LoadTypeURL), | |
189 opaque_(false), | |
190 paused_(true), | |
191 seeking_(false), | |
192 playback_rate_(0.0), | |
193 ended_(false), | |
194 pending_seek_(false), | |
195 pending_seek_seconds_(0.0f), | |
196 should_notify_time_changed_(false), | |
197 client_(client), | |
198 encrypted_client_(encrypted_client), | |
199 delegate_(delegate), | |
200 defer_load_cb_(params.defer_load_cb()), | |
201 context_3d_cb_(params.context_3d_cb()), | |
202 supports_save_(true), | |
203 chunk_demuxer_(NULL), | |
204 // Threaded compositing isn't enabled universally yet. | |
205 compositor_task_runner_( | |
206 params.compositor_task_runner() | |
207 ? params.compositor_task_runner() | |
208 : base::MessageLoop::current()->task_runner()), | |
209 compositor_(new VideoFrameCompositor( | |
210 compositor_task_runner_, | |
211 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | |
212 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | |
213 encrypted_media_support_(cdm_factory, | |
214 client, | |
215 encrypted_client, | |
216 params.media_permission(), | |
217 base::Bind(&WebMediaPlayerImpl::SetCdm, | |
218 AsWeakPtr(), | |
150 base::Bind(&IgnoreCdmAttached))), | 219 base::Bind(&IgnoreCdmAttached))), |
151 renderer_factory_(renderer_factory.Pass()) { | 220 renderer_factory_(renderer_factory.Pass()) { |
152 media_log_->AddEvent( | 221 media_log_->AddEvent( |
153 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 222 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
154 | 223 |
155 if (params.initial_cdm()) { | 224 if (params.initial_cdm()) { |
156 SetCdm(base::Bind(&IgnoreCdmAttached), | 225 SetCdm(base::Bind(&IgnoreCdmAttached), |
157 ToWebContentDecryptionModuleImpl(params.initial_cdm()) | 226 ToWebContentDecryptionModuleImpl(params.initial_cdm()) |
158 ->GetCdmContext()); | 227 ->GetCdmContext()); |
159 } | 228 } |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 } | 748 } |
680 | 749 |
681 // TODO(xhwang): Update this UMA name. | 750 // TODO(xhwang): Update this UMA name. |
682 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); | 751 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); |
683 | 752 |
684 encrypted_media_support_.SetInitDataType(init_data_type); | 753 encrypted_media_support_.SetInitDataType(init_data_type); |
685 | 754 |
686 client_->encrypted(ConvertToWebInitDataType(init_data_type), | 755 client_->encrypted(ConvertToWebInitDataType(init_data_type), |
687 vector_as_array(&init_data), | 756 vector_as_array(&init_data), |
688 base::saturated_cast<unsigned int>(init_data.size())); | 757 base::saturated_cast<unsigned int>(init_data.size())); |
758 if (encrypted_client_) | |
759 encrypted_client_->encrypted( | |
760 ConvertToWebInitDataType(init_data_type), vector_as_array(&init_data), | |
761 base::saturated_cast<unsigned int>(init_data.size())); | |
689 } | 762 } |
690 | 763 |
691 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { | 764 void WebMediaPlayerImpl::OnWaitingForDecryptionKey() { |
692 client_->didBlockPlaybackWaitingForKey(); | 765 client_->didBlockPlaybackWaitingForKey(); |
766 if (encrypted_client_) | |
767 encrypted_client_->didBlockPlaybackWaitingForKey(); | |
693 | 768 |
694 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 769 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
695 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 770 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
696 // |has_additional_usable_key| = true). http://crbug.com/461903 | 771 // |has_additional_usable_key| = true). http://crbug.com/461903 |
697 client_->didResumePlaybackBlockedForKey(); | 772 client_->didResumePlaybackBlockedForKey(); |
773 if (encrypted_client_) | |
774 encrypted_client_->didResumePlaybackBlockedForKey(); | |
698 } | 775 } |
699 | 776 |
700 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, | 777 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, |
701 CdmContext* cdm_context) { | 778 CdmContext* cdm_context) { |
702 // If CDM initialization succeeded, tell the pipeline about it. | 779 // If CDM initialization succeeded, tell the pipeline about it. |
703 if (cdm_context) | 780 if (cdm_context) |
704 pipeline_.SetCdm(cdm_context, cdm_attached_cb); | 781 pipeline_.SetCdm(cdm_context, cdm_attached_cb); |
705 } | 782 } |
706 | 783 |
707 void WebMediaPlayerImpl::OnCdmAttached( | 784 void WebMediaPlayerImpl::OnCdmAttached( |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 | 1092 |
1016 // pause() may be called after playback has ended and the HTMLMediaElement | 1093 // pause() may be called after playback has ended and the HTMLMediaElement |
1017 // requires that currentTime() == duration() after ending. We want to ensure | 1094 // requires that currentTime() == duration() after ending. We want to ensure |
1018 // |paused_time_| matches currentTime() in this case or a future seek() may | 1095 // |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. | 1096 // incorrectly discard what it thinks is a seek to the existing time. |
1020 paused_time_ = | 1097 paused_time_ = |
1021 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1098 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1022 } | 1099 } |
1023 | 1100 |
1024 } // namespace media | 1101 } // namespace media |
OLD | NEW |