| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/pipeline_integration_test_base.h" | 5 #include "media/test/pipeline_integration_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 11 #include "media/base/cdm_context.h" | 11 #include "media/base/cdm_context.h" |
| 12 #include "media/base/media_log.h" | 12 #include "media/base/media_log.h" |
| 13 #include "media/base/test_data_util.h" | 13 #include "media/base/test_data_util.h" |
| 14 #include "media/filters/chunk_demuxer.h" | 14 #include "media/filters/chunk_demuxer.h" |
| 15 #if !defined(MEDIA_DISABLE_FFMPEG) | 15 #if !defined(MEDIA_DISABLE_FFMPEG) |
| 16 #include "media/filters/ffmpeg_audio_decoder.h" | 16 #include "media/filters/ffmpeg_audio_decoder.h" |
| 17 #include "media/filters/ffmpeg_demuxer.h" | 17 #include "media/filters/ffmpeg_demuxer.h" |
| 18 #include "media/filters/ffmpeg_video_decoder.h" | 18 #include "media/filters/ffmpeg_video_decoder.h" |
| 19 #endif | 19 #endif |
| 20 #include "media/filters/file_data_source.h" | 20 #include "media/filters/file_data_source.h" |
| 21 #include "media/filters/memory_data_source.h" |
| 21 #include "media/filters/opus_audio_decoder.h" | 22 #include "media/filters/opus_audio_decoder.h" |
| 22 #include "media/renderers/audio_renderer_impl.h" | 23 #include "media/renderers/audio_renderer_impl.h" |
| 23 #include "media/renderers/renderer_impl.h" | 24 #include "media/renderers/renderer_impl.h" |
| 24 #if !defined(MEDIA_DISABLE_LIBVPX) | 25 #if !defined(MEDIA_DISABLE_LIBVPX) |
| 25 #include "media/filters/vpx_video_decoder.h" | 26 #include "media/filters/vpx_video_decoder.h" |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 using ::testing::_; | 29 using ::testing::_; |
| 29 using ::testing::AnyNumber; | 30 using ::testing::AnyNumber; |
| 30 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 base::MD5Init(&md5_context_); | 51 base::MD5Init(&md5_context_); |
| 51 } | 52 } |
| 52 | 53 |
| 53 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { | 54 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { |
| 54 if (!pipeline_->IsRunning()) | 55 if (!pipeline_->IsRunning()) |
| 55 return; | 56 return; |
| 56 | 57 |
| 57 Stop(); | 58 Stop(); |
| 58 } | 59 } |
| 59 | 60 |
| 61 // TODO(xhwang): Method definitions in this file needs to be reordered. |
| 62 |
| 60 void PipelineIntegrationTestBase::OnSeeked(base::TimeDelta seek_time, | 63 void PipelineIntegrationTestBase::OnSeeked(base::TimeDelta seek_time, |
| 61 PipelineStatus status) { | 64 PipelineStatus status) { |
| 62 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | 65 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
| 63 pipeline_status_ = status; | 66 pipeline_status_ = status; |
| 64 } | 67 } |
| 65 | 68 |
| 66 void PipelineIntegrationTestBase::OnStatusCallback(PipelineStatus status) { | 69 void PipelineIntegrationTestBase::OnStatusCallback(PipelineStatus status) { |
| 67 pipeline_status_ = status; | 70 pipeline_status_ = status; |
| 68 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 71 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 69 } | 72 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 message_loop_.Run(); | 100 message_loop_.Run(); |
| 98 return pipeline_status_; | 101 return pipeline_status_; |
| 99 } | 102 } |
| 100 | 103 |
| 101 void PipelineIntegrationTestBase::OnError(PipelineStatus status) { | 104 void PipelineIntegrationTestBase::OnError(PipelineStatus status) { |
| 102 DCHECK_NE(status, PIPELINE_OK); | 105 DCHECK_NE(status, PIPELINE_OK); |
| 103 pipeline_status_ = status; | 106 pipeline_status_ = status; |
| 104 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 107 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 105 } | 108 } |
| 106 | 109 |
| 107 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename) { | 110 PipelineStatus PipelineIntegrationTestBase::StartInternal( |
| 108 return Start(filename, nullptr); | 111 scoped_ptr<DataSource> data_source, |
| 109 } | 112 CdmContext* cdm_context, |
| 113 uint8_t test_type) { |
| 114 hashing_enabled_ = test_type & kHashed; |
| 115 clockless_playback_ = test_type & kClockless; |
| 110 | 116 |
| 111 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, | |
| 112 CdmContext* cdm_context) { | |
| 113 EXPECT_CALL(*this, OnMetadata(_)) | 117 EXPECT_CALL(*this, OnMetadata(_)) |
| 114 .Times(AtMost(1)) | 118 .Times(AtMost(1)) |
| 115 .WillRepeatedly(SaveArg<0>(&metadata_)); | 119 .WillRepeatedly(SaveArg<0>(&metadata_)); |
| 116 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) | 120 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_ENOUGH)) |
| 117 .Times(AnyNumber()); | 121 .Times(AnyNumber()); |
| 118 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) | 122 EXPECT_CALL(*this, OnBufferingStateChanged(BUFFERING_HAVE_NOTHING)) |
| 119 .Times(AnyNumber()); | 123 .Times(AnyNumber()); |
| 120 CreateDemuxer(filename); | 124 CreateDemuxer(std::move(data_source)); |
| 121 | 125 |
| 122 if (cdm_context) { | 126 if (cdm_context) { |
| 123 EXPECT_CALL(*this, DecryptorAttached(true)); | 127 EXPECT_CALL(*this, DecryptorAttached(true)); |
| 124 pipeline_->SetCdm( | 128 pipeline_->SetCdm( |
| 125 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, | 129 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, |
| 126 base::Unretained(this))); | 130 base::Unretained(this))); |
| 127 } | 131 } |
| 128 | 132 |
| 129 // Should never be called as the required decryption keys for the encrypted | 133 // Should never be called as the required decryption keys for the encrypted |
| 130 // media files are provided in advance. | 134 // media files are provided in advance. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 base::Bind(&PipelineIntegrationTestBase::OnBufferingStateChanged, | 145 base::Bind(&PipelineIntegrationTestBase::OnBufferingStateChanged, |
| 142 base::Unretained(this)), | 146 base::Unretained(this)), |
| 143 base::Closure(), base::Bind(&PipelineIntegrationTestBase::OnAddTextTrack, | 147 base::Closure(), base::Bind(&PipelineIntegrationTestBase::OnAddTextTrack, |
| 144 base::Unretained(this)), | 148 base::Unretained(this)), |
| 145 base::Bind(&PipelineIntegrationTestBase::OnWaitingForDecryptionKey, | 149 base::Bind(&PipelineIntegrationTestBase::OnWaitingForDecryptionKey, |
| 146 base::Unretained(this))); | 150 base::Unretained(this))); |
| 147 message_loop_.Run(); | 151 message_loop_.Run(); |
| 148 return pipeline_status_; | 152 return pipeline_status_; |
| 149 } | 153 } |
| 150 | 154 |
| 155 PipelineStatus PipelineIntegrationTestBase::StartWithFile( |
| 156 const std::string& filename, |
| 157 CdmContext* cdm_context, |
| 158 uint8_t test_type) { |
| 159 scoped_ptr<FileDataSource> file_data_source(new FileDataSource()); |
| 160 base::FilePath file_path(GetTestDataFilePath(filename)); |
| 161 CHECK(file_data_source->Initialize(file_path)) << "Is " << file_path.value() |
| 162 << " missing?"; |
| 163 return StartInternal(std::move(file_data_source), cdm_context, test_type); |
| 164 } |
| 165 |
| 166 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename) { |
| 167 return StartWithFile(filename, nullptr, kNormal); |
| 168 } |
| 169 |
| 170 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, |
| 171 CdmContext* cdm_context) { |
| 172 return StartWithFile(filename, cdm_context, kNormal); |
| 173 } |
| 174 |
| 151 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, | 175 PipelineStatus PipelineIntegrationTestBase::Start(const std::string& filename, |
| 152 uint8_t test_type) { | 176 uint8_t test_type) { |
| 153 hashing_enabled_ = test_type & kHashed; | 177 return StartWithFile(filename, nullptr, test_type); |
| 154 clockless_playback_ = test_type & kClockless; | 178 } |
| 155 return Start(filename); | 179 |
| 180 PipelineStatus PipelineIntegrationTestBase::Start(const uint8_t* data, |
| 181 size_t size, |
| 182 uint8_t test_type) { |
| 183 return StartInternal(make_scoped_ptr(new MemoryDataSource(data, size)), |
| 184 nullptr, test_type); |
| 156 } | 185 } |
| 157 | 186 |
| 158 void PipelineIntegrationTestBase::Play() { | 187 void PipelineIntegrationTestBase::Play() { |
| 159 pipeline_->SetPlaybackRate(1); | 188 pipeline_->SetPlaybackRate(1); |
| 160 } | 189 } |
| 161 | 190 |
| 162 void PipelineIntegrationTestBase::Pause() { | 191 void PipelineIntegrationTestBase::Pause() { |
| 163 pipeline_->SetPlaybackRate(0); | 192 pipeline_->SetPlaybackRate(0); |
| 164 } | 193 } |
| 165 | 194 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 251 |
| 223 message_loop_.PostDelayedTask( | 252 message_loop_.PostDelayedTask( |
| 224 FROM_HERE, | 253 FROM_HERE, |
| 225 base::Bind(&PipelineIntegrationTestBase::QuitAfterCurrentTimeTask, | 254 base::Bind(&PipelineIntegrationTestBase::QuitAfterCurrentTimeTask, |
| 226 base::Unretained(this), wait_time), | 255 base::Unretained(this), wait_time), |
| 227 base::TimeDelta::FromMilliseconds(10)); | 256 base::TimeDelta::FromMilliseconds(10)); |
| 228 message_loop_.Run(); | 257 message_loop_.Run(); |
| 229 return (pipeline_status_ == PIPELINE_OK); | 258 return (pipeline_status_ == PIPELINE_OK); |
| 230 } | 259 } |
| 231 | 260 |
| 232 void PipelineIntegrationTestBase::CreateDemuxer(const std::string& filename) { | 261 void PipelineIntegrationTestBase::CreateDemuxer( |
| 233 FileDataSource* file_data_source = new FileDataSource(); | 262 scoped_ptr<DataSource> data_source) { |
| 234 base::FilePath file_path(GetTestDataFilePath(filename)); | 263 data_source_ = std::move(data_source); |
| 235 CHECK(file_data_source->Initialize(file_path)) << "Is " << file_path.value() | |
| 236 << " missing?"; | |
| 237 data_source_.reset(file_data_source); | |
| 238 | |
| 239 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = | |
| 240 base::Bind(&PipelineIntegrationTestBase::DemuxerEncryptedMediaInitDataCB, | |
| 241 base::Unretained(this)); | |
| 242 | 264 |
| 243 #if !defined(MEDIA_DISABLE_FFMPEG) | 265 #if !defined(MEDIA_DISABLE_FFMPEG) |
| 244 demuxer_ = scoped_ptr<Demuxer>( | 266 demuxer_ = scoped_ptr<Demuxer>(new FFmpegDemuxer( |
| 245 new FFmpegDemuxer(message_loop_.task_runner(), data_source_.get(), | 267 message_loop_.task_runner(), data_source_.get(), |
| 246 encrypted_media_init_data_cb, new MediaLog())); | 268 base::Bind(&PipelineIntegrationTestBase::DemuxerEncryptedMediaInitDataCB, |
| 269 base::Unretained(this)), |
| 270 new MediaLog())); |
| 247 #endif | 271 #endif |
| 248 } | 272 } |
| 249 | 273 |
| 250 scoped_ptr<Renderer> PipelineIntegrationTestBase::CreateRenderer() { | 274 scoped_ptr<Renderer> PipelineIntegrationTestBase::CreateRenderer() { |
| 251 ScopedVector<VideoDecoder> video_decoders; | 275 ScopedVector<VideoDecoder> video_decoders; |
| 252 #if !defined(MEDIA_DISABLE_LIBVPX) | 276 #if !defined(MEDIA_DISABLE_LIBVPX) |
| 253 video_decoders.push_back(new VpxVideoDecoder()); | 277 video_decoders.push_back(new VpxVideoDecoder()); |
| 254 #endif // !defined(MEDIA_DISABLE_LIBVPX) | 278 #endif // !defined(MEDIA_DISABLE_LIBVPX) |
| 255 | 279 |
| 256 #if !defined(MEDIA_DISABLE_FFMPEG) | 280 #if !defined(MEDIA_DISABLE_FFMPEG) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 DCHECK(clockless_playback_); | 373 DCHECK(clockless_playback_); |
| 350 return clockless_audio_sink_->render_time(); | 374 return clockless_audio_sink_->render_time(); |
| 351 } | 375 } |
| 352 | 376 |
| 353 base::TimeTicks DummyTickClock::NowTicks() { | 377 base::TimeTicks DummyTickClock::NowTicks() { |
| 354 now_ += base::TimeDelta::FromSeconds(60); | 378 now_ += base::TimeDelta::FromSeconds(60); |
| 355 return now_; | 379 return now_; |
| 356 } | 380 } |
| 357 | 381 |
| 358 } // namespace media | 382 } // namespace media |
| OLD | NEW |