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_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_
6 #define MEDIA_FILTERS_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/filters/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();
64 bool Start(const base::FilePath& file_path, PipelineStatus expected_status);
65 // Enable playback with audio and video hashing enabled, or clockless
66 // playback (audio only). Frame dropping and audio underflow will be disabled
67 // if hashing enabled to ensure consistent hashes.
68 enum kTestType { kHashed, kClockless };
69 bool Start(const base::FilePath& file_path,
70 PipelineStatus expected_status,
72 // Initialize the pipeline and ignore any status updates. Useful for testing
73 // invalid audio/video clips which don't have deterministic results.
74 bool Start(const base::FilePath& file_path);
75 bool Start(const base::FilePath& file_path, Decryptor* decryptor);
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::NeedKeyCB need_key_cb_;
111 VideoFrame::Format last_video_frame_format_;
112 DummyTickClock dummy_clock_;
113 AudioHardwareConfig hardware_config_;
114 PipelineMetadata metadata_;
116 void SaveStatus(PipelineStatus status);
117 void OnStatusCallbackChecked(PipelineStatus expected_status,
118 PipelineStatus status);
119 void OnStatusCallback(PipelineStatus status);
120 PipelineStatusCB QuitOnStatusCB(PipelineStatus expected_status);
121 void DemuxerNeedKeyCB(const std::string& type,
122 const std::vector<uint8>& init_data);
123 void set_need_key_cb(const Demuxer::NeedKeyCB& need_key_cb) {
124 need_key_cb_ = need_key_cb;
128 void OnError(PipelineStatus status);
129 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time);
131 // Creates Demuxer and sets |demuxer_|.
132 void CreateDemuxer(const base::FilePath& file_path);
134 // Creates and returns a Renderer.
135 scoped_ptr<Renderer> CreateRenderer(Decryptor* decryptor);
137 void SetDecryptor(Decryptor* decryptor,
138 const DecryptorReadyCB& decryptor_ready_cb);
139 void OnVideoRendererPaint(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));
151 #endif // MEDIA_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_