Chromium Code Reviews| 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 "media/base/media_log.h" | 14 #include "media/base/media_log.h" |
| 14 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoFrame.h" | |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerClient. h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 22 #include "webkit/compositor_bindings/web_layer_impl.h" | |
| 22 #include "webkit/media/media_stream_audio_renderer.h" | 23 #include "webkit/media/media_stream_audio_renderer.h" |
| 23 #include "webkit/media/media_stream_client.h" | 24 #include "webkit/media/media_stream_client.h" |
| 24 #include "webkit/media/video_frame_provider.h" | 25 #include "webkit/media/video_frame_provider.h" |
| 25 #include "webkit/media/webmediaplayer_delegate.h" | 26 #include "webkit/media/webmediaplayer_delegate.h" |
| 26 #include "webkit/media/webmediaplayer_util.h" | 27 #include "webkit/media/webmediaplayer_util.h" |
| 27 #include "webkit/media/webvideoframe_impl.h" | |
| 28 | 28 |
| 29 using WebKit::WebCanvas; | 29 using WebKit::WebCanvas; |
| 30 using WebKit::WebMediaPlayer; | 30 using WebKit::WebMediaPlayer; |
| 31 using WebKit::WebRect; | 31 using WebKit::WebRect; |
| 32 using WebKit::WebSize; | 32 using WebKit::WebSize; |
| 33 | 33 |
| 34 namespace webkit_media { | 34 namespace webkit_media { |
| 35 | 35 |
| 36 WebMediaPlayerMS::WebMediaPlayerMS( | 36 WebMediaPlayerMS::WebMediaPlayerMS( |
| 37 WebKit::WebFrame* frame, | 37 WebKit::WebFrame* frame, |
| 38 WebKit::WebMediaPlayerClient* client, | 38 WebKit::WebMediaPlayerClient* client, |
| 39 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 39 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
| 40 MediaStreamClient* media_stream_client, | 40 MediaStreamClient* media_stream_client, |
| 41 media::MediaLog* media_log) | 41 media::MediaLog* media_log) |
| 42 : frame_(frame), | 42 : frame_(frame), |
| 43 network_state_(WebMediaPlayer::NetworkStateEmpty), | 43 network_state_(WebMediaPlayer::NetworkStateEmpty), |
| 44 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), | 44 ready_state_(WebMediaPlayer::ReadyStateHaveNothing), |
| 45 buffered_(static_cast<size_t>(1)), | 45 buffered_(static_cast<size_t>(1)), |
| 46 client_(client), | 46 client_(client), |
| 47 delegate_(delegate), | 47 delegate_(delegate), |
| 48 media_stream_client_(media_stream_client), | 48 media_stream_client_(media_stream_client), |
| 49 paused_(true), | 49 paused_(true), |
| 50 current_frame_used_(false), | 50 current_frame_used_(false), |
| 51 pending_repaint_(false), | 51 pending_repaint_(false), |
| 52 video_frame_provider_client_(NULL), | |
| 52 received_first_frame_(false), | 53 received_first_frame_(false), |
| 53 sequence_started_(false), | 54 sequence_started_(false), |
| 54 total_frame_count_(0), | 55 total_frame_count_(0), |
| 55 dropped_frame_count_(0), | 56 dropped_frame_count_(0), |
| 56 media_log_(media_log) { | 57 media_log_(media_log) { |
| 57 DVLOG(1) << "WebMediaPlayerMS::ctor"; | 58 DVLOG(1) << "WebMediaPlayerMS::ctor"; |
| 58 DCHECK(media_stream_client); | 59 DCHECK(media_stream_client); |
| 59 media_log_->AddEvent( | 60 media_log_->AddEvent( |
| 60 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 61 media_log_->CreateEvent(media::MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 WebMediaPlayerMS::~WebMediaPlayerMS() { | 64 WebMediaPlayerMS::~WebMediaPlayerMS() { |
| 64 DVLOG(1) << "WebMediaPlayerMS::dtor"; | 65 DVLOG(1) << "WebMediaPlayerMS::dtor"; |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 if (video_frame_provider_) { | 67 |
| 68 SetVideoFrameProviderClient(NULL); | |
| 69 // No need for a lock here, as GetCurrentFrame/PutCurrentFrame can't be | |
| 70 // called now that the client is no longer using this provider. Also, load() | |
| 71 // and this destructor are called from the same thread. | |
| 72 setStreamTextureClient(NULL); | |
|
scherkus (not reviewing)
2013/03/18 21:38:24
ditto
| |
| 73 | |
| 74 if (video_frame_provider_) | |
| 67 video_frame_provider_->Stop(); | 75 video_frame_provider_->Stop(); |
| 68 } | |
| 69 | 76 |
| 70 if (audio_renderer_) { | 77 if (audio_renderer_) { |
| 71 if (audio_renderer_->IsLocalRenderer()) { | 78 if (audio_renderer_->IsLocalRenderer()) { |
| 72 audio_renderer_->Stop(); | 79 audio_renderer_->Stop(); |
| 73 } else if (!paused_) { | 80 } else if (!paused_) { |
| 74 // The |audio_renderer_| can be shared by multiple remote streams, and | 81 // The |audio_renderer_| can be shared by multiple remote streams, and |
| 75 // it will be stopped when WebRtcAudioDeviceImpl goes away. So we simply | 82 // it will be stopped when WebRtcAudioDeviceImpl goes away. So we simply |
| 76 // pause the |audio_renderer_| here to avoid re-creating the | 83 // pause the |audio_renderer_| here to avoid re-creating the |
| 77 // |audio_renderer_|. | 84 // |audio_renderer_|. |
| 78 audio_renderer_->Pause(); | 85 audio_renderer_->Pause(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 NOTIMPLEMENTED(); | 358 NOTIMPLEMENTED(); |
| 352 return 0; | 359 return 0; |
| 353 } | 360 } |
| 354 | 361 |
| 355 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { | 362 unsigned WebMediaPlayerMS::videoDecodedByteCount() const { |
| 356 DCHECK(thread_checker_.CalledOnValidThread()); | 363 DCHECK(thread_checker_.CalledOnValidThread()); |
| 357 NOTIMPLEMENTED(); | 364 NOTIMPLEMENTED(); |
| 358 return 0; | 365 return 0; |
| 359 } | 366 } |
| 360 | 367 |
| 361 WebKit::WebVideoFrame* WebMediaPlayerMS::getCurrentFrame() { | 368 WebKit::WebLayer* WebMediaPlayerMS::createCompositingLayer() { |
| 369 return new webkit::WebLayerImpl(cc::VideoLayer::Create(this)); | |
| 370 } | |
| 371 | |
| 372 void WebMediaPlayerMS::SetVideoFrameProviderClient( | |
| 373 cc::VideoFrameProvider::Client* client) { | |
| 374 base::AutoLock auto_lock(provider_lock_); | |
| 375 if (video_frame_provider_client_) | |
| 376 video_frame_provider_client_->StopUsingProvider(); | |
| 377 video_frame_provider_client_ = client; | |
| 378 setStreamTextureClient(client ? this : NULL); | |
| 379 } | |
| 380 | |
| 381 scoped_refptr<media::VideoFrame> WebMediaPlayerMS::GetCurrentFrame() { | |
| 362 DVLOG(3) << "WebMediaPlayerMS::getCurrentFrame"; | 382 DVLOG(3) << "WebMediaPlayerMS::getCurrentFrame"; |
| 363 base::AutoLock auto_lock(current_frame_lock_); | 383 base::AutoLock auto_lock(current_frame_lock_); |
| 364 DCHECK(!pending_repaint_); | 384 DCHECK(!pending_repaint_); |
| 365 if (current_frame_.get()) { | 385 if (!current_frame_) |
| 366 pending_repaint_ = true; | 386 return NULL; |
| 367 current_frame_used_ = true; | 387 pending_repaint_ = true; |
| 368 return new webkit_media::WebVideoFrameImpl(current_frame_); | 388 current_frame_used_ = true; |
| 369 } | 389 return current_frame_; |
| 370 return NULL; | |
| 371 } | 390 } |
| 372 | 391 |
| 373 void WebMediaPlayerMS::putCurrentFrame( | 392 void WebMediaPlayerMS::PutCurrentFrame( |
| 374 WebKit::WebVideoFrame* web_video_frame) { | 393 const scoped_refptr<media::VideoFrame>& frame) { |
| 375 DVLOG(3) << "WebMediaPlayerMS::putCurrentFrame"; | 394 DVLOG(3) << "WebMediaPlayerMS::putCurrentFrame"; |
| 376 base::AutoLock auto_lock(current_frame_lock_); | 395 base::AutoLock auto_lock(current_frame_lock_); |
| 377 DCHECK(pending_repaint_); | 396 DCHECK(pending_repaint_); |
| 378 pending_repaint_ = false; | 397 pending_repaint_ = false; |
| 379 if (web_video_frame) { | 398 } |
| 380 delete web_video_frame; | 399 |
| 381 } | 400 void WebMediaPlayerMS::didReceiveFrame() { |
| 401 // No lock since this gets called on the client's thread. | |
| 402 video_frame_provider_client_->DidReceiveFrame(); | |
| 403 } | |
| 404 | |
| 405 void WebMediaPlayerMS::didUpdateMatrix(const float* matrix) { | |
| 406 // No lock since this gets called on the client's thread. | |
| 407 video_frame_provider_client_->DidUpdateMatrix(matrix); | |
| 382 } | 408 } |
| 383 | 409 |
| 384 void WebMediaPlayerMS::OnFrameAvailable( | 410 void WebMediaPlayerMS::OnFrameAvailable( |
| 385 const scoped_refptr<media::VideoFrame>& frame) { | 411 const scoped_refptr<media::VideoFrame>& frame) { |
| 386 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; | 412 DVLOG(3) << "WebMediaPlayerMS::OnFrameAvailable"; |
| 387 DCHECK(thread_checker_.CalledOnValidThread()); | 413 DCHECK(thread_checker_.CalledOnValidThread()); |
| 388 ++total_frame_count_; | 414 ++total_frame_count_; |
| 389 if (!received_first_frame_) { | 415 if (!received_first_frame_) { |
| 390 received_first_frame_ = true; | 416 received_first_frame_ = true; |
| 391 { | 417 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 GetClient()->readyStateChanged(); | 478 GetClient()->readyStateChanged(); |
| 453 } | 479 } |
| 454 | 480 |
| 455 WebKit::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { | 481 WebKit::WebMediaPlayerClient* WebMediaPlayerMS::GetClient() { |
| 456 DCHECK(thread_checker_.CalledOnValidThread()); | 482 DCHECK(thread_checker_.CalledOnValidThread()); |
| 457 DCHECK(client_); | 483 DCHECK(client_); |
| 458 return client_; | 484 return client_; |
| 459 } | 485 } |
| 460 | 486 |
| 461 } // namespace webkit_media | 487 } // namespace webkit_media |
| OLD | NEW |