Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: media/test/pipeline_integration_test_base.cc

Issue 2808583002: RELAND: Media Remoting end to end integration tests. (Closed)
Patch Set: Rebased. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/test/pipeline_integration_test_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "media/base/cdm_context.h"
16 #include "media/base/media_log.h" 15 #include "media/base/media_log.h"
17 #include "media/base/media_tracks.h" 16 #include "media/base/media_tracks.h"
18 #include "media/base/test_data_util.h" 17 #include "media/base/test_data_util.h"
19 #include "media/filters/chunk_demuxer.h"
20 #if !defined(MEDIA_DISABLE_FFMPEG) 18 #if !defined(MEDIA_DISABLE_FFMPEG)
21 #include "media/filters/ffmpeg_audio_decoder.h" 19 #include "media/filters/ffmpeg_audio_decoder.h"
22 #include "media/filters/ffmpeg_demuxer.h" 20 #include "media/filters/ffmpeg_demuxer.h"
23 #include "media/filters/ffmpeg_video_decoder.h" 21 #include "media/filters/ffmpeg_video_decoder.h"
24 #endif 22 #endif
25 #include "media/filters/file_data_source.h" 23 #include "media/filters/file_data_source.h"
26 #include "media/filters/memory_data_source.h" 24 #include "media/filters/memory_data_source.h"
27 #include "media/renderers/audio_renderer_impl.h" 25 #include "media/renderers/audio_renderer_impl.h"
28 #include "media/renderers/renderer_impl.h" 26 #include "media/renderers/renderer_impl.h"
27 #include "media/test/fake_encrypted_media.h"
28 #include "media/test/mock_media_source.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 using ::testing::_; 33 using ::testing::_;
34 using ::testing::AnyNumber; 34 using ::testing::AnyNumber;
35 using ::testing::AtLeast; 35 using ::testing::AtLeast;
36 using ::testing::AtMost; 36 using ::testing::AtMost;
37 using ::testing::Invoke; 37 using ::testing::Invoke;
38 using ::testing::InvokeWithoutArgs; 38 using ::testing::InvokeWithoutArgs;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #if !defined(MEDIA_DISABLE_FFMPEG) 76 #if !defined(MEDIA_DISABLE_FFMPEG)
77 audio_decoders.push_back( 77 audio_decoders.push_back(
78 new FFmpegAudioDecoder(media_task_runner, media_log)); 78 new FFmpegAudioDecoder(media_task_runner, media_log));
79 #endif 79 #endif
80 return audio_decoders; 80 return audio_decoders;
81 } 81 }
82 82
83 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e"; 83 const char kNullVideoHash[] = "d41d8cd98f00b204e9800998ecf8427e";
84 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,"; 84 const char kNullAudioHash[] = "0.00,0.00,0.00,0.00,0.00,0.00,";
85 85
86 class RendererFactoryImpl final : public PipelineTestRendererFactory {
87 public:
88 explicit RendererFactoryImpl(PipelineIntegrationTestBase* integration_test)
89 : integration_test_(integration_test) {}
90 ~RendererFactoryImpl() override {}
91
92 // PipelineTestRendererFactory implementation.
93 std::unique_ptr<Renderer> CreateRenderer(
94 CreateVideoDecodersCB prepend_video_decoders_cb,
95 CreateAudioDecodersCB prepend_audio_decoders_cb) override {
96 return integration_test_->CreateRenderer(prepend_video_decoders_cb,
97 prepend_audio_decoders_cb);
98 }
99
100 private:
101 PipelineIntegrationTestBase* integration_test_;
102
103 DISALLOW_COPY_AND_ASSIGN(RendererFactoryImpl);
104 };
105
86 PipelineIntegrationTestBase::PipelineIntegrationTestBase() 106 PipelineIntegrationTestBase::PipelineIntegrationTestBase()
87 : hashing_enabled_(false), 107 : hashing_enabled_(false),
88 clockless_playback_(false), 108 clockless_playback_(false),
89 pipeline_(new PipelineImpl(message_loop_.task_runner(), &media_log_)), 109 pipeline_(new PipelineImpl(message_loop_.task_runner(), &media_log_)),
90 ended_(false), 110 ended_(false),
91 pipeline_status_(PIPELINE_OK), 111 pipeline_status_(PIPELINE_OK),
92 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN), 112 last_video_frame_format_(PIXEL_FORMAT_UNKNOWN),
93 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED), 113 last_video_frame_color_space_(COLOR_SPACE_UNSPECIFIED),
94 current_duration_(kInfiniteDuration) { 114 current_duration_(kInfiniteDuration),
115 renderer_factory_(new RendererFactoryImpl(this)) {
95 ResetVideoHash(); 116 ResetVideoHash();
96 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber()); 117 EXPECT_CALL(*this, OnVideoAverageKeyframeDistanceUpdate()).Times(AnyNumber());
97 } 118 }
98 119
99 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() { 120 PipelineIntegrationTestBase::~PipelineIntegrationTestBase() {
100 if (pipeline_->IsRunning()) 121 if (pipeline_->IsRunning())
101 Stop(); 122 Stop();
102 123
103 demuxer_.reset(); 124 demuxer_.reset();
104 pipeline_.reset(); 125 pipeline_.reset();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 EXPECT_CALL(*this, DecryptorAttached(true)); 231 EXPECT_CALL(*this, DecryptorAttached(true));
211 pipeline_->SetCdm( 232 pipeline_->SetCdm(
212 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached, 233 cdm_context, base::Bind(&PipelineIntegrationTestBase::DecryptorAttached,
213 base::Unretained(this))); 234 base::Unretained(this)));
214 } 235 }
215 236
216 // 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
217 // media files are provided in advance. 238 // media files are provided in advance.
218 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); 239 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
219 240
220 pipeline_->Start( 241 pipeline_->Start(demuxer_.get(),
221 demuxer_.get(), 242 renderer_factory_->CreateRenderer(prepend_video_decoders_cb,
222 CreateRenderer(prepend_video_decoders_cb, prepend_audio_decoders_cb), 243 prepend_audio_decoders_cb),
223 this, 244 this,
224 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback, 245 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback,
225 base::Unretained(this))); 246 base::Unretained(this)));
226 base::RunLoop().Run(); 247 base::RunLoop().Run();
227 return pipeline_status_; 248 return pipeline_status_;
228 } 249 }
229 250
230 PipelineStatus PipelineIntegrationTestBase::StartWithFile( 251 PipelineStatus PipelineIntegrationTestBase::StartWithFile(
231 const std::string& filename, 252 const std::string& filename,
232 CdmContext* cdm_context, 253 CdmContext* cdm_context,
233 uint8_t test_type, 254 uint8_t test_type,
234 CreateVideoDecodersCB prepend_video_decoders_cb, 255 CreateVideoDecodersCB prepend_video_decoders_cb,
235 CreateAudioDecodersCB prepend_audio_decoders_cb) { 256 CreateAudioDecodersCB prepend_audio_decoders_cb) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 base::Unretained(this))); 312 base::Unretained(this)));
292 base::RunLoop().Run(); 313 base::RunLoop().Run();
293 return (pipeline_status_ == PIPELINE_OK); 314 return (pipeline_status_ == PIPELINE_OK);
294 } 315 }
295 316
296 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) { 317 bool PipelineIntegrationTestBase::Resume(base::TimeDelta seek_time) {
297 ended_ = false; 318 ended_ = false;
298 319
299 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 320 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
300 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow)); 321 .WillOnce(InvokeWithoutArgs(&message_loop_, &base::MessageLoop::QuitNow));
301 pipeline_->Resume(CreateRenderer(), seek_time, 322 pipeline_->Resume(renderer_factory_->CreateRenderer(CreateVideoDecodersCB(),
323 CreateAudioDecodersCB()),
324 seek_time,
302 base::Bind(&PipelineIntegrationTestBase::OnSeeked, 325 base::Bind(&PipelineIntegrationTestBase::OnSeeked,
303 base::Unretained(this), seek_time)); 326 base::Unretained(this), seek_time));
304 base::RunLoop().Run(); 327 base::RunLoop().Run();
305 return (pipeline_status_ == PIPELINE_OK); 328 return (pipeline_status_ == PIPELINE_OK);
306 } 329 }
307 330
308 void PipelineIntegrationTestBase::Stop() { 331 void PipelineIntegrationTestBase::Stop() {
309 DCHECK(pipeline_->IsRunning()); 332 DCHECK(pipeline_->IsRunning());
310 pipeline_->Stop(); 333 pipeline_->Stop();
311 base::RunLoop().RunUntilIdle(); 334 base::RunLoop().RunUntilIdle();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 if (clockless_playback_) 488 if (clockless_playback_)
466 return clockless_audio_sink_->GetAudioHashForTesting(); 489 return clockless_audio_sink_->GetAudioHashForTesting();
467 return audio_sink_->GetAudioHashForTesting(); 490 return audio_sink_->GetAudioHashForTesting();
468 } 491 }
469 492
470 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() { 493 base::TimeDelta PipelineIntegrationTestBase::GetAudioTime() {
471 DCHECK(clockless_playback_); 494 DCHECK(clockless_playback_);
472 return clockless_audio_sink_->render_time(); 495 return clockless_audio_sink_->render_time();
473 } 496 }
474 497
498 PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource(
499 MockMediaSource* source) {
500 return StartPipelineWithMediaSource(source, kNormal, nullptr);
501 }
502
503 PipelineStatus PipelineIntegrationTestBase::StartPipelineWithEncryptedMedia(
504 MockMediaSource* source,
505 FakeEncryptedMedia* encrypted_media) {
506 return StartPipelineWithMediaSource(source, kNormal, encrypted_media);
507 }
508
509 PipelineStatus PipelineIntegrationTestBase::StartPipelineWithMediaSource(
510 MockMediaSource* source,
511 uint8_t test_type,
512 FakeEncryptedMedia* encrypted_media) {
513 hashing_enabled_ = test_type & kHashed;
514 clockless_playback_ = test_type & kClockless;
515
516 if (!(test_type & kExpectDemuxerFailure))
517 EXPECT_CALL(*source, InitSegmentReceivedMock(_)).Times(AtLeast(1));
518
519 EXPECT_CALL(*this, OnMetadata(_))
520 .Times(AtMost(1))
521 .WillRepeatedly(SaveArg<0>(&metadata_));
522 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
523 .Times(AnyNumber());
524 EXPECT_CALL(*this, OnBufferingStateChange(BUFFERING_HAVE_NOTHING))
525 .Times(AnyNumber());
526 EXPECT_CALL(*this, OnDurationChange()).Times(AnyNumber());
527 EXPECT_CALL(*this, OnVideoNaturalSizeChange(_)).Times(AtMost(1));
528 EXPECT_CALL(*this, OnVideoOpacityChange(_)).Times(AtMost(1));
529
530 source->set_demuxer_failure_cb(base::Bind(
531 &PipelineIntegrationTestBase::OnStatusCallback, base::Unretained(this)));
532 demuxer_ = source->GetDemuxer();
533
534 if (encrypted_media) {
535 EXPECT_CALL(*this, DecryptorAttached(true));
536
537 // Encrypted content used but keys provided in advance, so this is
538 // never called.
539 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
540 pipeline_->SetCdm(
541 encrypted_media->GetCdmContext(),
542 base::Bind(&PipelineIntegrationTestBase::DecryptorAttached,
543 base::Unretained(this)));
544 } else {
545 // Encrypted content not used, so this is never called.
546 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0);
547 }
548
549 pipeline_->Start(demuxer_.get(),
550 renderer_factory_->CreateRenderer(CreateVideoDecodersCB(),
551 CreateAudioDecodersCB()),
552 this,
553 base::Bind(&PipelineIntegrationTestBase::OnStatusCallback,
554 base::Unretained(this)));
555
556 if (encrypted_media) {
557 source->set_encrypted_media_init_data_cb(
558 base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData,
559 base::Unretained(encrypted_media)));
560 }
561 base::RunLoop().Run();
562 return pipeline_status_;
563 }
564
475 base::TimeTicks DummyTickClock::NowTicks() { 565 base::TimeTicks DummyTickClock::NowTicks() {
476 now_ += base::TimeDelta::FromSeconds(60); 566 now_ += base::TimeDelta::FromSeconds(60);
477 return now_; 567 return now_;
478 } 568 }
479 569
480 } // namespace media 570 } // namespace media
OLDNEW
« no previous file with comments | « media/test/pipeline_integration_test_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698