| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 setPreload(GetClient()->preload()); | 214 setPreload(GetClient()->preload()); |
| 215 | 215 |
| 216 SetNetworkState(WebKit::WebMediaPlayer::Loading); | 216 SetNetworkState(WebKit::WebMediaPlayer::Loading); |
| 217 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); | 217 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); |
| 218 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 218 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
| 219 | 219 |
| 220 // Media streams pipelines can start immediately. | 220 // Media streams pipelines can start immediately. |
| 221 if (BuildMediaStreamCollection(url, media_stream_client_, | 221 if (BuildMediaStreamCollection(url, media_stream_client_, |
| 222 message_loop_factory_.get(), | 222 message_loop_factory_.get(), |
| 223 filter_collection_.get())) { | 223 filter_collection_.get())) { |
| 224 StartPipeline(gurl); | 224 StartPipeline(); |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Media source pipelines can start immediately. | 228 // Media source pipelines can start immediately. |
| 229 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; | 229 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; |
| 230 if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_, | 230 if (BuildMediaSourceCollection(url, GetClient()->sourceURL(), proxy_, |
| 231 message_loop_factory_.get(), | 231 message_loop_factory_.get(), |
| 232 filter_collection_.get(), | 232 filter_collection_.get(), |
| 233 &video_decoder)) { | 233 &video_decoder)) { |
| 234 StartPipeline(gurl); | |
| 235 proxy_->set_video_decoder(video_decoder); | 234 proxy_->set_video_decoder(video_decoder); |
| 235 StartPipeline(); |
| 236 return; | 236 return; |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Otherwise it's a regular request which requires resolving the URL first. | 239 // Otherwise it's a regular request which requires resolving the URL first. |
| 240 proxy_->set_data_source( | 240 proxy_->set_data_source( |
| 241 new BufferedDataSource(main_loop_, frame_, media_log_)); | 241 new BufferedDataSource(main_loop_, frame_, media_log_)); |
| 242 proxy_->data_source()->Initialize(url, base::Bind( | 242 proxy_->data_source()->Initialize(url, base::Bind( |
| 243 &WebMediaPlayerImpl::DataSourceInitialized, | 243 &WebMediaPlayerImpl::DataSourceInitialized, |
| 244 base::Unretained(this), gurl)); | 244 base::Unretained(this), gurl)); |
| 245 } | 245 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 360 |
| 361 void WebMediaPlayerImpl::setVisible(bool visible) { | 361 void WebMediaPlayerImpl::setVisible(bool visible) { |
| 362 DCHECK_EQ(main_loop_, MessageLoop::current()); | 362 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 363 | 363 |
| 364 // TODO(hclam): add appropriate method call when pipeline has it implemented. | 364 // TODO(hclam): add appropriate method call when pipeline has it implemented. |
| 365 return; | 365 return; |
| 366 } | 366 } |
| 367 | 367 |
| 368 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ | 368 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \ |
| 369 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::webkit_name) == \ | 369 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::webkit_name) == \ |
| 370 static_cast<int>(media::chromium_name), \ | 370 static_cast<int>(webkit_media::chromium_name), \ |
| 371 mismatching_enums) | 371 mismatching_enums) |
| 372 COMPILE_ASSERT_MATCHING_ENUM(None, NONE); | 372 COMPILE_ASSERT_MATCHING_ENUM(None, NONE); |
| 373 COMPILE_ASSERT_MATCHING_ENUM(MetaData, METADATA); | 373 COMPILE_ASSERT_MATCHING_ENUM(MetaData, METADATA); |
| 374 COMPILE_ASSERT_MATCHING_ENUM(Auto, AUTO); | 374 COMPILE_ASSERT_MATCHING_ENUM(Auto, AUTO); |
| 375 | 375 |
| 376 void WebMediaPlayerImpl::setPreload(WebKit::WebMediaPlayer::Preload preload) { | 376 void WebMediaPlayerImpl::setPreload(WebKit::WebMediaPlayer::Preload preload) { |
| 377 DCHECK_EQ(main_loop_, MessageLoop::current()); | 377 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 378 | 378 |
| 379 pipeline_->SetPreload(static_cast<media::Preload>(preload)); | 379 if (proxy_ && proxy_->data_source()) { |
| 380 // XXX: Why do I need to use webkit_media:: prefix? clang complains! |
| 381 proxy_->data_source()->SetPreload( |
| 382 static_cast<webkit_media::Preload>(preload)); |
| 383 } |
| 380 } | 384 } |
| 381 | 385 |
| 382 bool WebMediaPlayerImpl::totalBytesKnown() { | 386 bool WebMediaPlayerImpl::totalBytesKnown() { |
| 383 DCHECK_EQ(main_loop_, MessageLoop::current()); | 387 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 384 | 388 |
| 385 return pipeline_->GetTotalBytes() != 0; | 389 return pipeline_->GetTotalBytes() != 0; |
| 386 } | 390 } |
| 387 | 391 |
| 388 bool WebMediaPlayerImpl::hasVideo() const { | 392 bool WebMediaPlayerImpl::hasVideo() const { |
| 389 DCHECK_EQ(main_loop_, MessageLoop::current()); | 393 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 const GURL& gurl, | 820 const GURL& gurl, |
| 817 media::PipelineStatus status) { | 821 media::PipelineStatus status) { |
| 818 DCHECK_EQ(main_loop_, MessageLoop::current()); | 822 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 819 | 823 |
| 820 if (status != media::PIPELINE_OK) { | 824 if (status != media::PIPELINE_OK) { |
| 821 SetNetworkState(WebKit::WebMediaPlayer::FormatError); | 825 SetNetworkState(WebKit::WebMediaPlayer::FormatError); |
| 822 Repaint(); | 826 Repaint(); |
| 823 return; | 827 return; |
| 824 } | 828 } |
| 825 | 829 |
| 830 // TODO(scherkus): this is leftover from removing DemuxerFactory -- instead |
| 831 // our DataSource should report this information. See http://crbug.com/120426 |
| 832 bool local_source = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
| 833 |
| 826 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; | 834 scoped_refptr<media::FFmpegVideoDecoder> video_decoder; |
| 827 BuildDefaultCollection(proxy_->data_source(), | 835 BuildDefaultCollection(proxy_->data_source(), |
| 836 local_source, |
| 828 message_loop_factory_.get(), | 837 message_loop_factory_.get(), |
| 829 filter_collection_.get(), | 838 filter_collection_.get(), |
| 830 &video_decoder); | 839 &video_decoder); |
| 831 proxy_->set_video_decoder(video_decoder); | 840 proxy_->set_video_decoder(video_decoder); |
| 832 StartPipeline(gurl); | 841 StartPipeline(); |
| 833 } | 842 } |
| 834 | 843 |
| 835 void WebMediaPlayerImpl::StartPipeline(const GURL& gurl) { | 844 void WebMediaPlayerImpl::StartPipeline() { |
| 836 started_ = true; | 845 started_ = true; |
| 837 pipeline_->Start( | 846 pipeline_->Start( |
| 838 filter_collection_.Pass(), | 847 filter_collection_.Pass(), |
| 839 gurl.spec(), | |
| 840 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), | 848 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), |
| 841 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), | 849 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), |
| 842 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, proxy_.get()), | 850 base::Bind(&WebMediaPlayerProxy::NetworkEventCallback, proxy_.get()), |
| 843 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, | 851 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, |
| 844 proxy_.get())); | 852 proxy_.get())); |
| 845 } | 853 } |
| 846 | 854 |
| 847 void WebMediaPlayerImpl::SetNetworkState( | 855 void WebMediaPlayerImpl::SetNetworkState( |
| 848 WebKit::WebMediaPlayer::NetworkState state) { | 856 WebKit::WebMediaPlayer::NetworkState state) { |
| 849 DCHECK_EQ(main_loop_, MessageLoop::current()); | 857 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 return audio_source_provider_; | 914 return audio_source_provider_; |
| 907 } | 915 } |
| 908 | 916 |
| 909 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 917 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 910 DCHECK_EQ(main_loop_, MessageLoop::current()); | 918 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 911 incremented_externally_allocated_memory_ = true; | 919 incremented_externally_allocated_memory_ = true; |
| 912 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 920 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 913 } | 921 } |
| 914 | 922 |
| 915 } // namespace webkit_media | 923 } // namespace webkit_media |
| OLD | NEW |