OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 using ::testing::InSequence; | 23 using ::testing::InSequence; |
24 using ::testing::Mock; | 24 using ::testing::Mock; |
25 using ::testing::Return; | 25 using ::testing::Return; |
26 using ::testing::SaveArg; | 26 using ::testing::SaveArg; |
27 using ::testing::StrictMock; | 27 using ::testing::StrictMock; |
28 | 28 |
29 namespace media { | 29 namespace media { |
30 | 30 |
31 const int64_t kStartPlayingTimeInMs = 100; | 31 const int64_t kStartPlayingTimeInMs = 100; |
32 | 32 |
33 ACTION_P2(SetBufferingState, cb, buffering_state) { | 33 ACTION_P2(SetBufferingState, renderer_client, buffering_state) { |
34 cb->Run(buffering_state); | 34 (*renderer_client)->OnBufferingStateChange(buffering_state); |
35 } | 35 } |
36 | 36 |
37 ACTION_P2(AudioError, cb, error) { | 37 ACTION_P2(SetError, renderer_client, error) { |
38 cb->Run(error); | 38 (*renderer_client)->OnError(error); |
39 } | 39 } |
40 | 40 |
41 class RendererImplTest : public ::testing::Test { | 41 class RendererImplTest : public ::testing::Test { |
42 public: | 42 public: |
43 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 43 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
44 // also lets us test for missing callbacks. | 44 // also lets us test for missing callbacks. |
45 class CallbackHelper { | 45 class CallbackHelper : public MockRendererClient { |
46 public: | 46 public: |
47 CallbackHelper() {} | 47 CallbackHelper() {} |
48 virtual ~CallbackHelper() {} | 48 virtual ~CallbackHelper() {} |
49 | 49 |
| 50 // Completion callbacks. |
50 MOCK_METHOD1(OnInitialize, void(PipelineStatus)); | 51 MOCK_METHOD1(OnInitialize, void(PipelineStatus)); |
51 MOCK_METHOD0(OnFlushed, void()); | 52 MOCK_METHOD0(OnFlushed, void()); |
52 MOCK_METHOD0(OnEnded, void()); | |
53 MOCK_METHOD1(OnError, void(PipelineStatus)); | |
54 MOCK_METHOD1(OnUpdateStatistics, void(const PipelineStatistics&)); | |
55 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | |
56 MOCK_METHOD0(OnWaitingForDecryptionKey, void()); | |
57 MOCK_METHOD1(OnCdmAttached, void(bool)); | 53 MOCK_METHOD1(OnCdmAttached, void(bool)); |
58 | 54 |
59 private: | 55 private: |
60 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 56 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
61 }; | 57 }; |
62 | 58 |
63 RendererImplTest() | 59 RendererImplTest() |
64 : demuxer_(new StrictMock<MockDemuxer>()), | 60 : demuxer_(new StrictMock<MockDemuxer>()), |
65 video_renderer_(new StrictMock<MockVideoRenderer>()), | 61 video_renderer_(new StrictMock<MockVideoRenderer>()), |
66 audio_renderer_(new StrictMock<MockAudioRenderer>()), | 62 audio_renderer_(new StrictMock<MockAudioRenderer>()), |
67 renderer_impl_( | 63 renderer_impl_( |
68 new RendererImpl(message_loop_.task_runner(), | 64 new RendererImpl(message_loop_.task_runner(), |
69 std::unique_ptr<AudioRenderer>(audio_renderer_), | 65 std::unique_ptr<AudioRenderer>(audio_renderer_), |
70 std::unique_ptr<VideoRenderer>(video_renderer_))), | 66 std::unique_ptr<VideoRenderer>(video_renderer_))), |
71 cdm_context_(new StrictMock<MockCdmContext>()), | 67 cdm_context_(new StrictMock<MockCdmContext>()), |
| 68 video_renderer_client_(nullptr), |
| 69 audio_renderer_client_(nullptr), |
72 initialization_status_(PIPELINE_OK) { | 70 initialization_status_(PIPELINE_OK) { |
73 // SetDemuxerExpectations() adds overriding expectations for expected | 71 // SetDemuxerExpectations() adds overriding expectations for expected |
74 // non-NULL streams. | 72 // non-NULL streams. |
75 DemuxerStream* null_pointer = NULL; | 73 DemuxerStream* null_pointer = NULL; |
76 EXPECT_CALL(*demuxer_, GetStream(_)) | 74 EXPECT_CALL(*demuxer_, GetStream(_)) |
77 .WillRepeatedly(Return(null_pointer)); | 75 .WillRepeatedly(Return(null_pointer)); |
78 } | 76 } |
79 | 77 |
80 virtual ~RendererImplTest() { Destroy(); } | 78 virtual ~RendererImplTest() { Destroy(); } |
81 | 79 |
82 protected: | 80 protected: |
83 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 81 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
84 | 82 |
85 void Destroy() { | 83 void Destroy() { |
86 renderer_impl_.reset(); | 84 renderer_impl_.reset(); |
87 base::RunLoop().RunUntilIdle(); | 85 base::RunLoop().RunUntilIdle(); |
88 } | 86 } |
89 | 87 |
90 std::unique_ptr<StrictMock<MockDemuxerStream>> CreateStream( | 88 std::unique_ptr<StrictMock<MockDemuxerStream>> CreateStream( |
91 DemuxerStream::Type type) { | 89 DemuxerStream::Type type) { |
92 std::unique_ptr<StrictMock<MockDemuxerStream>> stream( | 90 std::unique_ptr<StrictMock<MockDemuxerStream>> stream( |
93 new StrictMock<MockDemuxerStream>(type)); | 91 new StrictMock<MockDemuxerStream>(type)); |
94 return stream; | 92 return stream; |
95 } | 93 } |
96 | 94 |
97 // Sets up expectations to allow the audio renderer to initialize. | 95 // Sets up expectations to allow the audio renderer to initialize. |
98 void SetAudioRendererInitializeExpectations(PipelineStatus status) { | 96 void SetAudioRendererInitializeExpectations(PipelineStatus status) { |
99 EXPECT_CALL(*audio_renderer_, | 97 EXPECT_CALL(*audio_renderer_, Initialize(audio_stream_.get(), _, _, _)) |
100 Initialize(audio_stream_.get(), _, _, _, _, _, _, _)) | 98 .WillOnce( |
101 .WillOnce(DoAll(SaveArg<4>(&audio_buffering_state_cb_), | 99 DoAll(SaveArg<2>(&audio_renderer_client_), RunCallback<3>(status))); |
102 SaveArg<5>(&audio_ended_cb_), | |
103 SaveArg<6>(&audio_error_cb_), RunCallback<1>(status))); | |
104 } | 100 } |
105 | 101 |
106 // Sets up expectations to allow the video renderer to initialize. | 102 // Sets up expectations to allow the video renderer to initialize. |
107 void SetVideoRendererInitializeExpectations(PipelineStatus status) { | 103 void SetVideoRendererInitializeExpectations(PipelineStatus status) { |
108 EXPECT_CALL(*video_renderer_, | 104 EXPECT_CALL(*video_renderer_, Initialize(video_stream_.get(), _, _, _, _)) |
109 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)) | 105 .WillOnce( |
110 .WillOnce(DoAll(SaveArg<4>(&video_buffering_state_cb_), | 106 DoAll(SaveArg<2>(&video_renderer_client_), RunCallback<4>(status))); |
111 SaveArg<5>(&video_ended_cb_), RunCallback<1>(status))); | |
112 } | 107 } |
113 | 108 |
114 void InitializeAndExpect(PipelineStatus start_status) { | 109 void InitializeAndExpect(PipelineStatus start_status) { |
115 EXPECT_CALL(callbacks_, OnInitialize(start_status)) | 110 EXPECT_CALL(callbacks_, OnInitialize(start_status)) |
116 .WillOnce(SaveArg<0>(&initialization_status_)); | 111 .WillOnce(SaveArg<0>(&initialization_status_)); |
117 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0); | 112 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0); |
118 | 113 |
119 if (start_status == PIPELINE_OK && audio_stream_) { | 114 if (start_status == PIPELINE_OK && audio_stream_) { |
120 EXPECT_CALL(*audio_renderer_, GetTimeSource()) | 115 EXPECT_CALL(*audio_renderer_, GetTimeSource()) |
121 .WillOnce(Return(&time_source_)); | 116 .WillOnce(Return(&time_source_)); |
122 } else { | 117 } else { |
123 renderer_impl_->set_time_source_for_testing(&time_source_); | 118 renderer_impl_->set_time_source_for_testing(&time_source_); |
124 } | 119 } |
125 | 120 |
126 renderer_impl_->Initialize( | 121 renderer_impl_->Initialize(demuxer_.get(), &callbacks_, |
127 demuxer_.get(), | 122 base::Bind(&CallbackHelper::OnInitialize, |
128 base::Bind(&CallbackHelper::OnInitialize, | 123 base::Unretained(&callbacks_))); |
129 base::Unretained(&callbacks_)), | |
130 base::Bind(&CallbackHelper::OnUpdateStatistics, | |
131 base::Unretained(&callbacks_)), | |
132 base::Bind(&CallbackHelper::OnBufferingStateChange, | |
133 base::Unretained(&callbacks_)), | |
134 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | |
135 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | |
136 base::Bind(&CallbackHelper::OnWaitingForDecryptionKey, | |
137 base::Unretained(&callbacks_))); | |
138 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
139 } | 125 } |
140 | 126 |
141 void CreateAudioStream() { | 127 void CreateAudioStream() { |
142 audio_stream_ = CreateStream(DemuxerStream::AUDIO); | 128 audio_stream_ = CreateStream(DemuxerStream::AUDIO); |
143 streams_.push_back(audio_stream_.get()); | 129 streams_.push_back(audio_stream_.get()); |
144 EXPECT_CALL(*demuxer_, GetStream(DemuxerStream::AUDIO)) | 130 EXPECT_CALL(*demuxer_, GetStream(DemuxerStream::AUDIO)) |
145 .WillRepeatedly(Return(audio_stream_.get())); | 131 .WillRepeatedly(Return(audio_stream_.get())); |
146 } | 132 } |
147 | 133 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 DCHECK(audio_stream_ || video_stream_); | 171 DCHECK(audio_stream_ || video_stream_); |
186 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 172 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
187 | 173 |
188 base::TimeDelta start_time( | 174 base::TimeDelta start_time( |
189 base::TimeDelta::FromMilliseconds(kStartPlayingTimeInMs)); | 175 base::TimeDelta::FromMilliseconds(kStartPlayingTimeInMs)); |
190 EXPECT_CALL(time_source_, SetMediaTime(start_time)); | 176 EXPECT_CALL(time_source_, SetMediaTime(start_time)); |
191 EXPECT_CALL(time_source_, StartTicking()); | 177 EXPECT_CALL(time_source_, StartTicking()); |
192 | 178 |
193 if (audio_stream_) { | 179 if (audio_stream_) { |
194 EXPECT_CALL(*audio_renderer_, StartPlaying()) | 180 EXPECT_CALL(*audio_renderer_, StartPlaying()) |
195 .WillOnce(SetBufferingState(&audio_buffering_state_cb_, | 181 .WillOnce(SetBufferingState(&audio_renderer_client_, |
196 BUFFERING_HAVE_ENOUGH)); | 182 BUFFERING_HAVE_ENOUGH)); |
197 } | 183 } |
198 | 184 |
199 if (video_stream_) { | 185 if (video_stream_) { |
200 EXPECT_CALL(*video_renderer_, StartPlayingFrom(start_time)) | 186 EXPECT_CALL(*video_renderer_, StartPlayingFrom(start_time)) |
201 .WillOnce(SetBufferingState(&video_buffering_state_cb_, | 187 .WillOnce(SetBufferingState(&video_renderer_client_, |
202 BUFFERING_HAVE_ENOUGH)); | 188 BUFFERING_HAVE_ENOUGH)); |
203 } | 189 } |
204 | 190 |
205 renderer_impl_->StartPlayingFrom(start_time); | 191 renderer_impl_->StartPlayingFrom(start_time); |
206 base::RunLoop().RunUntilIdle(); | 192 base::RunLoop().RunUntilIdle(); |
207 } | 193 } |
208 | 194 |
209 void Flush(bool underflowed) { | 195 void Flush(bool underflowed) { |
210 if (!underflowed) | 196 if (!underflowed) |
211 EXPECT_CALL(time_source_, StopTicking()); | 197 EXPECT_CALL(time_source_, StopTicking()); |
212 | 198 |
213 if (audio_stream_) { | 199 if (audio_stream_) { |
214 EXPECT_CALL(*audio_renderer_, Flush(_)) | 200 EXPECT_CALL(*audio_renderer_, Flush(_)) |
215 .WillOnce(DoAll(SetBufferingState(&audio_buffering_state_cb_, | 201 .WillOnce(DoAll(SetBufferingState(&audio_renderer_client_, |
216 BUFFERING_HAVE_NOTHING), | 202 BUFFERING_HAVE_NOTHING), |
217 RunClosure<0>())); | 203 RunClosure<0>())); |
218 } | 204 } |
219 | 205 |
220 if (video_stream_) { | 206 if (video_stream_) { |
221 EXPECT_CALL(*video_renderer_, Flush(_)) | 207 EXPECT_CALL(*video_renderer_, Flush(_)) |
222 .WillOnce(DoAll(SetBufferingState(&video_buffering_state_cb_, | 208 .WillOnce(DoAll(SetBufferingState(&video_renderer_client_, |
223 BUFFERING_HAVE_NOTHING), | 209 BUFFERING_HAVE_NOTHING), |
224 RunClosure<0>())); | 210 RunClosure<0>())); |
225 } | 211 } |
226 | 212 |
227 EXPECT_CALL(callbacks_, OnFlushed()); | 213 EXPECT_CALL(callbacks_, OnFlushed()); |
228 | 214 |
229 renderer_impl_->Flush( | 215 renderer_impl_->Flush( |
230 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | 216 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); |
231 base::RunLoop().RunUntilIdle(); | 217 base::RunLoop().RunUntilIdle(); |
232 } | 218 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 std::unique_ptr<StrictMock<MockDemuxer>> demuxer_; | 261 std::unique_ptr<StrictMock<MockDemuxer>> demuxer_; |
276 StrictMock<MockVideoRenderer>* video_renderer_; | 262 StrictMock<MockVideoRenderer>* video_renderer_; |
277 StrictMock<MockAudioRenderer>* audio_renderer_; | 263 StrictMock<MockAudioRenderer>* audio_renderer_; |
278 std::unique_ptr<RendererImpl> renderer_impl_; | 264 std::unique_ptr<RendererImpl> renderer_impl_; |
279 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; | 265 std::unique_ptr<StrictMock<MockCdmContext>> cdm_context_; |
280 | 266 |
281 StrictMock<MockTimeSource> time_source_; | 267 StrictMock<MockTimeSource> time_source_; |
282 std::unique_ptr<StrictMock<MockDemuxerStream>> audio_stream_; | 268 std::unique_ptr<StrictMock<MockDemuxerStream>> audio_stream_; |
283 std::unique_ptr<StrictMock<MockDemuxerStream>> video_stream_; | 269 std::unique_ptr<StrictMock<MockDemuxerStream>> video_stream_; |
284 MockDemuxerStreamVector streams_; | 270 MockDemuxerStreamVector streams_; |
285 BufferingStateCB audio_buffering_state_cb_; | 271 RendererClient* video_renderer_client_; |
286 BufferingStateCB video_buffering_state_cb_; | 272 RendererClient* audio_renderer_client_; |
287 base::Closure audio_ended_cb_; | |
288 base::Closure video_ended_cb_; | |
289 PipelineStatusCB audio_error_cb_; | |
290 VideoDecoderConfig video_decoder_config_; | 273 VideoDecoderConfig video_decoder_config_; |
291 PipelineStatus initialization_status_; | 274 PipelineStatus initialization_status_; |
292 | 275 |
293 private: | 276 private: |
294 DISALLOW_COPY_AND_ASSIGN(RendererImplTest); | 277 DISALLOW_COPY_AND_ASSIGN(RendererImplTest); |
295 }; | 278 }; |
296 | 279 |
297 TEST_F(RendererImplTest, Destroy_BeforeInitialize) { | 280 TEST_F(RendererImplTest, Destroy_BeforeInitialize) { |
298 Destroy(); | 281 Destroy(); |
299 } | 282 } |
300 | 283 |
301 TEST_F(RendererImplTest, Destroy_PendingInitialize) { | 284 TEST_F(RendererImplTest, Destroy_PendingInitialize) { |
302 CreateAudioAndVideoStream(); | 285 CreateAudioAndVideoStream(); |
303 | 286 |
304 SetAudioRendererInitializeExpectations(PIPELINE_OK); | 287 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
305 // Not returning the video initialization callback. | 288 // Not returning the video initialization callback. |
306 EXPECT_CALL(*video_renderer_, | 289 EXPECT_CALL(*video_renderer_, Initialize(video_stream_.get(), _, _, _, _)); |
307 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)); | |
308 | 290 |
309 InitializeAndExpect(PIPELINE_ERROR_ABORT); | 291 InitializeAndExpect(PIPELINE_ERROR_ABORT); |
310 EXPECT_EQ(PIPELINE_OK, initialization_status_); | 292 EXPECT_EQ(PIPELINE_OK, initialization_status_); |
311 | 293 |
312 Destroy(); | 294 Destroy(); |
313 } | 295 } |
314 | 296 |
315 TEST_F(RendererImplTest, Destroy_PendingInitializeWithoutCdm) { | 297 TEST_F(RendererImplTest, Destroy_PendingInitializeWithoutCdm) { |
316 CreateAudioStream(); | 298 CreateAudioStream(); |
317 CreateEncryptedVideoStream(); | 299 CreateEncryptedVideoStream(); |
(...skipping 13 matching lines...) Expand all Loading... |
331 CreateEncryptedVideoStream(); | 313 CreateEncryptedVideoStream(); |
332 | 314 |
333 // Audio is clear and video is encrypted. Initialization will not start | 315 // Audio is clear and video is encrypted. Initialization will not start |
334 // because no CDM is set. | 316 // because no CDM is set. |
335 InitializeAndExpect(PIPELINE_ERROR_ABORT); | 317 InitializeAndExpect(PIPELINE_ERROR_ABORT); |
336 EXPECT_EQ(PIPELINE_OK, initialization_status_); | 318 EXPECT_EQ(PIPELINE_OK, initialization_status_); |
337 | 319 |
338 SetAudioRendererInitializeExpectations(PIPELINE_OK); | 320 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
339 // Not returning the video initialization callback. So initialization will | 321 // Not returning the video initialization callback. So initialization will |
340 // be pending. | 322 // be pending. |
341 EXPECT_CALL(*video_renderer_, | 323 EXPECT_CALL(*video_renderer_, Initialize(video_stream_.get(), _, _, _, _)); |
342 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)); | |
343 | 324 |
344 // SetCdm() will trigger the initialization to start. But it will not complete | 325 // SetCdm() will trigger the initialization to start. But it will not complete |
345 // because the |video_renderer_| is not returning the initialization callback. | 326 // because the |video_renderer_| is not returning the initialization callback. |
346 SetCdmAndExpect(false); | 327 SetCdmAndExpect(false); |
347 EXPECT_EQ(PIPELINE_OK, initialization_status_); | 328 EXPECT_EQ(PIPELINE_OK, initialization_status_); |
348 | 329 |
349 Destroy(); | 330 Destroy(); |
350 } | 331 } |
351 | 332 |
352 TEST_F(RendererImplTest, InitializeWithAudio) { | 333 TEST_F(RendererImplTest, InitializeWithAudio) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 Play(); | 466 Play(); |
486 Flush(false); | 467 Flush(false); |
487 } | 468 } |
488 | 469 |
489 TEST_F(RendererImplTest, FlushAfterUnderflow) { | 470 TEST_F(RendererImplTest, FlushAfterUnderflow) { |
490 InitializeWithAudioAndVideo(); | 471 InitializeWithAudioAndVideo(); |
491 Play(); | 472 Play(); |
492 | 473 |
493 // Simulate underflow. | 474 // Simulate underflow. |
494 EXPECT_CALL(time_source_, StopTicking()); | 475 EXPECT_CALL(time_source_, StopTicking()); |
495 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 476 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
496 | 477 |
497 // Flush while underflowed. We shouldn't call StopTicking() again. | 478 // Flush while underflowed. We shouldn't call StopTicking() again. |
498 Flush(true); | 479 Flush(true); |
499 } | 480 } |
500 | 481 |
501 TEST_F(RendererImplTest, SetPlaybackRate) { | 482 TEST_F(RendererImplTest, SetPlaybackRate) { |
502 InitializeWithAudioAndVideo(); | 483 InitializeWithAudioAndVideo(); |
503 SetPlaybackRate(1.0); | 484 SetPlaybackRate(1.0); |
504 SetPlaybackRate(2.0); | 485 SetPlaybackRate(2.0); |
505 } | 486 } |
506 | 487 |
507 TEST_F(RendererImplTest, SetVolume) { | 488 TEST_F(RendererImplTest, SetVolume) { |
508 InitializeWithAudioAndVideo(); | 489 InitializeWithAudioAndVideo(); |
509 EXPECT_CALL(*audio_renderer_, SetVolume(2.0f)); | 490 EXPECT_CALL(*audio_renderer_, SetVolume(2.0f)); |
510 renderer_impl_->SetVolume(2.0f); | 491 renderer_impl_->SetVolume(2.0f); |
511 } | 492 } |
512 | 493 |
513 TEST_F(RendererImplTest, AudioStreamEnded) { | 494 TEST_F(RendererImplTest, AudioStreamEnded) { |
514 InitializeWithAudio(); | 495 InitializeWithAudio(); |
515 Play(); | 496 Play(); |
516 | 497 |
517 EXPECT_CALL(time_source_, StopTicking()); | 498 EXPECT_CALL(time_source_, StopTicking()); |
518 EXPECT_CALL(callbacks_, OnEnded()); | 499 EXPECT_CALL(callbacks_, OnEnded()); |
519 | 500 |
520 audio_ended_cb_.Run(); | 501 audio_renderer_client_->OnEnded(); |
521 base::RunLoop().RunUntilIdle(); | 502 base::RunLoop().RunUntilIdle(); |
522 } | 503 } |
523 | 504 |
524 TEST_F(RendererImplTest, VideoStreamEnded) { | 505 TEST_F(RendererImplTest, VideoStreamEnded) { |
525 InitializeWithVideo(); | 506 InitializeWithVideo(); |
526 Play(); | 507 Play(); |
527 | 508 |
528 EXPECT_CALL(time_source_, StopTicking()); | 509 EXPECT_CALL(time_source_, StopTicking()); |
529 EXPECT_CALL(callbacks_, OnEnded()); | 510 EXPECT_CALL(callbacks_, OnEnded()); |
530 | 511 |
531 video_ended_cb_.Run(); | 512 video_renderer_client_->OnEnded(); |
532 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
533 } | 514 } |
534 | 515 |
535 TEST_F(RendererImplTest, AudioVideoStreamsEnded) { | 516 TEST_F(RendererImplTest, AudioVideoStreamsEnded) { |
536 InitializeWithAudioAndVideo(); | 517 InitializeWithAudioAndVideo(); |
537 Play(); | 518 Play(); |
538 | 519 |
539 // OnEnded() is called only when all streams have finished. | 520 // OnEnded() is called only when all streams have finished. |
540 audio_ended_cb_.Run(); | 521 audio_renderer_client_->OnEnded(); |
541 base::RunLoop().RunUntilIdle(); | 522 base::RunLoop().RunUntilIdle(); |
542 | 523 |
543 EXPECT_CALL(time_source_, StopTicking()); | 524 EXPECT_CALL(time_source_, StopTicking()); |
544 EXPECT_CALL(callbacks_, OnEnded()); | 525 EXPECT_CALL(callbacks_, OnEnded()); |
545 | 526 |
546 video_ended_cb_.Run(); | 527 video_renderer_client_->OnEnded(); |
547 base::RunLoop().RunUntilIdle(); | 528 base::RunLoop().RunUntilIdle(); |
548 } | 529 } |
549 | 530 |
550 TEST_F(RendererImplTest, ErrorAfterInitialize) { | 531 TEST_F(RendererImplTest, ErrorAfterInitialize) { |
551 InitializeWithAudio(); | 532 InitializeWithAudio(); |
552 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); | 533 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); |
553 audio_error_cb_.Run(PIPELINE_ERROR_DECODE); | 534 audio_renderer_client_->OnError(PIPELINE_ERROR_DECODE); |
554 base::RunLoop().RunUntilIdle(); | 535 base::RunLoop().RunUntilIdle(); |
555 } | 536 } |
556 | 537 |
557 TEST_F(RendererImplTest, ErrorDuringPlaying) { | 538 TEST_F(RendererImplTest, ErrorDuringPlaying) { |
558 InitializeWithAudio(); | 539 InitializeWithAudio(); |
559 Play(); | 540 Play(); |
560 | 541 |
561 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); | 542 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); |
562 audio_error_cb_.Run(PIPELINE_ERROR_DECODE); | 543 audio_renderer_client_->OnError(PIPELINE_ERROR_DECODE); |
563 base::RunLoop().RunUntilIdle(); | 544 base::RunLoop().RunUntilIdle(); |
564 } | 545 } |
565 | 546 |
566 TEST_F(RendererImplTest, ErrorDuringFlush) { | 547 TEST_F(RendererImplTest, ErrorDuringFlush) { |
567 InitializeWithAudio(); | 548 InitializeWithAudio(); |
568 Play(); | 549 Play(); |
569 | 550 |
570 InSequence s; | 551 InSequence s; |
571 EXPECT_CALL(time_source_, StopTicking()); | 552 EXPECT_CALL(time_source_, StopTicking()); |
572 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(DoAll( | 553 EXPECT_CALL(*audio_renderer_, Flush(_)) |
573 AudioError(&audio_error_cb_, PIPELINE_ERROR_DECODE), | 554 .WillOnce(DoAll(SetError(&audio_renderer_client_, PIPELINE_ERROR_DECODE), |
574 RunClosure<0>())); | 555 RunClosure<0>())); |
575 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); | 556 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); |
576 EXPECT_CALL(callbacks_, OnFlushed()); | 557 EXPECT_CALL(callbacks_, OnFlushed()); |
577 renderer_impl_->Flush( | 558 renderer_impl_->Flush( |
578 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | 559 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); |
579 base::RunLoop().RunUntilIdle(); | 560 base::RunLoop().RunUntilIdle(); |
580 } | 561 } |
581 | 562 |
582 TEST_F(RendererImplTest, ErrorAfterFlush) { | 563 TEST_F(RendererImplTest, ErrorAfterFlush) { |
583 InitializeWithAudio(); | 564 InitializeWithAudio(); |
584 Play(); | 565 Play(); |
585 Flush(false); | 566 Flush(false); |
586 | 567 |
587 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); | 568 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_DECODE)); |
588 audio_error_cb_.Run(PIPELINE_ERROR_DECODE); | 569 audio_renderer_client_->OnError(PIPELINE_ERROR_DECODE); |
589 base::RunLoop().RunUntilIdle(); | 570 base::RunLoop().RunUntilIdle(); |
590 } | 571 } |
591 | 572 |
592 TEST_F(RendererImplTest, ErrorDuringInitialize) { | 573 TEST_F(RendererImplTest, ErrorDuringInitialize) { |
593 CreateAudioAndVideoStream(); | 574 CreateAudioAndVideoStream(); |
594 SetAudioRendererInitializeExpectations(PIPELINE_OK); | 575 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
595 | 576 |
596 // Force an audio error to occur during video renderer initialization. | 577 // Force an audio error to occur during video renderer initialization. |
597 EXPECT_CALL(*video_renderer_, | 578 EXPECT_CALL(*video_renderer_, Initialize(video_stream_.get(), _, _, _, _)) |
598 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)) | 579 .WillOnce(DoAll(SetError(&audio_renderer_client_, PIPELINE_ERROR_DECODE), |
599 .WillOnce(DoAll(AudioError(&audio_error_cb_, PIPELINE_ERROR_DECODE), | 580 SaveArg<2>(&video_renderer_client_), |
600 SaveArg<4>(&video_buffering_state_cb_), | 581 RunCallback<4>(PIPELINE_OK))); |
601 SaveArg<5>(&video_ended_cb_), | |
602 RunCallback<1>(PIPELINE_OK))); | |
603 | 582 |
604 InitializeAndExpect(PIPELINE_ERROR_DECODE); | 583 InitializeAndExpect(PIPELINE_ERROR_DECODE); |
605 } | 584 } |
606 | 585 |
607 TEST_F(RendererImplTest, AudioUnderflow) { | 586 TEST_F(RendererImplTest, AudioUnderflow) { |
608 InitializeWithAudio(); | 587 InitializeWithAudio(); |
609 Play(); | 588 Play(); |
610 | 589 |
611 // Underflow should occur immediately with a single audio track. | 590 // Underflow should occur immediately with a single audio track. |
612 EXPECT_CALL(time_source_, StopTicking()); | 591 EXPECT_CALL(time_source_, StopTicking()); |
613 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 592 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
614 } | 593 } |
615 | 594 |
616 TEST_F(RendererImplTest, AudioUnderflowWithVideo) { | 595 TEST_F(RendererImplTest, AudioUnderflowWithVideo) { |
617 InitializeWithAudioAndVideo(); | 596 InitializeWithAudioAndVideo(); |
618 Play(); | 597 Play(); |
619 | 598 |
620 // Underflow should be immediate when both audio and video are present and | 599 // Underflow should be immediate when both audio and video are present and |
621 // audio underflows. | 600 // audio underflows. |
622 EXPECT_CALL(time_source_, StopTicking()); | 601 EXPECT_CALL(time_source_, StopTicking()); |
623 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 602 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
624 } | 603 } |
625 | 604 |
626 TEST_F(RendererImplTest, VideoUnderflow) { | 605 TEST_F(RendererImplTest, VideoUnderflow) { |
627 InitializeWithVideo(); | 606 InitializeWithVideo(); |
628 Play(); | 607 Play(); |
629 | 608 |
630 // Underflow should occur immediately with a single video track. | 609 // Underflow should occur immediately with a single video track. |
631 EXPECT_CALL(time_source_, StopTicking()); | 610 EXPECT_CALL(time_source_, StopTicking()); |
632 video_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 611 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
633 } | 612 } |
634 | 613 |
635 TEST_F(RendererImplTest, VideoUnderflowWithAudio) { | 614 TEST_F(RendererImplTest, VideoUnderflowWithAudio) { |
636 InitializeWithAudioAndVideo(); | 615 InitializeWithAudioAndVideo(); |
637 Play(); | 616 Play(); |
638 | 617 |
639 // Set a zero threshold such that the underflow will be executed on the next | 618 // Set a zero threshold such that the underflow will be executed on the next |
640 // run of the message loop. | 619 // run of the message loop. |
641 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 620 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
642 | 621 |
643 // Underflow should be delayed when both audio and video are present and video | 622 // Underflow should be delayed when both audio and video are present and video |
644 // underflows. | 623 // underflows. |
645 video_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 624 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
646 Mock::VerifyAndClearExpectations(&time_source_); | 625 Mock::VerifyAndClearExpectations(&time_source_); |
647 | 626 |
648 EXPECT_CALL(time_source_, StopTicking()); | 627 EXPECT_CALL(time_source_, StopTicking()); |
649 base::RunLoop().RunUntilIdle(); | 628 base::RunLoop().RunUntilIdle(); |
650 } | 629 } |
651 | 630 |
652 TEST_F(RendererImplTest, VideoUnderflowWithAudioVideoRecovers) { | 631 TEST_F(RendererImplTest, VideoUnderflowWithAudioVideoRecovers) { |
653 InitializeWithAudioAndVideo(); | 632 InitializeWithAudioAndVideo(); |
654 Play(); | 633 Play(); |
655 | 634 |
656 // Set a zero threshold such that the underflow will be executed on the next | 635 // Set a zero threshold such that the underflow will be executed on the next |
657 // run of the message loop. | 636 // run of the message loop. |
658 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 637 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
659 | 638 |
660 // Underflow should be delayed when both audio and video are present and video | 639 // Underflow should be delayed when both audio and video are present and video |
661 // underflows. | 640 // underflows. |
662 video_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 641 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
663 Mock::VerifyAndClearExpectations(&time_source_); | 642 Mock::VerifyAndClearExpectations(&time_source_); |
664 | 643 |
665 // If video recovers, the underflow should never occur. | 644 // If video recovers, the underflow should never occur. |
666 video_buffering_state_cb_.Run(BUFFERING_HAVE_ENOUGH); | 645 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_ENOUGH); |
667 base::RunLoop().RunUntilIdle(); | 646 base::RunLoop().RunUntilIdle(); |
668 } | 647 } |
669 | 648 |
670 TEST_F(RendererImplTest, VideoAndAudioUnderflow) { | 649 TEST_F(RendererImplTest, VideoAndAudioUnderflow) { |
671 InitializeWithAudioAndVideo(); | 650 InitializeWithAudioAndVideo(); |
672 Play(); | 651 Play(); |
673 | 652 |
674 // Set a zero threshold such that the underflow will be executed on the next | 653 // Set a zero threshold such that the underflow will be executed on the next |
675 // run of the message loop. | 654 // run of the message loop. |
676 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); | 655 renderer_impl_->set_video_underflow_threshold_for_testing(base::TimeDelta()); |
677 | 656 |
678 // Underflow should be delayed when both audio and video are present and video | 657 // Underflow should be delayed when both audio and video are present and video |
679 // underflows. | 658 // underflows. |
680 video_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 659 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
681 Mock::VerifyAndClearExpectations(&time_source_); | 660 Mock::VerifyAndClearExpectations(&time_source_); |
682 | 661 |
683 EXPECT_CALL(time_source_, StopTicking()); | 662 EXPECT_CALL(time_source_, StopTicking()); |
684 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 663 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
685 | 664 |
686 // Nothing else should primed on the message loop. | 665 // Nothing else should primed on the message loop. |
687 base::RunLoop().RunUntilIdle(); | 666 base::RunLoop().RunUntilIdle(); |
688 } | 667 } |
689 | 668 |
690 TEST_F(RendererImplTest, VideoUnderflowWithAudioFlush) { | 669 TEST_F(RendererImplTest, VideoUnderflowWithAudioFlush) { |
691 InitializeWithAudioAndVideo(); | 670 InitializeWithAudioAndVideo(); |
692 Play(); | 671 Play(); |
693 | 672 |
694 // Set a massive threshold such that it shouldn't fire within this test. | 673 // Set a massive threshold such that it shouldn't fire within this test. |
695 renderer_impl_->set_video_underflow_threshold_for_testing( | 674 renderer_impl_->set_video_underflow_threshold_for_testing( |
696 base::TimeDelta::FromSeconds(100)); | 675 base::TimeDelta::FromSeconds(100)); |
697 | 676 |
698 // Simulate the cases where audio underflows and then video underflows. | 677 // Simulate the cases where audio underflows and then video underflows. |
699 EXPECT_CALL(time_source_, StopTicking()); | 678 EXPECT_CALL(time_source_, StopTicking()); |
700 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 679 audio_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
701 video_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 680 video_renderer_client_->OnBufferingStateChange(BUFFERING_HAVE_NOTHING); |
702 Mock::VerifyAndClearExpectations(&time_source_); | 681 Mock::VerifyAndClearExpectations(&time_source_); |
703 | 682 |
704 // Flush the audio and video renderers, both think they're in an underflow | 683 // Flush the audio and video renderers, both think they're in an underflow |
705 // state, but if the video renderer underflow was deferred, RendererImpl would | 684 // state, but if the video renderer underflow was deferred, RendererImpl would |
706 // think it still has enough data. | 685 // think it still has enough data. |
707 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 686 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
708 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); | 687 EXPECT_CALL(*video_renderer_, Flush(_)).WillOnce(RunClosure<0>()); |
709 EXPECT_CALL(callbacks_, OnFlushed()); | 688 EXPECT_CALL(callbacks_, OnFlushed()); |
710 renderer_impl_->Flush( | 689 renderer_impl_->Flush( |
711 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); | 690 base::Bind(&CallbackHelper::OnFlushed, base::Unretained(&callbacks_))); |
712 base::RunLoop().RunUntilIdle(); | 691 base::RunLoop().RunUntilIdle(); |
713 | 692 |
714 // Start playback after the flush, but never return BUFFERING_HAVE_ENOUGH from | 693 // Start playback after the flush, but never return BUFFERING_HAVE_ENOUGH from |
715 // the video renderer (which simulates spool up time for the video renderer). | 694 // the video renderer (which simulates spool up time for the video renderer). |
716 const base::TimeDelta kStartTime; | 695 const base::TimeDelta kStartTime; |
717 EXPECT_CALL(time_source_, SetMediaTime(kStartTime)); | 696 EXPECT_CALL(time_source_, SetMediaTime(kStartTime)); |
718 EXPECT_CALL(*audio_renderer_, StartPlaying()) | 697 EXPECT_CALL(*audio_renderer_, StartPlaying()) |
719 .WillOnce( | 698 .WillOnce( |
720 SetBufferingState(&audio_buffering_state_cb_, BUFFERING_HAVE_ENOUGH)); | 699 SetBufferingState(&audio_renderer_client_, BUFFERING_HAVE_ENOUGH)); |
721 EXPECT_CALL(*video_renderer_, StartPlayingFrom(kStartTime)); | 700 EXPECT_CALL(*video_renderer_, StartPlayingFrom(kStartTime)); |
722 renderer_impl_->StartPlayingFrom(kStartTime); | 701 renderer_impl_->StartPlayingFrom(kStartTime); |
723 | 702 |
724 // Nothing else should primed on the message loop. | 703 // Nothing else should primed on the message loop. |
725 base::RunLoop().RunUntilIdle(); | 704 base::RunLoop().RunUntilIdle(); |
726 } | 705 } |
727 | 706 |
728 } // namespace media | 707 } // namespace media |
OLD | NEW |