extensions: Remove dependency on libxml.
[chromium-blink-merge.git] / media / test / pipeline_integration_test_base.h
blobc65ea45401459a07d352cb851c9eec55486c7fc4
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_
8 #include "base/md5.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"
23 namespace base {
24 class FilePath;
27 namespace media {
29 class CdmContext;
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 {
40 public:
41 DummyTickClock() : now_() {}
42 ~DummyTickClock() override {}
43 base::TimeTicks NowTicks() override;
45 private:
46 base::TimeTicks now_;
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
57 // than real-time.
58 class PipelineIntegrationTestBase {
59 public:
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).
75 enum kTestType { kHashed, kClockless };
76 PipelineStatus Start(const std::string& filename, kTestType test_type);
78 void Play();
79 void Pause();
80 bool Seek(base::TimeDelta seek_time);
81 void Stop();
82 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta& wait_time);
84 // Returns the MD5 hash of all video frames seen. Should only be called once
85 // after playback completes. First time hashes should be generated with
86 // --video-threads=1 to ensure correctness. Pipeline must have been started
87 // with hashing enabled.
88 std::string GetVideoHash();
90 // Returns the hash of all audio frames seen. Should only be called once
91 // after playback completes. Pipeline must have been started with hashing
92 // enabled.
93 std::string GetAudioHash();
95 // Returns the time taken to render the complete audio file.
96 // Pipeline must have been started with clockless playback enabled.
97 base::TimeDelta GetAudioTime();
99 protected:
100 base::MessageLoop message_loop_;
101 base::MD5Context md5_context_;
102 bool hashing_enabled_;
103 bool clockless_playback_;
104 scoped_ptr<Demuxer> demuxer_;
105 scoped_ptr<DataSource> data_source_;
106 scoped_ptr<Pipeline> pipeline_;
107 scoped_refptr<NullAudioSink> audio_sink_;
108 scoped_refptr<ClocklessAudioSink> clockless_audio_sink_;
109 scoped_ptr<NullVideoSink> video_sink_;
110 bool ended_;
111 PipelineStatus pipeline_status_;
112 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_;
113 VideoPixelFormat last_video_frame_format_;
114 ColorSpace last_video_frame_color_space_;
115 DummyTickClock dummy_clock_;
116 AudioHardwareConfig hardware_config_;
117 PipelineMetadata metadata_;
119 void OnSeeked(base::TimeDelta seek_time, PipelineStatus status);
120 void OnStatusCallback(PipelineStatus status);
121 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type,
122 const std::vector<uint8>& init_data);
123 void set_encrypted_media_init_data_cb(
124 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) {
125 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb;
128 void OnEnded();
129 void OnError(PipelineStatus status);
130 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time);
132 // Creates Demuxer and sets |demuxer_|.
133 void CreateDemuxer(const std::string& filename);
135 // Creates and returns a Renderer.
136 virtual scoped_ptr<Renderer> CreateRenderer();
138 void OnVideoFramePaint(const scoped_refptr<VideoFrame>& frame);
140 MOCK_METHOD1(OnMetadata, void(PipelineMetadata));
141 MOCK_METHOD1(OnBufferingStateChanged, void(BufferingState));
142 MOCK_METHOD1(DecryptorAttached, void(bool));
143 MOCK_METHOD2(OnAddTextTrack,
144 void(const TextTrackConfig& config,
145 const AddTextTrackDoneCB& done_cb));
146 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
149 } // namespace media
151 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_