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