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
3 // found in the LICENSE file.
5 #ifndef MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_
6 #define MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_
9 #include "base/message_loop/message_loop.h"
10 #include "media/audio/clockless_audio_sink.h"
11 #include "media/audio/null_audio_sink.h"
12 #include "media/base/audio_hardware_config.h"
13 #include "media/base/demuxer.h"
14 #include "media/base/media_keys.h"
15 #include "media/base/null_video_sink.h"
16 #include "media/base/pipeline.h"
17 #include "media/base/text_track.h"
18 #include "media/base/text_track_config.h"
19 #include "media/base/video_frame.h"
20 #include "media/renderers/video_renderer_impl.h"
21 #include "testing/gmock/include/gmock/gmock.h"
31 // Empty MD5 hash string. Used to verify empty video tracks.
32 extern const char kNullVideoHash
[];
34 // Empty hash string. Used to verify empty audio tracks.
35 extern const char kNullAudioHash
[];
37 // Dummy tick clock which advances extremely quickly (1 minute every time
38 // NowTicks() is called).
39 class DummyTickClock
: public base::TickClock
{
41 DummyTickClock() : now_() {}
42 ~DummyTickClock() override
{}
43 base::TimeTicks
NowTicks() override
;
49 // Integration tests for Pipeline. Real demuxers, real decoders, and
50 // base renderer implementations are used to verify pipeline functionality. The
51 // renderers used in these tests rely heavily on the AudioRendererBase &
52 // VideoRendererImpl implementations which contain a majority of the code used
53 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in
54 // the browser. The renderers in this test don't actually write data to a
55 // display or audio device. Both of these devices are simulated since they have
56 // little effect on verifying pipeline behavior and allow tests to run faster
58 class PipelineIntegrationTestBase
{
60 PipelineIntegrationTestBase();
61 virtual ~PipelineIntegrationTestBase();
63 bool WaitUntilOnEnded();
64 PipelineStatus
WaitUntilEndedOrError();
66 // Starts the pipeline (optionally with a CdmContext), returning the final
67 // status code after it has started. |filename| points at a test file located
68 // under media/test/data/.
69 PipelineStatus
Start(const std::string
& filename
);
70 PipelineStatus
Start(const std::string
& filename
, CdmContext
* cdm_context
);
72 // Starts the pipeline in a particular mode for advanced testing and
73 // benchmarking purposes (e.g., underflow is disabled to ensure consistent
74 // hashes). May be combined using the bitwise or operator (and as such must
75 // have values that are powers of two).
76 enum TestTypeFlags
{ kHashed
= 1, kClockless
= 2};
77 PipelineStatus
Start(const std::string
& filename
, uint8_t test_type
);
81 bool Seek(base::TimeDelta seek_time
);
83 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta
& wait_time
);
85 // Returns the MD5 hash of all video frames seen. Should only be called once
86 // after playback completes. First time hashes should be generated with
87 // --video-threads=1 to ensure correctness. Pipeline must have been started
88 // with hashing enabled.
89 std::string
GetVideoHash();
91 // Returns the hash of all audio frames seen. Should only be called once
92 // after playback completes. Pipeline must have been started with hashing
94 std::string
GetAudioHash();
96 // Returns the time taken to render the complete audio file.
97 // Pipeline must have been started with clockless playback enabled.
98 base::TimeDelta
GetAudioTime();
101 base::MessageLoop message_loop_
;
102 base::MD5Context md5_context_
;
103 bool hashing_enabled_
;
104 bool clockless_playback_
;
105 scoped_ptr
<Demuxer
> demuxer_
;
106 scoped_ptr
<DataSource
> data_source_
;
107 scoped_ptr
<Pipeline
> pipeline_
;
108 scoped_refptr
<NullAudioSink
> audio_sink_
;
109 scoped_refptr
<ClocklessAudioSink
> clockless_audio_sink_
;
110 scoped_ptr
<NullVideoSink
> video_sink_
;
112 PipelineStatus pipeline_status_
;
113 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
114 VideoPixelFormat last_video_frame_format_
;
115 ColorSpace last_video_frame_color_space_
;
116 DummyTickClock dummy_clock_
;
117 AudioHardwareConfig hardware_config_
;
118 PipelineMetadata metadata_
;
120 void OnSeeked(base::TimeDelta seek_time
, PipelineStatus status
);
121 void OnStatusCallback(PipelineStatus status
);
122 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type
,
123 const std::vector
<uint8
>& init_data
);
124 void set_encrypted_media_init_data_cb(
125 const Demuxer::EncryptedMediaInitDataCB
& encrypted_media_init_data_cb
) {
126 encrypted_media_init_data_cb_
= encrypted_media_init_data_cb
;
130 void OnError(PipelineStatus status
);
131 void QuitAfterCurrentTimeTask(const base::TimeDelta
& quit_time
);
133 // Creates Demuxer and sets |demuxer_|.
134 void CreateDemuxer(const std::string
& filename
);
136 // Creates and returns a Renderer.
137 virtual scoped_ptr
<Renderer
> CreateRenderer();
139 void OnVideoFramePaint(const scoped_refptr
<VideoFrame
>& frame
);
141 MOCK_METHOD1(OnMetadata
, void(PipelineMetadata
));
142 MOCK_METHOD1(OnBufferingStateChanged
, void(BufferingState
));
143 MOCK_METHOD1(DecryptorAttached
, void(bool));
144 MOCK_METHOD2(OnAddTextTrack
,
145 void(const TextTrackConfig
& config
,
146 const AddTextTrackDoneCB
& done_cb
));
147 MOCK_METHOD0(OnWaitingForDecryptionKey
, void(void));
152 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_