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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 // Also our timers are not very accurate (especially for ogg), which becomes | 74 // Also our timers are not very accurate (especially for ogg), which becomes |
75 // evident at low speeds and on Vista. Since other speeds are risky and outside | 75 // evident at low speeds and on Vista. Since other speeds are risky and outside |
76 // the norms, we think 1/16x to 16x is a safe and useful range for now. | 76 // the norms, we think 1/16x to 16x is a safe and useful range for now. |
77 const float kMinRate = 0.0625f; | 77 const float kMinRate = 0.0625f; |
78 const float kMaxRate = 16.0f; | 78 const float kMaxRate = 16.0f; |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 namespace webkit_media { | 82 namespace webkit_media { |
83 | 83 |
84 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | |
85 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::name) == \ | |
86 static_cast<int>(BufferedResourceLoader::k ## name), \ | |
87 mismatching_enums) | |
88 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); | |
89 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); | |
90 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); | |
91 #undef COMPILE_ASSERT_MATCHING_ENUM | |
92 | |
84 WebMediaPlayerImpl::WebMediaPlayerImpl( | 93 WebMediaPlayerImpl::WebMediaPlayerImpl( |
85 WebKit::WebFrame* frame, | 94 WebKit::WebFrame* frame, |
86 WebKit::WebMediaPlayerClient* client, | 95 WebKit::WebMediaPlayerClient* client, |
87 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 96 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
88 media::FilterCollection* collection, | 97 media::FilterCollection* collection, |
89 WebKit::WebAudioSourceProvider* audio_source_provider, | 98 WebKit::WebAudioSourceProvider* audio_source_provider, |
90 media::MessageLoopFactory* message_loop_factory, | 99 media::MessageLoopFactory* message_loop_factory, |
91 MediaStreamClient* media_stream_client, | 100 MediaStreamClient* media_stream_client, |
92 media::MediaLog* media_log) | 101 media::MediaLog* media_log) |
93 : frame_(frame), | 102 : frame_(frame), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 if (url.SchemeIs("file")) return kFileURLScheme; | 200 if (url.SchemeIs("file")) return kFileURLScheme; |
192 if (url.SchemeIs("blob")) return kBlobURLScheme; | 201 if (url.SchemeIs("blob")) return kBlobURLScheme; |
193 if (url.SchemeIs("data")) return kDataURLScheme; | 202 if (url.SchemeIs("data")) return kDataURLScheme; |
194 if (url.SchemeIs("filesystem")) return kFileSystemScheme; | 203 if (url.SchemeIs("filesystem")) return kFileSystemScheme; |
195 return kUnknownURLScheme; | 204 return kUnknownURLScheme; |
196 } | 205 } |
197 | 206 |
198 } // anonymous namespace | 207 } // anonymous namespace |
199 | 208 |
200 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { | 209 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { |
210 load(url, Unspecified); | |
211 } | |
212 | |
213 void WebMediaPlayerImpl::load(const WebKit::WebURL& url, CORSMode cors_mode) { | |
201 DCHECK_EQ(main_loop_, MessageLoop::current()); | 214 DCHECK_EQ(main_loop_, MessageLoop::current()); |
202 | 215 |
203 GURL gurl(url); | 216 GURL gurl(url); |
204 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); | 217 UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(gurl), kMaxURLScheme); |
205 | 218 |
206 // Handle any volume/preload changes that occured before load(). | 219 // Handle any volume/preload changes that occured before load(). |
207 setVolume(GetClient()->volume()); | 220 setVolume(GetClient()->volume()); |
208 setPreload(GetClient()->preload()); | 221 setPreload(GetClient()->preload()); |
209 | 222 |
210 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 223 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
211 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 224 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
212 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 225 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
213 | 226 |
214 // Media streams pipelines can start immediately. | 227 // Media streams pipelines can start immediately. |
215 if (BuildMediaStreamCollection(url, media_stream_client_, | 228 if (cors_mode == Unspecified && |
scherkus (not reviewing)
2012/06/06 01:19:58
isn't the proper behaviour to ignore the attribute
Ami GONE FROM CHROMIUM
2012/06/06 01:28:40
Done.
| |
229 BuildMediaStreamCollection(url, media_stream_client_, | |
216 message_loop_factory_.get(), | 230 message_loop_factory_.get(), |
217 filter_collection_.get())) { | 231 filter_collection_.get())) { |
218 StartPipeline(); | 232 StartPipeline(); |
219 return; | 233 return; |
220 } | 234 } |
221 | 235 |
222 // Media source pipelines can start immediately. | 236 // Media source pipelines can start immediately. |
223 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; | 237 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; |
224 if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_, | 238 if (cors_mode == Unspecified && |
239 BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_, | |
225 message_loop_factory_.get(), | 240 message_loop_factory_.get(), |
226 filter_collection_.get(), | 241 filter_collection_.get(), |
227 &video_decoder)) { | 242 &video_decoder)) { |
228 proxy_->set_video_decoder(video_decoder); | 243 proxy_->set_video_decoder(video_decoder); |
229 StartPipeline(); | 244 StartPipeline(); |
230 return; | 245 return; |
231 } | 246 } |
232 | 247 |
233 // Otherwise it's a regular request which requires resolving the URL first. | 248 // Otherwise it's a regular request which requires resolving the URL first. |
234 proxy_->set_data_source( | 249 proxy_->set_data_source( |
235 new BufferedDataSource(main_loop_, frame_, media_log_)); | 250 new BufferedDataSource(main_loop_, frame_, media_log_)); |
236 proxy_->data_source()->Initialize(url, base::Bind( | 251 proxy_->data_source()->Initialize( |
237 &WebMediaPlayerImpl::DataSourceInitialized, | 252 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
238 base::Unretained(this), gurl)); | 253 base::Bind( |
254 &WebMediaPlayerImpl::DataSourceInitialized, | |
255 base::Unretained(this), gurl)); | |
239 | 256 |
240 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 257 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
241 | 258 |
242 BuildDefaultCollection(proxy_->data_source(), | 259 BuildDefaultCollection(proxy_->data_source(), |
243 message_loop_factory_.get(), | 260 message_loop_factory_.get(), |
244 filter_collection_.get(), | 261 filter_collection_.get(), |
245 &video_decoder); | 262 &video_decoder); |
246 proxy_->set_video_decoder(video_decoder); | 263 proxy_->set_video_decoder(video_decoder); |
247 } | 264 } |
248 | 265 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 return; | 372 return; |
356 } | 373 } |
357 | 374 |
358 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ | 375 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ |
359 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ | 376 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::webkit_name) == \ |
360 static_cast<int>(webkit_media::chromium_name), \ | 377 static_cast<int>(webkit_media::chromium_name), \ |
361 mismatching_enums) | 378 mismatching_enums) |
362 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); | 379 COMPILE_ASSERT_MATCHING_ENUM(PreloadNone, NONE); |
363 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); | 380 COMPILE_ASSERT_MATCHING_ENUM(PreloadMetaData, METADATA); |
364 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); | 381 COMPILE_ASSERT_MATCHING_ENUM(PreloadAuto, AUTO); |
382 #undef COMPILE_ASSERT_MATCHING_ENUM | |
365 | 383 |
366 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { | 384 void WebMediaPlayerImpl::setPreload(WebMediaPlayer::Preload preload) { |
367 DCHECK_EQ(main_loop_, MessageLoop::current()); | 385 DCHECK_EQ(main_loop_, MessageLoop::current()); |
368 | 386 |
369 if (proxy_ && proxy_->data_source()) { | 387 if (proxy_ && proxy_->data_source()) { |
370 // XXX: Why do I need to use webkit_media:: prefix? clang complains! | 388 // XXX: Why do I need to use webkit_media:: prefix? clang complains! |
371 proxy_->data_source()->SetPreload( | 389 proxy_->data_source()->SetPreload( |
372 static_cast<webkit_media::Preload>(preload)); | 390 static_cast<webkit_media::Preload>(preload)); |
373 } | 391 } |
374 } | 392 } |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 return audio_source_provider_; | 1050 return audio_source_provider_; |
1033 } | 1051 } |
1034 | 1052 |
1035 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1053 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1036 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1054 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1037 incremented_externally_allocated_memory_ = true; | 1055 incremented_externally_allocated_memory_ = true; |
1038 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1056 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1039 } | 1057 } |
1040 | 1058 |
1041 } // namespace webkit_media | 1059 } // namespace webkit_media |
OLD | NEW |