| 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/base/media_format.h" | 9 #include "media/base/media_format.h" |
| 10 #include "media/filters/ffmpeg_audio_decoder.h" | 10 #include "media/filters/ffmpeg_audio_decoder.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void WebMediaPlayerImpl::Proxy::PipelineInitializationCallback() { | 105 void WebMediaPlayerImpl::Proxy::PipelineInitializationCallback() { |
| 106 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 106 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 107 &WebMediaPlayerImpl::Proxy::PipelineInitializationTask)); | 107 &WebMediaPlayerImpl::Proxy::PipelineInitializationTask)); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void WebMediaPlayerImpl::Proxy::PipelineSeekCallback() { | 110 void WebMediaPlayerImpl::Proxy::PipelineSeekCallback() { |
| 111 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 111 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 112 &WebMediaPlayerImpl::Proxy::PipelineSeekTask)); | 112 &WebMediaPlayerImpl::Proxy::PipelineSeekTask)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void WebMediaPlayerImpl::Proxy::PipelineEndedCallback() { |
| 116 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 117 &WebMediaPlayerImpl::Proxy::PipelineEndedTask)); |
| 118 } |
| 119 |
| 115 void WebMediaPlayerImpl::Proxy::PipelineErrorCallback() { | 120 void WebMediaPlayerImpl::Proxy::PipelineErrorCallback() { |
| 116 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | 121 render_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, |
| 117 &WebMediaPlayerImpl::Proxy::PipelineErrorTask)); | 122 &WebMediaPlayerImpl::Proxy::PipelineErrorTask)); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void WebMediaPlayerImpl::Proxy::RepaintTask() { | 125 void WebMediaPlayerImpl::Proxy::RepaintTask() { |
| 121 DCHECK(MessageLoop::current() == render_loop_); | 126 DCHECK(MessageLoop::current() == render_loop_); |
| 122 { | 127 { |
| 123 AutoLock auto_lock(lock_); | 128 AutoLock auto_lock(lock_); |
| 124 --outstanding_repaints_; | 129 --outstanding_repaints_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 } | 141 } |
| 137 } | 142 } |
| 138 | 143 |
| 139 void WebMediaPlayerImpl::Proxy::PipelineSeekTask() { | 144 void WebMediaPlayerImpl::Proxy::PipelineSeekTask() { |
| 140 DCHECK(MessageLoop::current() == render_loop_); | 145 DCHECK(MessageLoop::current() == render_loop_); |
| 141 if (webmediaplayer_) { | 146 if (webmediaplayer_) { |
| 142 webmediaplayer_->OnPipelineSeek(); | 147 webmediaplayer_->OnPipelineSeek(); |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 | 150 |
| 151 void WebMediaPlayerImpl::Proxy::PipelineEndedTask() { |
| 152 DCHECK(MessageLoop::current() == render_loop_); |
| 153 if (webmediaplayer_) { |
| 154 webmediaplayer_->OnPipelineEnded(); |
| 155 } |
| 156 } |
| 157 |
| 146 void WebMediaPlayerImpl::Proxy::PipelineErrorTask() { | 158 void WebMediaPlayerImpl::Proxy::PipelineErrorTask() { |
| 147 DCHECK(MessageLoop::current() == render_loop_); | 159 DCHECK(MessageLoop::current() == render_loop_); |
| 148 if (webmediaplayer_) { | 160 if (webmediaplayer_) { |
| 149 webmediaplayer_->OnPipelineError(); | 161 webmediaplayer_->OnPipelineError(); |
| 150 } | 162 } |
| 151 } | 163 } |
| 152 | 164 |
| 153 ///////////////////////////////////////////////////////////////////////////// | 165 ///////////////////////////////////////////////////////////////////////////// |
| 154 // WebMediaPlayerImpl implementation | 166 // WebMediaPlayerImpl implementation |
| 155 | 167 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 } | 186 } |
| 175 | 187 |
| 176 pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); | 188 pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); |
| 177 | 189 |
| 178 // Also we want to be notified of |main_loop_| destruction. | 190 // Also we want to be notified of |main_loop_| destruction. |
| 179 main_loop_->AddDestructionObserver(this); | 191 main_loop_->AddDestructionObserver(this); |
| 180 | 192 |
| 181 // Creates the proxy. | 193 // Creates the proxy. |
| 182 proxy_ = new Proxy(main_loop_, this); | 194 proxy_ = new Proxy(main_loop_, this); |
| 183 | 195 |
| 184 // Sets the pipeline's error reporting callback. | 196 // Set our pipeline callbacks. |
| 197 pipeline_->SetPipelineEndedCallback(NewCallback(proxy_.get(), |
| 198 &WebMediaPlayerImpl::Proxy::PipelineEndedCallback)); |
| 185 pipeline_->SetPipelineErrorCallback(NewCallback(proxy_.get(), | 199 pipeline_->SetPipelineErrorCallback(NewCallback(proxy_.get(), |
| 186 &WebMediaPlayerImpl::Proxy::PipelineErrorCallback)); | 200 &WebMediaPlayerImpl::Proxy::PipelineErrorCallback)); |
| 187 | 201 |
| 188 // Add in the default filter factories. | 202 // Add in the default filter factories. |
| 189 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory()); | 203 filter_factory_->AddFactory(media::FFmpegDemuxer::CreateFilterFactory()); |
| 190 filter_factory_->AddFactory(media::FFmpegAudioDecoder::CreateFactory()); | 204 filter_factory_->AddFactory(media::FFmpegAudioDecoder::CreateFactory()); |
| 191 filter_factory_->AddFactory(media::FFmpegVideoDecoder::CreateFactory()); | 205 filter_factory_->AddFactory(media::FFmpegVideoDecoder::CreateFactory()); |
| 192 filter_factory_->AddFactory(media::NullAudioRenderer::CreateFilterFactory()); | 206 filter_factory_->AddFactory(media::NullAudioRenderer::CreateFilterFactory()); |
| 193 filter_factory_->AddFactory(VideoRendererImpl::CreateFactory(proxy_)); | 207 filter_factory_->AddFactory(VideoRendererImpl::CreateFactory(proxy_)); |
| 194 } | 208 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 255 } |
| 242 | 256 |
| 243 bool WebMediaPlayerImpl::supportsSave() const { | 257 bool WebMediaPlayerImpl::supportsSave() const { |
| 244 DCHECK(MessageLoop::current() == main_loop_); | 258 DCHECK(MessageLoop::current() == main_loop_); |
| 245 return true; | 259 return true; |
| 246 } | 260 } |
| 247 | 261 |
| 248 void WebMediaPlayerImpl::seek(float seconds) { | 262 void WebMediaPlayerImpl::seek(float seconds) { |
| 249 DCHECK(MessageLoop::current() == main_loop_); | 263 DCHECK(MessageLoop::current() == main_loop_); |
| 250 | 264 |
| 265 // TODO(scherkus): WebKit fires a seek(0) at the very start, however pipeline |
| 266 // already does a seek(0) internally. Investigate whether doing two seek(0) |
| 267 // at the start impacts startup latency. |
| 268 |
| 251 // Try to preserve as much accuracy as possible. | 269 // Try to preserve as much accuracy as possible. |
| 252 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; | 270 float microseconds = seconds * base::Time::kMicrosecondsPerSecond; |
| 253 if (seconds != 0) | |
| 254 pipeline_->Seek( | 271 pipeline_->Seek( |
| 255 base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)), | 272 base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)), |
| 256 NewCallback(proxy_.get(), | 273 NewCallback(proxy_.get(), |
| 257 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); | 274 &WebMediaPlayerImpl::Proxy::PipelineSeekCallback)); |
| 258 } | 275 } |
| 259 | 276 |
| 260 void WebMediaPlayerImpl::setEndTime(float seconds) { | 277 void WebMediaPlayerImpl::setEndTime(float seconds) { |
| 261 DCHECK(MessageLoop::current() == main_loop_); | 278 DCHECK(MessageLoop::current() == main_loop_); |
| 262 | 279 |
| 263 // TODO(hclam): add method call when it has been implemented. | 280 // TODO(hclam): add method call when it has been implemented. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 463 } |
| 447 } | 464 } |
| 448 | 465 |
| 449 void WebMediaPlayerImpl::OnPipelineSeek() { | 466 void WebMediaPlayerImpl::OnPipelineSeek() { |
| 450 DCHECK(MessageLoop::current() == main_loop_); | 467 DCHECK(MessageLoop::current() == main_loop_); |
| 451 if (pipeline_->GetError() == media::PIPELINE_OK) { | 468 if (pipeline_->GetError() == media::PIPELINE_OK) { |
| 452 GetClient()->timeChanged(); | 469 GetClient()->timeChanged(); |
| 453 } | 470 } |
| 454 } | 471 } |
| 455 | 472 |
| 473 void WebMediaPlayerImpl::OnPipelineEnded() { |
| 474 DCHECK(MessageLoop::current() == main_loop_); |
| 475 if (pipeline_->GetError() == media::PIPELINE_OK) { |
| 476 GetClient()->timeChanged(); |
| 477 } |
| 478 } |
| 479 |
| 456 void WebMediaPlayerImpl::OnPipelineError() { | 480 void WebMediaPlayerImpl::OnPipelineError() { |
| 457 DCHECK(MessageLoop::current() == main_loop_); | 481 DCHECK(MessageLoop::current() == main_loop_); |
| 458 switch (pipeline_->GetError()) { | 482 switch (pipeline_->GetError()) { |
| 459 case media::PIPELINE_OK: | 483 case media::PIPELINE_OK: |
| 460 case media::PIPELINE_STOPPING: | 484 case media::PIPELINE_STOPPING: |
| 461 NOTREACHED() << "We shouldn't get called with these non-errors"; | 485 NOTREACHED() << "We shouldn't get called with these non-errors"; |
| 462 break; | 486 break; |
| 463 | 487 |
| 464 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: | 488 case media::PIPELINE_ERROR_INITIALIZATION_FAILED: |
| 465 case media::PIPELINE_ERROR_REQUIRED_FILTER_MISSING: | 489 case media::PIPELINE_ERROR_REQUIRED_FILTER_MISSING: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 543 } |
| 520 } | 544 } |
| 521 | 545 |
| 522 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 546 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 523 DCHECK(MessageLoop::current() == main_loop_); | 547 DCHECK(MessageLoop::current() == main_loop_); |
| 524 DCHECK(client_); | 548 DCHECK(client_); |
| 525 return client_; | 549 return client_; |
| 526 } | 550 } |
| 527 | 551 |
| 528 } // namespace webkit_glue | 552 } // namespace webkit_glue |
| OLD | NEW |