| 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 "media/tools/player_wtl/movie.h" | 5 #include "media/tools/player_wtl/movie.h" |
| 6 | 6 |
| 7 #include "base/singleton.h" | 7 #include "base/singleton.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "media/base/filter_collection.h" | 10 #include "media/base/filter_collection.h" |
| 11 #include "media/base/message_loop_factory_impl.h" | 11 #include "media/base/message_loop_factory_impl.h" |
| 12 #include "media/base/pipeline_impl.h" | 12 #include "media/base/pipeline_impl.h" |
| 13 #include "media/filters/audio_renderer_impl.h" | 13 #include "media/filters/audio_renderer_impl.h" |
| 14 #include "media/filters/ffmpeg_audio_decoder.h" | 14 #include "media/filters/ffmpeg_audio_decoder.h" |
| 15 #include "media/filters/ffmpeg_demuxer.h" | 15 #include "media/filters/ffmpeg_demuxer_factory.h" |
| 16 #include "media/filters/ffmpeg_video_decoder.h" | 16 #include "media/filters/ffmpeg_video_decoder.h" |
| 17 #include "media/filters/file_data_source_factory.h" | 17 #include "media/filters/file_data_source_factory.h" |
| 18 #include "media/filters/null_audio_renderer.h" | 18 #include "media/filters/null_audio_renderer.h" |
| 19 #include "media/tools/player_wtl/wtl_renderer.h" | 19 #include "media/tools/player_wtl/wtl_renderer.h" |
| 20 | 20 |
| 21 using media::AudioRendererImpl; | 21 using media::AudioRendererImpl; |
| 22 using media::FFmpegAudioDecoder; | 22 using media::FFmpegAudioDecoder; |
| 23 using media::FFmpegDemuxer; | 23 using media::FFmpegDemuxerFactory; |
| 24 using media::FFmpegVideoDecoder; | 24 using media::FFmpegVideoDecoder; |
| 25 using media::FileDataSourceFactory; | 25 using media::FileDataSourceFactory; |
| 26 using media::FilterCollection; | 26 using media::FilterCollection; |
| 27 using media::PipelineImpl; | 27 using media::PipelineImpl; |
| 28 | 28 |
| 29 namespace media { | 29 namespace media { |
| 30 | 30 |
| 31 Movie::Movie() | 31 Movie::Movie() |
| 32 : enable_audio_(true), | 32 : enable_audio_(true), |
| 33 enable_draw_(true), | 33 enable_draw_(true), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { | 58 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { |
| 59 // Close previous movie. | 59 // Close previous movie. |
| 60 if (pipeline_) { | 60 if (pipeline_) { |
| 61 Close(); | 61 Close(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 message_loop_factory_.reset(new media::MessageLoopFactoryImpl()); | 64 message_loop_factory_.reset(new media::MessageLoopFactoryImpl()); |
| 65 | 65 |
| 66 MessageLoop* pipeline_loop = |
| 67 message_loop_factory_->GetMessageLoop("PipelineThread"); |
| 68 pipeline_ = new PipelineImpl(pipeline_loop); |
| 69 |
| 66 // Create filter collection. | 70 // Create filter collection. |
| 67 scoped_ptr<FilterCollection> collection(new FilterCollection()); | 71 scoped_ptr<FilterCollection> collection(new FilterCollection()); |
| 68 collection->SetDataSourceFactory(new FileDataSourceFactory()); | 72 collection->SetDemuxerFactory( |
| 73 new FFmpegDemuxerFactory( |
| 74 new FileDataSourceFactory(), pipeline_loop, pipeline_.get())); |
| 69 collection->AddAudioDecoder(new FFmpegAudioDecoder( | 75 collection->AddAudioDecoder(new FFmpegAudioDecoder( |
| 70 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); | 76 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
| 71 collection->AddDemuxer(new FFmpegDemuxer( | |
| 72 message_loop_factory_->GetMessageLoop("DemuxThread"))); | |
| 73 collection->AddVideoDecoder(new FFmpegVideoDecoder( | 77 collection->AddVideoDecoder(new FFmpegVideoDecoder( |
| 74 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); | 78 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); |
| 75 | 79 |
| 76 if (enable_audio_) { | 80 if (enable_audio_) { |
| 77 collection->AddAudioRenderer(new AudioRendererImpl()); | 81 collection->AddAudioRenderer(new AudioRendererImpl()); |
| 78 } else { | 82 } else { |
| 79 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 83 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
| 80 } | 84 } |
| 81 collection->AddVideoRenderer(video_renderer); | 85 collection->AddVideoRenderer(video_renderer); |
| 82 | 86 |
| 83 pipeline_ = new PipelineImpl( | |
| 84 message_loop_factory_->GetMessageLoop("PipelineThread")); | |
| 85 | |
| 86 // Create and start our pipeline. | 87 // Create and start our pipeline. |
| 87 pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), NULL); | 88 pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), NULL); |
| 88 while (true) { | 89 while (true) { |
| 89 base::PlatformThread::Sleep(100); | 90 base::PlatformThread::Sleep(100); |
| 90 if (pipeline_->IsInitialized()) | 91 if (pipeline_->IsInitialized()) |
| 91 break; | 92 break; |
| 92 if (pipeline_->GetError() != media::PIPELINE_OK) | 93 if (pipeline_->GetError() != media::PIPELINE_OK) |
| 93 return false; | 94 return false; |
| 94 } | 95 } |
| 95 pipeline_->SetPlaybackRate(play_rate_); | 96 pipeline_->SetPlaybackRate(play_rate_); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void Movie::Close() { | 174 void Movie::Close() { |
| 174 if (pipeline_) { | 175 if (pipeline_) { |
| 175 pipeline_->Stop(NULL); | 176 pipeline_->Stop(NULL); |
| 176 pipeline_ = NULL; | 177 pipeline_ = NULL; |
| 177 } | 178 } |
| 178 | 179 |
| 179 message_loop_factory_.reset(); | 180 message_loop_factory_.reset(); |
| 180 } | 181 } |
| 181 | 182 |
| 182 } // namespace media | 183 } // namespace media |
| OLD | NEW |