OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/media/webmediaplayer_impl.h" | 5 #include "webkit/media/webmediaplayer_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
34 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
35 #include "webkit/media/buffered_data_source.h" | 35 #include "webkit/media/buffered_data_source.h" |
36 #include "webkit/media/filter_helpers.h" | 36 #include "webkit/media/filter_helpers.h" |
37 #include "webkit/media/webmediaplayer_delegate.h" | 37 #include "webkit/media/webmediaplayer_delegate.h" |
38 #include "webkit/media/webmediaplayer_params.h" | |
38 #include "webkit/media/webmediaplayer_proxy.h" | 39 #include "webkit/media/webmediaplayer_proxy.h" |
39 #include "webkit/media/webmediaplayer_util.h" | 40 #include "webkit/media/webmediaplayer_util.h" |
40 #include "webkit/media/webvideoframe_impl.h" | 41 #include "webkit/media/webvideoframe_impl.h" |
41 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 42 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
42 | 43 |
43 using WebKit::WebCanvas; | 44 using WebKit::WebCanvas; |
44 using WebKit::WebMediaPlayer; | 45 using WebKit::WebMediaPlayer; |
45 using WebKit::WebRect; | 46 using WebKit::WebRect; |
46 using WebKit::WebSize; | 47 using WebKit::WebSize; |
47 using WebKit::WebString; | 48 using WebKit::WebString; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 | 121 |
121 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, | 122 static void LogMediaSourceError(const scoped_refptr<media::MediaLog>& media_log, |
122 const std::string& error) { | 123 const std::string& error) { |
123 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); | 124 media_log->AddEvent(media_log->CreateMediaSourceErrorEvent(error)); |
124 } | 125 } |
125 | 126 |
126 WebMediaPlayerImpl::WebMediaPlayerImpl( | 127 WebMediaPlayerImpl::WebMediaPlayerImpl( |
127 WebKit::WebFrame* frame, | 128 WebKit::WebFrame* frame, |
128 WebKit::WebMediaPlayerClient* client, | 129 WebKit::WebMediaPlayerClient* client, |
129 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 130 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
130 media::FilterCollection* collection, | 131 const WebMediaPlayerParams& params) |
131 WebKit::WebAudioSourceProvider* audio_source_provider, | |
132 media::AudioRendererSink* audio_renderer_sink, | |
133 media::MessageLoopFactory* message_loop_factory, | |
134 MediaStreamClient* media_stream_client, | |
135 media::MediaLog* media_log) | |
136 : frame_(frame), | 132 : frame_(frame), |
137 network_state_(WebMediaPlayer::NetworkStateEmpty), | 133 network_state_(WebMediaPlayer::NetworkStateEmpty), |
138 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 134 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
139 main_loop_(MessageLoop::current()), | 135 main_loop_(MessageLoop::current()), |
140 filter_collection_(collection), | 136 filter_collection_(new media::FilterCollection()), |
141 message_loop_factory_(message_loop_factory), | 137 media_thread_("MediaPipeline"), |
142 paused_(true), | 138 paused_(true), |
143 seeking_(false), | 139 seeking_(false), |
144 playback_rate_(0.0f), | 140 playback_rate_(0.0f), |
145 pending_seek_(false), | 141 pending_seek_(false), |
146 pending_seek_seconds_(0.0f), | 142 pending_seek_seconds_(0.0f), |
147 client_(client), | 143 client_(client), |
148 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), | 144 proxy_(new WebMediaPlayerProxy(main_loop_->message_loop_proxy(), this)), |
149 delegate_(delegate), | 145 delegate_(delegate), |
150 media_stream_client_(media_stream_client), | 146 media_stream_client_(params.media_stream_client()), |
151 media_log_(media_log), | 147 media_log_(params.media_log()), |
152 accelerated_compositing_reported_(false), | 148 accelerated_compositing_reported_(false), |
153 incremented_externally_allocated_memory_(false), | 149 incremented_externally_allocated_memory_(false), |
154 audio_source_provider_(audio_source_provider), | 150 audio_source_provider_(params.audio_source_provider()), |
155 audio_renderer_sink_(audio_renderer_sink), | |
156 is_local_source_(false), | 151 is_local_source_(false), |
157 supports_save_(true), | 152 supports_save_(true), |
158 starting_(false) { | 153 starting_(false) { |
159 media_log_->AddEvent( | 154 media_log_->AddEvent( |
160 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 155 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
161 | 156 |
162 scoped_refptr<base::MessageLoopProxy> pipeline_message_loop = | 157 CHECK(media_thread_.Start()); |
163 message_loop_factory_->GetMessageLoop( | 158 pipeline_ = new media::Pipeline( |
164 media::MessageLoopFactory::kPipeline); | 159 media_thread_.message_loop_proxy(), media_log_); |
165 pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_); | |
166 | 160 |
167 // Let V8 know we started new thread if we did not did it yet. | 161 // Let V8 know we started new thread if we did not did it yet. |
acolwell GONE FROM CHROMIUM
2012/12/26 17:47:51
nit: s/did not did/did not do
scherkus (not reviewing)
2013/01/02 17:01:48
Done.
| |
168 // Made separate task to avoid deletion of player currently being created. | 162 // Made separate task to avoid deletion of player currently being created. |
169 // Also, delaying GC until after player starts gets rid of starting lag -- | 163 // Also, delaying GC until after player starts gets rid of starting lag -- |
170 // collection happens in parallel with playing. | 164 // collection happens in parallel with playing. |
171 // | 165 // |
172 // TODO(enal): remove when we get rid of per-audio-stream thread. | 166 // TODO(enal): remove when we get rid of per-audio-stream thread. |
173 MessageLoop::current()->PostTask( | 167 MessageLoop::current()->PostTask( |
174 FROM_HERE, | 168 FROM_HERE, |
175 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 169 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
176 AsWeakPtr())); | 170 AsWeakPtr())); |
177 | 171 |
178 // Also we want to be notified of |main_loop_| destruction. | 172 // Also we want to be notified of |main_loop_| destruction. |
179 main_loop_->AddDestructionObserver(this); | 173 main_loop_->AddDestructionObserver(this); |
180 | 174 |
181 media::SetDecryptorReadyCB set_decryptor_ready_cb; | 175 media::SetDecryptorReadyCB set_decryptor_ready_cb; |
182 if (WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled()) { | 176 if (WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled()) { |
183 decryptor_.reset(new ProxyDecryptor(proxy_.get(), client, frame)); | 177 decryptor_.reset(new ProxyDecryptor(proxy_.get(), client, frame)); |
184 set_decryptor_ready_cb = base::Bind(&ProxyDecryptor::SetDecryptorReadyCB, | 178 set_decryptor_ready_cb = base::Bind(&ProxyDecryptor::SetDecryptorReadyCB, |
185 base::Unretained(decryptor_.get())); | 179 base::Unretained(decryptor_.get())); |
186 } | 180 } |
187 | 181 |
182 // Create the GPU video decoder if factories were provided. | |
183 if (params.gpu_factories()) { | |
184 filter_collection_->GetVideoDecoders()->push_back( | |
185 new media::GpuVideoDecoder( | |
186 media_thread_.message_loop_proxy(), | |
187 params.gpu_factories())); | |
188 } | |
189 | |
188 // Create default video renderer. | 190 // Create default video renderer. |
189 scoped_refptr<media::VideoRendererBase> video_renderer = | 191 scoped_refptr<media::VideoRendererBase> video_renderer = |
190 new media::VideoRendererBase( | 192 new media::VideoRendererBase( |
191 pipeline_message_loop, | 193 media_thread_.message_loop_proxy(), |
192 set_decryptor_ready_cb, | 194 set_decryptor_ready_cb, |
193 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), | 195 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), |
194 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), | 196 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), |
195 true); | 197 true); |
196 filter_collection_->AddVideoRenderer(video_renderer); | 198 filter_collection_->AddVideoRenderer(video_renderer); |
197 proxy_->set_frame_provider(video_renderer); | 199 proxy_->set_frame_provider(video_renderer); |
198 | 200 |
199 // Create default audio renderer using the null sink if no sink was provided. | 201 // Create default audio renderer using the null sink if no sink was provided. |
202 scoped_refptr<media::AudioRendererSink> audio_renderer_sink = | |
203 params.audio_renderer_sink(); | |
200 if (!audio_renderer_sink) | 204 if (!audio_renderer_sink) |
201 audio_renderer_sink = new media::NullAudioSink(); | 205 audio_renderer_sink = new media::NullAudioSink(); |
202 | 206 |
203 filter_collection_->AddAudioRenderer(new media::AudioRendererImpl( | 207 filter_collection_->AddAudioRenderer(new media::AudioRendererImpl( |
204 audio_renderer_sink, set_decryptor_ready_cb)); | 208 audio_renderer_sink, set_decryptor_ready_cb)); |
205 } | 209 } |
206 | 210 |
207 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 211 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
208 DCHECK_EQ(main_loop_, MessageLoop::current()); | 212 DCHECK_EQ(main_loop_, MessageLoop::current()); |
209 Destroy(); | 213 Destroy(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); | 265 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); |
262 | 266 |
263 // Handle any volume/preload changes that occured before load(). | 267 // Handle any volume/preload changes that occured before load(). |
264 setVolume(GetClient()->volume()); | 268 setVolume(GetClient()->volume()); |
265 setPreload(GetClient()->preload()); | 269 setPreload(GetClient()->preload()); |
266 | 270 |
267 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 271 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
268 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 272 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
269 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 273 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
270 | 274 |
271 scoped_refptr<base::MessageLoopProxy> message_loop = | |
272 message_loop_factory_->GetMessageLoop( | |
273 media::MessageLoopFactory::kPipeline); | |
274 | |
275 // Media streams pipelines can start immediately. | 275 // Media streams pipelines can start immediately. |
276 if (BuildMediaStreamCollection(url, media_stream_client_, | 276 if (BuildMediaStreamCollection(url, media_stream_client_, |
277 message_loop, | 277 media_thread_.message_loop_proxy(), |
278 filter_collection_.get())) { | 278 filter_collection_.get())) { |
279 supports_save_ = false; | 279 supports_save_ = false; |
280 StartPipeline(); | 280 StartPipeline(); |
281 return; | 281 return; |
282 } | 282 } |
283 | 283 |
284 // Media source pipelines can start immediately. | 284 // Media source pipelines can start immediately. |
285 if (!url.isEmpty() && url == GetClient()->sourceURL()) { | 285 if (!url.isEmpty() && url == GetClient()->sourceURL()) { |
286 chunk_demuxer_ = new media::ChunkDemuxer( | 286 chunk_demuxer_ = new media::ChunkDemuxer( |
287 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), | 287 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnDemuxerOpened), |
288 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""), | 288 BIND_TO_RENDER_LOOP_2(&WebMediaPlayerImpl::OnNeedKey, "", ""), |
289 base::Bind(&LogMediaSourceError, media_log_)); | 289 base::Bind(&LogMediaSourceError, media_log_)); |
290 | 290 |
291 BuildMediaSourceCollection(chunk_demuxer_, | 291 BuildMediaSourceCollection(chunk_demuxer_, |
292 message_loop, | 292 media_thread_.message_loop_proxy(), |
293 filter_collection_.get()); | 293 filter_collection_.get()); |
294 supports_save_ = false; | 294 supports_save_ = false; |
295 StartPipeline(); | 295 StartPipeline(); |
296 return; | 296 return; |
297 } | 297 } |
298 | 298 |
299 // Otherwise it's a regular request which requires resolving the URL first. | 299 // Otherwise it's a regular request which requires resolving the URL first. |
300 proxy_->set_data_source( | 300 proxy_->set_data_source( |
301 new BufferedDataSource(main_loop_, frame_, media_log_, | 301 new BufferedDataSource(main_loop_, frame_, media_log_, |
302 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | 302 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, |
303 AsWeakPtr()))); | 303 AsWeakPtr()))); |
304 proxy_->data_source()->Initialize( | 304 proxy_->data_source()->Initialize( |
305 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 305 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
306 base::Bind( | 306 base::Bind( |
307 &WebMediaPlayerImpl::DataSourceInitialized, | 307 &WebMediaPlayerImpl::DataSourceInitialized, |
308 AsWeakPtr(), gurl)); | 308 AsWeakPtr(), gurl)); |
309 | 309 |
310 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 310 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
311 | 311 |
312 BuildDefaultCollection(proxy_->data_source(), | 312 BuildDefaultCollection(proxy_->data_source(), |
313 message_loop, | 313 media_thread_.message_loop_proxy(), |
314 filter_collection_.get()); | 314 filter_collection_.get()); |
315 } | 315 } |
316 | 316 |
317 void WebMediaPlayerImpl::cancelLoad() { | 317 void WebMediaPlayerImpl::cancelLoad() { |
318 DCHECK_EQ(main_loop_, MessageLoop::current()); | 318 DCHECK_EQ(main_loop_, MessageLoop::current()); |
319 } | 319 } |
320 | 320 |
321 void WebMediaPlayerImpl::play() { | 321 void WebMediaPlayerImpl::play() { |
322 DCHECK_EQ(main_loop_, MessageLoop::current()); | 322 DCHECK_EQ(main_loop_, MessageLoop::current()); |
323 | 323 |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 pipeline_->Stop(base::Bind( | 1184 pipeline_->Stop(base::Bind( |
1185 &base::WaitableEvent::Signal, base::Unretained(&waiter))); | 1185 &base::WaitableEvent::Signal, base::Unretained(&waiter))); |
1186 waiter.Wait(); | 1186 waiter.Wait(); |
1187 | 1187 |
1188 // Let V8 know we are not using extra resources anymore. | 1188 // Let V8 know we are not using extra resources anymore. |
1189 if (incremented_externally_allocated_memory_) { | 1189 if (incremented_externally_allocated_memory_) { |
1190 v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory); | 1190 v8::V8::AdjustAmountOfExternalAllocatedMemory(-kPlayerExtraMemory); |
1191 incremented_externally_allocated_memory_ = false; | 1191 incremented_externally_allocated_memory_ = false; |
1192 } | 1192 } |
1193 | 1193 |
1194 message_loop_factory_.reset(); | 1194 media_thread_.Stop(); |
1195 | 1195 |
1196 // And then detach the proxy, it may live on the render thread for a little | 1196 // And then detach the proxy, it may live on the render thread for a little |
1197 // longer until all the tasks are finished. | 1197 // longer until all the tasks are finished. |
1198 if (proxy_) { | 1198 if (proxy_) { |
1199 proxy_->Detach(); | 1199 proxy_->Detach(); |
1200 proxy_ = NULL; | 1200 proxy_ = NULL; |
1201 } | 1201 } |
1202 } | 1202 } |
1203 | 1203 |
1204 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 1204 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
1205 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1205 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1206 DCHECK(client_); | 1206 DCHECK(client_); |
1207 return client_; | 1207 return client_; |
1208 } | 1208 } |
1209 | 1209 |
1210 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() { | 1210 WebKit::WebAudioSourceProvider* WebMediaPlayerImpl::audioSourceProvider() { |
1211 return audio_source_provider_; | 1211 return audio_source_provider_; |
1212 } | 1212 } |
1213 | 1213 |
1214 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1214 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1215 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1215 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1216 incremented_externally_allocated_memory_ = true; | 1216 incremented_externally_allocated_memory_ = true; |
1217 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1217 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1218 } | 1218 } |
1219 | 1219 |
1220 } // namespace webkit_media | 1220 } // namespace webkit_media |
OLD | NEW |