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. 4 5 #ifndef MEDIA_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_ 6 #define MEDIA_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_ 7 8 #include "base/md5.h" 9 #include "base/message_loop/message_loop.h" 10 #include "media/audio/null_audio_sink.h" 11 #include "media/base/filter_collection.h" 12 #include "media/base/media_keys.h" 13 #include "media/base/pipeline.h" 14 #include "media/base/video_frame.h" 15 #include "media/filters/video_renderer_base.h" 16 #include "testing/gmock/include/gmock/gmock.h" 17 18 namespace base { 19 class FilePath; 20 } 21 22 namespace media { 23 24 class Decryptor; 25 class Demuxer; 26 27 // Empty MD5 hash string. Used to verify empty video tracks. 28 extern const char kNullVideoHash[]; 29 30 // Empty hash string. Used to verify empty audio tracks. 31 extern const char kNullAudioHash[]; 32 33 // Integration tests for Pipeline. Real demuxers, real decoders, and 34 // base renderer implementations are used to verify pipeline functionality. The 35 // renderers used in these tests rely heavily on the AudioRendererBase & 36 // VideoRendererBase implementations which contain a majority of the code used 37 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in 38 // the browser. The renderers in this test don't actually write data to a 39 // display or audio device. Both of these devices are simulated since they have 40 // little effect on verifying pipeline behavior and allow tests to run faster 41 // than real-time. 42 class PipelineIntegrationTestBase { 43 public: 44 PipelineIntegrationTestBase(); 45 virtual ~PipelineIntegrationTestBase(); 46 47 bool WaitUntilOnEnded(); 48 PipelineStatus WaitUntilEndedOrError(); 49 bool Start(const base::FilePath& file_path, PipelineStatus expected_status); 50 // Enable playback with audio and video hashing enabled. Frame dropping and 51 // audio underflow will be disabled to ensure consistent hashes. 52 bool Start(const base::FilePath& file_path, PipelineStatus expected_status, 53 bool hashing_enabled); 54 // Initialize the pipeline and ignore any status updates. Useful for testing 55 // invalid audio/video clips which don't have deterministic results. 56 bool Start(const base::FilePath& file_path); 57 bool Start(const base::FilePath& file_path, Decryptor* decryptor); 58 59 void Play(); 60 void Pause(); 61 bool Seek(base::TimeDelta seek_time); 62 void Stop(); 63 bool WaitUntilCurrentTimeIsAfter(const base::TimeDelta& wait_time); 64 scoped_ptr<FilterCollection> CreateFilterCollection( 65 const base::FilePath& file_path, Decryptor* decryptor); 66 67 // Returns the MD5 hash of all video frames seen. Should only be called once 68 // after playback completes. First time hashes should be generated with 69 // --video-threads=1 to ensure correctness. Pipeline must have been started 70 // with hashing enabled. 71 std::string GetVideoHash(); 72 73 // Returns the hash of all audio frames seen. Should only be called once 74 // after playback completes. Pipeline must have been started with hashing 75 // enabled. 76 std::string GetAudioHash(); 77 78 protected: 79 base::MessageLoop message_loop_; 80 base::MD5Context md5_context_; 81 bool hashing_enabled_; 82 scoped_ptr<Demuxer> demuxer_; 83 scoped_ptr<DataSource> data_source_; 84 scoped_ptr<Pipeline> pipeline_; 85 scoped_refptr<NullAudioSink> audio_sink_; 86 bool ended_; 87 PipelineStatus pipeline_status_; 88 NeedKeyCB need_key_cb_; 89 VideoFrame::Format last_video_frame_format_; 90 91 void OnStatusCallbackChecked(PipelineStatus expected_status, 92 PipelineStatus status); 93 void OnStatusCallback(PipelineStatus status); 94 PipelineStatusCB QuitOnStatusCB(PipelineStatus expected_status); 95 void DemuxerNeedKeyCB(const std::string& type, 96 scoped_ptr<uint8[]> init_data, int init_data_size); 97 void set_need_key_cb(const NeedKeyCB& need_key_cb) { 98 need_key_cb_ = need_key_cb; 99 } 100 101 void OnEnded(); 102 void OnError(PipelineStatus status); 103 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time); 104 scoped_ptr<FilterCollection> CreateFilterCollection( 105 scoped_ptr<Demuxer> demuxer, Decryptor* decryptor); 106 void SetDecryptor(Decryptor* decryptor, 107 const DecryptorReadyCB& decryptor_ready_cb); 108 void OnVideoRendererPaint(const scoped_refptr<VideoFrame>& frame); 109 110 MOCK_METHOD1(OnSetOpaque, void(bool)); 111 MOCK_METHOD1(OnBufferingState, void(Pipeline::BufferingState)); 112 }; 113 114 } // namespace media 115 116 #endif // MEDIA_FILTERS_PIPELINE_INTEGRATION_TEST_BASE_H_ 117