| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glue/webmediaplayer_impl.h" | 5 #include "webkit/glue/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "media/base/composite_data_source_factory.h" | 12 #include "media/base/composite_data_source_factory.h" |
| 13 #include "media/base/filter_collection.h" | 13 #include "media/base/filter_collection.h" |
| 14 #include "media/base/limits.h" | 14 #include "media/base/limits.h" |
| 15 #include "media/base/media_log.h" | |
| 16 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 17 #include "media/base/pipeline_impl.h" | 16 #include "media/base/pipeline_impl.h" |
| 18 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 19 #include "media/filters/adaptive_demuxer.h" | 18 #include "media/filters/adaptive_demuxer.h" |
| 20 #include "media/filters/chunk_demuxer_factory.h" | 19 #include "media/filters/chunk_demuxer_factory.h" |
| 21 #include "media/filters/ffmpeg_audio_decoder.h" | 20 #include "media/filters/ffmpeg_audio_decoder.h" |
| 22 #include "media/filters/ffmpeg_demuxer_factory.h" | 21 #include "media/filters/ffmpeg_demuxer_factory.h" |
| 23 #include "media/filters/ffmpeg_video_decoder.h" | 22 #include "media/filters/ffmpeg_video_decoder.h" |
| 24 #include "media/filters/null_audio_renderer.h" | 23 #include "media/filters/null_audio_renderer.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 chunk_demuxer_ = NULL; | 312 chunk_demuxer_ = NULL; |
| 314 } | 313 } |
| 315 | 314 |
| 316 ///////////////////////////////////////////////////////////////////////////// | 315 ///////////////////////////////////////////////////////////////////////////// |
| 317 // WebMediaPlayerImpl implementation | 316 // WebMediaPlayerImpl implementation |
| 318 | 317 |
| 319 WebMediaPlayerImpl::WebMediaPlayerImpl( | 318 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 320 WebKit::WebMediaPlayerClient* client, | 319 WebKit::WebMediaPlayerClient* client, |
| 321 media::FilterCollection* collection, | 320 media::FilterCollection* collection, |
| 322 media::MessageLoopFactory* message_loop_factory, | 321 media::MessageLoopFactory* message_loop_factory, |
| 323 MediaStreamClient* media_stream_client, | 322 MediaStreamClient* media_stream_client) |
| 324 media::MediaLog* media_log) | |
| 325 : network_state_(WebKit::WebMediaPlayer::Empty), | 323 : network_state_(WebKit::WebMediaPlayer::Empty), |
| 326 ready_state_(WebKit::WebMediaPlayer::HaveNothing), | 324 ready_state_(WebKit::WebMediaPlayer::HaveNothing), |
| 327 main_loop_(NULL), | 325 main_loop_(NULL), |
| 328 filter_collection_(collection), | 326 filter_collection_(collection), |
| 329 pipeline_(NULL), | 327 pipeline_(NULL), |
| 330 message_loop_factory_(message_loop_factory), | 328 message_loop_factory_(message_loop_factory), |
| 331 paused_(true), | 329 paused_(true), |
| 332 seeking_(false), | 330 seeking_(false), |
| 333 playback_rate_(0.0f), | 331 playback_rate_(0.0f), |
| 334 client_(client), | 332 client_(client), |
| 335 proxy_(NULL), | 333 proxy_(NULL), |
| 336 media_stream_client_(media_stream_client), | 334 media_stream_client_(media_stream_client) { |
| 337 media_log_(media_log) { | |
| 338 // Saves the current message loop. | 335 // Saves the current message loop. |
| 339 DCHECK(!main_loop_); | 336 DCHECK(!main_loop_); |
| 340 main_loop_ = MessageLoop::current(); | 337 main_loop_ = MessageLoop::current(); |
| 341 media_log_->AddEventOfType(media::MediaLogEvent::CREATING); | |
| 342 } | 338 } |
| 343 | 339 |
| 344 bool WebMediaPlayerImpl::Initialize( | 340 bool WebMediaPlayerImpl::Initialize( |
| 345 WebKit::WebFrame* frame, | 341 WebKit::WebFrame* frame, |
| 346 bool use_simple_data_source, | 342 bool use_simple_data_source, |
| 347 scoped_refptr<WebVideoRenderer> web_video_renderer) { | 343 scoped_refptr<WebVideoRenderer> web_video_renderer) { |
| 348 MessageLoop* pipeline_message_loop = | 344 MessageLoop* pipeline_message_loop = |
| 349 message_loop_factory_->GetMessageLoop("PipelineThread"); | 345 message_loop_factory_->GetMessageLoop("PipelineThread"); |
| 350 if (!pipeline_message_loop) { | 346 if (!pipeline_message_loop) { |
| 351 NOTREACHED() << "Could not start PipelineThread"; | 347 NOTREACHED() << "Could not start PipelineThread"; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder( | 414 filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder( |
| 419 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); | 415 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
| 420 filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder( | 416 filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder( |
| 421 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); | 417 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); |
| 422 filter_collection_->AddAudioRenderer(new media::NullAudioRenderer()); | 418 filter_collection_->AddAudioRenderer(new media::NullAudioRenderer()); |
| 423 | 419 |
| 424 return true; | 420 return true; |
| 425 } | 421 } |
| 426 | 422 |
| 427 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 423 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 428 media_log_->AddEventOfType(media::MediaLogEvent::DESTROYING); | |
| 429 Destroy(); | 424 Destroy(); |
| 430 | 425 |
| 431 // Finally tell the |main_loop_| we don't want to be notified of destruction | 426 // Finally tell the |main_loop_| we don't want to be notified of destruction |
| 432 // event. | 427 // event. |
| 433 if (main_loop_) { | 428 if (main_loop_) { |
| 434 main_loop_->RemoveDestructionObserver(this); | 429 main_loop_->RemoveDestructionObserver(this); |
| 435 } | 430 } |
| 436 } | 431 } |
| 437 | 432 |
| 438 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { | 433 void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 456 setPreload(GetClient()->preload()); | 451 setPreload(GetClient()->preload()); |
| 457 | 452 |
| 458 // Initialize the pipeline. | 453 // Initialize the pipeline. |
| 459 SetNetworkState(WebKit::WebMediaPlayer::Loading); | 454 SetNetworkState(WebKit::WebMediaPlayer::Loading); |
| 460 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); | 455 SetReadyState(WebKit::WebMediaPlayer::HaveNothing); |
| 461 pipeline_->Start( | 456 pipeline_->Start( |
| 462 filter_collection_.release(), | 457 filter_collection_.release(), |
| 463 url.spec(), | 458 url.spec(), |
| 464 NewCallback(proxy_.get(), | 459 NewCallback(proxy_.get(), |
| 465 &WebMediaPlayerImpl::Proxy::PipelineInitializationCallback)); | 460 &WebMediaPlayerImpl::Proxy::PipelineInitializationCallback)); |
| 466 | |
| 467 media_log_->Load(url.spec()); | |
| 468 } | 461 } |
| 469 | 462 |
| 470 void WebMediaPlayerImpl::cancelLoad() { | 463 void WebMediaPlayerImpl::cancelLoad() { |
| 471 DCHECK(MessageLoop::current() == main_loop_); | 464 DCHECK(MessageLoop::current() == main_loop_); |
| 472 } | 465 } |
| 473 | 466 |
| 474 void WebMediaPlayerImpl::play() { | 467 void WebMediaPlayerImpl::play() { |
| 475 DCHECK(MessageLoop::current() == main_loop_); | 468 DCHECK(MessageLoop::current() == main_loop_); |
| 476 | 469 |
| 477 paused_ = false; | 470 paused_ = false; |
| 478 pipeline_->SetPlaybackRate(playback_rate_); | 471 pipeline_->SetPlaybackRate(playback_rate_); |
| 479 | |
| 480 media_log_->AddEventOfType(media::MediaLogEvent::PLAY); | |
| 481 } | 472 } |
| 482 | 473 |
| 483 void WebMediaPlayerImpl::pause() { | 474 void WebMediaPlayerImpl::pause() { |
| 484 DCHECK(MessageLoop::current() == main_loop_); | 475 DCHECK(MessageLoop::current() == main_loop_); |
| 485 | 476 |
| 486 paused_ = true; | 477 paused_ = true; |
| 487 pipeline_->SetPlaybackRate(0.0f); | 478 pipeline_->SetPlaybackRate(0.0f); |
| 488 paused_time_ = pipeline_->GetCurrentTime(); | 479 paused_time_ = pipeline_->GetCurrentTime(); |
| 489 | |
| 490 media_log_->AddEventOfType(media::MediaLogEvent::PAUSE); | |
| 491 } | 480 } |
| 492 | 481 |
| 493 bool WebMediaPlayerImpl::supportsFullscreen() const { | 482 bool WebMediaPlayerImpl::supportsFullscreen() const { |
| 494 DCHECK(MessageLoop::current() == main_loop_); | 483 DCHECK(MessageLoop::current() == main_loop_); |
| 495 return true; | 484 return true; |
| 496 } | 485 } |
| 497 | 486 |
| 498 bool WebMediaPlayerImpl::supportsSave() const { | 487 bool WebMediaPlayerImpl::supportsSave() const { |
| 499 DCHECK(MessageLoop::current() == main_loop_); | 488 DCHECK(MessageLoop::current() == main_loop_); |
| 500 return true; | 489 return true; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 } | 1032 } |
| 1044 } | 1033 } |
| 1045 | 1034 |
| 1046 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 1035 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 1047 DCHECK(MessageLoop::current() == main_loop_); | 1036 DCHECK(MessageLoop::current() == main_loop_); |
| 1048 DCHECK(client_); | 1037 DCHECK(client_); |
| 1049 return client_; | 1038 return client_; |
| 1050 } | 1039 } |
| 1051 | 1040 |
| 1052 } // namespace webkit_glue | 1041 } // namespace webkit_glue |
| OLD | NEW |