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 | |
37 using ::testing::_; | 33 using ::testing::_; |
38 using ::testing::AnyNumber; | 34 using ::testing::AnyNumber; |
39 using ::testing::AtLeast; | 35 using ::testing::AtLeast; |
40 using ::testing::AtMost; | 36 using ::testing::AtMost; |
41 using ::testing::Invoke; | 37 using ::testing::Invoke; |
42 using ::testing::InvokeWithoutArgs; | 38 using ::testing::InvokeWithoutArgs; |
43 using ::testing::Return; | 39 using ::testing::Return; |
44 using ::testing::SaveArg; | 40 using ::testing::SaveArg; |
45 | 41 |
46 namespace media { | 42 namespace media { |
47 | 43 |
48 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e"; | 44 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e"; |
49 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,"; | 45 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,"; |
50 | 46 |
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 | |
106 PipelineIntegrationTestBase::PipelineIntegrationTestBase() | 47 PipelineIntegrationTestBase::PipelineIntegrationTestBase() |
107 : hashing_enabled_(false), | 48 : hashing_enabled_(false), |
108 clockless_playback_(false), | 49 clockless_playback_(false), |
109 pipeline_(new PipelineImpl(message_loop_.task_runner(), new MediaLog())), | 50 pipeline_(new PipelineImpl(message_loop_.task_runner(), new MediaLog())), |
110 ended_(false), | 51 ended_(false), |
111 pipeline_status_(PIPELINE_OK), | 52 pipeline_status_(PIPELINE_OK), |
112 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN), | 53 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN), |
113 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED), | 54 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED), |
114 current_duration_(kInfiniteDuration), | 55 current_duration_(kInfiniteDuration) { |
115 renderer_factory_(new RendererFactoryImpl(this)) { | |
116 ResetVideoHash(); | 56 ResetVideoHash(); |
117 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber()); | 57 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber()); |
118 } | 58 } |
119 | 59 |
120 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { | 60 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { |
121 if (pipeline_->IsRunning()) | 61 if (pipeline_->IsRunning()) |
122 Stop(); | 62 Stop(); |
123 | 63 |
124 demuxer_.reset(); | 64 demuxer_.reset(); |
125 pipeline_.reset(); | 65 pipeline_.reset(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 pipeline_->SetCdm( | 172 pipeline_->SetCdm( |
233 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, | 173 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, |
234 base::Unretained(this))); | 174 base::Unretained(this))); |
235 } | 175 } |
236 | 176 |
237 // Should never be called as the required decryption keys for the encrypted | 177 // Should never be called as the required decryption keys for the encrypted |
238 // media files are provided in advance. | 178 // media files are provided in advance. |
239 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); | 179 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); |
240 | 180 |
241 pipeline_->Start( | 181 pipeline_->Start( |
242 demuxer_.get(), | 182 demuxer_.get(), CreateRenderer(std::move(prepend_video_decoders), |
243 renderer_factory_->CreateRenderer(std::move(prepend_video_decoders), | 183 std::move(prepend_audio_decoders)), |
244 std::move(prepend_audio_decoders)), | 184 this, base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, |
245 this, | 185 base::Unretained(this))); |
246 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, | |
247 base::Unretained(this))); | |
248 base::RunLoop().Run(); | 186 base::RunLoop().Run(); |
249 return pipeline_status_; | 187 return pipeline_status_; |
250 } | 188 } |
251 | 189 |
252 PipelineStatus PipelineIntegrationTestBase::StartWithFile( | 190 PipelineStatus PipelineIntegrationTestBase::StartWithFile( |
253 const std::string& filename, | 191 const std::string& filename, |
254 CdmContext* cdm_context, | 192 CdmContext* cdm_context, |
255 uint8_t test_type, | 193 uint8_t test_type, |
256 ScopedVector<VideoDecoder> prepend_video_decoders, | 194 ScopedVector<VideoDecoder> prepend_video_decoders, |
257 ScopedVector<AudioDecoder> prepend_audio_decoders) { | 195 ScopedVector<AudioDecoder> prepend_audio_decoders) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 base::Unretained(this))); | 253 base::Unretained(this))); |
316 base::RunLoop().Run(); | 254 base::RunLoop().Run(); |
317 return (pipeline_status_ == PIPELINE_OK); | 255 return (pipeline_status_ == PIPELINE_OK); |
318 } | 256 } |
319 | 257 |
320 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { | 258 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { |
321 ended_ = false; | 259 ended_ = false; |
322 | 260 |
323 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) | 261 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) |
324 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow)); | 262 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow)); |
325 pipeline_->Resume(renderer_factory_->CreateRenderer(), seek_time, | 263 pipeline_->Resume(CreateRenderer(), seek_time, |
326 base::Bind(&PipelineIntegrationTestBase::OnSeeked, | 264 base::Bind(&PipelineIntegrationTestBase::OnSeeked, |
327 base::Unretained(this), seek_time)); | 265 base::Unretained(this), seek_time)); |
328 base::RunLoop().Run(); | 266 base::RunLoop().Run(); |
329 return (pipeline_status_ == PIPELINE_OK); | 267 return (pipeline_status_ == PIPELINE_OK); |
330 } | 268 } |
331 | 269 |
332 void PipelineIntegrationTestBase::Stop() { | 270 void PipelineIntegrationTestBase::Stop() { |
333 DCHECK(pipeline_->IsRunning()); | 271 DCHECK(pipeline_->IsRunning()); |
334 pipeline_->Stop(); | 272 pipeline_->Stop(); |
335 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() { | 446 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() { |
509 DCHECK(clockless_playback_); | 447 DCHECK(clockless_playback_); |
510 return clockless_audio_sink_->render_time(); | 448 return clockless_audio_sink_->render_time(); |
511 } | 449 } |
512 | 450 |
513 base::TimeTicks DummyTickClock::NowTicks() { | 451 base::TimeTicks DummyTickClock::NowTicks() { |
514 now_ += base::TimeDelta::FromSeconds(60); | 452 now_ += base::TimeDelta::FromSeconds(60); |
515 return now_; | 453 return now_; |
516 } | 454 } |
517 | 455 |
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 | |
526 } // namespace media | 456 } // namespace media |
OLD | NEW |