| 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/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "media/filters/ffmpeg_video_decoder.h" | 23 #include "media/filters/ffmpeg_video_decoder.h" |
| 24 #endif | 24 #endif |
| 25 #include "media/filters/file_data_source.h" | 25 #include "media/filters/file_data_source.h" |
| 26 #include "media/filters/memory_data_source.h" | 26 #include "media/filters/memory_data_source.h" |
| 27 #include "media/renderers/audio_renderer_impl.h" | 27 #include "media/renderers/audio_renderer_impl.h" |
| 28 #include "media/renderers/renderer_impl.h" | 28 #include "media/renderers/renderer_impl.h" |
| 29 #if !defined(MEDIA_DISABLE_LIBVPX) | 29 #if !defined(MEDIA_DISABLE_LIBVPX) |
| 30 #include "media/filters/vpx_video_decoder.h" | 30 #include "media/filters/vpx_video_decoder.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 34 #include "media/remoting/end2end_test_renderer.h" // nogncheck |
| 35 #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 36 |
| 33 using ::testing::_; | 37 using ::testing::_; |
| 34 using ::testing::AnyNumber; | 38 using ::testing::AnyNumber; |
| 35 using ::testing::AtLeast; | 39 using ::testing::AtLeast; |
| 36 using ::testing::AtMost; | 40 using ::testing::AtMost; |
| 37 using ::testing::Invoke; | 41 using ::testing::Invoke; |
| 38 using ::testing::InvokeWithoutArgs; | 42 using ::testing::InvokeWithoutArgs; |
| 39 using ::testing::Return; | 43 using ::testing::Return; |
| 40 using ::testing::SaveArg; | 44 using ::testing::SaveArg; |
| 41 | 45 |
| 42 namespace media { | 46 namespace media { |
| 43 | 47 |
| 44 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e"; | 48 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e"; |
| 45 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,"; | 49 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,"; |
| 46 | 50 |
| 51 namespace { |
| 52 |
| 53 class RendererFactoryImpl final : public PipelineTestRendererFactory { |
| 54 public: |
| 55 explicit RendererFactoryImpl(PipelineIntegrationTestBase* integration_test) |
| 56 : integration_test_(integration_test) {} |
| 57 ~RendererFactoryImpl() override {} |
| 58 |
| 59 // PipelineTestRendererFactory implementation. |
| 60 std::unique_ptr<Renderer> CreateRenderer( |
| 61 ScopedVector<VideoDecoder> prepend_video_decoders = |
| 62 ScopedVector<VideoDecoder>(), |
| 63 ScopedVector<AudioDecoder> prepend_audio_decoders = |
| 64 ScopedVector<AudioDecoder>()) override { |
| 65 return integration_test_->CreateRenderer(std::move(prepend_video_decoders), |
| 66 std::move(prepend_audio_decoders)); |
| 67 } |
| 68 |
| 69 private: |
| 70 PipelineIntegrationTestBase* integration_test_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(RendererFactoryImpl); |
| 73 }; |
| 74 |
| 75 #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 76 class RemotingTestRendererFactory final : public PipelineTestRendererFactory { |
| 77 public: |
| 78 explicit RemotingTestRendererFactory( |
| 79 std::unique_ptr<PipelineTestRendererFactory> renderer_factory) |
| 80 : default_renderer_factory_(std::move(renderer_factory)) {} |
| 81 ~RemotingTestRendererFactory() override {} |
| 82 |
| 83 // PipelineTestRendererFactory implementation. |
| 84 std::unique_ptr<Renderer> CreateRenderer( |
| 85 ScopedVector<VideoDecoder> prepend_video_decoders = |
| 86 ScopedVector<VideoDecoder>(), |
| 87 ScopedVector<AudioDecoder> prepend_audio_decoders = |
| 88 ScopedVector<AudioDecoder>()) override { |
| 89 std::unique_ptr<Renderer> renderer_impl = |
| 90 default_renderer_factory_->CreateRenderer( |
| 91 std::move(prepend_video_decoders), |
| 92 std::move(prepend_audio_decoders)); |
| 93 return base::MakeUnique<remoting::End2EndTestRenderer>( |
| 94 std::move(renderer_impl)); |
| 95 } |
| 96 |
| 97 private: |
| 98 std::unique_ptr<PipelineTestRendererFactory> default_renderer_factory_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(RemotingTestRendererFactory); |
| 101 }; |
| 102 #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 103 |
| 104 } // namespace |
| 105 |
| 47 PipelineIntegrationTestBase::PipelineIntegrationTestBase() | 106 PipelineIntegrationTestBase::PipelineIntegrationTestBase() |
| 48 : hashing_enabled_(false), | 107 : hashing_enabled_(false), |
| 49 clockless_playback_(false), | 108 clockless_playback_(false), |
| 50 pipeline_(new PipelineImpl(message_loop_.task_runner(), new MediaLog())), | 109 pipeline_(new PipelineImpl(message_loop_.task_runner(), new MediaLog())), |
| 51 ended_(false), | 110 ended_(false), |
| 52 pipeline_status_(PIPELINE_OK), | 111 pipeline_status_(PIPELINE_OK), |
| 53 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN), | 112 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN), |
| 54 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED), | 113 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED), |
| 55 current_duration_(kInfiniteDuration) { | 114 current_duration_(kInfiniteDuration), |
| 115 renderer_factory_(new RendererFactoryImpl(this)) { |
| 56 ResetVideoHash(); | 116 ResetVideoHash(); |
| 57 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber()); | 117 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber()); |
| 58 } | 118 } |
| 59 | 119 |
| 60 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { | 120 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { |
| 61 if (pipeline_->IsRunning()) | 121 if (pipeline_->IsRunning()) |
| 62 Stop(); | 122 Stop(); |
| 63 | 123 |
| 64 demuxer_.reset(); | 124 demuxer_.reset(); |
| 65 pipeline_.reset(); | 125 pipeline_.reset(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 pipeline_->SetCdm( | 232 pipeline_->SetCdm( |
| 173 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, | 233 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, |
| 174 base::Unretained(this))); | 234 base::Unretained(this))); |
| 175 } | 235 } |
| 176 | 236 |
| 177 // Should never be called as the required decryption keys for the encrypted | 237 // Should never be called as the required decryption keys for the encrypted |
| 178 // media files are provided in advance. | 238 // media files are provided in advance. |
| 179 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 239 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
| 180 | 240 |
| 181 pipeline_->Start( | 241 pipeline_->Start( |
| 182 demuxer_.get(), CreateRenderer(std::move(prepend_video_decoders), | 242 demuxer_.get(), |
| 183 std::move(prepend_audio_decoders)), | 243 renderer_factory_->CreateRenderer(std::move(prepend_video_decoders), |
| 184 this, base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, | 244 std::move(prepend_audio_decoders)), |
| 185 base::Unretained(this))); | 245 this, |
| 246 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, |
| 247 base::Unretained(this))); |
| 186 base::RunLoop().Run(); | 248 base::RunLoop().Run(); |
| 187 return pipeline_status_; | 249 return pipeline_status_; |
| 188 } | 250 } |
| 189 | 251 |
| 190 PipelineStatus PipelineIntegrationTestBase::StartWithFile( | 252 PipelineStatus PipelineIntegrationTestBase::StartWithFile( |
| 191 const std::string& filename, | 253 const std::string& filename, |
| 192 CdmContext* cdm_context, | 254 CdmContext* cdm_context, |
| 193 uint8_t test_type, | 255 uint8_t test_type, |
| 194 ScopedVector<VideoDecoder> prepend_video_decoders, | 256 ScopedVector<VideoDecoder> prepend_video_decoders, |
| 195 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 257 ScopedVector<AudioDecoder> prepend_audio_decoders) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 base::Unretained(this))); | 315 base::Unretained(this))); |
| 254 base::RunLoop().Run(); | 316 base::RunLoop().Run(); |
| 255 return (pipeline_status_ == PIPELINE_OK); | 317 return (pipeline_status_ == PIPELINE_OK); |
| 256 } | 318 } |
| 257 | 319 |
| 258 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { | 320 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { |
| 259 ended_ = false; | 321 ended_ = false; |
| 260 | 322 |
| 261 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 323 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
| 262 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow)); | 324 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow)); |
| 263 pipeline_->Resume(CreateRenderer(), seek_time, | 325 pipeline_->Resume(renderer_factory_->CreateRenderer(), seek_time, |
| 264 base::Bind(&PipelineIntegrationTestBase::OnSeeked, | 326 base::Bind(&PipelineIntegrationTestBase::OnSeeked, |
| 265 base::Unretained(this), seek_time)); | 327 base::Unretained(this), seek_time)); |
| 266 base::RunLoop().Run(); | 328 base::RunLoop().Run(); |
| 267 return (pipeline_status_ == PIPELINE_OK); | 329 return (pipeline_status_ == PIPELINE_OK); |
| 268 } | 330 } |
| 269 | 331 |
| 270 void PipelineIntegrationTestBase::Stop() { | 332 void PipelineIntegrationTestBase::Stop() { |
| 271 DCHECK(pipeline_->IsRunning()); | 333 DCHECK(pipeline_->IsRunning()); |
| 272 pipeline_->Stop(); | 334 pipeline_->Stop(); |
| 273 base::RunLoop().RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() { | 508 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() { |
| 447 DCHECK(clockless_playback_); | 509 DCHECK(clockless_playback_); |
| 448 return clockless_audio_sink_->render_time(); | 510 return clockless_audio_sink_->render_time(); |
| 449 } | 511 } |
| 450 | 512 |
| 451 base::TimeTicks DummyTickClock::NowTicks() { | 513 base::TimeTicks DummyTickClock::NowTicks() { |
| 452 now_ += base::TimeDelta::FromSeconds(60); | 514 now_ += base::TimeDelta::FromSeconds(60); |
| 453 return now_; | 515 return now_; |
| 454 } | 516 } |
| 455 | 517 |
| 518 #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 519 void PipelineIntegrationTestBase::SetUpRemotingPipeline() { |
| 520 std::unique_ptr<PipelineTestRendererFactory> factory = |
| 521 std::move(renderer_factory_); |
| 522 renderer_factory_.reset(new RemotingTestRendererFactory(std::move(factory))); |
| 523 } |
| 524 #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 525 |
| 456 } // namespace media | 526 } // namespace media |
| OLD | NEW |