| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "media/audio/audio_output_dispatcher_impl.h" | 9 #include "media/audio/audio_output_dispatcher_impl.h" |
| 10 #include "media/audio/audio_output_proxy.h" | 10 #include "media/audio/audio_output_proxy.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 class MockAudioManager : public AudioManagerBase { | 88 class MockAudioManager : public AudioManagerBase { |
| 89 public: | 89 public: |
| 90 MockAudioManager() {} | 90 MockAudioManager() {} |
| 91 virtual ~MockAudioManager() { | 91 virtual ~MockAudioManager() { |
| 92 Shutdown(); | 92 Shutdown(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 MOCK_METHOD0(HasAudioOutputDevices, bool()); | 95 MOCK_METHOD0(HasAudioOutputDevices, bool()); |
| 96 MOCK_METHOD0(HasAudioInputDevices, bool()); | 96 MOCK_METHOD0(HasAudioInputDevices, bool()); |
| 97 MOCK_METHOD0(GetAudioInputDeviceModel, string16()); | 97 MOCK_METHOD0(GetAudioInputDeviceModel, string16()); |
| 98 MOCK_METHOD1(MakeAudioOutputStream, AudioOutputStream*( | 98 MOCK_METHOD2(MakeAudioOutputStream, AudioOutputStream*( |
| 99 const AudioParameters& params)); | 99 const AudioParameters& params, const std::string& input_device_id)); |
| 100 MOCK_METHOD1(MakeAudioOutputStreamProxy, AudioOutputStream*( | 100 MOCK_METHOD2(MakeAudioOutputStreamProxy, AudioOutputStream*( |
| 101 const AudioParameters& params)); | 101 const AudioParameters& params, const std::string& input_device_id)); |
| 102 MOCK_METHOD2(MakeAudioInputStream, AudioInputStream*( | 102 MOCK_METHOD2(MakeAudioInputStream, AudioInputStream*( |
| 103 const AudioParameters& params, const std::string& device_id)); | 103 const AudioParameters& params, const std::string& device_id)); |
| 104 MOCK_METHOD0(ShowAudioInputSettings, void()); | 104 MOCK_METHOD0(ShowAudioInputSettings, void()); |
| 105 MOCK_METHOD0(GetMessageLoop, scoped_refptr<base::MessageLoopProxy>()); | 105 MOCK_METHOD0(GetMessageLoop, scoped_refptr<base::MessageLoopProxy>()); |
| 106 MOCK_METHOD1(GetAudioInputDeviceNames, void( | 106 MOCK_METHOD1(GetAudioInputDeviceNames, void( |
| 107 media::AudioDeviceNames* device_name)); | 107 media::AudioDeviceNames* device_name)); |
| 108 MOCK_METHOD0(IsRecordingInProcess, bool()); | 108 MOCK_METHOD0(IsRecordingInProcess, bool()); |
| 109 | 109 |
| 110 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( | 110 MOCK_METHOD1(MakeLinearOutputStream, AudioOutputStream*( |
| 111 const AudioParameters& params)); | 111 const AudioParameters& params)); |
| 112 MOCK_METHOD1(MakeLowLatencyOutputStream, AudioOutputStream*( | 112 MOCK_METHOD2(MakeLowLatencyOutputStream, AudioOutputStream*( |
| 113 const AudioParameters& params)); | 113 const AudioParameters& params, const std::string& input_device_id)); |
| 114 MOCK_METHOD2(MakeLinearInputStream, AudioInputStream*( | 114 MOCK_METHOD2(MakeLinearInputStream, AudioInputStream*( |
| 115 const AudioParameters& params, const std::string& device_id)); | 115 const AudioParameters& params, const std::string& device_id)); |
| 116 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( | 116 MOCK_METHOD2(MakeLowLatencyInputStream, AudioInputStream*( |
| 117 const AudioParameters& params, const std::string& device_id)); | 117 const AudioParameters& params, const std::string& device_id)); |
| 118 MOCK_METHOD1(GetPreferredOutputStreamParameters, AudioParameters( | 118 MOCK_METHOD1(GetPreferredOutputStreamParameters, AudioParameters( |
| 119 const AudioParameters& params)); | 119 const AudioParameters& params)); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { | 122 class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { |
| 123 public: | 123 public: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 virtual void InitDispatcher(base::TimeDelta close_delay) { | 156 virtual void InitDispatcher(base::TimeDelta close_delay) { |
| 157 // Use a low sample rate and large buffer size when testing otherwise the | 157 // Use a low sample rate and large buffer size when testing otherwise the |
| 158 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., | 158 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., |
| 159 // RunUntilIdle() will never terminate. | 159 // RunUntilIdle() will never terminate. |
| 160 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 160 params_ = AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, |
| 161 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); | 161 CHANNEL_LAYOUT_STEREO, 8000, 16, 2048); |
| 162 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), | 162 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), |
| 163 params_, | 163 params_, |
| 164 std::string(), |
| 164 close_delay); | 165 close_delay); |
| 165 | 166 |
| 166 // Necessary to know how long the dispatcher will wait before posting | 167 // Necessary to know how long the dispatcher will wait before posting |
| 167 // StopStreamTask. | 168 // StopStreamTask. |
| 168 pause_delay_ = dispatcher_impl_->pause_delay_; | 169 pause_delay_ = dispatcher_impl_->pause_delay_; |
| 169 } | 170 } |
| 170 | 171 |
| 171 virtual void OnStart() {} | 172 virtual void OnStart() {} |
| 172 | 173 |
| 173 MockAudioManager& manager() { | 174 MockAudioManager& manager() { |
| 174 return manager_; | 175 return manager_; |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Wait for the close timer to fire. | 178 // Wait for the close timer to fire. |
| 178 void WaitForCloseTimer(const int timer_delay_ms) { | 179 void WaitForCloseTimer(const int timer_delay_ms) { |
| 179 message_loop_.RunUntilIdle(); // OpenTask() may reset the timer. | 180 message_loop_.RunUntilIdle(); // OpenTask() may reset the timer. |
| 180 base::PlatformThread::Sleep( | 181 base::PlatformThread::Sleep( |
| 181 base::TimeDelta::FromMilliseconds(timer_delay_ms) * 2); | 182 base::TimeDelta::FromMilliseconds(timer_delay_ms) * 2); |
| 182 message_loop_.RunUntilIdle(); | 183 message_loop_.RunUntilIdle(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Methods that do actual tests. | 186 // Methods that do actual tests. |
| 186 void OpenAndClose(AudioOutputDispatcher* dispatcher) { | 187 void OpenAndClose(AudioOutputDispatcher* dispatcher) { |
| 187 MockAudioOutputStream stream(&manager_, params_); | 188 MockAudioOutputStream stream(&manager_, params_); |
| 188 | 189 |
| 189 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 190 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 190 .WillOnce(Return(&stream)); | 191 .WillOnce(Return(&stream)); |
| 191 EXPECT_CALL(stream, Open()) | 192 EXPECT_CALL(stream, Open()) |
| 192 .WillOnce(Return(true)); | 193 .WillOnce(Return(true)); |
| 193 EXPECT_CALL(stream, Close()) | 194 EXPECT_CALL(stream, Close()) |
| 194 .Times(1); | 195 .Times(1); |
| 195 | 196 |
| 196 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 197 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 197 EXPECT_TRUE(proxy->Open()); | 198 EXPECT_TRUE(proxy->Open()); |
| 198 proxy->Close(); | 199 proxy->Close(); |
| 199 WaitForCloseTimer(kTestCloseDelayMs); | 200 WaitForCloseTimer(kTestCloseDelayMs); |
| 200 } | 201 } |
| 201 | 202 |
| 202 // Create a stream, and then calls Start() and Stop(). | 203 // Create a stream, and then calls Start() and Stop(). |
| 203 void StartAndStop(AudioOutputDispatcher* dispatcher) { | 204 void StartAndStop(AudioOutputDispatcher* dispatcher) { |
| 204 MockAudioOutputStream stream(&manager_, params_); | 205 MockAudioOutputStream stream(&manager_, params_); |
| 205 | 206 |
| 206 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 207 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 207 .WillOnce(Return(&stream)); | 208 .WillOnce(Return(&stream)); |
| 208 EXPECT_CALL(stream, Open()) | 209 EXPECT_CALL(stream, Open()) |
| 209 .WillOnce(Return(true)); | 210 .WillOnce(Return(true)); |
| 210 EXPECT_CALL(stream, SetVolume(_)) | 211 EXPECT_CALL(stream, SetVolume(_)) |
| 211 .Times(1); | 212 .Times(1); |
| 212 EXPECT_CALL(stream, Close()) | 213 EXPECT_CALL(stream, Close()) |
| 213 .Times(1); | 214 .Times(1); |
| 214 | 215 |
| 215 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 216 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 216 EXPECT_TRUE(proxy->Open()); | 217 EXPECT_TRUE(proxy->Open()); |
| 217 | 218 |
| 218 proxy->Start(&callback_); | 219 proxy->Start(&callback_); |
| 219 OnStart(); | 220 OnStart(); |
| 220 proxy->Stop(); | 221 proxy->Stop(); |
| 221 | 222 |
| 222 proxy->Close(); | 223 proxy->Close(); |
| 223 WaitForCloseTimer(kTestCloseDelayMs); | 224 WaitForCloseTimer(kTestCloseDelayMs); |
| 224 EXPECT_TRUE(stream.stop_called()); | 225 EXPECT_TRUE(stream.stop_called()); |
| 225 EXPECT_TRUE(stream.start_called()); | 226 EXPECT_TRUE(stream.start_called()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 // Verify that the stream is closed after Stop is called. | 229 // Verify that the stream is closed after Stop is called. |
| 229 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { | 230 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { |
| 230 MockAudioOutputStream stream(&manager_, params_); | 231 MockAudioOutputStream stream(&manager_, params_); |
| 231 | 232 |
| 232 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 233 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 233 .WillOnce(Return(&stream)); | 234 .WillOnce(Return(&stream)); |
| 234 EXPECT_CALL(stream, Open()) | 235 EXPECT_CALL(stream, Open()) |
| 235 .WillOnce(Return(true)); | 236 .WillOnce(Return(true)); |
| 236 EXPECT_CALL(stream, SetVolume(_)) | 237 EXPECT_CALL(stream, SetVolume(_)) |
| 237 .Times(1); | 238 .Times(1); |
| 238 EXPECT_CALL(stream, Close()) | 239 EXPECT_CALL(stream, Close()) |
| 239 .Times(1); | 240 .Times(1); |
| 240 | 241 |
| 241 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 242 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 242 EXPECT_TRUE(proxy->Open()); | 243 EXPECT_TRUE(proxy->Open()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 | 255 |
| 255 proxy->Close(); | 256 proxy->Close(); |
| 256 EXPECT_TRUE(stream.stop_called()); | 257 EXPECT_TRUE(stream.stop_called()); |
| 257 EXPECT_TRUE(stream.start_called()); | 258 EXPECT_TRUE(stream.start_called()); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // Create two streams, but don't start them. Only one device must be open. | 261 // Create two streams, but don't start them. Only one device must be open. |
| 261 void TwoStreams(AudioOutputDispatcher* dispatcher) { | 262 void TwoStreams(AudioOutputDispatcher* dispatcher) { |
| 262 MockAudioOutputStream stream(&manager_, params_); | 263 MockAudioOutputStream stream(&manager_, params_); |
| 263 | 264 |
| 264 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 265 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 265 .WillOnce(Return(&stream)); | 266 .WillOnce(Return(&stream)); |
| 266 EXPECT_CALL(stream, Open()) | 267 EXPECT_CALL(stream, Open()) |
| 267 .WillOnce(Return(true)); | 268 .WillOnce(Return(true)); |
| 268 EXPECT_CALL(stream, Close()) | 269 EXPECT_CALL(stream, Close()) |
| 269 .Times(1); | 270 .Times(1); |
| 270 | 271 |
| 271 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); | 272 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); |
| 272 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); | 273 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); |
| 273 EXPECT_TRUE(proxy1->Open()); | 274 EXPECT_TRUE(proxy1->Open()); |
| 274 EXPECT_TRUE(proxy2->Open()); | 275 EXPECT_TRUE(proxy2->Open()); |
| 275 proxy1->Close(); | 276 proxy1->Close(); |
| 276 proxy2->Close(); | 277 proxy2->Close(); |
| 277 WaitForCloseTimer(kTestCloseDelayMs); | 278 WaitForCloseTimer(kTestCloseDelayMs); |
| 278 EXPECT_FALSE(stream.stop_called()); | 279 EXPECT_FALSE(stream.stop_called()); |
| 279 EXPECT_FALSE(stream.start_called()); | 280 EXPECT_FALSE(stream.start_called()); |
| 280 } | 281 } |
| 281 | 282 |
| 282 // Open() method failed. | 283 // Open() method failed. |
| 283 void OpenFailed(AudioOutputDispatcher* dispatcher) { | 284 void OpenFailed(AudioOutputDispatcher* dispatcher) { |
| 284 MockAudioOutputStream stream(&manager_, params_); | 285 MockAudioOutputStream stream(&manager_, params_); |
| 285 | 286 |
| 286 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 287 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 287 .WillOnce(Return(&stream)); | 288 .WillOnce(Return(&stream)); |
| 288 EXPECT_CALL(stream, Open()) | 289 EXPECT_CALL(stream, Open()) |
| 289 .WillOnce(Return(false)); | 290 .WillOnce(Return(false)); |
| 290 EXPECT_CALL(stream, Close()) | 291 EXPECT_CALL(stream, Close()) |
| 291 .Times(1); | 292 .Times(1); |
| 292 | 293 |
| 293 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 294 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 294 EXPECT_FALSE(proxy->Open()); | 295 EXPECT_FALSE(proxy->Open()); |
| 295 proxy->Close(); | 296 proxy->Close(); |
| 296 WaitForCloseTimer(kTestCloseDelayMs); | 297 WaitForCloseTimer(kTestCloseDelayMs); |
| 297 EXPECT_FALSE(stream.stop_called()); | 298 EXPECT_FALSE(stream.stop_called()); |
| 298 EXPECT_FALSE(stream.start_called()); | 299 EXPECT_FALSE(stream.start_called()); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void CreateAndWait(AudioOutputDispatcher* dispatcher) { | 302 void CreateAndWait(AudioOutputDispatcher* dispatcher) { |
| 302 MockAudioOutputStream stream(&manager_, params_); | 303 MockAudioOutputStream stream(&manager_, params_); |
| 303 | 304 |
| 304 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 305 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 305 .WillOnce(Return(&stream)); | 306 .WillOnce(Return(&stream)); |
| 306 EXPECT_CALL(stream, Open()) | 307 EXPECT_CALL(stream, Open()) |
| 307 .WillOnce(Return(true)); | 308 .WillOnce(Return(true)); |
| 308 EXPECT_CALL(stream, Close()) | 309 EXPECT_CALL(stream, Close()) |
| 309 .Times(1); | 310 .Times(1); |
| 310 | 311 |
| 311 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 312 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 312 EXPECT_TRUE(proxy->Open()); | 313 EXPECT_TRUE(proxy->Open()); |
| 313 | 314 |
| 314 // Simulate a delay. | 315 // Simulate a delay. |
| 315 base::PlatformThread::Sleep( | 316 base::PlatformThread::Sleep( |
| 316 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | 317 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
| 317 message_loop_.RunUntilIdle(); | 318 message_loop_.RunUntilIdle(); |
| 318 | 319 |
| 319 // Verify expectation before calling Close(). | 320 // Verify expectation before calling Close(). |
| 320 Mock::VerifyAndClear(&stream); | 321 Mock::VerifyAndClear(&stream); |
| 321 | 322 |
| 322 proxy->Close(); | 323 proxy->Close(); |
| 323 EXPECT_FALSE(stream.stop_called()); | 324 EXPECT_FALSE(stream.stop_called()); |
| 324 EXPECT_FALSE(stream.start_called()); | 325 EXPECT_FALSE(stream.start_called()); |
| 325 } | 326 } |
| 326 | 327 |
| 327 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) { | 328 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) { |
| 328 MockAudioOutputStream stream1(&manager_, params_); | 329 MockAudioOutputStream stream1(&manager_, params_); |
| 329 MockAudioOutputStream stream2(&manager_, params_); | 330 MockAudioOutputStream stream2(&manager_, params_); |
| 330 | 331 |
| 331 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 332 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 332 .WillOnce(Return(&stream1)) | 333 .WillOnce(Return(&stream1)) |
| 333 .WillOnce(Return(&stream2)); | 334 .WillOnce(Return(&stream2)); |
| 334 | 335 |
| 335 EXPECT_CALL(stream1, Open()) | 336 EXPECT_CALL(stream1, Open()) |
| 336 .WillOnce(Return(true)); | 337 .WillOnce(Return(true)); |
| 337 EXPECT_CALL(stream1, SetVolume(_)) | 338 EXPECT_CALL(stream1, SetVolume(_)) |
| 338 .Times(1); | 339 .Times(1); |
| 339 EXPECT_CALL(stream1, Close()) | 340 EXPECT_CALL(stream1, Close()) |
| 340 .Times(1); | 341 .Times(1); |
| 341 | 342 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 359 EXPECT_TRUE(stream1.stop_called()); | 360 EXPECT_TRUE(stream1.stop_called()); |
| 360 EXPECT_TRUE(stream1.start_called()); | 361 EXPECT_TRUE(stream1.start_called()); |
| 361 EXPECT_FALSE(stream2.stop_called()); | 362 EXPECT_FALSE(stream2.stop_called()); |
| 362 EXPECT_FALSE(stream2.start_called()); | 363 EXPECT_FALSE(stream2.start_called()); |
| 363 } | 364 } |
| 364 | 365 |
| 365 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { | 366 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { |
| 366 MockAudioOutputStream stream1(&manager_, params_); | 367 MockAudioOutputStream stream1(&manager_, params_); |
| 367 MockAudioOutputStream stream2(&manager_, params_); | 368 MockAudioOutputStream stream2(&manager_, params_); |
| 368 | 369 |
| 369 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 370 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 370 .WillOnce(Return(&stream1)) | 371 .WillOnce(Return(&stream1)) |
| 371 .WillOnce(Return(&stream2)); | 372 .WillOnce(Return(&stream2)); |
| 372 | 373 |
| 373 EXPECT_CALL(stream1, Open()) | 374 EXPECT_CALL(stream1, Open()) |
| 374 .WillOnce(Return(true)); | 375 .WillOnce(Return(true)); |
| 375 EXPECT_CALL(stream1, SetVolume(_)) | 376 EXPECT_CALL(stream1, SetVolume(_)) |
| 376 .Times(1); | 377 .Times(1); |
| 377 EXPECT_CALL(stream1, Close()) | 378 EXPECT_CALL(stream1, Close()) |
| 378 .Times(1); | 379 .Times(1); |
| 379 | 380 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 399 proxy2->Close(); | 400 proxy2->Close(); |
| 400 EXPECT_TRUE(stream1.stop_called()); | 401 EXPECT_TRUE(stream1.stop_called()); |
| 401 EXPECT_TRUE(stream1.start_called()); | 402 EXPECT_TRUE(stream1.start_called()); |
| 402 EXPECT_TRUE(stream2.stop_called()); | 403 EXPECT_TRUE(stream2.stop_called()); |
| 403 EXPECT_TRUE(stream2.start_called()); | 404 EXPECT_TRUE(stream2.start_called()); |
| 404 } | 405 } |
| 405 | 406 |
| 406 void StartFailed(AudioOutputDispatcher* dispatcher) { | 407 void StartFailed(AudioOutputDispatcher* dispatcher) { |
| 407 MockAudioOutputStream stream(&manager_, params_); | 408 MockAudioOutputStream stream(&manager_, params_); |
| 408 | 409 |
| 409 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 410 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 410 .WillOnce(Return(&stream)); | 411 .WillOnce(Return(&stream)); |
| 411 EXPECT_CALL(stream, Open()) | 412 EXPECT_CALL(stream, Open()) |
| 412 .WillOnce(Return(true)); | 413 .WillOnce(Return(true)); |
| 413 EXPECT_CALL(stream, Close()) | 414 EXPECT_CALL(stream, Close()) |
| 414 .Times(1); | 415 .Times(1); |
| 415 | 416 |
| 416 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); | 417 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); |
| 417 EXPECT_TRUE(proxy->Open()); | 418 EXPECT_TRUE(proxy->Open()); |
| 418 | 419 |
| 419 // Simulate a delay. | 420 // Simulate a delay. |
| 420 base::PlatformThread::Sleep( | 421 base::PlatformThread::Sleep( |
| 421 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); | 422 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2); |
| 422 message_loop_.RunUntilIdle(); | 423 message_loop_.RunUntilIdle(); |
| 423 | 424 |
| 424 // Verify expectation before calling Close(). | 425 // Verify expectation before calling Close(). |
| 425 Mock::VerifyAndClear(&stream); | 426 Mock::VerifyAndClear(&stream); |
| 426 | 427 |
| 427 // |stream| is closed at this point. Start() should reopen it again. | 428 // |stream| is closed at this point. Start() should reopen it again. |
| 428 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 429 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 429 .Times(2) | 430 .Times(2) |
| 430 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); | 431 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); |
| 431 | 432 |
| 432 EXPECT_CALL(callback_, OnError(_)) | 433 EXPECT_CALL(callback_, OnError(_)) |
| 433 .Times(2); | 434 .Times(2); |
| 434 | 435 |
| 435 proxy->Start(&callback_); | 436 proxy->Start(&callback_); |
| 436 | 437 |
| 437 // Double Start() in the error case should be allowed since it's possible a | 438 // Double Start() in the error case should be allowed since it's possible a |
| 438 // callback may not have had time to process the OnError() in between. | 439 // callback may not have had time to process the OnError() in between. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 460 | 461 |
| 461 virtual void InitDispatcher(base::TimeDelta close_delay) OVERRIDE { | 462 virtual void InitDispatcher(base::TimeDelta close_delay) OVERRIDE { |
| 462 AudioOutputProxyTest::InitDispatcher(close_delay); | 463 AudioOutputProxyTest::InitDispatcher(close_delay); |
| 463 // Use a low sample rate and large buffer size when testing otherwise the | 464 // Use a low sample rate and large buffer size when testing otherwise the |
| 464 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., | 465 // FakeAudioOutputStream will keep the message loop busy indefinitely; i.e., |
| 465 // RunUntilIdle() will never terminate. | 466 // RunUntilIdle() will never terminate. |
| 466 resampler_params_ = AudioParameters( | 467 resampler_params_ = AudioParameters( |
| 467 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 468 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 468 16000, 16, 1024); | 469 16000, 16, 1024); |
| 469 resampler_ = new AudioOutputResampler( | 470 resampler_ = new AudioOutputResampler( |
| 470 &manager(), params_, resampler_params_, close_delay); | 471 &manager(), params_, resampler_params_, std::string(), close_delay); |
| 471 } | 472 } |
| 472 | 473 |
| 473 virtual void OnStart() OVERRIDE { | 474 virtual void OnStart() OVERRIDE { |
| 474 // Let start run for a bit. | 475 // Let start run for a bit. |
| 475 message_loop_.RunUntilIdle(); | 476 message_loop_.RunUntilIdle(); |
| 476 base::PlatformThread::Sleep( | 477 base::PlatformThread::Sleep( |
| 477 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); | 478 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); |
| 478 } | 479 } |
| 479 | 480 |
| 480 protected: | 481 protected: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 TEST_F(AudioOutputProxyTest, StartFailed) { | 562 TEST_F(AudioOutputProxyTest, StartFailed) { |
| 562 StartFailed(dispatcher_impl_.get()); | 563 StartFailed(dispatcher_impl_.get()); |
| 563 } | 564 } |
| 564 | 565 |
| 565 TEST_F(AudioOutputResamplerTest, StartFailed) { StartFailed(resampler_.get()); } | 566 TEST_F(AudioOutputResamplerTest, StartFailed) { StartFailed(resampler_.get()); } |
| 566 | 567 |
| 567 // Simulate AudioOutputStream::Create() failure with a low latency stream and | 568 // Simulate AudioOutputStream::Create() failure with a low latency stream and |
| 568 // ensure AudioOutputResampler falls back to the high latency path. | 569 // ensure AudioOutputResampler falls back to the high latency path. |
| 569 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { | 570 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { |
| 570 MockAudioOutputStream stream(&manager_, params_); | 571 MockAudioOutputStream stream(&manager_, params_); |
| 571 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 572 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 572 .Times(2) | 573 .Times(2) |
| 573 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) | 574 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) |
| 574 .WillRepeatedly(Return(&stream)); | 575 .WillRepeatedly(Return(&stream)); |
| 575 EXPECT_CALL(stream, Open()) | 576 EXPECT_CALL(stream, Open()) |
| 576 .WillOnce(Return(true)); | 577 .WillOnce(Return(true)); |
| 577 EXPECT_CALL(stream, Close()) | 578 EXPECT_CALL(stream, Close()) |
| 578 .Times(1); | 579 .Times(1); |
| 579 | 580 |
| 580 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 581 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 581 EXPECT_TRUE(proxy->Open()); | 582 EXPECT_TRUE(proxy->Open()); |
| 582 proxy->Close(); | 583 proxy->Close(); |
| 583 WaitForCloseTimer(kTestCloseDelayMs); | 584 WaitForCloseTimer(kTestCloseDelayMs); |
| 584 } | 585 } |
| 585 | 586 |
| 586 // Simulate AudioOutputStream::Open() failure with a low latency stream and | 587 // Simulate AudioOutputStream::Open() failure with a low latency stream and |
| 587 // ensure AudioOutputResampler falls back to the high latency path. | 588 // ensure AudioOutputResampler falls back to the high latency path. |
| 588 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { | 589 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { |
| 589 MockAudioOutputStream failed_stream(&manager_, params_); | 590 MockAudioOutputStream failed_stream(&manager_, params_); |
| 590 MockAudioOutputStream okay_stream(&manager_, params_); | 591 MockAudioOutputStream okay_stream(&manager_, params_); |
| 591 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 592 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 592 .Times(2) | 593 .Times(2) |
| 593 .WillOnce(Return(&failed_stream)) | 594 .WillOnce(Return(&failed_stream)) |
| 594 .WillRepeatedly(Return(&okay_stream)); | 595 .WillRepeatedly(Return(&okay_stream)); |
| 595 EXPECT_CALL(failed_stream, Open()) | 596 EXPECT_CALL(failed_stream, Open()) |
| 596 .WillOnce(Return(false)); | 597 .WillOnce(Return(false)); |
| 597 EXPECT_CALL(failed_stream, Close()) | 598 EXPECT_CALL(failed_stream, Close()) |
| 598 .Times(1); | 599 .Times(1); |
| 599 EXPECT_CALL(okay_stream, Open()) | 600 EXPECT_CALL(okay_stream, Open()) |
| 600 .WillOnce(Return(true)); | 601 .WillOnce(Return(true)); |
| 601 EXPECT_CALL(okay_stream, Close()) | 602 EXPECT_CALL(okay_stream, Close()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 612 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { | 613 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { |
| 613 MockAudioOutputStream okay_stream(&manager_, params_); | 614 MockAudioOutputStream okay_stream(&manager_, params_); |
| 614 | 615 |
| 615 // Only Windows has a high latency output driver that is not the same as the low | 616 // Only Windows has a high latency output driver that is not the same as the low |
| 616 // latency path. | 617 // latency path. |
| 617 #if defined(OS_WIN) | 618 #if defined(OS_WIN) |
| 618 static const int kFallbackCount = 2; | 619 static const int kFallbackCount = 2; |
| 619 #else | 620 #else |
| 620 static const int kFallbackCount = 1; | 621 static const int kFallbackCount = 1; |
| 621 #endif | 622 #endif |
| 622 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 623 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 623 .Times(kFallbackCount) | 624 .Times(kFallbackCount) |
| 624 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 625 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 625 | 626 |
| 626 // To prevent shared memory issues the sample rate and buffer size should | 627 // To prevent shared memory issues the sample rate and buffer size should |
| 627 // match the input stream parameters. | 628 // match the input stream parameters. |
| 628 EXPECT_CALL(manager(), MakeAudioOutputStream(AllOf( | 629 EXPECT_CALL(manager(), MakeAudioOutputStream(AllOf( |
| 629 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), | 630 testing::Property(&AudioParameters::format, AudioParameters::AUDIO_FAKE), |
| 630 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), | 631 testing::Property(&AudioParameters::sample_rate, params_.sample_rate()), |
| 631 testing::Property( | 632 testing::Property( |
| 632 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())))) | 633 &AudioParameters::frames_per_buffer, params_.frames_per_buffer())), |
| 634 _)) |
| 633 .Times(1) | 635 .Times(1) |
| 634 .WillOnce(Return(&okay_stream)); | 636 .WillOnce(Return(&okay_stream)); |
| 635 EXPECT_CALL(okay_stream, Open()) | 637 EXPECT_CALL(okay_stream, Open()) |
| 636 .WillOnce(Return(true)); | 638 .WillOnce(Return(true)); |
| 637 EXPECT_CALL(okay_stream, Close()) | 639 EXPECT_CALL(okay_stream, Close()) |
| 638 .Times(1); | 640 .Times(1); |
| 639 | 641 |
| 640 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 642 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 641 EXPECT_TRUE(proxy->Open()); | 643 EXPECT_TRUE(proxy->Open()); |
| 642 proxy->Close(); | 644 proxy->Close(); |
| 643 WaitForCloseTimer(kTestCloseDelayMs); | 645 WaitForCloseTimer(kTestCloseDelayMs); |
| 644 } | 646 } |
| 645 | 647 |
| 646 // Simulate failures to open both the low latency, the fallback high latency | 648 // Simulate failures to open both the low latency, the fallback high latency |
| 647 // stream, and the fake audio output stream and ensure AudioOutputResampler | 649 // stream, and the fake audio output stream and ensure AudioOutputResampler |
| 648 // terminates normally. | 650 // terminates normally. |
| 649 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { | 651 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { |
| 650 // Only Windows has a high latency output driver that is not the same as the low | 652 // Only Windows has a high latency output driver that is not the same as the low |
| 651 // latency path. | 653 // latency path. |
| 652 #if defined(OS_WIN) | 654 #if defined(OS_WIN) |
| 653 static const int kFallbackCount = 3; | 655 static const int kFallbackCount = 3; |
| 654 #else | 656 #else |
| 655 static const int kFallbackCount = 2; | 657 static const int kFallbackCount = 2; |
| 656 #endif | 658 #endif |
| 657 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 659 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 658 .Times(kFallbackCount) | 660 .Times(kFallbackCount) |
| 659 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 661 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 660 | 662 |
| 661 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); | 663 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); |
| 662 EXPECT_FALSE(proxy->Open()); | 664 EXPECT_FALSE(proxy->Open()); |
| 663 proxy->Close(); | 665 proxy->Close(); |
| 664 WaitForCloseTimer(kTestCloseDelayMs); | 666 WaitForCloseTimer(kTestCloseDelayMs); |
| 665 } | 667 } |
| 666 | 668 |
| 667 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls | 669 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls |
| 668 // eventually followed by one which fails; root cause of http://crbug.com/150619 | 670 // eventually followed by one which fails; root cause of http://crbug.com/150619 |
| 669 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { | 671 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { |
| 670 MockAudioOutputStream stream1(&manager_, params_); | 672 MockAudioOutputStream stream1(&manager_, params_); |
| 671 MockAudioOutputStream stream2(&manager_, params_); | 673 MockAudioOutputStream stream2(&manager_, params_); |
| 672 MockAudioOutputStream stream3(&manager_, params_); | 674 MockAudioOutputStream stream3(&manager_, params_); |
| 673 | 675 |
| 674 // Setup the mock such that all three streams are successfully created. | 676 // Setup the mock such that all three streams are successfully created. |
| 675 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) | 677 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _)) |
| 676 .WillOnce(Return(&stream1)) | 678 .WillOnce(Return(&stream1)) |
| 677 .WillOnce(Return(&stream2)) | 679 .WillOnce(Return(&stream2)) |
| 678 .WillOnce(Return(&stream3)) | 680 .WillOnce(Return(&stream3)) |
| 679 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); | 681 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); |
| 680 | 682 |
| 681 // Stream1 should be able to successfully open and start. | 683 // Stream1 should be able to successfully open and start. |
| 682 EXPECT_CALL(stream1, Open()) | 684 EXPECT_CALL(stream1, Open()) |
| 683 .WillOnce(Return(true)); | 685 .WillOnce(Return(true)); |
| 684 EXPECT_CALL(stream1, Close()) | 686 EXPECT_CALL(stream1, Close()) |
| 685 .Times(1); | 687 .Times(1); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 WaitForCloseTimer(kTestCloseDelayMs); | 733 WaitForCloseTimer(kTestCloseDelayMs); |
| 732 EXPECT_TRUE(stream1.stop_called()); | 734 EXPECT_TRUE(stream1.stop_called()); |
| 733 EXPECT_TRUE(stream1.start_called()); | 735 EXPECT_TRUE(stream1.start_called()); |
| 734 EXPECT_TRUE(stream2.stop_called()); | 736 EXPECT_TRUE(stream2.stop_called()); |
| 735 EXPECT_TRUE(stream2.start_called()); | 737 EXPECT_TRUE(stream2.start_called()); |
| 736 EXPECT_FALSE(stream3.stop_called()); | 738 EXPECT_FALSE(stream3.stop_called()); |
| 737 EXPECT_FALSE(stream3.start_called()); | 739 EXPECT_FALSE(stream3.start_called()); |
| 738 } | 740 } |
| 739 | 741 |
| 740 } // namespace media | 742 } // namespace media |
| OLD | NEW |