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/demuxer.h"
13 #include "media/base/filter_collection.h"
14 #include "media/base/media_keys.h"
15 #include "media/base/pipeline.h"
16 #include "media/base/video_frame.h"
17 #include "media/filters/video_renderer_base.h"
18 #include "testing/gmock/include/gmock/gmock.h"
28 // Empty MD5 hash string. Used to verify empty video tracks.
29 extern const char kNullVideoHash[];
31 // Empty hash string. Used to verify empty audio tracks.
32 extern const char kNullAudioHash[];
34 // Integration tests for Pipeline. Real demuxers, real decoders, and
35 // base renderer implementations are used to verify pipeline functionality. The
36 // renderers used in these tests rely heavily on the AudioRendererBase &
37 // VideoRendererBase implementations which contain a majority of the code used
38 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in
39 // the browser. The renderers in this test don't actually write data to a
40 // display or audio device. Both of these devices are simulated since they have
41 // little effect on verifying pipeline behavior and allow tests to run faster
43 class PipelineIntegrationTestBase {
45 PipelineIntegrationTestBase();
46 virtual ~PipelineIntegrationTestBase();
48 bool WaitUntilOnEnded();
49 PipelineStatus WaitUntilEndedOrError();
50 bool Start(const base::FilePath& file_path, PipelineStatus expected_status);
51 // Enable playback with audio and video hashing enabled, or clockless
52 // playback (audio only). Frame dropping and audio underflow will be disabled
53 // if hashing enabled to ensure consistent hashes.
54 enum kTestType { kHashed, kClockless };
55 bool Start(const base::FilePath& file_path,
56 PipelineStatus expected_status,
58 // Initialize the pipeline and ignore any status updates. Useful for testing
59 // invalid audio/video clips which don't have deterministic results.
60 bool Start(const base::FilePath& file_path);
61 bool Start(const base::FilePath& file_path, Decryptor* decryptor);
65 bool Seek(base::TimeDelta seek_time);
67 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta& wait_time);
68 scoped_ptr<FilterCollection> CreateFilterCollection(
69 const base::FilePath& file_path, Decryptor* decryptor);
71 // Returns the MD5 hash of all video frames seen. Should only be called once
72 // after playback completes. First time hashes should be generated with
73 // --video-threads=1 to ensure correctness. Pipeline must have been started
74 // with hashing enabled.
75 std::string GetVideoHash();
77 // Returns the hash of all audio frames seen. Should only be called once
78 // after playback completes. Pipeline must have been started with hashing
80 std::string GetAudioHash();
82 // Returns the time taken to render the complete audio file.
83 // Pipeline must have been started with clockless playback enabled.
84 base::TimeDelta GetAudioTime();
87 base::MessageLoop message_loop_;
88 base::MD5Context md5_context_;
89 bool hashing_enabled_;
90 bool clockless_playback_;
91 scoped_ptr<Demuxer> demuxer_;
92 scoped_ptr<DataSource> data_source_;
93 scoped_ptr<Pipeline> pipeline_;
94 scoped_refptr<NullAudioSink> audio_sink_;
95 scoped_refptr<ClocklessAudioSink> clockless_audio_sink_;
97 PipelineStatus pipeline_status_;
98 Demuxer::NeedKeyCB need_key_cb_;
99 VideoFrame::Format last_video_frame_format_;
101 void OnStatusCallbackChecked(PipelineStatus expected_status,
102 PipelineStatus status);
103 void OnStatusCallback(PipelineStatus status);
104 PipelineStatusCB QuitOnStatusCB(PipelineStatus expected_status);
105 void DemuxerNeedKeyCB(const std::string& type,
106 const std::vector<uint8>& init_data);
107 void set_need_key_cb(const Demuxer::NeedKeyCB& need_key_cb) {
108 need_key_cb_ = need_key_cb;
112 void OnError(PipelineStatus status);
113 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time);
114 scoped_ptr<FilterCollection> CreateFilterCollection(
115 scoped_ptr<Demuxer> demuxer, Decryptor* decryptor);
117 void SetDecryptor(Decryptor* decryptor,
118 const DecryptorReadyCB& decryptor_ready_cb);
119 void OnVideoRendererPaint(const scoped_refptr<VideoFrame>& frame);
121 MOCK_METHOD1(OnSetOpaque, void(bool));
122 MOCK_METHOD1(OnBufferingState, void(Pipeline::BufferingState));
127 #endif // MEDIA_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_