| 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 "content/renderer/media/webmediaplayer_ms.h" | 5 #include "content/renderer/media/webmediaplayer_ms.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "cc/blink/context_provider_web_context.h" | 14 #include "cc/blink/context_provider_web_context.h" |
| 14 #include "cc/blink/web_layer_impl.h" | 15 #include "cc/blink/web_layer_impl.h" |
| 15 #include "cc/layers/video_layer.h" | 16 #include "cc/layers/video_layer.h" |
| 16 #include "content/public/renderer/render_view.h" | 17 #include "content/public/renderer/render_view.h" |
| 17 #include "content/renderer/media/media_stream_audio_renderer.h" | 18 #include "content/renderer/media/media_stream_audio_renderer.h" |
| 18 #include "content/renderer/media/media_stream_renderer_factory.h" | 19 #include "content/renderer/media/media_stream_renderer_factory.h" |
| 19 #include "content/renderer/media/video_frame_provider.h" | 20 #include "content/renderer/media/video_frame_provider.h" |
| 20 #include "content/renderer/render_frame_impl.h" | 21 #include "content/renderer/render_frame_impl.h" |
| 21 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 22 #include "gpu/blink/webgraphicscontext3d_impl.h" | 23 #include "gpu/blink/webgraphicscontext3d_impl.h" |
| 23 #include "media/base/media_log.h" | 24 #include "media/base/media_log.h" |
| 24 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
| 25 #include "media/base/video_rotation.h" | 26 #include "media/base/video_rotation.h" |
| 26 #include "media/base/video_util.h" | 27 #include "media/base/video_util.h" |
| 27 #include "media/blink/webmediaplayer_delegate.h" | 28 #include "media/blink/webmediaplayer_delegate.h" |
| 28 #include "media/blink/webmediaplayer_util.h" | 29 #include "media/blink/webmediaplayer_util.h" |
| 29 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 30 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
| 30 #include "third_party/WebKit/public/platform/WebRect.h" | 31 #include "third_party/WebKit/public/platform/WebRect.h" |
| 31 #include "third_party/WebKit/public/platform/WebSize.h" | 32 #include "third_party/WebKit/public/platform/WebSize.h" |
| 33 #include "third_party/WebKit/public/platform/WebString.h" |
| 32 #include "third_party/WebKit/public/platform/WebURL.h" | 34 #include "third_party/WebKit/public/platform/WebURL.h" |
| 33 #include "third_party/WebKit/public/web/WebFrame.h" | 35 #include "third_party/WebKit/public/web/WebFrame.h" |
| 34 #include "third_party/WebKit/public/web/WebView.h" | 36 #include "third_party/WebKit/public/web/WebView.h" |
| 35 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 36 | 38 |
| 37 using blink::WebCanvas; | 39 using blink::WebCanvas; |
| 38 using blink::WebMediaPlayer; | 40 using blink::WebMediaPlayer; |
| 39 using blink::WebRect; | 41 using blink::WebRect; |
| 40 using blink::WebSize; | 42 using blink::WebSize; |
| 41 | 43 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 blink::WebFrame* frame, | 99 blink::WebFrame* frame, |
| 98 blink::WebMediaPlayerClient* client, | 100 blink::WebMediaPlayerClient* client, |
| 99 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 101 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 100 media::MediaLog* media_log, | 102 media::MediaLog* media_log, |
| 101 scoped_ptr<MediaStreamRendererFactory> factory) | 103 scoped_ptr<MediaStreamRendererFactory> factory) |
| 102 : frame_(frame), | 104 : frame_(frame), |
| 103 network_state_(WebMediaPlayer::NetworkStateEmpty), | 105 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 104 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 106 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 105 buffered_(static_cast<size_t>(0)), | 107 buffered_(static_cast<size_t>(0)), |
| 106 volume_(1.0f), | 108 volume_(1.0f), |
| 109 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 107 client_(client), | 110 client_(client), |
| 108 delegate_(delegate), | 111 delegate_(delegate), |
| 109 paused_(true), | 112 paused_(true), |
| 110 current_frame_used_(false), | 113 current_frame_used_(false), |
| 111 pending_repaint_(false), | 114 pending_repaint_(false), |
| 112 video_frame_provider_client_(NULL), | 115 video_frame_provider_client_(NULL), |
| 113 received_first_frame_(false), | 116 received_first_frame_(false), |
| 114 total_frame_count_(0), | 117 total_frame_count_(0), |
| 115 dropped_frame_count_(0), | 118 dropped_frame_count_(0), |
| 116 media_log_(media_log), | 119 media_log_(media_log), |
| 117 renderer_factory_(factory.Pass()) { | 120 renderer_factory_(factory.Pass()) { |
| 118 DVLOG(1) << "WebMediaPlayerMS::ctor"; | 121 DVLOG(1) << "WebMediaPlayerMS::ctor"; |
| 119 media_log_->AddEvent( | 122 media_log_->AddEvent( |
| 120 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 123 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 121 } | 124 } |
| 122 | 125 |
| 123 WebMediaPlayerMS::~WebMediaPlayerMS() { | 126 WebMediaPlayerMS::~WebMediaPlayerMS() { |
| 124 DVLOG(1) << "WebMediaPlayerMS::dtor"; | 127 DVLOG(1) << "WebMediaPlayerMS::dtor"; |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | 128 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 126 | 129 |
| 127 SetVideoFrameProviderClient(NULL); | 130 SetVideoFrameProviderClient(NULL); |
| 128 GetClient()->setWebLayer(NULL); | 131 GetClient()->setWebLayer(NULL); |
| 129 | 132 |
| 130 if (video_frame_provider_.get()) | 133 if (video_frame_provider_.get()) |
| 131 video_frame_provider_->Stop(); | 134 video_frame_provider_->Stop(); |
| 132 | 135 |
| 133 if (audio_renderer_.get()) | 136 if (audio_renderer_.get()) |
| 134 audio_renderer_->Stop(); | 137 audio_renderer_->Stop(); |
| 135 | 138 |
| 136 media_log_->AddEvent( | 139 media_log_->AddEvent( |
| 137 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); | 140 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_DESTROYED)); |
| 138 | 141 |
| 139 if (delegate_.get()) | 142 if (delegate_.get()) |
| 140 delegate_->PlayerGone(this); | 143 delegate_->PlayerGone(this); |
| 141 } | 144 } |
| 142 | 145 |
| 143 void WebMediaPlayerMS::load(LoadType load_type, | 146 void WebMediaPlayerMS::load(LoadType load_type, |
| 144 const blink::WebURL& url, | 147 const blink::WebURL& url, |
| 145 CORSMode cors_mode) { | 148 CORSMode cors_mode) { |
| 146 DVLOG(1) << "WebMediaPlayerMS::load"; | 149 DVLOG(1) << "WebMediaPlayerMS::load"; |
| 147 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 148 | 151 |
| 149 // TODO(acolwell): Change this to DCHECK_EQ(load_type, | 152 // TODO(acolwell): Change this to DCHECK_EQ(load_type, |
| 150 // LoadTypeMediaStream) once Blink-side changes land. | 153 // LoadTypeMediaStream) once Blink-side changes land. |
| 151 DCHECK_NE(load_type, LoadTypeMediaSource); | 154 DCHECK_NE(load_type, LoadTypeMediaSource); |
| 152 | 155 |
| 153 GURL gurl(url); | 156 GURL gurl(url); |
| 154 | 157 |
| 155 SetNetworkState(WebMediaPlayer::NetworkStateLoading); | 158 SetNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 156 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 159 SetReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 157 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); | 160 media_log_->AddEvent(media_log_->CreateLoadEvent(url.spec())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 180 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 183 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 181 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 184 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 182 } | 185 } |
| 183 } else { | 186 } else { |
| 184 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError); | 187 SetNetworkState(WebMediaPlayer::NetworkStateNetworkError); |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 void WebMediaPlayerMS::play() { | 191 void WebMediaPlayerMS::play() { |
| 189 DVLOG(1) << "WebMediaPlayerMS::play"; | 192 DVLOG(1) << "WebMediaPlayerMS::play"; |
| 190 DCHECK(thread_checker_.CalledOnValidThread()); | 193 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 191 | 194 |
| 192 if (paused_) { | 195 if (paused_) { |
| 193 if (video_frame_provider_.get()) | 196 if (video_frame_provider_.get()) |
| 194 video_frame_provider_->Play(); | 197 video_frame_provider_->Play(); |
| 195 | 198 |
| 196 if (audio_renderer_.get()) | 199 if (audio_renderer_.get()) |
| 197 audio_renderer_->Play(); | 200 audio_renderer_->Play(); |
| 198 | 201 |
| 199 if (delegate_.get()) | 202 if (delegate_.get()) |
| 200 delegate_->DidPlay(this); | 203 delegate_->DidPlay(this); |
| 201 } | 204 } |
| 202 | 205 |
| 203 paused_ = false; | 206 paused_ = false; |
| 204 | 207 |
| 205 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); | 208 media_log_->AddEvent(media_log_->CreateEvent(media::MediaLogEvent::PLAY)); |
| 206 } | 209 } |
| 207 | 210 |
| 208 void WebMediaPlayerMS::pause() { | 211 void WebMediaPlayerMS::pause() { |
| 209 DVLOG(1) << "WebMediaPlayerMS::pause"; | 212 DVLOG(1) << "WebMediaPlayerMS::pause"; |
| 210 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 211 | 214 |
| 212 if (video_frame_provider_.get()) | 215 if (video_frame_provider_.get()) |
| 213 video_frame_provider_->Pause(); | 216 video_frame_provider_->Pause(); |
| 214 | 217 |
| 215 if (!paused_) { | 218 if (!paused_) { |
| 216 if (audio_renderer_.get()) | 219 if (audio_renderer_.get()) |
| 217 audio_renderer_->Pause(); | 220 audio_renderer_->Pause(); |
| 218 | 221 |
| 219 if (delegate_.get()) | 222 if (delegate_.get()) |
| 220 delegate_->DidPause(this); | 223 delegate_->DidPause(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 232 // there might be a finite number of available buffers. E.g, video that | 235 // there might be a finite number of available buffers. E.g, video that |
| 233 // originates from a video camera. | 236 // originates from a video camera. |
| 234 scoped_refptr<media::VideoFrame> new_frame = | 237 scoped_refptr<media::VideoFrame> new_frame = |
| 235 CopyFrameToYV12(current_frame_, &video_renderer_); | 238 CopyFrameToYV12(current_frame_, &video_renderer_); |
| 236 | 239 |
| 237 base::AutoLock auto_lock(current_frame_lock_); | 240 base::AutoLock auto_lock(current_frame_lock_); |
| 238 current_frame_ = new_frame; | 241 current_frame_ = new_frame; |
| 239 } | 242 } |
| 240 | 243 |
| 241 bool WebMediaPlayerMS::supportsSave() const { | 244 bool WebMediaPlayerMS::supportsSave() const { |
| 242 DCHECK(thread_checker_.CalledOnValidThread()); | 245 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 243 return false; | 246 return false; |
| 244 } | 247 } |
| 245 | 248 |
| 246 void WebMediaPlayerMS::seek(double seconds) { | 249 void WebMediaPlayerMS::seek(double seconds) { |
| 247 DCHECK(thread_checker_.CalledOnValidThread()); | 250 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 248 } | 251 } |
| 249 | 252 |
| 250 void WebMediaPlayerMS::setRate(double rate) { | 253 void WebMediaPlayerMS::setRate(double rate) { |
| 251 DCHECK(thread_checker_.CalledOnValidThread()); | 254 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 252 } | 255 } |
| 253 | 256 |
| 254 void WebMediaPlayerMS::setVolume(double volume) { | 257 void WebMediaPlayerMS::setVolume(double volume) { |
| 255 DCHECK(thread_checker_.CalledOnValidThread()); | 258 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 256 DVLOG(1) << "WebMediaPlayerMS::setVolume(volume=" << volume << ")"; | 259 DVLOG(1) << "WebMediaPlayerMS::setVolume(volume=" << volume << ")"; |
| 257 volume_ = volume; | 260 volume_ = volume; |
| 258 if (audio_renderer_.get()) | 261 if (audio_renderer_.get()) |
| 259 audio_renderer_->SetVolume(volume_); | 262 audio_renderer_->SetVolume(volume_); |
| 260 } | 263 } |
| 261 | 264 |
| 265 void WebMediaPlayerMS::setAudioOutputDevice( |
| 266 const blink::WebSetAudioOutputDeviceRequest& request) { |
| 267 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 268 std::string device_id_str(request.deviceID().utf8()); |
| 269 GURL security_origin(request.securityOrigin().toString().utf8()); |
| 270 DVLOG(1) << __FUNCTION__ << device_id_str << ", " |
| 271 << security_origin << ")"; |
| 272 |
| 273 blink::WebSetAudioOutputDeviceRequest* request_copy = |
| 274 new blink::WebSetAudioOutputDeviceRequest(request); |
| 275 if (audio_renderer_.get()) { |
| 276 audio_renderer_->SwitchOutputDevice( |
| 277 device_id_str, |
| 278 security_origin, |
| 279 base::Bind(&WebMediaPlayerMS::PrepareFinishSetAudioOutputRequest, |
| 280 base::Unretained(this), |
| 281 main_task_runner_, |
| 282 request_copy)); |
| 283 |
| 284 } else { |
| 285 request.finish(-1); |
| 286 } |
| 287 } |
| 288 |
| 289 void WebMediaPlayerMS::FinishSetAudioOutputRequest( |
| 290 blink::WebSetAudioOutputDeviceRequest *request, |
| 291 int result) { |
| 292 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 293 DVLOG(1) << __PRETTY_FUNCTION__; |
| 294 request->finish(result); |
| 295 delete request; |
| 296 } |
| 297 |
| 298 void WebMediaPlayerMS::PrepareFinishSetAudioOutputRequest( |
| 299 WebMediaPlayerMS* media_player, |
| 300 const scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 301 blink::WebSetAudioOutputDeviceRequest *request, |
| 302 int result) { |
| 303 DCHECK(!task_runner->BelongsToCurrentThread()); |
| 304 DVLOG(1) << __PRETTY_FUNCTION__; |
| 305 // TODO(guidou): Change base::Unretained to a weak pointer |
| 306 media_player->main_task_runner_->PostTask( |
| 307 FROM_HERE, base::Bind(&WebMediaPlayerMS::FinishSetAudioOutputRequest, |
| 308 base::Unretained(media_player), |
| 309 request, |
| 310 result)); |
| 311 } |
| 312 |
| 313 |
| 262 void WebMediaPlayerMS::setPreload(WebMediaPlayer::Preload preload) { | 314 void WebMediaPlayerMS::setPreload(WebMediaPlayer::Preload preload) { |
| 263 DCHECK(thread_checker_.CalledOnValidThread()); | 315 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 264 } | 316 } |
| 265 | 317 |
| 266 bool WebMediaPlayerMS::hasVideo() const { | 318 bool WebMediaPlayerMS::hasVideo() const { |
| 267 DCHECK(thread_checker_.CalledOnValidThread()); | 319 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 268 return (video_frame_provider_.get() != NULL); | 320 return (video_frame_provider_.get() != NULL); |
| 269 } | 321 } |
| 270 | 322 |
| 271 bool WebMediaPlayerMS::hasAudio() const { | 323 bool WebMediaPlayerMS::hasAudio() const { |
| 272 DCHECK(thread_checker_.CalledOnValidThread()); | 324 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 273 return (audio_renderer_.get() != NULL); | 325 return (audio_renderer_.get() != NULL); |
| 274 } | 326 } |
| 275 | 327 |
| 276 blink::WebSize WebMediaPlayerMS::naturalSize() const { | 328 blink::WebSize WebMediaPlayerMS::naturalSize() const { |
| 277 DCHECK(thread_checker_.CalledOnValidThread()); | 329 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 278 | 330 |
| 279 gfx::Size size; | 331 gfx::Size size; |
| 280 if (current_frame_.get()) | 332 if (current_frame_.get()) |
| 281 size = current_frame_->natural_size(); | 333 size = current_frame_->natural_size(); |
| 282 DVLOG(3) << "WebMediaPlayerMS::naturalSize, " << size.ToString(); | 334 DVLOG(3) << "WebMediaPlayerMS::naturalSize, " << size.ToString(); |
| 283 return blink::WebSize(size); | 335 return blink::WebSize(size); |
| 284 } | 336 } |
| 285 | 337 |
| 286 bool WebMediaPlayerMS::paused() const { | 338 bool WebMediaPlayerMS::paused() const { |
| 287 DCHECK(thread_checker_.CalledOnValidThread()); | 339 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 288 return paused_; | 340 return paused_; |
| 289 } | 341 } |
| 290 | 342 |
| 291 bool WebMediaPlayerMS::seeking() const { | 343 bool WebMediaPlayerMS::seeking() const { |
| 292 DCHECK(thread_checker_.CalledOnValidThread()); | 344 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 293 return false; | 345 return false; |
| 294 } | 346 } |
| 295 | 347 |
| 296 double WebMediaPlayerMS::duration() const { | 348 double WebMediaPlayerMS::duration() const { |
| 297 DCHECK(thread_checker_.CalledOnValidThread()); | 349 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 298 return std::numeric_limits<double>::infinity(); | 350 return std::numeric_limits<double>::infinity(); |
| 299 } | 351 } |
| 300 | 352 |
| 301 double WebMediaPlayerMS::currentTime() const { | 353 double WebMediaPlayerMS::currentTime() const { |
| 302 DCHECK(thread_checker_.CalledOnValidThread()); | 354 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 303 if (current_time_.ToInternalValue() != 0) { | 355 if (current_time_.ToInternalValue() != 0) { |
| 304 return current_time_.InSecondsF(); | 356 return current_time_.InSecondsF(); |
| 305 } else if (audio_renderer_.get()) { | 357 } else if (audio_renderer_.get()) { |
| 306 return audio_renderer_->GetCurrentRenderTime().InSecondsF(); | 358 return audio_renderer_->GetCurrentRenderTime().InSecondsF(); |
| 307 } | 359 } |
| 308 return 0.0; | 360 return 0.0; |
| 309 } | 361 } |
| 310 | 362 |
| 311 WebMediaPlayer::NetworkState WebMediaPlayerMS::networkState() const { | 363 WebMediaPlayer::NetworkState WebMediaPlayerMS::networkState() const { |
| 312 DCHECK(thread_checker_.CalledOnValidThread()); | 364 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 313 DVLOG(1) << "WebMediaPlayerMS::networkState, state:" << network_state_; | 365 DVLOG(1) << "WebMediaPlayerMS::networkState, state:" << network_state_; |
| 314 return network_state_; | 366 return network_state_; |
| 315 } | 367 } |
| 316 | 368 |
| 317 WebMediaPlayer::ReadyState WebMediaPlayerMS::readyState() const { | 369 WebMediaPlayer::ReadyState WebMediaPlayerMS::readyState() const { |
| 318 DCHECK(thread_checker_.CalledOnValidThread()); | 370 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 319 DVLOG(1) << "WebMediaPlayerMS::readyState, state:" << ready_state_; | 371 DVLOG(1) << "WebMediaPlayerMS::readyState, state:" << ready_state_; |
| 320 return ready_state_; | 372 return ready_state_; |
| 321 } | 373 } |
| 322 | 374 |
| 323 blink::WebTimeRanges WebMediaPlayerMS::buffered() const { | 375 blink::WebTimeRanges WebMediaPlayerMS::buffered() const { |
| 324 DCHECK(thread_checker_.CalledOnValidThread()); | 376 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 325 return buffered_; | 377 return buffered_; |
| 326 } | 378 } |
| 327 | 379 |
| 328 blink::WebTimeRanges WebMediaPlayerMS::seekable() const { | 380 blink::WebTimeRanges WebMediaPlayerMS::seekable() const { |
| 329 DCHECK(thread_checker_.CalledOnValidThread()); | 381 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 330 return blink::WebTimeRanges(); | 382 return blink::WebTimeRanges(); |
| 331 } | 383 } |
| 332 | 384 |
| 333 bool WebMediaPlayerMS::didLoadingProgress() { | 385 bool WebMediaPlayerMS::didLoadingProgress() { |
| 334 DCHECK(thread_checker_.CalledOnValidThread()); | 386 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 335 return true; | 387 return true; |
| 336 } | 388 } |
| 337 | 389 |
| 338 void WebMediaPlayerMS::paint(blink::WebCanvas* canvas, | 390 void WebMediaPlayerMS::paint(blink::WebCanvas* canvas, |
| 339 const blink::WebRect& rect, | 391 const blink::WebRect& rect, |
| 340 unsigned char alpha, | 392 unsigned char alpha, |
| 341 SkXfermode::Mode mode) { | 393 SkXfermode::Mode mode) { |
| 342 DVLOG(3) << "WebMediaPlayerMS::paint"; | 394 DVLOG(3) << "WebMediaPlayerMS::paint"; |
| 343 DCHECK(thread_checker_.CalledOnValidThread()); | 395 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 344 | 396 |
| 345 media::Context3D context_3d; | 397 media::Context3D context_3d; |
| 346 if (current_frame_.get() && | 398 if (current_frame_.get() && |
| 347 current_frame_->format() == media::VideoFrame::NATIVE_TEXTURE) { | 399 current_frame_->format() == media::VideoFrame::NATIVE_TEXTURE) { |
| 348 cc::ContextProvider* provider = | 400 cc::ContextProvider* provider = |
| 349 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 401 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
| 350 // GPU Process crashed. | 402 // GPU Process crashed. |
| 351 if (!provider) | 403 if (!provider) |
| 352 return; | 404 return; |
| 353 context_3d = media::Context3D(provider->ContextGL(), provider->GrContext()); | 405 context_3d = media::Context3D(provider->ContextGL(), provider->GrContext()); |
| 354 DCHECK(context_3d.gl); | 406 DCHECK(context_3d.gl); |
| 355 } | 407 } |
| 356 gfx::RectF dest_rect(rect.x, rect.y, rect.width, rect.height); | 408 gfx::RectF dest_rect(rect.x, rect.y, rect.width, rect.height); |
| 357 video_renderer_.Paint(current_frame_, canvas, dest_rect, alpha, mode, | 409 video_renderer_.Paint(current_frame_, canvas, dest_rect, alpha, mode, |
| 358 media::VIDEO_ROTATION_0, context_3d); | 410 media::VIDEO_ROTATION_0, context_3d); |
| 359 | 411 |
| 360 { | 412 { |
| 361 base::AutoLock auto_lock(current_frame_lock_); | 413 base::AutoLock auto_lock(current_frame_lock_); |
| 362 if (current_frame_.get()) | 414 if (current_frame_.get()) |
| 363 current_frame_used_ = true; | 415 current_frame_used_ = true; |
| 364 } | 416 } |
| 365 } | 417 } |
| 366 | 418 |
| 367 bool WebMediaPlayerMS::hasSingleSecurityOrigin() const { | 419 bool WebMediaPlayerMS::hasSingleSecurityOrigin() const { |
| 368 DCHECK(thread_checker_.CalledOnValidThread()); | 420 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 369 return true; | 421 return true; |
| 370 } | 422 } |
| 371 | 423 |
| 372 bool WebMediaPlayerMS::didPassCORSAccessCheck() const { | 424 bool WebMediaPlayerMS::didPassCORSAccessCheck() const { |
| 373 DCHECK(thread_checker_.CalledOnValidThread()); | 425 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 374 return true; | 426 return true; |
| 375 } | 427 } |
| 376 | 428 |
| 377 double WebMediaPlayerMS::mediaTimeForTimeValue(double timeValue) const { | 429 double WebMediaPlayerMS::mediaTimeForTimeValue(double timeValue) const { |
| 378 return media::ConvertSecondsToTimestamp(timeValue).InSecondsF(); | 430 return media::ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| 379 } | 431 } |
| 380 | 432 |
| 381 unsigned WebMediaPlayerMS::decodedFrameCount() const { | 433 unsigned WebMediaPlayerMS::decodedFrameCount() const { |
| 382 DCHECK(thread_checker_.CalledOnValidThread()); | 434 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 383 DVLOG(1) << "WebMediaPlayerMS::decodedFrameCount, " << total_frame_count_; | 435 DVLOG(1) << "WebMediaPlayerMS::decodedFrameCount, " << total_frame_count_; |
| 384 return total_frame_count_; | 436 return total_frame_count_; |
| 385 } | 437 } |
| 386 | 438 |
| 387 unsigned WebMediaPlayerMS::droppedFrameCount() const { | 439 unsigned WebMediaPlayerMS::droppedFrameCount() const { |
| 388 DCHECK(thread_checker_.CalledOnValidThread()); | 440 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 389 DVLOG(1) << "WebMediaPlayerMS::droppedFrameCount, " << dropped_frame_count_; | 441 DVLOG(1) << "WebMediaPlayerMS::droppedFrameCount, " << dropped_frame_count_; |
| 390 return dropped_frame_count_; | 442 return dropped_frame_count_; |
| 391 } | 443 } |
| 392 | 444 |
| 393 unsigned WebMediaPlayerMS::audioDecodedByteCount() const { | 445 unsigned WebMediaPlayerMS::audioDecodedByteCount() const { |
| 394 DCHECK(thread_checker_.CalledOnValidThread()); | 446 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 395 NOTIMPLEMENTED(); | 447 NOTIMPLEMENTED(); |
| 396 return 0; | 448 return 0; |
| 397 } | 449 } |
| 398 | 450 |
| 399 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { | 451 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { |
| 400 DCHECK(thread_checker_.CalledOnValidThread()); | 452 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 401 NOTIMPLEMENTED(); | 453 NOTIMPLEMENTED(); |
| 402 return 0; | 454 return 0; |
| 403 } | 455 } |
| 404 | 456 |
| 405 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( | 457 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( |
| 406 blink::WebGraphicsContext3D* web_graphics_context, | 458 blink::WebGraphicsContext3D* web_graphics_context, |
| 407 unsigned int texture, | 459 unsigned int texture, |
| 408 unsigned int level, | 460 unsigned int level, |
| 409 unsigned int internal_format, | 461 unsigned int internal_format, |
| 410 unsigned int type, | 462 unsigned int type, |
| 411 bool premultiply_alpha, | 463 bool premultiply_alpha, |
| 412 bool flip_y) { | 464 bool flip_y) { |
| 413 return copyVideoTextureToPlatformTexture(web_graphics_context, texture, | 465 return copyVideoTextureToPlatformTexture(web_graphics_context, texture, |
| 414 internal_format, type, | 466 internal_format, type, |
| 415 premultiply_alpha, flip_y); | 467 premultiply_alpha, flip_y); |
| 416 } | 468 } |
| 417 | 469 |
| 418 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( | 470 bool WebMediaPlayerMS::copyVideoTextureToPlatformTexture( |
| 419 blink::WebGraphicsContext3D* web_graphics_context, | 471 blink::WebGraphicsContext3D* web_graphics_context, |
| 420 unsigned int texture, | 472 unsigned int texture, |
| 421 unsigned int internal_format, | 473 unsigned int internal_format, |
| 422 unsigned int type, | 474 unsigned int type, |
| 423 bool premultiply_alpha, | 475 bool premultiply_alpha, |
| 424 bool flip_y) { | 476 bool flip_y) { |
| 425 TRACE_EVENT0("media", "WebMediaPlayerMS:copyVideoTextureToPlatformTexture"); | 477 TRACE_EVENT0("media", "WebMediaPlayerMS:copyVideoTextureToPlatformTexture"); |
| 426 DCHECK(thread_checker_.CalledOnValidThread()); | 478 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 427 | 479 |
| 428 scoped_refptr<media::VideoFrame> video_frame; | 480 scoped_refptr<media::VideoFrame> video_frame; |
| 429 { | 481 { |
| 430 base::AutoLock auto_lock(current_frame_lock_); | 482 base::AutoLock auto_lock(current_frame_lock_); |
| 431 video_frame = current_frame_; | 483 video_frame = current_frame_; |
| 432 } | 484 } |
| 433 | 485 |
| 434 if (!video_frame.get() || | 486 if (!video_frame.get() || |
| 435 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) { | 487 video_frame->format() != media::VideoFrame::NATIVE_TEXTURE) { |
| 436 return false; | 488 return false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 529 |
| 478 void WebMediaPlayerMS::PutCurrentFrame() { | 530 void WebMediaPlayerMS::PutCurrentFrame() { |
| 479 DVLOG(3) << "WebMediaPlayerMS::PutCurrentFrame"; | 531 DVLOG(3) << "WebMediaPlayerMS::PutCurrentFrame"; |
| 480 DCHECK(pending_repaint_); | 532 DCHECK(pending_repaint_); |
| 481 pending_repaint_ = false; | 533 pending_repaint_ = false; |
| 482 } | 534 } |
| 483 | 535 |
| 484 void WebMediaPlayerMS::OnFrameAvailable( | 536 void WebMediaPlayerMS::OnFrameAvailable( |
| 485 const scoped_refptr<media::VideoFrame>& frame) { | 537 const scoped_refptr<media::VideoFrame>& frame) { |
| 486 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; | 538 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; |
| 487 DCHECK(thread_checker_.CalledOnValidThread()); | 539 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 488 ++total_frame_count_; | 540 ++total_frame_count_; |
| 489 if (!received_first_frame_) { | 541 if (!received_first_frame_) { |
| 490 received_first_frame_ = true; | 542 received_first_frame_ = true; |
| 491 { | 543 { |
| 492 base::AutoLock auto_lock(current_frame_lock_); | 544 base::AutoLock auto_lock(current_frame_lock_); |
| 493 DCHECK(!current_frame_used_); | 545 DCHECK(!current_frame_used_); |
| 494 current_frame_ = frame; | 546 current_frame_ = frame; |
| 495 } | 547 } |
| 496 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 548 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 497 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 549 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 522 } | 574 } |
| 523 | 575 |
| 524 if (size_changed) | 576 if (size_changed) |
| 525 GetClient()->sizeChanged(); | 577 GetClient()->sizeChanged(); |
| 526 | 578 |
| 527 GetClient()->repaint(); | 579 GetClient()->repaint(); |
| 528 } | 580 } |
| 529 | 581 |
| 530 void WebMediaPlayerMS::RepaintInternal() { | 582 void WebMediaPlayerMS::RepaintInternal() { |
| 531 DVLOG(1) << "WebMediaPlayerMS::RepaintInternal"; | 583 DVLOG(1) << "WebMediaPlayerMS::RepaintInternal"; |
| 532 DCHECK(thread_checker_.CalledOnValidThread()); | 584 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 533 GetClient()->repaint(); | 585 GetClient()->repaint(); |
| 534 } | 586 } |
| 535 | 587 |
| 536 void WebMediaPlayerMS::OnSourceError() { | 588 void WebMediaPlayerMS::OnSourceError() { |
| 537 DVLOG(1) << "WebMediaPlayerMS::OnSourceError"; | 589 DVLOG(1) << "WebMediaPlayerMS::OnSourceError"; |
| 538 DCHECK(thread_checker_.CalledOnValidThread()); | 590 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 539 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); | 591 SetNetworkState(WebMediaPlayer::NetworkStateFormatError); |
| 540 RepaintInternal(); | 592 RepaintInternal(); |
| 541 } | 593 } |
| 542 | 594 |
| 543 void WebMediaPlayerMS::SetNetworkState(WebMediaPlayer::NetworkState state) { | 595 void WebMediaPlayerMS::SetNetworkState(WebMediaPlayer::NetworkState state) { |
| 544 DCHECK(thread_checker_.CalledOnValidThread()); | 596 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 545 network_state_ = state; | 597 network_state_ = state; |
| 546 // Always notify to ensure client has the latest value. | 598 // Always notify to ensure client has the latest value. |
| 547 GetClient()->networkStateChanged(); | 599 GetClient()->networkStateChanged(); |
| 548 } | 600 } |
| 549 | 601 |
| 550 void WebMediaPlayerMS::SetReadyState(WebMediaPlayer::ReadyState state) { | 602 void WebMediaPlayerMS::SetReadyState(WebMediaPlayer::ReadyState state) { |
| 551 DCHECK(thread_checker_.CalledOnValidThread()); | 603 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 552 ready_state_ = state; | 604 ready_state_ = state; |
| 553 // Always notify to ensure client has the latest value. | 605 // Always notify to ensure client has the latest value. |
| 554 GetClient()->readyStateChanged(); | 606 GetClient()->readyStateChanged(); |
| 555 } | 607 } |
| 556 | 608 |
| 557 blink::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { | 609 blink::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { |
| 558 DCHECK(thread_checker_.CalledOnValidThread()); | 610 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 559 DCHECK(client_); | 611 DCHECK(client_); |
| 560 return client_; | 612 return client_; |
| 561 } | 613 } |
| 562 | 614 |
| 563 } // namespace content | 615 } // namespace content |
| OLD | NEW |