| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 scoped_refptr<media::VideoFrame> frame) { | 218 scoped_refptr<media::VideoFrame> frame) { |
| 219 if (video_renderer_) | 219 if (video_renderer_) |
| 220 video_renderer_->PutCurrentFrame(frame); | 220 video_renderer_->PutCurrentFrame(frame); |
| 221 } | 221 } |
| 222 | 222 |
| 223 ///////////////////////////////////////////////////////////////////////////// | 223 ///////////////////////////////////////////////////////////////////////////// |
| 224 // WebMediaPlayerImpl implementation | 224 // WebMediaPlayerImpl implementation |
| 225 | 225 |
| 226 WebMediaPlayerImpl::WebMediaPlayerImpl( | 226 WebMediaPlayerImpl::WebMediaPlayerImpl( |
| 227 WebKit::WebMediaPlayerClient* client, | 227 WebKit::WebMediaPlayerClient* client, |
| 228 media::FilterCollection* collection) | 228 media::FilterCollection* collection, |
| 229 media::MessageLoopFactory* message_loop_factory) |
| 229 : network_state_(WebKit::WebMediaPlayer::Empty), | 230 : network_state_(WebKit::WebMediaPlayer::Empty), |
| 230 ready_state_(WebKit::WebMediaPlayer::HaveNothing), | 231 ready_state_(WebKit::WebMediaPlayer::HaveNothing), |
| 231 main_loop_(NULL), | 232 main_loop_(NULL), |
| 232 filter_collection_(collection), | 233 filter_collection_(collection), |
| 233 pipeline_(NULL), | 234 pipeline_(NULL), |
| 234 pipeline_thread_("PipelineThread"), | 235 message_loop_factory_(message_loop_factory), |
| 235 paused_(true), | 236 paused_(true), |
| 236 seeking_(false), | 237 seeking_(false), |
| 237 playback_rate_(0.0f), | 238 playback_rate_(0.0f), |
| 238 client_(client), | 239 client_(client), |
| 239 proxy_(NULL), | 240 proxy_(NULL), |
| 240 pipeline_stopped_(false, false) { | 241 pipeline_stopped_(false, false) { |
| 241 // Saves the current message loop. | 242 // Saves the current message loop. |
| 242 DCHECK(!main_loop_); | 243 DCHECK(!main_loop_); |
| 243 main_loop_ = MessageLoop::current(); | 244 main_loop_ = MessageLoop::current(); |
| 244 } | 245 } |
| 245 | 246 |
| 246 bool WebMediaPlayerImpl::Initialize( | 247 bool WebMediaPlayerImpl::Initialize( |
| 247 WebKit::WebFrame* frame, | 248 WebKit::WebFrame* frame, |
| 248 bool use_simple_data_source, | 249 bool use_simple_data_source, |
| 249 scoped_refptr<WebVideoRenderer> web_video_renderer) { | 250 scoped_refptr<WebVideoRenderer> web_video_renderer) { |
| 250 // Create the pipeline and its thread. | 251 MessageLoop* pipeline_message_loop = |
| 251 if (!pipeline_thread_.Start()) { | 252 message_loop_factory_->GetMessageLoop("PipelineThread"); |
| 253 if (!pipeline_message_loop) { |
| 252 NOTREACHED() << "Could not start PipelineThread"; | 254 NOTREACHED() << "Could not start PipelineThread"; |
| 253 return false; | 255 return false; |
| 254 } | 256 } |
| 255 | 257 |
| 256 pipeline_ = new media::PipelineImpl(pipeline_thread_.message_loop()); | 258 pipeline_ = new media::PipelineImpl(pipeline_message_loop); |
| 257 | 259 |
| 258 // Also we want to be notified of |main_loop_| destruction. | 260 // Also we want to be notified of |main_loop_| destruction. |
| 259 main_loop_->AddDestructionObserver(this); | 261 main_loop_->AddDestructionObserver(this); |
| 260 | 262 |
| 261 // Creates the proxy. | 263 // Creates the proxy. |
| 262 proxy_ = new Proxy(main_loop_, this); | 264 proxy_ = new Proxy(main_loop_, this); |
| 263 web_video_renderer->SetWebMediaPlayerImplProxy(proxy_); | 265 web_video_renderer->SetWebMediaPlayerImplProxy(proxy_); |
| 264 proxy_->SetVideoRenderer(web_video_renderer); | 266 proxy_->SetVideoRenderer(web_video_renderer); |
| 265 | 267 |
| 266 // Set our pipeline callbacks. | 268 // Set our pipeline callbacks. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 283 | 285 |
| 284 if (use_simple_data_source) { | 286 if (use_simple_data_source) { |
| 285 filter_collection_->AddDataSource(simple_data_source); | 287 filter_collection_->AddDataSource(simple_data_source); |
| 286 filter_collection_->AddDataSource(buffered_data_source); | 288 filter_collection_->AddDataSource(buffered_data_source); |
| 287 } else { | 289 } else { |
| 288 filter_collection_->AddDataSource(buffered_data_source); | 290 filter_collection_->AddDataSource(buffered_data_source); |
| 289 filter_collection_->AddDataSource(simple_data_source); | 291 filter_collection_->AddDataSource(simple_data_source); |
| 290 } | 292 } |
| 291 | 293 |
| 292 // Add in the default filter factories. | 294 // Add in the default filter factories. |
| 293 filter_collection_->AddDemuxer(new media::FFmpegDemuxer()); | 295 filter_collection_->AddDemuxer(new media::FFmpegDemuxer( |
| 294 filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder()); | 296 message_loop_factory_->GetMessageLoop("DemuxThread"))); |
| 295 filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder(NULL)); | 297 filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder( |
| 298 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
| 299 filter_collection_->AddVideoDecoder(new media::FFmpegVideoDecoder( |
| 300 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); |
| 296 filter_collection_->AddAudioRenderer(new media::NullAudioRenderer()); | 301 filter_collection_->AddAudioRenderer(new media::NullAudioRenderer()); |
| 297 | 302 |
| 298 return true; | 303 return true; |
| 299 } | 304 } |
| 300 | 305 |
| 301 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 306 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 302 Destroy(); | 307 Destroy(); |
| 303 | 308 |
| 304 // Finally tell the |main_loop_| we don't want to be notified of destruction | 309 // Finally tell the |main_loop_| we don't want to be notified of destruction |
| 305 // event. | 310 // event. |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // not blocked when issuing stop commands to the other filters. | 792 // not blocked when issuing stop commands to the other filters. |
| 788 if (proxy_) | 793 if (proxy_) |
| 789 proxy_->AbortDataSource(); | 794 proxy_->AbortDataSource(); |
| 790 | 795 |
| 791 // Make sure to kill the pipeline so there's no more media threads running. | 796 // Make sure to kill the pipeline so there's no more media threads running. |
| 792 // Note: stopping the pipeline might block for a long time. | 797 // Note: stopping the pipeline might block for a long time. |
| 793 if (pipeline_) { | 798 if (pipeline_) { |
| 794 pipeline_->Stop(NewCallback(this, | 799 pipeline_->Stop(NewCallback(this, |
| 795 &WebMediaPlayerImpl::PipelineStoppedCallback)); | 800 &WebMediaPlayerImpl::PipelineStoppedCallback)); |
| 796 pipeline_stopped_.Wait(); | 801 pipeline_stopped_.Wait(); |
| 797 pipeline_thread_.Stop(); | |
| 798 } | 802 } |
| 799 | 803 |
| 804 message_loop_factory_.reset(); |
| 805 |
| 800 // And then detach the proxy, it may live on the render thread for a little | 806 // And then detach the proxy, it may live on the render thread for a little |
| 801 // longer until all the tasks are finished. | 807 // longer until all the tasks are finished. |
| 802 if (proxy_) { | 808 if (proxy_) { |
| 803 proxy_->Detach(); | 809 proxy_->Detach(); |
| 804 proxy_ = NULL; | 810 proxy_ = NULL; |
| 805 } | 811 } |
| 806 } | 812 } |
| 807 | 813 |
| 808 void WebMediaPlayerImpl::PipelineStoppedCallback() { | 814 void WebMediaPlayerImpl::PipelineStoppedCallback() { |
| 809 pipeline_stopped_.Signal(); | 815 pipeline_stopped_.Signal(); |
| 810 } | 816 } |
| 811 | 817 |
| 812 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { | 818 WebKit::WebMediaPlayerClient* WebMediaPlayerImpl::GetClient() { |
| 813 DCHECK(MessageLoop::current() == main_loop_); | 819 DCHECK(MessageLoop::current() == main_loop_); |
| 814 DCHECK(client_); | 820 DCHECK(client_); |
| 815 return client_; | 821 return client_; |
| 816 } | 822 } |
| 817 | 823 |
| 818 } // namespace webkit_glue | 824 } // namespace webkit_glue |
| OLD | NEW |