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 // Integration tests for Pipeline. Real demuxers, real decoders, and
49 // base renderer implementations are used to verify pipeline functionality. The
50 // renderers used in these tests rely heavily on the AudioRendererBase &
51 // VideoRendererImpl implementations which contain a majority of the code used
52 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in
53 // the browser. The renderers in this test don't actually write data to a
54 // display or audio device. Both of these devices are simulated since they have
55 // little effect on verifying pipeline behavior and allow tests to run faster
57 class PipelineIntegrationTestBase
{
59 PipelineIntegrationTestBase();
60 virtual ~PipelineIntegrationTestBase();
62 bool WaitUntilOnEnded();
63 PipelineStatus
WaitUntilEndedOrError();
65 // Starts the pipeline (optionally with a CdmContext), returning the final
66 // status code after it has started. |filename| points at a test file located
67 // under media/test/data/.
68 PipelineStatus
Start(const std::string
& filename
);
69 PipelineStatus
Start(const std::string
& filename
, CdmContext
* cdm_context
);
71 // Starts the pipeline in a particular mode for advanced testing and
72 // benchmarking purposes (e.g., underflow is disabled to ensure consistent
74 enum kTestType
{ kHashed
, kClockless
};
75 PipelineStatus
Start(const std::string
& filename
, kTestType test_type
);
79 bool Seek(base::TimeDelta seek_time
);
81 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta
& wait_time
);
83 // Returns the MD5 hash of all video frames seen. Should only be called once
84 // after playback completes. First time hashes should be generated with
85 // --video-threads=1 to ensure correctness. Pipeline must have been started
86 // with hashing enabled.
87 std::string
GetVideoHash();
89 // Returns the hash of all audio frames seen. Should only be called once
90 // after playback completes. Pipeline must have been started with hashing
92 std::string
GetAudioHash();
94 // Returns the time taken to render the complete audio file.
95 // Pipeline must have been started with clockless playback enabled.
96 base::TimeDelta
GetAudioTime();
99 base::MessageLoop message_loop_
;
100 base::MD5Context md5_context_
;
101 bool hashing_enabled_
;
102 bool clockless_playback_
;
103 scoped_ptr
<Demuxer
> demuxer_
;
104 scoped_ptr
<DataSource
> data_source_
;
105 scoped_ptr
<Pipeline
> pipeline_
;
106 scoped_refptr
<NullAudioSink
> audio_sink_
;
107 scoped_refptr
<ClocklessAudioSink
> clockless_audio_sink_
;
109 PipelineStatus pipeline_status_
;
110 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_
;
111 VideoFrame::Format last_video_frame_format_
;
112 DummyTickClock dummy_clock_
;
113 AudioHardwareConfig hardware_config_
;
114 PipelineMetadata metadata_
;
116 void OnSeeked(base::TimeDelta seek_time
, PipelineStatus status
);
117 void OnStatusCallback(PipelineStatus status
);
118 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type
,
119 const std::vector
<uint8
>& init_data
);
120 void set_encrypted_media_init_data_cb(
121 const Demuxer::EncryptedMediaInitDataCB
& encrypted_media_init_data_cb
) {
122 encrypted_media_init_data_cb_
= encrypted_media_init_data_cb
;
126 void OnError(PipelineStatus status
);
127 void QuitAfterCurrentTimeTask(const base::TimeDelta
& quit_time
);
129 // Creates Demuxer and sets |demuxer_|.
130 void CreateDemuxer(const std::string
& filename
);
132 // Creates and returns a Renderer.
133 virtual scoped_ptr
<Renderer
> CreateRenderer();
135 void OnVideoFramePaint(const scoped_refptr
<VideoFrame
>& frame
);
137 MOCK_METHOD1(OnMetadata
, void(PipelineMetadata
));
138 MOCK_METHOD1(OnBufferingStateChanged
, void(BufferingState
));
139 MOCK_METHOD1(DecryptorAttached
, void(bool));
140 MOCK_METHOD2(OnAddTextTrack
,
141 void(const TextTrackConfig
& config
,
142 const AddTextTrackDoneCB
& done_cb
));
143 MOCK_METHOD0(OnWaitingForDecryptionKey
, void(void));
148 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_