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/pipeline.h"
16 #include "media/base/text_track.h"
17 #include "media/base/text_track_config.h"
18 #include "media/base/video_frame.h"
19 #include "media/renderers/video_renderer_impl.h"
20 #include "testing/gmock/include/gmock/gmock.h"
30 // Empty MD5 hash string. Used to verify empty video tracks.
31 extern const char kNullVideoHash
[];
33 // Empty hash string. Used to verify empty audio tracks.
34 extern const char kNullAudioHash
[];
36 // Dummy tick clock which advances extremely quickly (1 minute every time
37 // NowTicks() is called).
38 class DummyTickClock
: public base::TickClock
{
40 DummyTickClock() : now_() {}
41 ~DummyTickClock() override
{}
42 base::TimeTicks
NowTicks() override
;
48 // TODO(dalecurtis): Mocks won't be useful for the new rendering path, we'll
49 // need fake callback generators like we have for the audio path.
50 // http://crbug.com/473424
51 class MockVideoRendererSink
: public VideoRendererSink
{
53 MockVideoRendererSink();
54 ~MockVideoRendererSink() override
;
56 MOCK_METHOD1(Start
, void(VideoRendererSink::RenderCallback
*));
57 MOCK_METHOD0(Stop
, void());
58 MOCK_METHOD1(PaintFrameUsingOldRenderingPath
,
59 void(const scoped_refptr
<VideoFrame
>&));
62 // Integration tests for Pipeline. Real demuxers, real decoders, and
63 // base renderer implementations are used to verify pipeline functionality. The
64 // renderers used in these tests rely heavily on the AudioRendererBase &
65 // VideoRendererImpl implementations which contain a majority of the code used
66 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in
67 // the browser. The renderers in this test don't actually write data to a
68 // display or audio device. Both of these devices are simulated since they have
69 // little effect on verifying pipeline behavior and allow tests to run faster
71 class PipelineIntegrationTestBase
{
73 PipelineIntegrationTestBase();
74 virtual ~PipelineIntegrationTestBase();
76 bool WaitUntilOnEnded();
77 PipelineStatus
WaitUntilEndedOrError();
79 // Starts the pipeline (optionally with a CdmContext), returning the final
80 // status code after it has started. |filename| points at a test file located
81 // under media/test/data/.
82 PipelineStatus
Start(const std::string
& filename
);
83 PipelineStatus
Start(const std::string
& filename
, CdmContext
* cdm_context
);
85 // Starts the pipeline in a particular mode for advanced testing and
86 // benchmarking purposes (e.g., underflow is disabled to ensure consistent
88 enum kTestType
{ kHashed
, kClockless
};
89 PipelineStatus
Start(const std::string
& filename
, kTestType test_type
);
93 bool Seek(base::TimeDelta seek_time
);
95 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta
& wait_time
);
97 // Returns the MD5 hash of all video frames seen. Should only be called once
98 // after playback completes. First time hashes should be generated with
99 // --video-threads=1 to ensure correctness. Pipeline must have been started
100 // with hashing enabled.
101 std::string
GetVideoHash();
103 // Returns the hash of all audio frames seen. Should only be called once
104 // after playback completes. Pipeline must have been started with hashing
106 std::string
GetAudioHash();
108 // Returns the time taken to render the complete audio file.
109 // Pipeline must have been started with clockless playback enabled.
110 base::TimeDelta
GetAudioTime();
113 base::MessageLoop message_loop_
;
114 base::MD5Context md5_context_
;
115 bool hashing_enabled_
;
116 bool clockless_playback_
;
117 scoped_ptr
<Demuxer
> demuxer_
;
118 scoped_ptr
<DataSource
> data_source_
;
119 scoped_ptr
<Pipeline
> pipeline_
;
120 scoped_refptr
<NullAudioSink
> audio_sink_
;
121 scoped_refptr
<ClocklessAudioSink
> clockless_audio_sink_
;
122 testing::NiceMock
<MockVideoRendererSink
> video_sink_
;
124 PipelineStatus pipeline_status_
;
125 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
126 VideoFrame::Format last_video_frame_format_
;
127 DummyTickClock dummy_clock_
;
128 AudioHardwareConfig hardware_config_
;
129 PipelineMetadata metadata_
;
131 void OnSeeked(base::TimeDelta seek_time
, PipelineStatus status
);
132 void OnStatusCallback(PipelineStatus status
);
133 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type
,
134 const std::vector
<uint8
>& init_data
);
135 void set_encrypted_media_init_data_cb(
136 const Demuxer::EncryptedMediaInitDataCB
& encrypted_media_init_data_cb
) {
137 encrypted_media_init_data_cb_
= encrypted_media_init_data_cb
;
141 void OnError(PipelineStatus status
);
142 void QuitAfterCurrentTimeTask(const base::TimeDelta
& quit_time
);
144 // Creates Demuxer and sets |demuxer_|.
145 void CreateDemuxer(const std::string
& filename
);
147 // Creates and returns a Renderer.
148 virtual scoped_ptr
<Renderer
> CreateRenderer();
150 void OnVideoFramePaint(const scoped_refptr
<VideoFrame
>& frame
);
152 MOCK_METHOD1(OnMetadata
, void(PipelineMetadata
));
153 MOCK_METHOD1(OnBufferingStateChanged
, void(BufferingState
));
154 MOCK_METHOD1(DecryptorAttached
, void(bool));
155 MOCK_METHOD2(OnAddTextTrack
,
156 void(const TextTrackConfig
& config
,
157 const AddTextTrackDoneCB
& done_cb
));
158 MOCK_METHOD0(OnWaitingForDecryptionKey
, void(void));
163 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_