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 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 public: | 91 public: |
92 MockAudioManager() | 92 MockAudioManager() |
93 : AudioManagerBase(base::ThreadTaskRunnerHandle::Get(), | 93 : AudioManagerBase(base::ThreadTaskRunnerHandle::Get(), |
94 base::ThreadTaskRunnerHandle::Get(), | 94 base::ThreadTaskRunnerHandle::Get(), |
95 &fake_audio_log_factory_) {} | 95 &fake_audio_log_factory_) {} |
96 ~MockAudioManager() override { Shutdown(); } | 96 ~MockAudioManager() override { Shutdown(); } |
97 | 97 |
98 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 98 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
99 MOCK_METHOD0(HasAudioInputDevices, bool()); | 99 MOCK_METHOD0(HasAudioInputDevices, bool()); |
100 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16()); | 100 MOCK_METHOD0(GetAudioInputDeviceModel, base::string16()); |
101 MOCK_METHOD3(MakeAudioOutputStream, | 101 MOCK_METHOD2(MakeAudioOutputStream, AudioOutputStream*( |
102 AudioOutputStream*(const AudioParameters& params, | 102 const AudioParameters& params, |
103 const std::string& device_id, | 103 const std::string& device_id)); |
104 const LogCallback& log_callback)); | |
105 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( | 104 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( |
106 const AudioParameters& params, | 105 const AudioParameters& params, |
107 const std::string& device_id)); | 106 const std::string& device_id)); |
108 MOCK_METHOD3(MakeAudioInputStream, | 107 MOCK_METHOD2(MakeAudioInputStream, AudioInputStream*( |
109 AudioInputStream*(const AudioParameters& params, | 108 const AudioParameters& params, const std::string& device_id)); |
110 const std::string& device_id, | |
111 const LogCallback& log_callback)); | |
112 MOCK_METHOD0(ShowAudioInputSettings, void()); | 109 MOCK_METHOD0(ShowAudioInputSettings, void()); |
113 MOCK_METHOD0(GetTaskRunner, scoped_refptr<base::SingleThreadTaskRunner>()); | 110 MOCK_METHOD0(GetTaskRunner, scoped_refptr<base::SingleThreadTaskRunner>()); |
114 MOCK_METHOD0(GetWorkerTaskRunner, | 111 MOCK_METHOD0(GetWorkerTaskRunner, |
115 scoped_refptr<base::SingleThreadTaskRunner>()); | 112 scoped_refptr<base::SingleThreadTaskRunner>()); |
116 MOCK_METHOD1(GetAudioInputDeviceNames, void( | 113 MOCK_METHOD1(GetAudioInputDeviceNames, void( |
117 media::AudioDeviceNames* device_name)); | 114 media::AudioDeviceNames* device_name)); |
118 | 115 |
119 MOCK_METHOD2(MakeLinearOutputStream, | 116 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( |
120 AudioOutputStream*(const AudioParameters& params, | 117 const AudioParameters& params)); |
121 const LogCallback& log_callback)); | 118 MOCK_METHOD2(MakeLowLatencyOutputStream, AudioOutputStream*( |
122 MOCK_METHOD3(MakeLowLatencyOutputStream, | 119 const AudioParameters& params, const std::string& device_id)); |
123 AudioOutputStream*(const AudioParameters& params, | 120 MOCK_METHOD2(MakeLinearInputStream, AudioInputStream*( |
124 const std::string& device_id, | 121 const AudioParameters& params, const std::string& device_id)); |
125 const LogCallback& log_callback)); | 122 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( |
126 MOCK_METHOD3(MakeLinearInputStream, | 123 const AudioParameters& params, const std::string& device_id)); |
127 AudioInputStream*(const AudioParameters& params, | |
128 const std::string& device_id, | |
129 const LogCallback& log_callback)); | |
130 MOCK_METHOD3(MakeLowLatencyInputStream, | |
131 AudioInputStream*(const AudioParameters& params, | |
132 const std::string& device_id, | |
133 const LogCallback& log_callback)); | |
134 MOCK_METHOD2(GetPreferredOutputStreamParameters, AudioParameters( | 124 MOCK_METHOD2(GetPreferredOutputStreamParameters, AudioParameters( |
135 const std::string& device_id, const AudioParameters& params)); | 125 const std::string& device_id, const AudioParameters& params)); |
136 | 126 |
137 private: | 127 private: |
138 media::FakeAudioLogFactory fake_audio_log_factory_; | 128 media::FakeAudioLogFactory fake_audio_log_factory_; |
139 }; | 129 }; |
140 | 130 |
141 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { | 131 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { |
142 public: | 132 public: |
143 int OnMoreData(AudioBus* audio_bus, | 133 int OnMoreData(AudioBus* audio_bus, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 Mock::VerifyAndClear(stream); | 187 Mock::VerifyAndClear(stream); |
198 | 188 |
199 // Wait for the actual close event to come from the close timer. | 189 // Wait for the actual close event to come from the close timer. |
200 WaitForCloseTimer(stream); | 190 WaitForCloseTimer(stream); |
201 } | 191 } |
202 | 192 |
203 // Basic Open() and Close() test. | 193 // Basic Open() and Close() test. |
204 void OpenAndClose(AudioOutputDispatcher* dispatcher) { | 194 void OpenAndClose(AudioOutputDispatcher* dispatcher) { |
205 MockAudioOutputStream stream(&manager_, params_); | 195 MockAudioOutputStream stream(&manager_, params_); |
206 | 196 |
207 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 197 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
208 .WillOnce(Return(&stream)); | 198 .WillOnce(Return(&stream)); |
209 EXPECT_CALL(stream, Open()) | 199 EXPECT_CALL(stream, Open()) |
210 .WillOnce(Return(true)); | 200 .WillOnce(Return(true)); |
211 | 201 |
212 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 202 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
213 EXPECT_TRUE(proxy->Open()); | 203 EXPECT_TRUE(proxy->Open()); |
214 CloseAndWaitForCloseTimer(proxy, &stream); | 204 CloseAndWaitForCloseTimer(proxy, &stream); |
215 } | 205 } |
216 | 206 |
217 // Creates a stream, and then calls Start() and Stop(). | 207 // Creates a stream, and then calls Start() and Stop(). |
218 void StartAndStop(AudioOutputDispatcher* dispatcher) { | 208 void StartAndStop(AudioOutputDispatcher* dispatcher) { |
219 MockAudioOutputStream stream(&manager_, params_); | 209 MockAudioOutputStream stream(&manager_, params_); |
220 | 210 |
221 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 211 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
222 .WillOnce(Return(&stream)); | 212 .WillOnce(Return(&stream)); |
223 EXPECT_CALL(stream, Open()) | 213 EXPECT_CALL(stream, Open()) |
224 .WillOnce(Return(true)); | 214 .WillOnce(Return(true)); |
225 EXPECT_CALL(stream, SetVolume(_)) | 215 EXPECT_CALL(stream, SetVolume(_)) |
226 .Times(1); | 216 .Times(1); |
227 | 217 |
228 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 218 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
229 EXPECT_TRUE(proxy->Open()); | 219 EXPECT_TRUE(proxy->Open()); |
230 | 220 |
231 proxy->Start(&callback_); | 221 proxy->Start(&callback_); |
232 OnStart(); | 222 OnStart(); |
233 proxy->Stop(); | 223 proxy->Stop(); |
234 | 224 |
235 CloseAndWaitForCloseTimer(proxy, &stream); | 225 CloseAndWaitForCloseTimer(proxy, &stream); |
236 EXPECT_TRUE(stream.stop_called()); | 226 EXPECT_TRUE(stream.stop_called()); |
237 EXPECT_TRUE(stream.start_called()); | 227 EXPECT_TRUE(stream.start_called()); |
238 } | 228 } |
239 | 229 |
240 // Verify that the stream is closed after Stop() is called. | 230 // Verify that the stream is closed after Stop() is called. |
241 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { | 231 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { |
242 MockAudioOutputStream stream(&manager_, params_); | 232 MockAudioOutputStream stream(&manager_, params_); |
243 | 233 |
244 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 234 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
245 .WillOnce(Return(&stream)); | 235 .WillOnce(Return(&stream)); |
246 EXPECT_CALL(stream, Open()) | 236 EXPECT_CALL(stream, Open()) |
247 .WillOnce(Return(true)); | 237 .WillOnce(Return(true)); |
248 EXPECT_CALL(stream, SetVolume(_)) | 238 EXPECT_CALL(stream, SetVolume(_)) |
249 .Times(1); | 239 .Times(1); |
250 | 240 |
251 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 241 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
252 EXPECT_TRUE(proxy->Open()); | 242 EXPECT_TRUE(proxy->Open()); |
253 | 243 |
254 proxy->Start(&callback_); | 244 proxy->Start(&callback_); |
255 OnStart(); | 245 OnStart(); |
256 proxy->Stop(); | 246 proxy->Stop(); |
257 | 247 |
258 // Wait for the close timer to fire after StopStream(). | 248 // Wait for the close timer to fire after StopStream(). |
259 WaitForCloseTimer(&stream); | 249 WaitForCloseTimer(&stream); |
260 proxy->Close(); | 250 proxy->Close(); |
261 EXPECT_TRUE(stream.stop_called()); | 251 EXPECT_TRUE(stream.stop_called()); |
262 EXPECT_TRUE(stream.start_called()); | 252 EXPECT_TRUE(stream.start_called()); |
263 } | 253 } |
264 | 254 |
265 // Create two streams, but don't start them. Only one device must be opened. | 255 // Create two streams, but don't start them. Only one device must be opened. |
266 void TwoStreams(AudioOutputDispatcher* dispatcher) { | 256 void TwoStreams(AudioOutputDispatcher* dispatcher) { |
267 MockAudioOutputStream stream(&manager_, params_); | 257 MockAudioOutputStream stream(&manager_, params_); |
268 | 258 |
269 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 259 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
270 .WillOnce(Return(&stream)); | 260 .WillOnce(Return(&stream)); |
271 EXPECT_CALL(stream, Open()) | 261 EXPECT_CALL(stream, Open()) |
272 .WillOnce(Return(true)); | 262 .WillOnce(Return(true)); |
273 | 263 |
274 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 264 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
275 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 265 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
276 EXPECT_TRUE(proxy1->Open()); | 266 EXPECT_TRUE(proxy1->Open()); |
277 EXPECT_TRUE(proxy2->Open()); | 267 EXPECT_TRUE(proxy2->Open()); |
278 proxy1->Close(); | 268 proxy1->Close(); |
279 CloseAndWaitForCloseTimer(proxy2, &stream); | 269 CloseAndWaitForCloseTimer(proxy2, &stream); |
280 EXPECT_FALSE(stream.stop_called()); | 270 EXPECT_FALSE(stream.stop_called()); |
281 EXPECT_FALSE(stream.start_called()); | 271 EXPECT_FALSE(stream.start_called()); |
282 } | 272 } |
283 | 273 |
284 // Open() method failed. | 274 // Open() method failed. |
285 void OpenFailed(AudioOutputDispatcher* dispatcher) { | 275 void OpenFailed(AudioOutputDispatcher* dispatcher) { |
286 MockAudioOutputStream stream(&manager_, params_); | 276 MockAudioOutputStream stream(&manager_, params_); |
287 | 277 |
288 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 278 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
289 .WillOnce(Return(&stream)); | 279 .WillOnce(Return(&stream)); |
290 EXPECT_CALL(stream, Open()) | 280 EXPECT_CALL(stream, Open()) |
291 .WillOnce(Return(false)); | 281 .WillOnce(Return(false)); |
292 EXPECT_CALL(stream, Close()) | 282 EXPECT_CALL(stream, Close()) |
293 .Times(1); | 283 .Times(1); |
294 | 284 |
295 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 285 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
296 EXPECT_FALSE(proxy->Open()); | 286 EXPECT_FALSE(proxy->Open()); |
297 proxy->Close(); | 287 proxy->Close(); |
298 EXPECT_FALSE(stream.stop_called()); | 288 EXPECT_FALSE(stream.stop_called()); |
299 EXPECT_FALSE(stream.start_called()); | 289 EXPECT_FALSE(stream.start_called()); |
300 } | 290 } |
301 | 291 |
302 void CreateAndWait(AudioOutputDispatcher* dispatcher) { | 292 void CreateAndWait(AudioOutputDispatcher* dispatcher) { |
303 MockAudioOutputStream stream(&manager_, params_); | 293 MockAudioOutputStream stream(&manager_, params_); |
304 | 294 |
305 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 295 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
306 .WillOnce(Return(&stream)); | 296 .WillOnce(Return(&stream)); |
307 EXPECT_CALL(stream, Open()) | 297 EXPECT_CALL(stream, Open()) |
308 .WillOnce(Return(true)); | 298 .WillOnce(Return(true)); |
309 | 299 |
310 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 300 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
311 EXPECT_TRUE(proxy->Open()); | 301 EXPECT_TRUE(proxy->Open()); |
312 | 302 |
313 WaitForCloseTimer(&stream); | 303 WaitForCloseTimer(&stream); |
314 proxy->Close(); | 304 proxy->Close(); |
315 EXPECT_FALSE(stream.stop_called()); | 305 EXPECT_FALSE(stream.stop_called()); |
316 EXPECT_FALSE(stream.start_called()); | 306 EXPECT_FALSE(stream.start_called()); |
317 } | 307 } |
318 | 308 |
319 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { | 309 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { |
320 MockAudioOutputStream stream(&manager_, params_); | 310 MockAudioOutputStream stream(&manager_, params_); |
321 | 311 |
322 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 312 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
323 .WillOnce(Return(&stream)); | 313 .WillOnce(Return(&stream)); |
324 | 314 |
325 EXPECT_CALL(stream, Open()) | 315 EXPECT_CALL(stream, Open()) |
326 .WillOnce(Return(true)); | 316 .WillOnce(Return(true)); |
327 EXPECT_CALL(stream, SetVolume(_)) | 317 EXPECT_CALL(stream, SetVolume(_)) |
328 .Times(2); | 318 .Times(2); |
329 | 319 |
330 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 320 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
331 EXPECT_TRUE(proxy1->Open()); | 321 EXPECT_TRUE(proxy1->Open()); |
332 | 322 |
(...skipping 11 matching lines...) Expand all Loading... |
344 proxy1->Close(); | 334 proxy1->Close(); |
345 CloseAndWaitForCloseTimer(proxy2, &stream); | 335 CloseAndWaitForCloseTimer(proxy2, &stream); |
346 EXPECT_TRUE(stream.stop_called()); | 336 EXPECT_TRUE(stream.stop_called()); |
347 EXPECT_TRUE(stream.start_called()); | 337 EXPECT_TRUE(stream.start_called()); |
348 } | 338 } |
349 | 339 |
350 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { | 340 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { |
351 MockAudioOutputStream stream1(&manager_, params_); | 341 MockAudioOutputStream stream1(&manager_, params_); |
352 MockAudioOutputStream stream2(&manager_, params_); | 342 MockAudioOutputStream stream2(&manager_, params_); |
353 | 343 |
354 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 344 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
355 .WillOnce(Return(&stream1)) | 345 .WillOnce(Return(&stream1)) |
356 .WillOnce(Return(&stream2)); | 346 .WillOnce(Return(&stream2)); |
357 | 347 |
358 EXPECT_CALL(stream1, Open()) | 348 EXPECT_CALL(stream1, Open()) |
359 .WillOnce(Return(true)); | 349 .WillOnce(Return(true)); |
360 EXPECT_CALL(stream1, SetVolume(_)) | 350 EXPECT_CALL(stream1, SetVolume(_)) |
361 .Times(1); | 351 .Times(1); |
362 | 352 |
363 EXPECT_CALL(stream2, Open()) | 353 EXPECT_CALL(stream2, Open()) |
364 .WillOnce(Return(true)); | 354 .WillOnce(Return(true)); |
(...skipping 16 matching lines...) Expand all Loading... |
381 | 371 |
382 EXPECT_TRUE(stream1.stop_called()); | 372 EXPECT_TRUE(stream1.stop_called()); |
383 EXPECT_TRUE(stream1.start_called()); | 373 EXPECT_TRUE(stream1.start_called()); |
384 EXPECT_TRUE(stream2.stop_called()); | 374 EXPECT_TRUE(stream2.stop_called()); |
385 EXPECT_TRUE(stream2.start_called()); | 375 EXPECT_TRUE(stream2.start_called()); |
386 } | 376 } |
387 | 377 |
388 void StartFailed(AudioOutputDispatcher* dispatcher) { | 378 void StartFailed(AudioOutputDispatcher* dispatcher) { |
389 MockAudioOutputStream stream(&manager_, params_); | 379 MockAudioOutputStream stream(&manager_, params_); |
390 | 380 |
391 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 381 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
392 .WillOnce(Return(&stream)); | 382 .WillOnce(Return(&stream)); |
393 EXPECT_CALL(stream, Open()) | 383 EXPECT_CALL(stream, Open()) |
394 .WillOnce(Return(true)); | 384 .WillOnce(Return(true)); |
395 | 385 |
396 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 386 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
397 EXPECT_TRUE(proxy->Open()); | 387 EXPECT_TRUE(proxy->Open()); |
398 | 388 |
399 WaitForCloseTimer(&stream); | 389 WaitForCloseTimer(&stream); |
400 | 390 |
401 // |stream| is closed at this point. Start() should reopen it again. | 391 // |stream| is closed at this point. Start() should reopen it again. |
402 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 392 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
403 .Times(2) | 393 .Times(2) |
404 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 394 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
405 | 395 |
406 EXPECT_CALL(callback_, OnError(_)) | 396 EXPECT_CALL(callback_, OnError(_)) |
407 .Times(2); | 397 .Times(2); |
408 | 398 |
409 proxy->Start(&callback_); | 399 proxy->Start(&callback_); |
410 | 400 |
411 // Double Start() in the error case should be allowed since it's possible a | 401 // Double Start() in the error case should be allowed since it's possible a |
412 // callback may not have had time to process the OnError() in between. | 402 // callback may not have had time to process the OnError() in between. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 528 } |
539 | 529 |
540 TEST_F(AudioOutputResamplerTest, StartFailed) { | 530 TEST_F(AudioOutputResamplerTest, StartFailed) { |
541 StartFailed(resampler_.get()); | 531 StartFailed(resampler_.get()); |
542 } | 532 } |
543 | 533 |
544 // Simulate AudioOutputStream::Create() failure with a low latency stream and | 534 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
545 // ensure AudioOutputResampler falls back to the high latency path. | 535 // ensure AudioOutputResampler falls back to the high latency path. |
546 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 536 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
547 MockAudioOutputStream stream(&manager_, params_); | 537 MockAudioOutputStream stream(&manager_, params_); |
548 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 538 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
549 .Times(2) | 539 .Times(2) |
550 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 540 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
551 .WillRepeatedly(Return(&stream)); | 541 .WillRepeatedly(Return(&stream)); |
552 EXPECT_CALL(stream, Open()) | 542 EXPECT_CALL(stream, Open()) |
553 .WillOnce(Return(true)); | 543 .WillOnce(Return(true)); |
554 | 544 |
555 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 545 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
556 EXPECT_TRUE(proxy->Open()); | 546 EXPECT_TRUE(proxy->Open()); |
557 CloseAndWaitForCloseTimer(proxy, &stream); | 547 CloseAndWaitForCloseTimer(proxy, &stream); |
558 } | 548 } |
559 | 549 |
560 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 550 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
561 // ensure AudioOutputResampler falls back to the high latency path. | 551 // ensure AudioOutputResampler falls back to the high latency path. |
562 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 552 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
563 MockAudioOutputStream failed_stream(&manager_, params_); | 553 MockAudioOutputStream failed_stream(&manager_, params_); |
564 MockAudioOutputStream okay_stream(&manager_, params_); | 554 MockAudioOutputStream okay_stream(&manager_, params_); |
565 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 555 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
566 .Times(2) | 556 .Times(2) |
567 .WillOnce(Return(&failed_stream)) | 557 .WillOnce(Return(&failed_stream)) |
568 .WillRepeatedly(Return(&okay_stream)); | 558 .WillRepeatedly(Return(&okay_stream)); |
569 EXPECT_CALL(failed_stream, Open()) | 559 EXPECT_CALL(failed_stream, Open()) |
570 .WillOnce(Return(false)); | 560 .WillOnce(Return(false)); |
571 EXPECT_CALL(failed_stream, Close()) | 561 EXPECT_CALL(failed_stream, Close()) |
572 .Times(1); | 562 .Times(1); |
573 EXPECT_CALL(okay_stream, Open()) | 563 EXPECT_CALL(okay_stream, Open()) |
574 .WillOnce(Return(true)); | 564 .WillOnce(Return(true)); |
575 | 565 |
576 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 566 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
577 EXPECT_TRUE(proxy->Open()); | 567 EXPECT_TRUE(proxy->Open()); |
578 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 568 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
579 } | 569 } |
580 | 570 |
581 // Simulate failures to open both the low latency and the fallback high latency | 571 // Simulate failures to open both the low latency and the fallback high latency |
582 // stream and ensure AudioOutputResampler falls back to a fake stream. | 572 // stream and ensure AudioOutputResampler falls back to a fake stream. |
583 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { | 573 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { |
584 MockAudioOutputStream okay_stream(&manager_, params_); | 574 MockAudioOutputStream okay_stream(&manager_, params_); |
585 | 575 |
586 // Only Windows has a high latency output driver that is not the same as the low | 576 // Only Windows has a high latency output driver that is not the same as the low |
587 // latency path. | 577 // latency path. |
588 #if defined(OS_WIN) | 578 #if defined(OS_WIN) |
589 static const int kFallbackCount = 2; | 579 static const int kFallbackCount = 2; |
590 #else | 580 #else |
591 static const int kFallbackCount = 1; | 581 static const int kFallbackCount = 1; |
592 #endif | 582 #endif |
593 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 583 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
594 .Times(kFallbackCount) | 584 .Times(kFallbackCount) |
595 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 585 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
596 | 586 |
597 // To prevent shared memory issues the sample rate and buffer size should | 587 // To prevent shared memory issues the sample rate and buffer size should |
598 // match the input stream parameters. | 588 // match the input stream parameters. |
599 EXPECT_CALL(manager(), | 589 EXPECT_CALL(manager(), MakeAudioOutputStream(AllOf( |
600 MakeAudioOutputStream( | 590 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), |
601 AllOf(testing::Property(&AudioParameters::format, | 591 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), |
602 AudioParameters::AUDIO_FAKE), | 592 testing::Property( |
603 testing::Property(&AudioParameters::sample_rate, | 593 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), |
604 params_.sample_rate()), | 594 _)) |
605 testing::Property(&AudioParameters::frames_per_buffer, | |
606 params_.frames_per_buffer())), | |
607 _, _)) | |
608 .Times(1) | 595 .Times(1) |
609 .WillOnce(Return(&okay_stream)); | 596 .WillOnce(Return(&okay_stream)); |
610 EXPECT_CALL(okay_stream, Open()) | 597 EXPECT_CALL(okay_stream, Open()) |
611 .WillOnce(Return(true)); | 598 .WillOnce(Return(true)); |
612 | 599 |
613 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 600 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
614 EXPECT_TRUE(proxy->Open()); | 601 EXPECT_TRUE(proxy->Open()); |
615 CloseAndWaitForCloseTimer(proxy, &okay_stream); | 602 CloseAndWaitForCloseTimer(proxy, &okay_stream); |
616 } | 603 } |
617 | 604 |
618 // Simulate failures to open both the low latency, the fallback high latency | 605 // Simulate failures to open both the low latency, the fallback high latency |
619 // stream, and the fake audio output stream and ensure AudioOutputResampler | 606 // stream, and the fake audio output stream and ensure AudioOutputResampler |
620 // terminates normally. | 607 // terminates normally. |
621 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { | 608 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { |
622 // Only Windows has a high latency output driver that is not the same as the low | 609 // Only Windows has a high latency output driver that is not the same as the low |
623 // latency path. | 610 // latency path. |
624 #if defined(OS_WIN) | 611 #if defined(OS_WIN) |
625 static const int kFallbackCount = 3; | 612 static const int kFallbackCount = 3; |
626 #else | 613 #else |
627 static const int kFallbackCount = 2; | 614 static const int kFallbackCount = 2; |
628 #endif | 615 #endif |
629 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 616 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
630 .Times(kFallbackCount) | 617 .Times(kFallbackCount) |
631 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 618 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
632 | 619 |
633 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 620 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
634 EXPECT_FALSE(proxy->Open()); | 621 EXPECT_FALSE(proxy->Open()); |
635 proxy->Close(); | 622 proxy->Close(); |
636 } | 623 } |
637 | 624 |
638 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls | 625 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls |
639 // eventually followed by one which fails; root cause of http://crbug.com/150619 | 626 // eventually followed by one which fails; root cause of http://crbug.com/150619 |
640 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { | 627 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { |
641 MockAudioOutputStream stream1(&manager_, params_); | 628 MockAudioOutputStream stream1(&manager_, params_); |
642 MockAudioOutputStream stream2(&manager_, params_); | 629 MockAudioOutputStream stream2(&manager_, params_); |
643 | 630 |
644 // Setup the mock such that all three streams are successfully created. | 631 // Setup the mock such that all three streams are successfully created. |
645 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 632 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
646 .WillOnce(Return(&stream1)) | 633 .WillOnce(Return(&stream1)) |
647 .WillOnce(Return(&stream2)) | 634 .WillOnce(Return(&stream2)) |
648 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 635 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
649 | 636 |
650 // Stream1 should be able to successfully open and start. | 637 // Stream1 should be able to successfully open and start. |
651 EXPECT_CALL(stream1, Open()) | 638 EXPECT_CALL(stream1, Open()) |
652 .WillOnce(Return(true)); | 639 .WillOnce(Return(true)); |
653 EXPECT_CALL(stream1, SetVolume(_)) | 640 EXPECT_CALL(stream1, SetVolume(_)) |
654 .Times(1); | 641 .Times(1); |
655 | 642 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // non-fake stream. | 684 // non-fake stream. |
698 TEST_F(AudioOutputResamplerTest, FallbackRecovery) { | 685 TEST_F(AudioOutputResamplerTest, FallbackRecovery) { |
699 MockAudioOutputStream fake_stream(&manager_, params_); | 686 MockAudioOutputStream fake_stream(&manager_, params_); |
700 | 687 |
701 // Trigger the fallback mechanism until a fake output stream is created. | 688 // Trigger the fallback mechanism until a fake output stream is created. |
702 #if defined(OS_WIN) | 689 #if defined(OS_WIN) |
703 static const int kFallbackCount = 2; | 690 static const int kFallbackCount = 2; |
704 #else | 691 #else |
705 static const int kFallbackCount = 1; | 692 static const int kFallbackCount = 1; |
706 #endif | 693 #endif |
707 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) | 694 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
708 .Times(kFallbackCount) | 695 .Times(kFallbackCount) |
709 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 696 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
710 EXPECT_CALL(manager(), | 697 EXPECT_CALL(manager(), |
711 MakeAudioOutputStream( | 698 MakeAudioOutputStream( |
712 AllOf(testing::Property(&AudioParameters::format, | 699 AllOf(testing::Property(&AudioParameters::format, |
713 AudioParameters::AUDIO_FAKE), | 700 AudioParameters::AUDIO_FAKE), |
714 testing::Property(&AudioParameters::sample_rate, | 701 testing::Property(&AudioParameters::sample_rate, |
715 params_.sample_rate()), | 702 params_.sample_rate()), |
716 testing::Property(&AudioParameters::frames_per_buffer, | 703 testing::Property(&AudioParameters::frames_per_buffer, |
717 params_.frames_per_buffer())), | 704 params_.frames_per_buffer())), |
718 _, _)) | 705 _)).WillOnce(Return(&fake_stream)); |
719 .WillOnce(Return(&fake_stream)); | |
720 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); | 706 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); |
721 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 707 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
722 EXPECT_TRUE(proxy->Open()); | 708 EXPECT_TRUE(proxy->Open()); |
723 CloseAndWaitForCloseTimer(proxy, &fake_stream); | 709 CloseAndWaitForCloseTimer(proxy, &fake_stream); |
724 | 710 |
725 // Once all proxies have been closed, AudioOutputResampler will start the | 711 // Once all proxies have been closed, AudioOutputResampler will start the |
726 // reinitialization timer and execute it after the close delay elapses. | 712 // reinitialization timer and execute it after the close delay elapses. |
727 base::RunLoop run_loop; | 713 base::RunLoop run_loop; |
728 message_loop_.PostDelayedTask( | 714 message_loop_.PostDelayedTask( |
729 FROM_HERE, run_loop.QuitClosure(), | 715 FROM_HERE, run_loop.QuitClosure(), |
730 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); | 716 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); |
731 run_loop.Run(); | 717 run_loop.Run(); |
732 | 718 |
733 // Verify a non-fake stream can be created. | 719 // Verify a non-fake stream can be created. |
734 MockAudioOutputStream real_stream(&manager_, params_); | 720 MockAudioOutputStream real_stream(&manager_, params_); |
735 EXPECT_CALL(manager(), | 721 EXPECT_CALL(manager(), |
736 MakeAudioOutputStream( | 722 MakeAudioOutputStream( |
737 testing::Property(&AudioParameters::format, | 723 testing::Property(&AudioParameters::format, |
738 testing::Ne(AudioParameters::AUDIO_FAKE)), | 724 testing::Ne(AudioParameters::AUDIO_FAKE)), |
739 _, _)) | 725 _)).WillOnce(Return(&real_stream)); |
740 .WillOnce(Return(&real_stream)); | |
741 | 726 |
742 // Stream1 should be able to successfully open and start. | 727 // Stream1 should be able to successfully open and start. |
743 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); | 728 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); |
744 proxy = new AudioOutputProxy(resampler_.get()); | 729 proxy = new AudioOutputProxy(resampler_.get()); |
745 EXPECT_TRUE(proxy->Open()); | 730 EXPECT_TRUE(proxy->Open()); |
746 CloseAndWaitForCloseTimer(proxy, &real_stream); | 731 CloseAndWaitForCloseTimer(proxy, &real_stream); |
747 } | 732 } |
748 | 733 |
749 } // namespace media | 734 } // namespace media |
OLD | NEW |