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