| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifdef _OPENMP | 5 #ifdef _OPENMP |
| 6 #include <omp.h> | 6 #include <omp.h> |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 max_threads_(0), | 42 max_threads_(0), |
| 43 play_rate_(1.0f), | 43 play_rate_(1.0f), |
| 44 movie_dib_(NULL), | 44 movie_dib_(NULL), |
| 45 movie_hwnd_(0) { | 45 movie_hwnd_(0) { |
| 46 } | 46 } |
| 47 | 47 |
| 48 Movie::~Movie() { | 48 Movie::~Movie() { |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool Movie::IsOpen() { | 51 bool Movie::IsOpen() { |
| 52 return pipeline_.get() != NULL; | 52 return pipeline_ != NULL; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Movie::SetFrameBuffer(HBITMAP hbmp, HWND hwnd) { | 55 void Movie::SetFrameBuffer(HBITMAP hbmp, HWND hwnd) { |
| 56 movie_dib_ = hbmp; | 56 movie_dib_ = hbmp; |
| 57 movie_hwnd_ = hwnd; | 57 movie_hwnd_ = hwnd; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { | 60 bool Movie::Open(const wchar_t* url, WtlVideoRenderer* video_renderer) { |
| 61 // Close previous movie. | 61 // Close previous movie. |
| 62 if (pipeline_.get()) { | 62 if (pipeline_) { |
| 63 Close(); | 63 Close(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Create our filter factories. | 66 // Create our filter factories. |
| 67 scoped_refptr<FilterFactoryCollection> factories = | 67 scoped_refptr<FilterFactoryCollection> factories = |
| 68 new FilterFactoryCollection(); | 68 new FilterFactoryCollection(); |
| 69 factories->AddFactory(FileDataSource::CreateFactory()); | 69 factories->AddFactory(FileDataSource::CreateFactory()); |
| 70 factories->AddFactory(FFmpegAudioDecoder::CreateFactory()); | 70 factories->AddFactory(FFmpegAudioDecoder::CreateFactory()); |
| 71 factories->AddFactory(FFmpegDemuxer::CreateFilterFactory()); | 71 factories->AddFactory(FFmpegDemuxer::CreateFilterFactory()); |
| 72 factories->AddFactory(FFmpegVideoDecoder::CreateFactory()); | 72 factories->AddFactory(FFmpegVideoDecoder::CreateFactory()); |
| 73 | 73 |
| 74 if (enable_audio_) { | 74 if (enable_audio_) { |
| 75 factories->AddFactory(AudioRendererImpl::CreateFilterFactory()); | 75 factories->AddFactory(AudioRendererImpl::CreateFilterFactory()); |
| 76 } else { | 76 } else { |
| 77 factories->AddFactory(media::NullAudioRenderer::CreateFilterFactory()); | 77 factories->AddFactory(media::NullAudioRenderer::CreateFilterFactory()); |
| 78 } | 78 } |
| 79 factories->AddFactory( | 79 factories->AddFactory( |
| 80 new media::InstanceFilterFactory<WtlVideoRenderer>(video_renderer)); | 80 new media::InstanceFilterFactory<WtlVideoRenderer>(video_renderer)); |
| 81 | 81 |
| 82 thread_.reset(new base::Thread("PipelineThread")); | 82 thread_.reset(new base::Thread("PipelineThread")); |
| 83 thread_->Start(); | 83 thread_->Start(); |
| 84 pipeline_.reset(new PipelineImpl(thread_->message_loop())); | 84 pipeline_ = new PipelineImpl(thread_->message_loop()); |
| 85 | 85 |
| 86 // Create and start our pipeline. | 86 // Create and start our pipeline. |
| 87 pipeline_->Start(factories.get(), WideToUTF8(std::wstring(url)), NULL); | 87 pipeline_->Start(factories, WideToUTF8(std::wstring(url)), NULL); |
| 88 while (true) { | 88 while (true) { |
| 89 PlatformThread::Sleep(100); | 89 PlatformThread::Sleep(100); |
| 90 if (pipeline_->IsInitialized()) | 90 if (pipeline_->IsInitialized()) |
| 91 break; | 91 break; |
| 92 if (pipeline_->GetError() != media::PIPELINE_OK) | 92 if (pipeline_->GetError() != media::PIPELINE_OK) |
| 93 return false; | 93 return false; |
| 94 } | 94 } |
| 95 pipeline_->SetPlaybackRate(play_rate_); | 95 pipeline_->SetPlaybackRate(play_rate_); |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void Movie::Play(float rate) { | 99 void Movie::Play(float rate) { |
| 100 // Begin playback. | 100 // Begin playback. |
| 101 if (pipeline_.get()) | 101 if (pipeline_) |
| 102 pipeline_->SetPlaybackRate(enable_pause_ ? 0.0f : rate); | 102 pipeline_->SetPlaybackRate(enable_pause_ ? 0.0f : rate); |
| 103 if (rate > 0.0f) | 103 if (rate > 0.0f) |
| 104 play_rate_ = rate; | 104 play_rate_ = rate; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Get playback rate. | 107 // Get playback rate. |
| 108 float Movie::GetPlayRate() { | 108 float Movie::GetPlayRate() { |
| 109 return play_rate_; | 109 return play_rate_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Get movie duration in seconds. | 112 // Get movie duration in seconds. |
| 113 float Movie::GetDuration() { | 113 float Movie::GetDuration() { |
| 114 float duration = 0.f; | 114 float duration = 0.f; |
| 115 if (pipeline_.get()) | 115 if (pipeline_) |
| 116 duration = (pipeline_->GetDuration()).InMicroseconds() / 1000000.0f; | 116 duration = (pipeline_->GetDuration()).InMicroseconds() / 1000000.0f; |
| 117 return duration; | 117 return duration; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Get current movie position in seconds. | 120 // Get current movie position in seconds. |
| 121 float Movie::GetPosition() { | 121 float Movie::GetPosition() { |
| 122 float position = 0.f; | 122 float position = 0.f; |
| 123 if (pipeline_.get()) | 123 if (pipeline_) |
| 124 position = (pipeline_->GetCurrentTime()).InMicroseconds() / 1000000.0f; | 124 position = (pipeline_->GetCurrentTime()).InMicroseconds() / 1000000.0f; |
| 125 return position; | 125 return position; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Set current movie position in seconds. | 128 // Set current movie position in seconds. |
| 129 void Movie::SetPosition(float position) { | 129 void Movie::SetPosition(float position) { |
| 130 int64 us = static_cast<int64>(position * 1000000); | 130 int64 us = static_cast<int64>(position * 1000000); |
| 131 base::TimeDelta time = base::TimeDelta::FromMicroseconds(us); | 131 base::TimeDelta time = base::TimeDelta::FromMicroseconds(us); |
| 132 if (pipeline_.get()) | 132 if (pipeline_) |
| 133 pipeline_->Seek(time, NULL); | 133 pipeline_->Seek(time, NULL); |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 // Set playback pause. | 137 // Set playback pause. |
| 138 void Movie::SetPause(bool pause) { | 138 void Movie::SetPause(bool pause) { |
| 139 enable_pause_ = pause; | 139 enable_pause_ = pause; |
| 140 Play(play_rate_); | 140 Play(play_rate_); |
| 141 } | 141 } |
| 142 | 142 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 #endif | 188 #endif |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Get Enable/Disable OpenMP state. | 191 // Get Enable/Disable OpenMP state. |
| 192 bool Movie::GetOpenMpEnable() { | 192 bool Movie::GetOpenMpEnable() { |
| 193 return enable_openmp_; | 193 return enable_openmp_; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Teardown. | 196 // Teardown. |
| 197 void Movie::Close() { | 197 void Movie::Close() { |
| 198 if (pipeline_.get()) { | 198 if (pipeline_) { |
| 199 pipeline_->Stop(NULL); | 199 pipeline_->Stop(NULL); |
| 200 thread_->Stop(); | 200 thread_->Stop(); |
| 201 pipeline_.reset(); | 201 pipeline_ = NULL; |
| 202 thread_.reset(); | 202 thread_.reset(); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace media | 206 } // namespace media |
| OLD | NEW |