| 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/pipeline_impl.h" | 12 #include "media/base/pipeline_impl.h" |
| 12 #include "media/filters/audio_renderer_impl.h" | 13 #include "media/filters/audio_renderer_impl.h" |
| 13 #include "media/filters/ffmpeg_audio_decoder.h" | 14 #include "media/filters/ffmpeg_audio_decoder.h" |
| 14 #include "media/filters/ffmpeg_demuxer.h" | 15 #include "media/filters/ffmpeg_demuxer.h" |
| 15 #include "media/filters/ffmpeg_video_decoder.h" | 16 #include "media/filters/ffmpeg_video_decoder.h" |
| 16 #include "media/filters/file_data_source.h" | 17 #include "media/filters/file_data_source.h" |
| 17 #include "media/filters/null_audio_renderer.h" | 18 #include "media/filters/null_audio_renderer.h" |
| 18 #include "media/tools/player_wtl/wtl_renderer.h" | 19 #include "media/tools/player_wtl/wtl_renderer.h" |
| 19 | 20 |
| 20 using media::AudioRendererImpl; | 21 using media::AudioRendererImpl; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 movie_dib_ = hbmp; | 54 movie_dib_ = hbmp; |
| 54 movie_hwnd_ = hwnd; | 55 movie_hwnd_ = hwnd; |
| 55 } | 56 } |
| 56 | 57 |
| 57 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { | 58 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { |
| 58 // Close previous movie. | 59 // Close previous movie. |
| 59 if (pipeline_) { | 60 if (pipeline_) { |
| 60 Close(); | 61 Close(); |
| 61 } | 62 } |
| 62 | 63 |
| 64 message_loop_factory_ = new media::MessageLoopFactoryImpl(); |
| 65 |
| 63 // Create filter collection. | 66 // Create filter collection. |
| 64 scoped_ptr<FilterCollection> collection(new FilterCollection()); | 67 scoped_ptr<FilterCollection> collection(new FilterCollection()); |
| 65 collection->AddDataSource(new FileDataSource()); | 68 collection->AddDataSource(new FileDataSource()); |
| 66 collection->AddAudioDecoder(new FFmpegAudioDecoder()); | 69 collection->AddAudioDecoder(new FFmpegAudioDecoder( |
| 67 collection->AddDemuxer(new FFmpegDemuxer()); | 70 message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); |
| 68 collection->AddVideoDecoder(new FFmpegVideoDecoder(NULL)); | 71 collection->AddDemuxer(new FFmpegDemuxer( |
| 72 message_loop_factory_->GetMessageLoop("DemuxThread"))); |
| 73 collection->AddVideoDecoder(new FFmpegVideoDecoder( |
| 74 message_loop_factory_->GetMessageLoop("VideoDecoderThread"), NULL)); |
| 69 | 75 |
| 70 if (enable_audio_) { | 76 if (enable_audio_) { |
| 71 collection->AddAudioRenderer(new AudioRendererImpl()); | 77 collection->AddAudioRenderer(new AudioRendererImpl()); |
| 72 } else { | 78 } else { |
| 73 collection->AddAudioRenderer(new media::NullAudioRenderer()); | 79 collection->AddAudioRenderer(new media::NullAudioRenderer()); |
| 74 } | 80 } |
| 75 collection->AddVideoRenderer(video_renderer); | 81 collection->AddVideoRenderer(video_renderer); |
| 76 | 82 |
| 77 thread_.reset(new base::Thread("PipelineThread")); | 83 pipeline_ = new PipelineImpl( |
| 78 thread_->Start(); | 84 message_loop_factory_->GetMessageLoop("PipelineThread")); |
| 79 pipeline_ = new PipelineImpl(thread_->message_loop()); | |
| 80 | 85 |
| 81 // Create and start our pipeline. | 86 // Create and start our pipeline. |
| 82 pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), NULL); | 87 pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), NULL); |
| 83 while (true) { | 88 while (true) { |
| 84 base::PlatformThread::Sleep(100); | 89 base::PlatformThread::Sleep(100); |
| 85 if (pipeline_->IsInitialized()) | 90 if (pipeline_->IsInitialized()) |
| 86 break; | 91 break; |
| 87 if (pipeline_->GetError() != media::PIPELINE_OK) | 92 if (pipeline_->GetError() != media::PIPELINE_OK) |
| 88 return false; | 93 return false; |
| 89 } | 94 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 166 } |
| 162 | 167 |
| 163 bool Movie::GetDumpYuvFileEnable() { | 168 bool Movie::GetDumpYuvFileEnable() { |
| 164 return enable_dump_yuv_file_; | 169 return enable_dump_yuv_file_; |
| 165 } | 170 } |
| 166 | 171 |
| 167 // Teardown. | 172 // Teardown. |
| 168 void Movie::Close() { | 173 void Movie::Close() { |
| 169 if (pipeline_) { | 174 if (pipeline_) { |
| 170 pipeline_->Stop(NULL); | 175 pipeline_->Stop(NULL); |
| 171 thread_->Stop(); | |
| 172 pipeline_ = NULL; | 176 pipeline_ = NULL; |
| 173 thread_.reset(); | |
| 174 } | 177 } |
| 178 |
| 179 message_loop_factory_ = NULL; |
| 175 } | 180 } |
| 176 | 181 |
| 177 } // namespace media | 182 } // namespace media |
| OLD | NEW |