OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ | 5 #ifndef MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ |
6 #define MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ | 6 #define MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/md5.h" | 11 #include "base/md5.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/test/scoped_task_scheduler.h" | 13 #include "base/test/scoped_task_scheduler.h" |
14 #include "media/audio/clockless_audio_sink.h" | 14 #include "media/audio/clockless_audio_sink.h" |
15 #include "media/audio/null_audio_sink.h" | 15 #include "media/audio/null_audio_sink.h" |
16 #include "media/base/cdm_context.h" | |
17 #include "media/base/content_decryption_module.h" | |
16 #include "media/base/demuxer.h" | 18 #include "media/base/demuxer.h" |
17 #include "media/base/null_video_sink.h" | 19 #include "media/base/null_video_sink.h" |
18 #include "media/base/pipeline_impl.h" | 20 #include "media/base/pipeline_impl.h" |
19 #include "media/base/pipeline_status.h" | 21 #include "media/base/pipeline_status.h" |
20 #include "media/base/text_track.h" | 22 #include "media/base/text_track.h" |
21 #include "media/base/text_track_config.h" | 23 #include "media/base/text_track_config.h" |
22 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
25 #include "media/filters/chunk_demuxer.h" | |
23 #include "media/renderers/video_renderer_impl.h" | 26 #include "media/renderers/video_renderer_impl.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
25 | 28 |
26 namespace media { | 29 namespace media { |
27 | 30 |
28 class CdmContext; | 31 class AesDecryptor; |
29 | 32 |
30 // Empty MD5 hash string. Used to verify empty video tracks. | 33 // Empty MD5 hash string. Used to verify empty video tracks. |
31 extern const char kNullVideoHash[]; | 34 extern const char kNullVideoHash[]; |
32 | 35 |
33 // Empty hash string. Used to verify empty audio tracks. | 36 // Empty hash string. Used to verify empty audio tracks. |
34 extern const char kNullAudioHash[]; | 37 extern const char kNullAudioHash[]; |
35 | 38 |
39 // Indicates that the whole file should be appended. | |
40 extern const size_t kAppendWholeFile; | |
41 | |
36 // Dummy tick clock which advances extremely quickly (1 minute every time | 42 // Dummy tick clock which advances extremely quickly (1 minute every time |
37 // NowTicks() is called). | 43 // NowTicks() is called). |
38 class DummyTickClock : public base::TickClock { | 44 class DummyTickClock : public base::TickClock { |
39 public: | 45 public: |
40 DummyTickClock() : now_() {} | 46 DummyTickClock() : now_() {} |
41 ~DummyTickClock() override {} | 47 ~DummyTickClock() override {} |
42 base::TimeTicks NowTicks() override; | 48 base::TimeTicks NowTicks() override; |
43 | 49 |
44 private: | 50 private: |
45 base::TimeTicks now_; | 51 base::TimeTicks now_; |
46 }; | 52 }; |
47 | 53 |
54 class PipelineTestRendererFactory { | |
55 public: | |
56 virtual ~PipelineTestRendererFactory() {} | |
57 // Creates and returns a Renderer. | |
58 virtual std::unique_ptr<Renderer> CreateRenderer( | |
59 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), | |
60 CreateAudioDecodersCB prepend_audio_decoders_cb = | |
61 CreateAudioDecodersCB()) = 0; | |
62 }; | |
63 | |
64 // Helper class that emulates calls made on the ChunkDemuxer by the | |
DaleCurtis
2017/04/20 18:24:51
Should be extracted to a mock_media_source.{h,cc}
xjz
2017/04/20 21:26:10
Done.
| |
65 // Media Source API. | |
66 class MockMediaSource { | |
67 public: | |
68 MockMediaSource(const std::string& filename, | |
69 const std::string& mimetype, | |
70 size_t initial_append_size); | |
71 ~MockMediaSource(); | |
72 | |
73 std::unique_ptr<Demuxer> GetDemuxer(); | |
74 void set_encrypted_media_init_data_cb( | |
75 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb); | |
76 void set_demuxer_failure_cb(const PipelineStatusCB& demuxer_failure_cb); | |
77 void Seek(base::TimeDelta seek_time, | |
78 size_t new_position, | |
79 size_t seek_append_size); | |
80 void Seek(base::TimeDelta seek_time); | |
81 void AppendData(size_t size); | |
82 bool AppendAtTime(base::TimeDelta timestamp_offset, | |
83 const uint8_t* pData, | |
84 int size); | |
85 void AppendAtTimeWithWindow(base::TimeDelta timestamp_offset, | |
86 base::TimeDelta append_window_start, | |
87 base::TimeDelta append_window_end, | |
88 const uint8_t* pData, | |
89 int size); | |
90 void SetMemoryLimits(size_t limit_bytes); | |
91 void EvictCodedFrames(base::TimeDelta currentMediaTime, size_t newDataSize); | |
92 void RemoveRange(base::TimeDelta start, base::TimeDelta end); | |
93 void EndOfStream(); | |
94 void Shutdown(); | |
95 void DemuxerOpened(); | |
96 void DemuxerOpenedTask(); | |
97 ChunkDemuxer::Status AddId(); | |
98 void OnEncryptedMediaInitData(EmeInitDataType init_data_type, | |
99 const std::vector<uint8_t>& init_data); | |
100 base::TimeDelta last_timestamp_offset() const; | |
101 void InitSegmentReceived(std::unique_ptr<MediaTracks> tracks); | |
102 MOCK_METHOD1(InitSegmentReceivedMock, void(std::unique_ptr<MediaTracks>&)); | |
103 | |
104 private: | |
105 MediaLog media_log_; | |
106 scoped_refptr<DecoderBuffer> file_data_; | |
107 size_t current_position_; | |
108 size_t initial_append_size_; | |
109 std::string mimetype_; | |
110 ChunkDemuxer* chunk_demuxer_; | |
111 std::unique_ptr<Demuxer> owned_chunk_demuxer_; | |
112 PipelineStatusCB demuxer_failure_cb_; | |
113 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | |
114 base::TimeDelta last_timestamp_offset_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(MockMediaSource); | |
117 }; | |
118 | |
119 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. | |
DaleCurtis
2017/04/20 18:24:51
Ditto.
xjz
2017/04/20 21:26:10
Done.
| |
120 // They do not exercise the Decrypting{Audio|Video}Decoder path. | |
121 class FakeEncryptedMedia { | |
122 public: | |
123 // Defines the behavior of the "app" that responds to EME events. | |
124 class AppBase { | |
125 public: | |
126 virtual ~AppBase() {} | |
127 | |
128 virtual void OnSessionMessage( | |
129 const std::string& session_id, | |
130 ContentDecryptionModule::MessageType message_type, | |
131 const std::vector<uint8_t>& message, | |
132 AesDecryptor* decryptor) = 0; | |
133 | |
134 virtual void OnSessionClosed(const std::string& session_id) = 0; | |
135 | |
136 virtual void OnSessionKeysChange(const std::string& session_id, | |
137 bool has_additional_usable_key, | |
138 CdmKeysInfo keys_info) = 0; | |
139 | |
140 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type, | |
141 const std::vector<uint8_t>& init_data, | |
142 AesDecryptor* decryptor) = 0; | |
143 }; | |
144 | |
145 FakeEncryptedMedia(AppBase* app); | |
146 ~FakeEncryptedMedia(); | |
147 CdmContext* GetCdmContext(); | |
148 // Callbacks for firing session events. Delegate to |app_|. | |
149 void OnSessionMessage(const std::string& session_id, | |
150 ContentDecryptionModule::MessageType message_type, | |
151 const std::vector<uint8_t>& message); | |
152 void OnSessionClosed(const std::string& session_id); | |
153 void OnSessionKeysChange(const std::string& session_id, | |
154 bool has_additional_usable_key, | |
155 CdmKeysInfo keys_info); | |
156 void OnEncryptedMediaInitData(EmeInitDataType init_data_type, | |
157 const std::vector<uint8_t>& init_data); | |
158 | |
159 private: | |
160 class TestCdmContext : public CdmContext { | |
161 public: | |
162 TestCdmContext(Decryptor* decryptor); | |
163 Decryptor* GetDecryptor() final; | |
164 int GetCdmId() const final; | |
165 | |
166 private: | |
167 Decryptor* decryptor_; | |
168 }; | |
169 | |
170 scoped_refptr<AesDecryptor> decryptor_; | |
171 TestCdmContext cdm_context_; | |
172 std::unique_ptr<AppBase> app_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(FakeEncryptedMedia); | |
175 }; | |
176 | |
48 // Integration tests for Pipeline. Real demuxers, real decoders, and | 177 // Integration tests for Pipeline. Real demuxers, real decoders, and |
49 // base renderer implementations are used to verify pipeline functionality. The | 178 // base renderer implementations are used to verify pipeline functionality. The |
50 // renderers used in these tests rely heavily on the AudioRendererBase & | 179 // renderers used in these tests rely heavily on the AudioRendererBase & |
51 // VideoRendererImpl implementations which contain a majority of the code used | 180 // VideoRendererImpl implementations which contain a majority of the code used |
52 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in | 181 // in the real AudioRendererImpl & SkCanvasVideoRenderer implementations used in |
53 // the browser. The renderers in this test don't actually write data to a | 182 // 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 | 183 // 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 | 184 // little effect on verifying pipeline behavior and allow tests to run faster |
56 // than real-time. | 185 // than real-time. |
57 class PipelineIntegrationTestBase : public Pipeline::Client { | 186 class PipelineIntegrationTestBase : public Pipeline::Client { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 // Pipeline must have been started with clockless playback enabled. | 248 // Pipeline must have been started with clockless playback enabled. |
120 base::TimeDelta GetAudioTime(); | 249 base::TimeDelta GetAudioTime(); |
121 | 250 |
122 // Sets a callback to handle EME "encrypted" event. Must be called to test | 251 // Sets a callback to handle EME "encrypted" event. Must be called to test |
123 // potentially encrypted media. | 252 // potentially encrypted media. |
124 void set_encrypted_media_init_data_cb( | 253 void set_encrypted_media_init_data_cb( |
125 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) { | 254 const Demuxer::EncryptedMediaInitDataCB& encrypted_media_init_data_cb) { |
126 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; | 255 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; |
127 } | 256 } |
128 | 257 |
258 std::unique_ptr<Renderer> CreateRenderer( | |
259 CreateVideoDecodersCB prepend_video_decoders_cb, | |
260 CreateAudioDecodersCB prepend_audio_decoders_cb); | |
261 | |
129 protected: | 262 protected: |
130 MediaLog media_log_; | 263 MediaLog media_log_; |
131 base::MessageLoop message_loop_; | 264 base::MessageLoop message_loop_; |
132 base::MD5Context md5_context_; | 265 base::MD5Context md5_context_; |
133 bool hashing_enabled_; | 266 bool hashing_enabled_; |
134 bool clockless_playback_; | 267 bool clockless_playback_; |
135 | 268 |
136 // TaskScheduler is used only for FFmpegDemuxer. | 269 // TaskScheduler is used only for FFmpegDemuxer. |
137 std::unique_ptr<base::test::ScopedTaskScheduler> task_scheduler_; | 270 std::unique_ptr<base::test::ScopedTaskScheduler> task_scheduler_; |
138 std::unique_ptr<Demuxer> demuxer_; | 271 std::unique_ptr<Demuxer> demuxer_; |
139 std::unique_ptr<DataSource> data_source_; | 272 std::unique_ptr<DataSource> data_source_; |
140 std::unique_ptr<PipelineImpl> pipeline_; | 273 std::unique_ptr<PipelineImpl> pipeline_; |
141 scoped_refptr<NullAudioSink> audio_sink_; | 274 scoped_refptr<NullAudioSink> audio_sink_; |
142 scoped_refptr<ClocklessAudioSink> clockless_audio_sink_; | 275 scoped_refptr<ClocklessAudioSink> clockless_audio_sink_; |
143 std::unique_ptr<NullVideoSink> video_sink_; | 276 std::unique_ptr<NullVideoSink> video_sink_; |
144 bool ended_; | 277 bool ended_; |
145 PipelineStatus pipeline_status_; | 278 PipelineStatus pipeline_status_; |
146 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; | 279 Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb_; |
147 VideoPixelFormat last_video_frame_format_; | 280 VideoPixelFormat last_video_frame_format_; |
148 ColorSpace last_video_frame_color_space_; | 281 ColorSpace last_video_frame_color_space_; |
149 DummyTickClock dummy_clock_; | 282 DummyTickClock dummy_clock_; |
150 PipelineMetadata metadata_; | 283 PipelineMetadata metadata_; |
151 scoped_refptr<VideoFrame> last_frame_; | 284 scoped_refptr<VideoFrame> last_frame_; |
152 base::TimeDelta current_duration_; | 285 base::TimeDelta current_duration_; |
286 std::unique_ptr<PipelineTestRendererFactory> renderer_factory_; | |
153 | 287 |
154 PipelineStatus StartInternal( | 288 PipelineStatus StartInternal( |
155 std::unique_ptr<DataSource> data_source, | 289 std::unique_ptr<DataSource> data_source, |
156 CdmContext* cdm_context, | 290 CdmContext* cdm_context, |
157 uint8_t test_type, | 291 uint8_t test_type, |
158 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), | 292 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), |
159 CreateAudioDecodersCB prepend_audio_decoders_cb = | 293 CreateAudioDecodersCB prepend_audio_decoders_cb = |
160 CreateAudioDecodersCB()); | 294 CreateAudioDecodersCB()); |
161 | 295 |
162 PipelineStatus StartWithFile( | 296 PipelineStatus StartWithFile( |
163 const std::string& filename, | 297 const std::string& filename, |
164 CdmContext* cdm_context, | 298 CdmContext* cdm_context, |
165 uint8_t test_type, | 299 uint8_t test_type, |
166 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), | 300 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), |
167 CreateAudioDecodersCB prepend_audio_decoders_cb = | 301 CreateAudioDecodersCB prepend_audio_decoders_cb = |
168 CreateAudioDecodersCB()); | 302 CreateAudioDecodersCB()); |
169 | 303 |
304 PipelineStatus StartPipelineWithMediaSource(MockMediaSource* source); | |
305 PipelineStatus StartPipelineWithEncryptedMedia( | |
306 MockMediaSource* source, | |
307 FakeEncryptedMedia* encrypted_media); | |
308 PipelineStatus StartPipelineWithMediaSource( | |
309 MockMediaSource* source, | |
310 uint8_t test_type, | |
311 FakeEncryptedMedia* encrypted_media); | |
312 | |
170 void OnSeeked(base::TimeDelta seek_time, PipelineStatus status); | 313 void OnSeeked(base::TimeDelta seek_time, PipelineStatus status); |
171 void OnStatusCallback(PipelineStatus status); | 314 void OnStatusCallback(PipelineStatus status); |
172 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type, | 315 void DemuxerEncryptedMediaInitDataCB(EmeInitDataType type, |
173 const std::vector<uint8_t>& init_data); | 316 const std::vector<uint8_t>& init_data); |
174 | 317 |
175 void DemuxerMediaTracksUpdatedCB(std::unique_ptr<MediaTracks> tracks); | 318 void DemuxerMediaTracksUpdatedCB(std::unique_ptr<MediaTracks> tracks); |
176 | 319 |
177 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time); | 320 void QuitAfterCurrentTimeTask(const base::TimeDelta& quit_time); |
178 | 321 |
179 // Creates Demuxer and sets |demuxer_|. | 322 // Creates Demuxer and sets |demuxer_|. |
180 void CreateDemuxer(std::unique_ptr<DataSource> data_source); | 323 void CreateDemuxer(std::unique_ptr<DataSource> data_source); |
181 | 324 |
182 // Creates and returns a Renderer. | |
183 virtual std::unique_ptr<Renderer> CreateRenderer( | |
184 CreateVideoDecodersCB prepend_video_decoders_cb = CreateVideoDecodersCB(), | |
185 CreateAudioDecodersCB prepend_audio_decoders_cb = | |
186 CreateAudioDecodersCB()); | |
187 | |
188 void OnVideoFramePaint(const scoped_refptr<VideoFrame>& frame); | 325 void OnVideoFramePaint(const scoped_refptr<VideoFrame>& frame); |
189 | 326 |
190 void CheckDuration(); | 327 void CheckDuration(); |
191 | 328 |
192 // Return the media start time from |demuxer_|. | 329 // Return the media start time from |demuxer_|. |
193 base::TimeDelta GetStartTime(); | 330 base::TimeDelta GetStartTime(); |
194 | 331 |
332 bool TestSeekDuringRead(const std::string& filename, | |
DaleCurtis
2017/04/20 18:24:51
This should be on the normal PIT since you can dro
xjz
2017/04/20 21:26:10
Done.
| |
333 const std::string& mimetype, | |
334 int initial_append_size, | |
335 base::TimeDelta start_seek_time, | |
336 base::TimeDelta seek_time, | |
337 int seek_file_position, | |
338 int seek_append_size); | |
339 | |
195 MOCK_METHOD1(DecryptorAttached, void(bool)); | 340 MOCK_METHOD1(DecryptorAttached, void(bool)); |
196 // Pipeline::Client overrides. | 341 // Pipeline::Client overrides. |
197 void OnError(PipelineStatus status) override; | 342 void OnError(PipelineStatus status) override; |
198 void OnEnded() override; | 343 void OnEnded() override; |
199 MOCK_METHOD1(OnMetadata, void(PipelineMetadata)); | 344 MOCK_METHOD1(OnMetadata, void(PipelineMetadata)); |
200 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | 345 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
201 MOCK_METHOD0(OnDurationChange, void()); | 346 MOCK_METHOD0(OnDurationChange, void()); |
202 MOCK_METHOD2(OnAddTextTrack, | 347 MOCK_METHOD2(OnAddTextTrack, |
203 void(const TextTrackConfig& config, | 348 void(const TextTrackConfig& config, |
204 const AddTextTrackDoneCB& done_cb)); | 349 const AddTextTrackDoneCB& done_cb)); |
205 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); | 350 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void)); |
206 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); | 351 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); |
207 MOCK_METHOD1(OnVideoOpacityChange, void(bool)); | 352 MOCK_METHOD1(OnVideoOpacityChange, void(bool)); |
208 MOCK_METHOD0(OnVideoAverageKeyframeDistanceUpdate, void()); | 353 MOCK_METHOD0(OnVideoAverageKeyframeDistanceUpdate, void()); |
354 | |
355 private: | |
356 DISALLOW_COPY_AND_ASSIGN(PipelineIntegrationTestBase); | |
209 }; | 357 }; |
210 | 358 |
211 } // namespace media | 359 } // namespace media |
212 | 360 |
213 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ | 361 #endif // MEDIA_TEST_PIPELINE_INTEGRATION_TEST_BASE_H_ |
OLD | NEW |