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