| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #include "media/audio/null_audio_sink.h" | 18 #include "media/audio/null_audio_sink.h" |
| 19 #include "media/base/bind_to_loop.h" |
| 19 #include "media/base/filter_collection.h" | 20 #include "media/base/filter_collection.h" |
| 20 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
| 21 #include "media/base/media_log.h" | 22 #include "media/base/media_log.h" |
| 22 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 23 #include "media/base/pipeline.h" | 24 #include "media/base/pipeline.h" |
| 24 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
| 25 #include "media/filters/audio_renderer_impl.h" | 26 #include "media/filters/audio_renderer_impl.h" |
| 26 #include "media/filters/video_renderer_base.h" | 27 #include "media/filters/video_renderer_base.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 85 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 85 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::CORSMode ## name) == \ | 86 COMPILE_ASSERT(static_cast<int>(WebKit::WebMediaPlayer::CORSMode ## name) == \ |
| 86 static_cast<int>(BufferedResourceLoader::k ## name), \ | 87 static_cast<int>(BufferedResourceLoader::k ## name), \ |
| 87 mismatching_enums) | 88 mismatching_enums) |
| 88 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); | 89 COMPILE_ASSERT_MATCHING_ENUM(Unspecified); |
| 89 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); | 90 COMPILE_ASSERT_MATCHING_ENUM(Anonymous); |
| 90 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); | 91 COMPILE_ASSERT_MATCHING_ENUM(UseCredentials); |
| 91 #undef COMPILE_ASSERT_MATCHING_ENUM | 92 #undef COMPILE_ASSERT_MATCHING_ENUM |
| 92 | 93 |
| 94 #define BIND_TO_RENDER_LOOP(function) \ |
| 95 media::BindToLoop(main_loop_->message_loop_proxy(), base::Bind( \ |
| 96 function, AsWeakPtr())) |
| 97 |
| 93 static WebKit::WebTimeRanges ConvertToWebTimeRanges( | 98 static WebKit::WebTimeRanges ConvertToWebTimeRanges( |
| 94 const media::Ranges<base::TimeDelta>& ranges) { | 99 const media::Ranges<base::TimeDelta>& ranges) { |
| 95 WebKit::WebTimeRanges result(ranges.size()); | 100 WebKit::WebTimeRanges result(ranges.size()); |
| 96 for (size_t i = 0; i < ranges.size(); i++) { | 101 for (size_t i = 0; i < ranges.size(); i++) { |
| 97 result[i].start = ranges.start(i).InSecondsF(); | 102 result[i].start = ranges.start(i).InSecondsF(); |
| 98 result[i].end = ranges.end(i).InSecondsF(); | 103 result[i].end = ranges.end(i).InSecondsF(); |
| 99 } | 104 } |
| 100 return result; | 105 return result; |
| 101 } | 106 } |
| 102 | 107 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 157 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
| 153 AsWeakPtr())); | 158 AsWeakPtr())); |
| 154 | 159 |
| 155 // Also we want to be notified of |main_loop_| destruction. | 160 // Also we want to be notified of |main_loop_| destruction. |
| 156 main_loop_->AddDestructionObserver(this); | 161 main_loop_->AddDestructionObserver(this); |
| 157 | 162 |
| 158 // Create default video renderer. | 163 // Create default video renderer. |
| 159 scoped_refptr<media::VideoRendererBase> video_renderer = | 164 scoped_refptr<media::VideoRendererBase> video_renderer = |
| 160 new media::VideoRendererBase( | 165 new media::VideoRendererBase( |
| 161 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), | 166 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), |
| 162 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()), | 167 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), |
| 163 true); | 168 true); |
| 164 filter_collection_->AddVideoRenderer(video_renderer); | 169 filter_collection_->AddVideoRenderer(video_renderer); |
| 165 proxy_->set_frame_provider(video_renderer); | 170 proxy_->set_frame_provider(video_renderer); |
| 166 | 171 |
| 167 // Create default audio renderer. | 172 // Create default audio renderer. |
| 168 filter_collection_->AddAudioRenderer( | 173 filter_collection_->AddAudioRenderer( |
| 169 new media::AudioRendererImpl(new media::NullAudioSink())); | 174 new media::AudioRendererImpl(new media::NullAudioSink())); |
| 170 } | 175 } |
| 171 | 176 |
| 172 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 177 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 &decryptor_)) { | 254 &decryptor_)) { |
| 250 supports_save_ = false; | 255 supports_save_ = false; |
| 251 StartPipeline(); | 256 StartPipeline(); |
| 252 return; | 257 return; |
| 253 } | 258 } |
| 254 | 259 |
| 255 // Otherwise it's a regular request which requires resolving the URL first. | 260 // Otherwise it's a regular request which requires resolving the URL first. |
| 256 proxy_->set_data_source( | 261 proxy_->set_data_source( |
| 257 new BufferedDataSource(main_loop_, frame_, media_log_, | 262 new BufferedDataSource(main_loop_, frame_, media_log_, |
| 258 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | 263 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, |
| 259 base::Unretained(this)))); | 264 AsWeakPtr()))); |
| 260 proxy_->data_source()->Initialize( | 265 proxy_->data_source()->Initialize( |
| 261 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 266 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
| 262 base::Bind( | 267 base::Bind( |
| 263 &WebMediaPlayerImpl::DataSourceInitialized, | 268 &WebMediaPlayerImpl::DataSourceInitialized, |
| 264 base::Unretained(this), gurl)); | 269 AsWeakPtr(), gurl)); |
| 265 | 270 |
| 266 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 271 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
| 267 | 272 |
| 268 BuildDefaultCollection(proxy_->data_source(), | 273 BuildDefaultCollection(proxy_->data_source(), |
| 269 message_loop_factory_.get(), | 274 message_loop_factory_.get(), |
| 270 filter_collection_.get(), | 275 filter_collection_.get(), |
| 271 &decryptor_); | 276 &decryptor_); |
| 272 } | 277 } |
| 273 | 278 |
| 274 void WebMediaPlayerImpl::cancelLoad() { | 279 void WebMediaPlayerImpl::cancelLoad() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 if (paused_) | 333 if (paused_) |
| 329 paused_time_ = seek_time; | 334 paused_time_ = seek_time; |
| 330 | 335 |
| 331 seeking_ = true; | 336 seeking_ = true; |
| 332 | 337 |
| 333 proxy_->DemuxerStartWaitingForSeek(); | 338 proxy_->DemuxerStartWaitingForSeek(); |
| 334 | 339 |
| 335 // Kick off the asynchronous seek! | 340 // Kick off the asynchronous seek! |
| 336 pipeline_->Seek( | 341 pipeline_->Seek( |
| 337 seek_time, | 342 seek_time, |
| 338 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, | 343 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); |
| 339 proxy_.get())); | |
| 340 } | 344 } |
| 341 | 345 |
| 342 void WebMediaPlayerImpl::setEndTime(float seconds) { | 346 void WebMediaPlayerImpl::setEndTime(float seconds) { |
| 343 DCHECK_EQ(main_loop_, MessageLoop::current()); | 347 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 344 | 348 |
| 345 // TODO(hclam): add method call when it has been implemented. | 349 // TODO(hclam): add method call when it has been implemented. |
| 346 return; | 350 return; |
| 347 } | 351 } |
| 348 | 352 |
| 349 void WebMediaPlayerImpl::setRate(float rate) { | 353 void WebMediaPlayerImpl::setRate(float rate) { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 964 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 961 media_log_->AddEvent( | 965 media_log_->AddEvent( |
| 962 media_log_->CreateBooleanEvent( | 966 media_log_->CreateBooleanEvent( |
| 963 media::MediaLogEvent::NETWORK_ACTIVITY_SET, | 967 media::MediaLogEvent::NETWORK_ACTIVITY_SET, |
| 964 "is_downloading_data", is_downloading)); | 968 "is_downloading_data", is_downloading)); |
| 965 } | 969 } |
| 966 | 970 |
| 967 void WebMediaPlayerImpl::StartPipeline() { | 971 void WebMediaPlayerImpl::StartPipeline() { |
| 968 pipeline_->Start( | 972 pipeline_->Start( |
| 969 filter_collection_.Pass(), | 973 filter_collection_.Pass(), |
| 970 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), | 974 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
| 971 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), | 975 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
| 972 base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, | 976 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineInitialize)); |
| 973 proxy_.get())); | |
| 974 } | 977 } |
| 975 | 978 |
| 976 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 979 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 977 DCHECK_EQ(main_loop_, MessageLoop::current()); | 980 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 978 DVLOG(1) << "SetNetworkState: " << state; | 981 DVLOG(1) << "SetNetworkState: " << state; |
| 979 network_state_ = state; | 982 network_state_ = state; |
| 980 // Always notify to ensure client has the latest value. | 983 // Always notify to ensure client has the latest value. |
| 981 GetClient()->networkStateChanged(); | 984 GetClient()->networkStateChanged(); |
| 982 } | 985 } |
| 983 | 986 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 return audio_source_provider_; | 1035 return audio_source_provider_; |
| 1033 } | 1036 } |
| 1034 | 1037 |
| 1035 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1038 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| 1036 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1039 DCHECK_EQ(main_loop_, MessageLoop::current()); |
| 1037 incremented_externally_allocated_memory_ = true; | 1040 incremented_externally_allocated_memory_ = true; |
| 1038 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1041 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| 1039 } | 1042 } |
| 1040 | 1043 |
| 1041 } // namespace webkit_media | 1044 } // namespace webkit_media |
| OLD | NEW |