OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
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/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 14 #include "base/command_line.h" |
14 #include "base/debug/alias.h" | 15 #include "base/debug/alias.h" |
15 #include "base/debug/crash_logging.h" | 16 #include "base/debug/crash_logging.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
19 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
20 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
21 #include "cc/blink/web_layer_impl.h" | 22 #include "cc/blink/web_layer_impl.h" |
22 #include "cc/layers/video_layer.h" | 23 #include "cc/layers/video_layer.h" |
23 #include "gpu/blink/webgraphicscontext3d_impl.h" | 24 #include "gpu/blink/webgraphicscontext3d_impl.h" |
24 #include "media/audio/null_audio_sink.h" | 25 #include "media/audio/null_audio_sink.h" |
25 #include "media/base/bind_to_current_loop.h" | 26 #include "media/base/bind_to_current_loop.h" |
26 #include "media/base/cdm_context.h" | 27 #include "media/base/cdm_context.h" |
27 #include "media/base/limits.h" | 28 #include "media/base/limits.h" |
28 #include "media/base/media_log.h" | 29 #include "media/base/media_log.h" |
| 30 #include "media/base/media_switches.h" |
29 #include "media/base/text_renderer.h" | 31 #include "media/base/text_renderer.h" |
30 #include "media/base/timestamp_constants.h" | 32 #include "media/base/timestamp_constants.h" |
31 #include "media/base/video_frame.h" | 33 #include "media/base/video_frame.h" |
32 #include "media/blink/texttrack_impl.h" | 34 #include "media/blink/texttrack_impl.h" |
33 #include "media/blink/webaudiosourceprovider_impl.h" | 35 #include "media/blink/webaudiosourceprovider_impl.h" |
34 #include "media/blink/webcontentdecryptionmodule_impl.h" | 36 #include "media/blink/webcontentdecryptionmodule_impl.h" |
35 #include "media/blink/webinbandtexttrack_impl.h" | 37 #include "media/blink/webinbandtexttrack_impl.h" |
36 #include "media/blink/webmediaplayer_delegate.h" | 38 #include "media/blink/webmediaplayer_delegate.h" |
37 #include "media/blink/webmediaplayer_util.h" | 39 #include "media/blink/webmediaplayer_util.h" |
38 #include "media/blink/webmediasource_impl.h" | 40 #include "media/blink/webmediasource_impl.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const double kMaxRate = 16.0; | 83 const double kMaxRate = 16.0; |
82 | 84 |
83 } // namespace | 85 } // namespace |
84 | 86 |
85 namespace media { | 87 namespace media { |
86 | 88 |
87 class BufferedDataSourceHostImpl; | 89 class BufferedDataSourceHostImpl; |
88 | 90 |
89 #define STATIC_ASSERT_MATCHING_ENUM(name) \ | 91 #define STATIC_ASSERT_MATCHING_ENUM(name) \ |
90 static_assert(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 92 static_assert(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
91 static_cast<int>(BufferedResourceLoader::k ## name), \ | 93 static_cast<int>(UrlData::k ## name), \ |
92 "mismatching enum values: " #name) | 94 "mismatching enum values: " #name) |
93 STATIC_ASSERT_MATCHING_ENUM(Unspecified); | 95 STATIC_ASSERT_MATCHING_ENUM(Unspecified); |
94 STATIC_ASSERT_MATCHING_ENUM(Anonymous); | 96 STATIC_ASSERT_MATCHING_ENUM(Anonymous); |
95 STATIC_ASSERT_MATCHING_ENUM(UseCredentials); | 97 STATIC_ASSERT_MATCHING_ENUM(UseCredentials); |
96 #undef STATIC_ASSERT_MATCHING_ENUM | 98 #undef STATIC_ASSERT_MATCHING_ENUM |
97 | 99 |
98 #define BIND_TO_RENDER_LOOP(function) \ | 100 #define BIND_TO_RENDER_LOOP(function) \ |
99 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 101 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
100 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) | 102 BindToCurrentLoop(base::Bind(function, AsWeakPtr()))) |
101 | 103 |
102 #define BIND_TO_RENDER_LOOP1(function, arg1) \ | 104 #define BIND_TO_RENDER_LOOP1(function, arg1) \ |
103 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ | 105 (DCHECK(main_task_runner_->BelongsToCurrentThread()), \ |
104 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) | 106 BindToCurrentLoop(base::Bind(function, AsWeakPtr(), arg1))) |
105 | 107 |
106 WebMediaPlayerImpl::WebMediaPlayerImpl( | 108 WebMediaPlayerImpl::WebMediaPlayerImpl( |
107 blink::WebLocalFrame* frame, | 109 blink::WebLocalFrame* frame, |
108 blink::WebMediaPlayerClient* client, | 110 blink::WebMediaPlayerClient* client, |
109 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 111 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
110 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 112 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
111 scoped_ptr<RendererFactory> renderer_factory, | 113 scoped_ptr<RendererFactory> renderer_factory, |
112 CdmFactory* cdm_factory, | 114 CdmFactory* cdm_factory, |
| 115 ResourceMultiBuffer* resource_multibuffer, |
113 const WebMediaPlayerParams& params) | 116 const WebMediaPlayerParams& params) |
114 : frame_(frame), | 117 : frame_(frame), |
115 network_state_(WebMediaPlayer::NetworkStateEmpty), | 118 network_state_(WebMediaPlayer::NetworkStateEmpty), |
116 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 119 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
117 preload_(BufferedDataSource::AUTO), | 120 preload_(BufferedDataSource::AUTO), |
118 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 121 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
119 media_task_runner_(params.media_task_runner()), | 122 media_task_runner_(params.media_task_runner()), |
120 worker_task_runner_(params.worker_task_runner()), | 123 worker_task_runner_(params.worker_task_runner()), |
121 media_log_(params.media_log()), | 124 media_log_(params.media_log()), |
122 pipeline_(media_task_runner_, media_log_.get()), | 125 pipeline_(media_task_runner_, media_log_.get()), |
123 load_type_(LoadTypeURL), | 126 load_type_(LoadTypeURL), |
124 opaque_(false), | 127 opaque_(false), |
125 playback_rate_(0.0), | 128 playback_rate_(0.0), |
126 paused_(true), | 129 paused_(true), |
127 seeking_(false), | 130 seeking_(false), |
128 ended_(false), | 131 ended_(false), |
129 pending_seek_(false), | 132 pending_seek_(false), |
130 should_notify_time_changed_(false), | 133 should_notify_time_changed_(false), |
131 client_(client), | 134 client_(client), |
132 encrypted_client_(encrypted_client), | 135 encrypted_client_(encrypted_client), |
133 delegate_(delegate), | 136 delegate_(delegate), |
134 defer_load_cb_(params.defer_load_cb()), | 137 defer_load_cb_(params.defer_load_cb()), |
135 context_3d_cb_(params.context_3d_cb()), | 138 context_3d_cb_(params.context_3d_cb()), |
136 supports_save_(true), | 139 supports_save_(true), |
137 chunk_demuxer_(NULL), | 140 chunk_demuxer_(NULL), |
| 141 resource_multibuffer_(resource_multibuffer), |
138 // Threaded compositing isn't enabled universally yet. | 142 // Threaded compositing isn't enabled universally yet. |
139 compositor_task_runner_( | 143 compositor_task_runner_( |
140 params.compositor_task_runner() | 144 params.compositor_task_runner() |
141 ? params.compositor_task_runner() | 145 ? params.compositor_task_runner() |
142 : base::MessageLoop::current()->task_runner()), | 146 : base::MessageLoop::current()->task_runner()), |
143 compositor_(new VideoFrameCompositor( | 147 compositor_(new VideoFrameCompositor( |
144 compositor_task_runner_, | 148 compositor_task_runner_, |
145 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), | 149 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged), |
146 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), | 150 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))), |
147 encrypted_media_support_(cdm_factory, | 151 encrypted_media_support_(cdm_factory, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 236 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
233 | 237 |
234 // Media source pipelines can start immediately. | 238 // Media source pipelines can start immediately. |
235 if (load_type == LoadTypeMediaSource) { | 239 if (load_type == LoadTypeMediaSource) { |
236 supports_save_ = false; | 240 supports_save_ = false; |
237 StartPipeline(); | 241 StartPipeline(); |
238 return; | 242 return; |
239 } | 243 } |
240 | 244 |
241 // Otherwise it's a regular request which requires resolving the URL first. | 245 // Otherwise it's a regular request which requires resolving the URL first. |
242 data_source_.reset(new BufferedDataSource( | 246 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
243 url, | 247 switches::kMediaUseMultibuffer)) { |
244 static_cast<BufferedResourceLoader::CORSMode>(cors_mode), | 248 // Remove this when MultiBufferDataSource becomes default. |
245 main_task_runner_, | 249 LOG(WARNING) << "Using MultibufferDataSource"; |
246 frame_, | 250 data_source_.reset(new MultibufferDataSource( |
247 media_log_.get(), | 251 url, |
248 &buffered_data_source_host_, | 252 static_cast<UrlData::CORSMode>(cors_mode), |
249 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); | 253 main_task_runner_, |
| 254 resource_multibuffer_, |
| 255 frame_, |
| 256 media_log_.get(), |
| 257 &buffered_data_source_host_, |
| 258 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 259 } else { |
| 260 data_source_.reset(new BufferedDataSource( |
| 261 url, |
| 262 static_cast<BufferedResourceLoader::CORSMode>(cors_mode), |
| 263 main_task_runner_, |
| 264 frame_, |
| 265 media_log_.get(), |
| 266 &buffered_data_source_host_, |
| 267 base::Bind(&WebMediaPlayerImpl::NotifyDownloading, AsWeakPtr()))); |
| 268 } |
250 data_source_->SetPreload(preload_); | 269 data_source_->SetPreload(preload_); |
251 data_source_->Initialize( | 270 data_source_->Initialize( |
252 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); | 271 base::Bind(&WebMediaPlayerImpl::DataSourceInitialized, AsWeakPtr())); |
253 } | 272 } |
254 | 273 |
255 void WebMediaPlayerImpl::play() { | 274 void WebMediaPlayerImpl::play() { |
256 DVLOG(1) << __FUNCTION__; | 275 DVLOG(1) << __FUNCTION__; |
257 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 276 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
258 | 277 |
259 paused_ = false; | 278 paused_ = false; |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 | 1083 |
1065 // pause() may be called after playback has ended and the HTMLMediaElement | 1084 // pause() may be called after playback has ended and the HTMLMediaElement |
1066 // requires that currentTime() == duration() after ending. We want to ensure | 1085 // requires that currentTime() == duration() after ending. We want to ensure |
1067 // |paused_time_| matches currentTime() in this case or a future seek() may | 1086 // |paused_time_| matches currentTime() in this case or a future seek() may |
1068 // incorrectly discard what it thinks is a seek to the existing time. | 1087 // incorrectly discard what it thinks is a seek to the existing time. |
1069 paused_time_ = | 1088 paused_time_ = |
1070 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); | 1089 ended_ ? pipeline_.GetMediaDuration() : pipeline_.GetMediaTime(); |
1071 } | 1090 } |
1072 | 1091 |
1073 } // namespace media | 1092 } // namespace media |
OLD | NEW |