| 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_ms.h" | 5 #include "webkit/media/webmediaplayer_ms.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "cc/layers/video_layer.h" | 13 #include "cc/layers/video_layer.h" |
| 14 #include "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoFrame.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient.
h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 23 #include "webkit/compositor_bindings/web_layer_impl.h" | 22 #include "webkit/compositor_bindings/web_layer_impl.h" |
| 24 #include "webkit/media/media_stream_audio_renderer.h" | 23 #include "webkit/media/media_stream_audio_renderer.h" |
| 25 #include "webkit/media/media_stream_client.h" | 24 #include "webkit/media/media_stream_client.h" |
| 26 #include "webkit/media/video_frame_provider.h" | 25 #include "webkit/media/video_frame_provider.h" |
| 27 #include "webkit/media/webmediaplayer_delegate.h" | 26 #include "webkit/media/webmediaplayer_delegate.h" |
| 28 #include "webkit/media/webmediaplayer_util.h" | 27 #include "webkit/media/webmediaplayer_util.h" |
| 29 #include "webkit/media/webvideoframe_impl.h" | |
| 30 | 28 |
| 31 using WebKit::WebCanvas; | 29 using WebKit::WebCanvas; |
| 32 using WebKit::WebMediaPlayer; | 30 using WebKit::WebMediaPlayer; |
| 33 using WebKit::WebRect; | 31 using WebKit::WebRect; |
| 34 using WebKit::WebSize; | 32 using WebKit::WebSize; |
| 35 | 33 |
| 36 namespace webkit_media { | 34 namespace webkit_media { |
| 37 | 35 |
| 38 WebMediaPlayerMS::WebMediaPlayerMS( | 36 WebMediaPlayerMS::WebMediaPlayerMS( |
| 39 WebKit::WebFrame* frame, | 37 WebKit::WebFrame* frame, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 60 DVLOG(1) << "WebMediaPlayerMS::ctor"; | 58 DVLOG(1) << "WebMediaPlayerMS::ctor"; |
| 61 DCHECK(media_stream_client); | 59 DCHECK(media_stream_client); |
| 62 media_log_->AddEvent( | 60 media_log_->AddEvent( |
| 63 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 61 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 64 } | 62 } |
| 65 | 63 |
| 66 WebMediaPlayerMS::~WebMediaPlayerMS() { | 64 WebMediaPlayerMS::~WebMediaPlayerMS() { |
| 67 DVLOG(1) << "WebMediaPlayerMS::dtor"; | 65 DVLOG(1) << "WebMediaPlayerMS::dtor"; |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 69 | 67 |
| 70 #ifdef REMOVE_WEBVIDEOFRAME | |
| 71 SetVideoFrameProviderClient(NULL); | 68 SetVideoFrameProviderClient(NULL); |
| 72 GetClient()->setWebLayer(NULL); | 69 GetClient()->setWebLayer(NULL); |
| 73 #endif | |
| 74 | 70 |
| 75 if (video_frame_provider_) { | 71 if (video_frame_provider_) { |
| 76 video_frame_provider_->Stop(); | 72 video_frame_provider_->Stop(); |
| 77 } | 73 } |
| 78 | 74 |
| 79 if (audio_renderer_) { | 75 if (audio_renderer_) { |
| 80 if (audio_renderer_->IsLocalRenderer()) { | 76 if (audio_renderer_->IsLocalRenderer()) { |
| 81 audio_renderer_->Stop(); | 77 audio_renderer_->Stop(); |
| 82 } else if (!paused_) { | 78 } else if (!paused_) { |
| 83 // The |audio_renderer_| can be shared by multiple remote streams, and | 79 // The |audio_renderer_| can be shared by multiple remote streams, and |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 NOTIMPLEMENTED(); | 356 NOTIMPLEMENTED(); |
| 361 return 0; | 357 return 0; |
| 362 } | 358 } |
| 363 | 359 |
| 364 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { | 360 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { |
| 365 DCHECK(thread_checker_.CalledOnValidThread()); | 361 DCHECK(thread_checker_.CalledOnValidThread()); |
| 366 NOTIMPLEMENTED(); | 362 NOTIMPLEMENTED(); |
| 367 return 0; | 363 return 0; |
| 368 } | 364 } |
| 369 | 365 |
| 370 #ifndef REMOVE_WEBVIDEOFRAME | |
| 371 WebKit::WebVideoFrame* WebMediaPlayerMS::getCurrentFrame() { | |
| 372 DVLOG(3) << "WebMediaPlayerMS::getCurrentFrame"; | |
| 373 base::AutoLock auto_lock(current_frame_lock_); | |
| 374 DCHECK(!pending_repaint_); | |
| 375 if (current_frame_.get()) { | |
| 376 pending_repaint_ = true; | |
| 377 current_frame_used_ = true; | |
| 378 return new webkit_media::WebVideoFrameImpl(current_frame_); | |
| 379 } | |
| 380 return NULL; | |
| 381 } | |
| 382 | |
| 383 void WebMediaPlayerMS::putCurrentFrame( | |
| 384 WebKit::WebVideoFrame* web_video_frame) { | |
| 385 DVLOG(3) << "WebMediaPlayerMS::putCurrentFrame"; | |
| 386 base::AutoLock auto_lock(current_frame_lock_); | |
| 387 DCHECK(pending_repaint_); | |
| 388 pending_repaint_ = false; | |
| 389 if (web_video_frame) { | |
| 390 delete web_video_frame; | |
| 391 } | |
| 392 } | |
| 393 #else | |
| 394 void WebMediaPlayerMS::SetVideoFrameProviderClient( | 366 void WebMediaPlayerMS::SetVideoFrameProviderClient( |
| 395 cc::VideoFrameProvider::Client* client) { | 367 cc::VideoFrameProvider::Client* client) { |
| 396 // This is called from both the main renderer thread and the compositor | 368 // This is called from both the main renderer thread and the compositor |
| 397 // thread (when the main thread is blocked). | 369 // thread (when the main thread is blocked). |
| 398 if (video_frame_provider_client_) | 370 if (video_frame_provider_client_) |
| 399 video_frame_provider_client_->StopUsingProvider(); | 371 video_frame_provider_client_->StopUsingProvider(); |
| 400 video_frame_provider_client_ = client; | 372 video_frame_provider_client_ = client; |
| 401 } | 373 } |
| 402 | 374 |
| 403 scoped_refptr<media::VideoFrame> WebMediaPlayerMS::GetCurrentFrame() { | 375 scoped_refptr<media::VideoFrame> WebMediaPlayerMS::GetCurrentFrame() { |
| 404 DVLOG(3) << "WebMediaPlayerMS::GetCurrentFrame"; | 376 DVLOG(3) << "WebMediaPlayerMS::GetCurrentFrame"; |
| 405 base::AutoLock auto_lock(current_frame_lock_); | 377 base::AutoLock auto_lock(current_frame_lock_); |
| 406 DCHECK(!pending_repaint_); | 378 DCHECK(!pending_repaint_); |
| 407 if (!current_frame_) | 379 if (!current_frame_) |
| 408 return NULL; | 380 return NULL; |
| 409 pending_repaint_ = true; | 381 pending_repaint_ = true; |
| 410 current_frame_used_ = true; | 382 current_frame_used_ = true; |
| 411 return current_frame_; | 383 return current_frame_; |
| 412 } | 384 } |
| 413 | 385 |
| 414 void WebMediaPlayerMS::PutCurrentFrame( | 386 void WebMediaPlayerMS::PutCurrentFrame( |
| 415 const scoped_refptr<media::VideoFrame>& frame) { | 387 const scoped_refptr<media::VideoFrame>& frame) { |
| 416 DVLOG(3) << "WebMediaPlayerMS::PutCurrentFrame"; | 388 DVLOG(3) << "WebMediaPlayerMS::PutCurrentFrame"; |
| 417 DCHECK(pending_repaint_); | 389 DCHECK(pending_repaint_); |
| 418 pending_repaint_ = false; | 390 pending_repaint_ = false; |
| 419 } | 391 } |
| 420 #endif | |
| 421 | 392 |
| 422 void WebMediaPlayerMS::OnFrameAvailable( | 393 void WebMediaPlayerMS::OnFrameAvailable( |
| 423 const scoped_refptr<media::VideoFrame>& frame) { | 394 const scoped_refptr<media::VideoFrame>& frame) { |
| 424 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; | 395 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; |
| 425 DCHECK(thread_checker_.CalledOnValidThread()); | 396 DCHECK(thread_checker_.CalledOnValidThread()); |
| 426 ++total_frame_count_; | 397 ++total_frame_count_; |
| 427 if (!received_first_frame_) { | 398 if (!received_first_frame_) { |
| 428 received_first_frame_ = true; | 399 received_first_frame_ = true; |
| 429 { | 400 { |
| 430 base::AutoLock auto_lock(current_frame_lock_); | 401 base::AutoLock auto_lock(current_frame_lock_); |
| 431 DCHECK(!current_frame_used_); | 402 DCHECK(!current_frame_used_); |
| 432 current_frame_ = | 403 current_frame_ = |
| 433 media::VideoFrame::CreateBlackFrame(frame->natural_size()); | 404 media::VideoFrame::CreateBlackFrame(frame->natural_size()); |
| 434 } | 405 } |
| 435 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); | 406 SetReadyState(WebMediaPlayer::ReadyStateHaveMetadata); |
| 436 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); | 407 SetReadyState(WebMediaPlayer::ReadyStateHaveEnoughData); |
| 437 GetClient()->sizeChanged(); | 408 GetClient()->sizeChanged(); |
| 438 | 409 |
| 439 #ifdef REMOVE_WEBVIDEOFRAME | |
| 440 if (video_frame_provider_ && GetClient()->needsWebLayerForVideo()) { | 410 if (video_frame_provider_ && GetClient()->needsWebLayerForVideo()) { |
| 441 video_weblayer_.reset( | 411 video_weblayer_.reset( |
| 442 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); | 412 new webkit::WebLayerImpl(cc::VideoLayer::Create(this))); |
| 443 GetClient()->setWebLayer(video_weblayer_.get()); | 413 GetClient()->setWebLayer(video_weblayer_.get()); |
| 444 } | 414 } |
| 445 #endif | |
| 446 } | 415 } |
| 447 | 416 |
| 448 // Do not update |current_frame_| when paused. | 417 // Do not update |current_frame_| when paused. |
| 449 if (paused_) | 418 if (paused_) |
| 450 return; | 419 return; |
| 451 | 420 |
| 452 if (!sequence_started_) { | 421 if (!sequence_started_) { |
| 453 sequence_started_ = true; | 422 sequence_started_ = true; |
| 454 start_time_ = frame->GetTimestamp(); | 423 start_time_ = frame->GetTimestamp(); |
| 455 } | 424 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 GetClient()->readyStateChanged(); | 467 GetClient()->readyStateChanged(); |
| 499 } | 468 } |
| 500 | 469 |
| 501 WebKit::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { | 470 WebKit::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { |
| 502 DCHECK(thread_checker_.CalledOnValidThread()); | 471 DCHECK(thread_checker_.CalledOnValidThread()); |
| 503 DCHECK(client_); | 472 DCHECK(client_); |
| 504 return client_; | 473 return client_; |
| 505 } | 474 } |
| 506 | 475 |
| 507 } // namespace webkit_media | 476 } // namespace webkit_media |
| OLD | NEW |