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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, | 158 base::Bind(&WebMediaPlayerImpl::IncrementExternallyAllocatedMemory, |
154 AsWeakPtr())); | 159 AsWeakPtr())); |
155 | 160 |
156 // Also we want to be notified of |main_loop_| destruction. | 161 // Also we want to be notified of |main_loop_| destruction. |
157 main_loop_->AddDestructionObserver(this); | 162 main_loop_->AddDestructionObserver(this); |
158 | 163 |
159 // Create default video renderer. | 164 // Create default video renderer. |
160 scoped_refptr<media::VideoRendererBase> video_renderer = | 165 scoped_refptr<media::VideoRendererBase> video_renderer = |
161 new media::VideoRendererBase( | 166 new media::VideoRendererBase( |
162 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), | 167 base::Bind(&WebMediaPlayerProxy::Repaint, proxy_), |
163 base::Bind(&WebMediaPlayerProxy::SetOpaque, proxy_.get()), | 168 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::SetOpaque), |
164 true); | 169 true); |
165 filter_collection_->AddVideoRenderer(video_renderer); | 170 filter_collection_->AddVideoRenderer(video_renderer); |
166 proxy_->set_frame_provider(video_renderer); | 171 proxy_->set_frame_provider(video_renderer); |
167 | 172 |
168 // Create default audio renderer. | 173 // Create default audio renderer. |
169 filter_collection_->AddAudioRenderer( | 174 filter_collection_->AddAudioRenderer( |
170 new media::AudioRendererImpl(new media::NullAudioSink())); | 175 new media::AudioRendererImpl(new media::NullAudioSink())); |
171 } | 176 } |
172 | 177 |
173 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 178 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 &decryptor_)) { | 255 &decryptor_)) { |
251 supports_save_ = false; | 256 supports_save_ = false; |
252 StartPipeline(); | 257 StartPipeline(); |
253 return; | 258 return; |
254 } | 259 } |
255 | 260 |
256 // Otherwise it's a regular request which requires resolving the URL first. | 261 // Otherwise it's a regular request which requires resolving the URL first. |
257 proxy_->set_data_source( | 262 proxy_->set_data_source( |
258 new BufferedDataSource(main_loop_, frame_, media_log_, | 263 new BufferedDataSource(main_loop_, frame_, media_log_, |
259 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, | 264 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, |
260 base::Unretained(this)))); | 265 AsWeakPtr()))); |
261 proxy_->data_source()->Initialize( | 266 proxy_->data_source()->Initialize( |
262 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 267 url, static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
263 base::Bind( | 268 base::Bind( |
264 &WebMediaPlayerImpl::DataSourceInitialized, | 269 &WebMediaPlayerImpl::DataSourceInitialized, |
265 base::Unretained(this), gurl)); | 270 AsWeakPtr(), gurl)); |
266 | 271 |
267 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); | 272 is_local_source_ = !gurl.SchemeIs("http") && !gurl.SchemeIs("https"); |
268 | 273 |
269 BuildDefaultCollection(proxy_->data_source(), | 274 BuildDefaultCollection(proxy_->data_source(), |
270 message_loop_factory_.get(), | 275 message_loop_factory_.get(), |
271 filter_collection_.get(), | 276 filter_collection_.get(), |
272 &decryptor_); | 277 &decryptor_); |
273 } | 278 } |
274 | 279 |
275 void WebMediaPlayerImpl::cancelLoad() { | 280 void WebMediaPlayerImpl::cancelLoad() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 if (paused_) | 334 if (paused_) |
330 paused_time_ = seek_time; | 335 paused_time_ = seek_time; |
331 | 336 |
332 seeking_ = true; | 337 seeking_ = true; |
333 | 338 |
334 proxy_->DemuxerStartWaitingForSeek(); | 339 proxy_->DemuxerStartWaitingForSeek(); |
335 | 340 |
336 // Kick off the asynchronous seek! | 341 // Kick off the asynchronous seek! |
337 pipeline_->Seek( | 342 pipeline_->Seek( |
338 seek_time, | 343 seek_time, |
339 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, | 344 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek)); |
340 proxy_.get())); | |
341 } | 345 } |
342 | 346 |
343 void WebMediaPlayerImpl::setEndTime(float seconds) { | 347 void WebMediaPlayerImpl::setEndTime(float seconds) { |
344 DCHECK_EQ(main_loop_, MessageLoop::current()); | 348 DCHECK_EQ(main_loop_, MessageLoop::current()); |
345 | 349 |
346 // TODO(hclam): add method call when it has been implemented. | 350 // TODO(hclam): add method call when it has been implemented. |
347 return; | 351 return; |
348 } | 352 } |
349 | 353 |
350 void WebMediaPlayerImpl::setRate(float rate) { | 354 void WebMediaPlayerImpl::setRate(float rate) { |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 media_log_->AddEvent( | 966 media_log_->AddEvent( |
963 media_log_->CreateBooleanEvent( | 967 media_log_->CreateBooleanEvent( |
964 media::MediaLogEvent::NETWORK_ACTIVITY_SET, | 968 media::MediaLogEvent::NETWORK_ACTIVITY_SET, |
965 "is_downloading_data", is_downloading)); | 969 "is_downloading_data", is_downloading)); |
966 } | 970 } |
967 | 971 |
968 void WebMediaPlayerImpl::StartPipeline() { | 972 void WebMediaPlayerImpl::StartPipeline() { |
969 starting_ = true; | 973 starting_ = true; |
970 pipeline_->Start( | 974 pipeline_->Start( |
971 filter_collection_.Pass(), | 975 filter_collection_.Pass(), |
972 base::Bind(&WebMediaPlayerProxy::PipelineEndedCallback, proxy_.get()), | 976 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineEnded), |
973 base::Bind(&WebMediaPlayerProxy::PipelineErrorCallback, proxy_.get()), | 977 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineError), |
974 base::Bind(&WebMediaPlayerProxy::PipelineSeekCallback, proxy_.get()), | 978 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineSeek), |
975 base::Bind(&WebMediaPlayerProxy::PipelineBufferingStateCallback, | 979 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnPipelineBufferingState)); |
976 proxy_.get())); | |
977 } | 980 } |
978 | 981 |
979 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { | 982 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { |
980 DCHECK_EQ(main_loop_, MessageLoop::current()); | 983 DCHECK_EQ(main_loop_, MessageLoop::current()); |
981 DVLOG(1) << "SetNetworkState: " << state; | 984 DVLOG(1) << "SetNetworkState: " << state; |
982 network_state_ = state; | 985 network_state_ = state; |
983 // Always notify to ensure client has the latest value. | 986 // Always notify to ensure client has the latest value. |
984 GetClient()->networkStateChanged(); | 987 GetClient()->networkStateChanged(); |
985 } | 988 } |
986 | 989 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 return audio_source_provider_; | 1050 return audio_source_provider_; |
1048 } | 1051 } |
1049 | 1052 |
1050 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { | 1053 void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
1051 DCHECK_EQ(main_loop_, MessageLoop::current()); | 1054 DCHECK_EQ(main_loop_, MessageLoop::current()); |
1052 incremented_externally_allocated_memory_ = true; | 1055 incremented_externally_allocated_memory_ = true; |
1053 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); | 1056 v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
1054 } | 1057 } |
1055 | 1058 |
1056 } // namespace webkit_media | 1059 } // namespace webkit_media |
OLD | NEW |