| OLD | NEW |
| 1 // Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008-2009 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "media/filters/ffmpeg_audio_decoder.h" | 9 #include "media/filters/ffmpeg_audio_decoder.h" |
| 10 #include "media/filters/ffmpeg_demuxer.h" | 10 #include "media/filters/ffmpeg_demuxer.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void WebMediaPlayerImpl::Proxy::PipelineInitializationCallback() { | 85 void WebMediaPlayerImpl::Proxy::PipelineInitializationCallback() { |
| 86 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 86 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 87 &WebMediaPlayerImpl::Proxy::PipelineInitializationTask)); | 87 &WebMediaPlayerImpl::Proxy::PipelineInitializationTask)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void WebMediaPlayerImpl::Proxy::PipelineSeekCallback() { | 90 void WebMediaPlayerImpl::Proxy::PipelineSeekCallback() { |
| 91 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 91 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 92 &WebMediaPlayerImpl::Proxy::PipelineSeekTask)); | 92 &WebMediaPlayerImpl::Proxy::PipelineSeekTask)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void WebMediaPlayerImpl::Proxy::PipelineErrorCallback() { |
| 96 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 97 &WebMediaPlayerImpl::Proxy::PipelineErrorTask)); |
| 98 } |
| 99 |
| 95 void WebMediaPlayerImpl::Proxy::RepaintTask() { | 100 void WebMediaPlayerImpl::Proxy::RepaintTask() { |
| 96 DCHECK(MessageLoop::current() == render_loop_); | 101 DCHECK(MessageLoop::current() == render_loop_); |
| 97 { | 102 { |
| 98 AutoLock auto_lock(lock_); | 103 AutoLock auto_lock(lock_); |
| 99 --outstanding_repaints_; | 104 --outstanding_repaints_; |
| 100 DCHECK_GE(outstanding_repaints_, 0); | 105 DCHECK_GE(outstanding_repaints_, 0); |
| 101 } | 106 } |
| 102 if (webmediaplayer_) { | 107 if (webmediaplayer_) { |
| 103 webmediaplayer_->Repaint(); | 108 webmediaplayer_->Repaint(); |
| 104 } | 109 } |
| 105 } | 110 } |
| 106 | 111 |
| 107 void WebMediaPlayerImpl::Proxy::PipelineInitializationTask() { | 112 void WebMediaPlayerImpl::Proxy::PipelineInitializationTask() { |
| 108 DCHECK(MessageLoop::current() == render_loop_); | 113 DCHECK(MessageLoop::current() == render_loop_); |
| 109 if (webmediaplayer_) { | 114 if (webmediaplayer_) { |
| 110 webmediaplayer_->OnPipelineInitialize(); | 115 webmediaplayer_->OnPipelineInitialize(); |
| 111 } | 116 } |
| 112 } | 117 } |
| 113 | 118 |
| 114 void WebMediaPlayerImpl::Proxy::PipelineSeekTask() { | 119 void WebMediaPlayerImpl::Proxy::PipelineSeekTask() { |
| 115 DCHECK(MessageLoop::current() == render_loop_); | 120 DCHECK(MessageLoop::current() == render_loop_); |
| 116 if (webmediaplayer_) { | 121 if (webmediaplayer_) { |
| 117 webmediaplayer_->OnPipelineSeek(); | 122 webmediaplayer_->OnPipelineSeek(); |
| 118 } | 123 } |
| 119 } | 124 } |
| 120 | 125 |
| 126 void WebMediaPlayerImpl::Proxy::PipelineErrorTask() { |
| 127 DCHECK(MessageLoop::current() == render_loop_); |
| 128 if (webmediaplayer_) { |
| 129 webmediaplayer_->OnPipelineError(); |
| 130 } |
| 131 } |
| 132 |
| 121 ///////////////////////////////////////////////////////////////////////////// | 133 ///////////////////////////////////////////////////////////////////////////// |
| 122 // WebMediaPlayerImpl implementation | 134 // WebMediaPlayerImpl implementation |
| 123 | 135 |
| 124 WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client, | 136 WebMediaPlayerImpl::WebMediaPlayerImpl(WebKit::WebMediaPlayerClient* client, |
| 125 media::FilterFactoryCollection* factory) | 137 media::FilterFactoryCollection* factory) |
| 126 : network_state_(WebKit::WebMediaPlayer::Empty), | 138 : network_state_(WebKit::WebMediaPlayer::Empty), |
| 127 ready_state_(WebKit::WebMediaPlayer::HaveNothing), | 139 ready_state_(WebKit::WebMediaPlayer::HaveNothing), |
| 128 main_loop_(NULL), | 140 main_loop_(NULL), |
| 129 filter_factory_(factory), | 141 filter_factory_(factory), |
| 130 pipeline_thread_("PipelineThread"), | 142 pipeline_thread_("PipelineThread"), |
| 131 paused_(true), | 143 paused_(true), |
| 132 playback_rate_(0.0f), | 144 playback_rate_(0.0f), |
| 133 client_(client) { | 145 client_(client) { |
| 134 // Saves the current message loop. | 146 // Saves the current message loop. |
| 135 DCHECK(!main_loop_); | 147 DCHECK(!main_loop_); |
| 136 main_loop_ = MessageLoop::current(); | 148 main_loop_ = MessageLoop::current(); |
| 137 | 149 |
| 138 // Create the pipeline and its thread. | 150 // Create the pipeline and its thread. |
| 139 if (!pipeline_thread_.Start()) { | 151 if (!pipeline_thread_.Start()) { |
| 140 NOTREACHED() << "Could not start PipelineThread"; | 152 NOTREACHED() << "Could not start PipelineThread"; |
| 141 } else { | 153 } else { |
| 142 pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); | 154 pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); |
| 155 pipeline_->SetPipelineErrorCallback(NewCallback(proxy_.get(), |
| 156 &WebMediaPlayerImpl::Proxy::PipelineErrorCallback)); |
| 143 } | 157 } |
| 144 | 158 |
| 145 // Also we want to be notified of |main_loop_| destruction. | 159 // Also we want to be notified of |main_loop_| destruction. |
| 146 main_loop_->AddDestructionObserver(this); | 160 main_loop_->AddDestructionObserver(this); |
| 147 | 161 |
| 148 // Creates the proxy. | 162 // Creates the proxy. |
| 149 proxy_ = new Proxy(main_loop_, this); | 163 proxy_ = new Proxy(main_loop_, this); |
| 150 | 164 |
| 151 // Add in the default filter factories. | 165 // Add in the default filter factories. |
| 152 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory()); | 166 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory()); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 396 } |
| 383 } | 397 } |
| 384 | 398 |
| 385 void WebMediaPlayerImpl::OnPipelineSeek() { | 399 void WebMediaPlayerImpl::OnPipelineSeek() { |
| 386 DCHECK(MessageLoop::current() == main_loop_); | 400 DCHECK(MessageLoop::current() == main_loop_); |
| 387 if (pipeline_->GetError() == media::PIPELINE_OK) { | 401 if (pipeline_->GetError() == media::PIPELINE_OK) { |
| 388 GetClient()->timeChanged(); | 402 GetClient()->timeChanged(); |
| 389 } | 403 } |
| 390 } | 404 } |
| 391 | 405 |
| 406 void WebMediaPlayerImpl::OnPipelineError() { |
| 407 DCHECK(MessageLoop::current() == main_loop_); |
| 408 switch (pipeline_->GetError()) { |
| 409 case media::PIPELINE_OK: |
| 410 case media::PIPELINE_STOPPING: |
| 411 // We're in a good state. Do nothing. |
| 412 break; |
| 413 |
| 414 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: |
| 415 case media::PIPELINE_ERROR_REQUIRED_FILTER_MISSING: |
| 416 case media::PIPELINE_ERROR_COULD_NOT_RENDER: |
| 417 // Format error. |
| 418 SetNetworkState(WebMediaPlayer::FormatError); |
| 419 break; |
| 420 |
| 421 case media::PIPELINE_ERROR_URL_NOT_FOUND: |
| 422 case media::PIPELINE_ERROR_NETWORK: |
| 423 case media::PIPELINE_ERROR_DECODE: |
| 424 case media::PIPELINE_ERROR_ABORT: |
| 425 case media::PIPELINE_ERROR_OUT_OF_MEMORY: |
| 426 case media::PIPELINE_ERROR_READ: |
| 427 case media::PIPELINE_ERROR_AUDIO_HARDWARE: |
| 428 case media::DEMUXER_ERROR_COULD_NOT_OPEN: |
| 429 case media::DEMUXER_ERROR_COULD_NOT_PARSE: |
| 430 case media::DEMUXER_ERROR_NO_SUPPORTED_STREAMS: |
| 431 case media::DEMUXER_ERROR_COULD_NOT_CREATE_THREAD: |
| 432 // Decode error. |
| 433 SetNetworkState(WebMediaPlayer::DecodeError); |
| 434 break; |
| 435 } |
| 436 } |
| 437 |
| 392 void WebMediaPlayerImpl::SetNetworkState( | 438 void WebMediaPlayerImpl::SetNetworkState( |
| 393 WebKit::WebMediaPlayer::NetworkState state) { | 439 WebKit::WebMediaPlayer::NetworkState state) { |
| 394 DCHECK(MessageLoop::current() == main_loop_); | 440 DCHECK(MessageLoop::current() == main_loop_); |
| 395 if (network_state_ != state) { | 441 if (network_state_ != state) { |
| 396 network_state_ = state; | 442 network_state_ = state; |
| 397 GetClient()->networkStateChanged(); | 443 GetClient()->networkStateChanged(); |
| 398 } | 444 } |
| 399 } | 445 } |
| 400 | 446 |
| 401 void WebMediaPlayerImpl::SetReadyState( | 447 void WebMediaPlayerImpl::SetReadyState( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 423 } | 469 } |
| 424 } | 470 } |
| 425 | 471 |
| 426 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 472 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 427 DCHECK(MessageLoop::current() == main_loop_); | 473 DCHECK(MessageLoop::current() == main_loop_); |
| 428 DCHECK(client_); | 474 DCHECK(client_); |
| 429 return client_; | 475 return client_; |
| 430 } | 476 } |
| 431 | 477 |
| 432 } // namespace webkit_glue | 478 } // namespace webkit_glue |
| OLD | NEW |