| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
| 13 #include "base/memory/aligned_memory.h" | 13 #include "base/memory/aligned_memory.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/sync_socket.h" | 17 #include "base/sync_socket.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "base/win/scoped_com_initializer.h" | 19 #include "base/win/scoped_com_initializer.h" |
| 19 #include "base/win/windows_version.h" | 20 #include "base/win/windows_version.h" |
| 21 #include "media/audio/audio_device_info_accessor_for_tests.h" |
| 20 #include "media/audio/audio_io.h" | 22 #include "media/audio/audio_io.h" |
| 21 #include "media/audio/audio_manager.h" | 23 #include "media/audio/audio_manager.h" |
| 22 #include "media/audio/audio_unittest_util.h" | 24 #include "media/audio/audio_unittest_util.h" |
| 23 #include "media/audio/mock_audio_source_callback.h" | 25 #include "media/audio/mock_audio_source_callback.h" |
| 24 #include "media/audio/simple_sources.h" | 26 #include "media/audio/simple_sources.h" |
| 25 #include "media/base/limits.h" | 27 #include "media/base/limits.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 30 |
| 29 using ::testing::_; | 31 using ::testing::_; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 HANDLE fmap_; | 150 HANDLE fmap_; |
| 149 char* start_; | 151 char* start_; |
| 150 uint32_t size_; | 152 uint32_t size_; |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 class WinAudioTest : public ::testing::Test { | 155 class WinAudioTest : public ::testing::Test { |
| 154 public: | 156 public: |
| 155 WinAudioTest() { | 157 WinAudioTest() { |
| 156 audio_manager_ = | 158 audio_manager_ = |
| 157 AudioManager::CreateForTesting(message_loop_.task_runner()); | 159 AudioManager::CreateForTesting(message_loop_.task_runner()); |
| 160 audio_manager_device_info_ = |
| 161 base::MakeUnique<AudioDeviceInfoAccessorForTests>(audio_manager_.get()); |
| 158 base::RunLoop().RunUntilIdle(); | 162 base::RunLoop().RunUntilIdle(); |
| 159 } | 163 } |
| 160 ~WinAudioTest() override { | 164 ~WinAudioTest() override { |
| 165 audio_manager_device_info_.reset(); |
| 161 audio_manager_.reset(); | 166 audio_manager_.reset(); |
| 162 base::RunLoop().RunUntilIdle(); | 167 base::RunLoop().RunUntilIdle(); |
| 163 } | 168 } |
| 164 | 169 |
| 165 protected: | 170 protected: |
| 166 base::MessageLoop message_loop_; | 171 base::MessageLoop message_loop_; |
| 167 ScopedAudioManagerPtr audio_manager_; | 172 ScopedAudioManagerPtr audio_manager_; |
| 173 std::unique_ptr<AudioDeviceInfoAccessorForTests> audio_manager_device_info_; |
| 168 }; | 174 }; |
| 169 | 175 |
| 170 // =========================================================================== | 176 // =========================================================================== |
| 171 // Validation of AudioManager::AUDIO_PCM_LINEAR | 177 // Validation of AudioManager::AUDIO_PCM_LINEAR |
| 172 // | 178 // |
| 173 // NOTE: | 179 // NOTE: |
| 174 // The tests can fail on the build bots when somebody connects to them via | 180 // The tests can fail on the build bots when somebody connects to them via |
| 175 // remote-desktop and the rdp client installs an audio device that fails to open | 181 // remote-desktop and the rdp client installs an audio device that fails to open |
| 176 // at some point, possibly when the connection goes idle. | 182 // at some point, possibly when the connection goes idle. |
| 177 | 183 |
| 178 // Test that can it be created and closed. | 184 // Test that can it be created and closed. |
| 179 TEST_F(WinAudioTest, PCMWaveStreamGetAndClose) { | 185 TEST_F(WinAudioTest, PCMWaveStreamGetAndClose) { |
| 180 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 186 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 181 | 187 |
| 182 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 188 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 183 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 189 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 184 8000, 16, 256), | 190 8000, 16, 256), |
| 185 std::string(), AudioManager::LogCallback()); | 191 std::string(), AudioManager::LogCallback()); |
| 186 ASSERT_TRUE(NULL != oas); | 192 ASSERT_TRUE(NULL != oas); |
| 187 oas->Close(); | 193 oas->Close(); |
| 188 } | 194 } |
| 189 | 195 |
| 190 // Test that can it be cannot be created with invalid parameters. | 196 // Test that can it be cannot be created with invalid parameters. |
| 191 TEST_F(WinAudioTest, SanityOnMakeParams) { | 197 TEST_F(WinAudioTest, SanityOnMakeParams) { |
| 192 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 198 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 193 | 199 |
| 194 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 200 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
| 195 EXPECT_TRUE( | 201 EXPECT_TRUE( |
| 196 NULL == | 202 NULL == |
| 197 audio_manager_->MakeAudioOutputStream( | 203 audio_manager_->MakeAudioOutputStream( |
| 198 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), | 204 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
| 199 std::string(), AudioManager::LogCallback())); | 205 std::string(), AudioManager::LogCallback())); |
| 200 EXPECT_TRUE( | 206 EXPECT_TRUE( |
| 201 NULL == | 207 NULL == |
| 202 audio_manager_->MakeAudioOutputStream( | 208 audio_manager_->MakeAudioOutputStream( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 225 std::string(), AudioManager::LogCallback())); | 231 std::string(), AudioManager::LogCallback())); |
| 226 EXPECT_TRUE(NULL == | 232 EXPECT_TRUE(NULL == |
| 227 audio_manager_->MakeAudioOutputStream( | 233 audio_manager_->MakeAudioOutputStream( |
| 228 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 234 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, |
| 229 media::limits::kMaxSamplesPerPacket + 1), | 235 media::limits::kMaxSamplesPerPacket + 1), |
| 230 std::string(), AudioManager::LogCallback())); | 236 std::string(), AudioManager::LogCallback())); |
| 231 } | 237 } |
| 232 | 238 |
| 233 // Test that it can be opened and closed. | 239 // Test that it can be opened and closed. |
| 234 TEST_F(WinAudioTest, PCMWaveStreamOpenAndClose) { | 240 TEST_F(WinAudioTest, PCMWaveStreamOpenAndClose) { |
| 235 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 241 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 236 | 242 |
| 237 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 243 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 238 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 244 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 239 8000, 16, 256), | 245 8000, 16, 256), |
| 240 std::string(), AudioManager::LogCallback()); | 246 std::string(), AudioManager::LogCallback()); |
| 241 ASSERT_TRUE(NULL != oas); | 247 ASSERT_TRUE(NULL != oas); |
| 242 EXPECT_TRUE(oas->Open()); | 248 EXPECT_TRUE(oas->Open()); |
| 243 oas->Close(); | 249 oas->Close(); |
| 244 } | 250 } |
| 245 | 251 |
| 246 // Test that it has a maximum packet size. | 252 // Test that it has a maximum packet size. |
| 247 TEST_F(WinAudioTest, PCMWaveStreamOpenLimit) { | 253 TEST_F(WinAudioTest, PCMWaveStreamOpenLimit) { |
| 248 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 254 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 249 | 255 |
| 250 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 256 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 251 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 257 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
| 252 8000, 16, 1024 * 1024 * 1024), | 258 8000, 16, 1024 * 1024 * 1024), |
| 253 std::string(), AudioManager::LogCallback()); | 259 std::string(), AudioManager::LogCallback()); |
| 254 EXPECT_TRUE(NULL == oas); | 260 EXPECT_TRUE(NULL == oas); |
| 255 if (oas) | 261 if (oas) |
| 256 oas->Close(); | 262 oas->Close(); |
| 257 } | 263 } |
| 258 | 264 |
| 259 // Test potential deadlock situation if the source is slow or blocks for some | 265 // Test potential deadlock situation if the source is slow or blocks for some |
| 260 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 266 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
| 261 // the test completes in reasonable time. | 267 // the test completes in reasonable time. |
| 262 TEST_F(WinAudioTest, PCMWaveSlowSource) { | 268 TEST_F(WinAudioTest, PCMWaveSlowSource) { |
| 263 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 269 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 264 | 270 |
| 265 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 271 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 266 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 272 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 267 16000, 16, 256), | 273 16000, 16, 256), |
| 268 std::string(), AudioManager::LogCallback()); | 274 std::string(), AudioManager::LogCallback()); |
| 269 ASSERT_TRUE(NULL != oas); | 275 ASSERT_TRUE(NULL != oas); |
| 270 TestSourceLaggy test_laggy(90); | 276 TestSourceLaggy test_laggy(90); |
| 271 EXPECT_TRUE(oas->Open()); | 277 EXPECT_TRUE(oas->Open()); |
| 272 // The test parameters cause a callback every 32 ms and the source is | 278 // The test parameters cause a callback every 32 ms and the source is |
| 273 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 279 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
| 274 oas->Start(&test_laggy); | 280 oas->Start(&test_laggy); |
| 275 ::Sleep(500); | 281 ::Sleep(500); |
| 276 EXPECT_GT(test_laggy.callback_count(), 2); | 282 EXPECT_GT(test_laggy.callback_count(), 2); |
| 277 EXPECT_FALSE(test_laggy.had_error()); | 283 EXPECT_FALSE(test_laggy.had_error()); |
| 278 oas->Stop(); | 284 oas->Stop(); |
| 279 ::Sleep(500); | 285 ::Sleep(500); |
| 280 oas->Close(); | 286 oas->Close(); |
| 281 } | 287 } |
| 282 | 288 |
| 283 // Test another potential deadlock situation if the thread that calls Start() | 289 // Test another potential deadlock situation if the thread that calls Start() |
| 284 // gets paused. This test is best when run over RDP with audio enabled. See | 290 // gets paused. This test is best when run over RDP with audio enabled. See |
| 285 // bug 19276 for more details. | 291 // bug 19276 for more details. |
| 286 TEST_F(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 292 TEST_F(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
| 287 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 293 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 288 | 294 |
| 289 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 295 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 290 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 296 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 291 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 297 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 292 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 298 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 293 std::string(), AudioManager::LogCallback()); | 299 std::string(), AudioManager::LogCallback()); |
| 294 ASSERT_TRUE(NULL != oas); | 300 ASSERT_TRUE(NULL != oas); |
| 295 | 301 |
| 296 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 302 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
| 297 | 303 |
| 298 EXPECT_TRUE(oas->Open()); | 304 EXPECT_TRUE(oas->Open()); |
| 299 oas->SetVolume(1.0); | 305 oas->SetVolume(1.0); |
| 300 | 306 |
| 301 for (int ix = 0; ix != 5; ++ix) { | 307 for (int ix = 0; ix != 5; ++ix) { |
| 302 oas->Start(&source); | 308 oas->Start(&source); |
| 303 ::Sleep(10); | 309 ::Sleep(10); |
| 304 oas->Stop(); | 310 oas->Stop(); |
| 305 } | 311 } |
| 306 oas->Close(); | 312 oas->Close(); |
| 307 } | 313 } |
| 308 | 314 |
| 309 | 315 |
| 310 // This test produces actual audio for .5 seconds on the default wave | 316 // This test produces actual audio for .5 seconds on the default wave |
| 311 // device at 44.1K s/sec. Parameters have been chosen carefully so you should | 317 // device at 44.1K s/sec. Parameters have been chosen carefully so you should |
| 312 // not hear pops or noises while the sound is playing. | 318 // not hear pops or noises while the sound is playing. |
| 313 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 319 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
| 314 if (!audio_manager_->HasAudioOutputDevices()) { | 320 if (!audio_manager_device_info_->HasAudioOutputDevices()) { |
| 315 LOG(WARNING) << "No output device detected."; | 321 LOG(WARNING) << "No output device detected."; |
| 316 return; | 322 return; |
| 317 } | 323 } |
| 318 | 324 |
| 319 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 325 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 320 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 326 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 321 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 327 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 322 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 328 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 323 std::string(), AudioManager::LogCallback()); | 329 std::string(), AudioManager::LogCallback()); |
| 324 ASSERT_TRUE(NULL != oas); | 330 ASSERT_TRUE(NULL != oas); |
| 325 | 331 |
| 326 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 332 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
| 327 | 333 |
| 328 EXPECT_TRUE(oas->Open()); | 334 EXPECT_TRUE(oas->Open()); |
| 329 oas->SetVolume(1.0); | 335 oas->SetVolume(1.0); |
| 330 oas->Start(&source); | 336 oas->Start(&source); |
| 331 ::Sleep(500); | 337 ::Sleep(500); |
| 332 oas->Stop(); | 338 oas->Stop(); |
| 333 oas->Close(); | 339 oas->Close(); |
| 334 } | 340 } |
| 335 | 341 |
| 336 // This test produces actual audio for for .5 seconds on the default wave | 342 // This test produces actual audio for for .5 seconds on the default wave |
| 337 // device at 22K s/sec. Parameters have been chosen carefully so you should | 343 // device at 22K s/sec. Parameters have been chosen carefully so you should |
| 338 // not hear pops or noises while the sound is playing. The audio also should | 344 // not hear pops or noises while the sound is playing. The audio also should |
| 339 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 345 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
| 340 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 346 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
| 341 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 347 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 342 | 348 |
| 343 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 349 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
| 344 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 350 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 345 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 351 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 346 AudioParameters::kAudioCDSampleRate / 2, 16, | 352 AudioParameters::kAudioCDSampleRate / 2, 16, |
| 347 samples_100_ms), | 353 samples_100_ms), |
| 348 std::string(), AudioManager::LogCallback()); | 354 std::string(), AudioManager::LogCallback()); |
| 349 ASSERT_TRUE(NULL != oas); | 355 ASSERT_TRUE(NULL != oas); |
| 350 | 356 |
| 351 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); | 357 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 362 EXPECT_LT(volume, 0.51); | 368 EXPECT_LT(volume, 0.51); |
| 363 EXPECT_GT(volume, 0.49); | 369 EXPECT_GT(volume, 0.49); |
| 364 oas->Stop(); | 370 oas->Stop(); |
| 365 oas->Close(); | 371 oas->Close(); |
| 366 } | 372 } |
| 367 | 373 |
| 368 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We | 374 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We |
| 369 // try hard to generate situation where the two threads are accessing the | 375 // try hard to generate situation where the two threads are accessing the |
| 370 // object roughly at the same time. | 376 // object roughly at the same time. |
| 371 TEST_F(WinAudioTest, PushSourceFile16KHz) { | 377 TEST_F(WinAudioTest, PushSourceFile16KHz) { |
| 372 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 378 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 373 | 379 |
| 374 static const int kSampleRate = 16000; | 380 static const int kSampleRate = 16000; |
| 375 SineWaveAudioSource source(1, 200.0, kSampleRate); | 381 SineWaveAudioSource source(1, 200.0, kSampleRate); |
| 376 // Compute buffer size for 100ms of audio. | 382 // Compute buffer size for 100ms of audio. |
| 377 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100; | 383 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100; |
| 378 // Restrict SineWaveAudioSource to 100ms of samples. | 384 // Restrict SineWaveAudioSource to 100ms of samples. |
| 379 source.CapSamples(kSamples100ms); | 385 source.CapSamples(kSamples100ms); |
| 380 | 386 |
| 381 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 387 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 382 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 388 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 401 ::Sleep(500); | 407 ::Sleep(500); |
| 402 | 408 |
| 403 oas->Stop(); | 409 oas->Stop(); |
| 404 oas->Close(); | 410 oas->Close(); |
| 405 } | 411 } |
| 406 | 412 |
| 407 // This test is to make sure an AudioOutputStream can be started after it was | 413 // This test is to make sure an AudioOutputStream can be started after it was |
| 408 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds | 414 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds |
| 409 // of silence. | 415 // of silence. |
| 410 TEST_F(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 416 TEST_F(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
| 411 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 417 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 412 | 418 |
| 413 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 419 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 414 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 420 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 415 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 421 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 416 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 422 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 417 std::string(), AudioManager::LogCallback()); | 423 std::string(), AudioManager::LogCallback()); |
| 418 ASSERT_TRUE(NULL != oas); | 424 ASSERT_TRUE(NULL != oas); |
| 419 | 425 |
| 420 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 426 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
| 421 EXPECT_TRUE(oas->Open()); | 427 EXPECT_TRUE(oas->Open()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 434 ::Sleep(500); | 440 ::Sleep(500); |
| 435 oas->Stop(); | 441 oas->Stop(); |
| 436 | 442 |
| 437 oas->Close(); | 443 oas->Close(); |
| 438 } | 444 } |
| 439 | 445 |
| 440 // With the low latency mode, WASAPI is utilized by default for Vista and | 446 // With the low latency mode, WASAPI is utilized by default for Vista and |
| 441 // higher and Wave is used for XP and lower. It is possible to utilize a | 447 // higher and Wave is used for XP and lower. It is possible to utilize a |
| 442 // smaller buffer size for WASAPI than for Wave. | 448 // smaller buffer size for WASAPI than for Wave. |
| 443 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { | 449 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { |
| 444 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 450 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 445 | 451 |
| 446 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 452 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
| 447 // Take the existing native sample rate into account. | 453 // Take the existing native sample rate into account. |
| 448 const AudioParameters params = | 454 const AudioParameters params = |
| 449 audio_manager_->GetDefaultOutputStreamParameters(); | 455 audio_manager_device_info_->GetDefaultOutputStreamParameters(); |
| 450 int sample_rate = params.sample_rate(); | 456 int sample_rate = params.sample_rate(); |
| 451 uint32_t samples_10_ms = sample_rate / 100; | 457 uint32_t samples_10_ms = sample_rate / 100; |
| 452 int n = 1; | 458 int n = 1; |
| 453 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 459 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
| 454 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 460 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 455 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 461 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 456 CHANNEL_LAYOUT_MONO, sample_rate, 16, n * samples_10_ms), | 462 CHANNEL_LAYOUT_MONO, sample_rate, 16, n * samples_10_ms), |
| 457 std::string(), AudioManager::LogCallback()); | 463 std::string(), AudioManager::LogCallback()); |
| 458 ASSERT_TRUE(NULL != oas); | 464 ASSERT_TRUE(NULL != oas); |
| 459 | 465 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 471 | 477 |
| 472 // Play the wave for .8 seconds. | 478 // Play the wave for .8 seconds. |
| 473 oas->Start(&source); | 479 oas->Start(&source); |
| 474 ::Sleep(800); | 480 ::Sleep(800); |
| 475 oas->Stop(); | 481 oas->Stop(); |
| 476 oas->Close(); | 482 oas->Close(); |
| 477 } | 483 } |
| 478 | 484 |
| 479 // Check that the pending bytes value is correct what the stream starts. | 485 // Check that the pending bytes value is correct what the stream starts. |
| 480 TEST_F(WinAudioTest, PCMWaveStreamPendingBytes) { | 486 TEST_F(WinAudioTest, PCMWaveStreamPendingBytes) { |
| 481 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 487 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 482 | 488 |
| 483 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 489 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
| 484 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 490 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 485 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 491 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
| 486 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 492 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 487 std::string(), AudioManager::LogCallback()); | 493 std::string(), AudioManager::LogCallback()); |
| 488 ASSERT_TRUE(NULL != oas); | 494 ASSERT_TRUE(NULL != oas); |
| 489 | 495 |
| 490 NiceMock<MockAudioSourceCallback> source; | 496 NiceMock<MockAudioSourceCallback> source; |
| 491 EXPECT_TRUE(oas->Open()); | 497 EXPECT_TRUE(oas->Open()); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 | 624 |
| 619 // Test the basic operation of AudioOutputStream used with a SyncSocket. | 625 // Test the basic operation of AudioOutputStream used with a SyncSocket. |
| 620 // The emphasis is to verify that it is possible to feed data to the audio | 626 // The emphasis is to verify that it is possible to feed data to the audio |
| 621 // layer using a source based on SyncSocket. In a real situation we would | 627 // layer using a source based on SyncSocket. In a real situation we would |
| 622 // go for the low-latency version in combination with SyncSocket, but to keep | 628 // go for the low-latency version in combination with SyncSocket, but to keep |
| 623 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main | 629 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main |
| 624 // principle of the test still remains and we avoid the additional complexity | 630 // principle of the test still remains and we avoid the additional complexity |
| 625 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. | 631 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. |
| 626 // In this test you should hear a continuous 200Hz tone for 2 seconds. | 632 // In this test you should hear a continuous 200Hz tone for 2 seconds. |
| 627 TEST_F(WinAudioTest, SyncSocketBasic) { | 633 TEST_F(WinAudioTest, SyncSocketBasic) { |
| 628 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); | 634 ABORT_AUDIO_TEST_IF_NOT(audio_manager_device_info_->HasAudioOutputDevices()); |
| 629 | 635 |
| 630 static const int sample_rate = AudioParameters::kAudioCDSampleRate; | 636 static const int sample_rate = AudioParameters::kAudioCDSampleRate; |
| 631 static const uint32_t kSamples20ms = sample_rate / 50; | 637 static const uint32_t kSamples20ms = sample_rate / 50; |
| 632 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 638 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
| 633 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); | 639 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); |
| 634 | 640 |
| 635 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( | 641 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( |
| 636 params, std::string(), AudioManager::LogCallback()); | 642 params, std::string(), AudioManager::LogCallback()); |
| 637 ASSERT_TRUE(NULL != oas); | 643 ASSERT_TRUE(NULL != oas); |
| 638 | 644 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 658 oas->Start(&source); | 664 oas->Start(&source); |
| 659 | 665 |
| 660 ::WaitForSingleObject(thread, INFINITE); | 666 ::WaitForSingleObject(thread, INFINITE); |
| 661 ::CloseHandle(thread); | 667 ::CloseHandle(thread); |
| 662 | 668 |
| 663 oas->Stop(); | 669 oas->Stop(); |
| 664 oas->Close(); | 670 oas->Close(); |
| 665 } | 671 } |
| 666 | 672 |
| 667 } // namespace media | 673 } // namespace media |
| OLD | NEW |