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 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Test that can it be created and closed. | 177 // Test that can it be created and closed. |
178 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 178 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
179 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 179 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
180 if (!audio_man->HasAudioOutputDevices()) { | 180 if (!audio_man->HasAudioOutputDevices()) { |
181 LOG(WARNING) << "No output device detected."; | 181 LOG(WARNING) << "No output device detected."; |
182 return; | 182 return; |
183 } | 183 } |
184 | 184 |
185 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 185 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
186 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 186 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
187 8000, 16, 256)); | 187 8000, 16, 256), |
| 188 std::string()); |
188 ASSERT_TRUE(NULL != oas); | 189 ASSERT_TRUE(NULL != oas); |
189 oas->Close(); | 190 oas->Close(); |
190 } | 191 } |
191 | 192 |
192 // Test that can it be cannot be created with invalid parameters. | 193 // Test that can it be cannot be created with invalid parameters. |
193 TEST(WinAudioTest, SanityOnMakeParams) { | 194 TEST(WinAudioTest, SanityOnMakeParams) { |
194 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 195 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
195 if (!audio_man->HasAudioOutputDevices()) { | 196 if (!audio_man->HasAudioOutputDevices()) { |
196 LOG(WARNING) << "No output device detected."; | 197 LOG(WARNING) << "No output device detected."; |
197 return; | 198 return; |
198 } | 199 } |
199 | 200 |
200 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 201 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
201 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 202 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
202 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 203 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
| 204 std::string())); |
203 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 205 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
204 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); | 206 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), |
| 207 std::string())); |
205 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 208 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
206 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); | 209 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), |
| 210 std::string())); |
207 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 211 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
208 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 212 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
| 213 std::string())); |
209 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 214 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
210 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); | 215 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256), |
| 216 std::string())); |
211 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 217 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
212 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); | 218 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100), |
| 219 std::string())); |
213 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 220 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
214 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); | 221 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0), |
| 222 std::string())); |
215 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 223 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
216 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 224 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, |
217 media::limits::kMaxSamplesPerPacket + 1))); | 225 media::limits::kMaxSamplesPerPacket + 1), |
| 226 std::string())); |
218 } | 227 } |
219 | 228 |
220 // Test that it can be opened and closed. | 229 // Test that it can be opened and closed. |
221 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 230 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
222 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 231 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
223 if (!audio_man->HasAudioOutputDevices()) { | 232 if (!audio_man->HasAudioOutputDevices()) { |
224 LOG(WARNING) << "No output device detected."; | 233 LOG(WARNING) << "No output device detected."; |
225 return; | 234 return; |
226 } | 235 } |
227 | 236 |
228 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 237 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
229 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 238 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
230 8000, 16, 256)); | 239 8000, 16, 256), |
| 240 std::string()); |
231 ASSERT_TRUE(NULL != oas); | 241 ASSERT_TRUE(NULL != oas); |
232 EXPECT_TRUE(oas->Open()); | 242 EXPECT_TRUE(oas->Open()); |
233 oas->Close(); | 243 oas->Close(); |
234 } | 244 } |
235 | 245 |
236 // Test that it has a maximum packet size. | 246 // Test that it has a maximum packet size. |
237 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 247 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
238 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 248 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
239 if (!audio_man->HasAudioOutputDevices()) { | 249 if (!audio_man->HasAudioOutputDevices()) { |
240 LOG(WARNING) << "No output device detected."; | 250 LOG(WARNING) << "No output device detected."; |
241 return; | 251 return; |
242 } | 252 } |
243 | 253 |
244 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 254 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
245 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 255 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
246 8000, 16, 1024 * 1024 * 1024)); | 256 8000, 16, 1024 * 1024 * 1024), |
| 257 std::string()); |
247 EXPECT_TRUE(NULL == oas); | 258 EXPECT_TRUE(NULL == oas); |
248 if (oas) | 259 if (oas) |
249 oas->Close(); | 260 oas->Close(); |
250 } | 261 } |
251 | 262 |
252 // Test potential deadlock situation if the source is slow or blocks for some | 263 // Test potential deadlock situation if the source is slow or blocks for some |
253 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 264 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
254 // the test completes in reasonable time. | 265 // the test completes in reasonable time. |
255 TEST(WinAudioTest, PCMWaveSlowSource) { | 266 TEST(WinAudioTest, PCMWaveSlowSource) { |
256 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 267 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
257 if (!audio_man->HasAudioOutputDevices()) { | 268 if (!audio_man->HasAudioOutputDevices()) { |
258 LOG(WARNING) << "No output device detected."; | 269 LOG(WARNING) << "No output device detected."; |
259 return; | 270 return; |
260 } | 271 } |
261 | 272 |
262 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 273 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
263 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 274 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
264 16000, 16, 256)); | 275 16000, 16, 256), |
| 276 std::string()); |
265 ASSERT_TRUE(NULL != oas); | 277 ASSERT_TRUE(NULL != oas); |
266 TestSourceLaggy test_laggy(2, 90); | 278 TestSourceLaggy test_laggy(2, 90); |
267 EXPECT_TRUE(oas->Open()); | 279 EXPECT_TRUE(oas->Open()); |
268 // The test parameters cause a callback every 32 ms and the source is | 280 // The test parameters cause a callback every 32 ms and the source is |
269 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 281 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
270 oas->Start(&test_laggy); | 282 oas->Start(&test_laggy); |
271 ::Sleep(500); | 283 ::Sleep(500); |
272 EXPECT_GT(test_laggy.callback_count(), 2); | 284 EXPECT_GT(test_laggy.callback_count(), 2); |
273 EXPECT_FALSE(test_laggy.had_error()); | 285 EXPECT_FALSE(test_laggy.had_error()); |
274 oas->Stop(); | 286 oas->Stop(); |
275 ::Sleep(500); | 287 ::Sleep(500); |
276 oas->Close(); | 288 oas->Close(); |
277 } | 289 } |
278 | 290 |
279 // Test another potential deadlock situation if the thread that calls Start() | 291 // Test another potential deadlock situation if the thread that calls Start() |
280 // gets paused. This test is best when run over RDP with audio enabled. See | 292 // gets paused. This test is best when run over RDP with audio enabled. See |
281 // bug 19276 for more details. | 293 // bug 19276 for more details. |
282 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 294 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
283 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 295 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
284 if (!audio_man->HasAudioOutputDevices()) { | 296 if (!audio_man->HasAudioOutputDevices()) { |
285 LOG(WARNING) << "No output device detected."; | 297 LOG(WARNING) << "No output device detected."; |
286 return; | 298 return; |
287 } | 299 } |
288 | 300 |
289 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 301 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
290 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 302 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
291 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 303 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
292 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 304 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 305 std::string()); |
293 ASSERT_TRUE(NULL != oas); | 306 ASSERT_TRUE(NULL != oas); |
294 | 307 |
295 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 308 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
296 | 309 |
297 EXPECT_TRUE(oas->Open()); | 310 EXPECT_TRUE(oas->Open()); |
298 oas->SetVolume(1.0); | 311 oas->SetVolume(1.0); |
299 | 312 |
300 for (int ix = 0; ix != 5; ++ix) { | 313 for (int ix = 0; ix != 5; ++ix) { |
301 oas->Start(&source); | 314 oas->Start(&source); |
302 ::Sleep(10); | 315 ::Sleep(10); |
303 oas->Stop(); | 316 oas->Stop(); |
304 } | 317 } |
305 oas->Close(); | 318 oas->Close(); |
306 } | 319 } |
307 | 320 |
308 | 321 |
309 // This test produces actual audio for .5 seconds on the default wave | 322 // This test produces actual audio for .5 seconds on the default wave |
310 // device at 44.1K s/sec. Parameters have been chosen carefully so you should | 323 // device at 44.1K s/sec. Parameters have been chosen carefully so you should |
311 // not hear pops or noises while the sound is playing. | 324 // not hear pops or noises while the sound is playing. |
312 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 325 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
313 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 326 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
314 if (!audio_man->HasAudioOutputDevices()) { | 327 if (!audio_man->HasAudioOutputDevices()) { |
315 LOG(WARNING) << "No output device detected."; | 328 LOG(WARNING) << "No output device detected."; |
316 return; | 329 return; |
317 } | 330 } |
318 | 331 |
319 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 332 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
320 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 333 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
321 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 334 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
322 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 335 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 336 std::string()); |
323 ASSERT_TRUE(NULL != oas); | 337 ASSERT_TRUE(NULL != oas); |
324 | 338 |
325 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 339 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
326 | 340 |
327 EXPECT_TRUE(oas->Open()); | 341 EXPECT_TRUE(oas->Open()); |
328 oas->SetVolume(1.0); | 342 oas->SetVolume(1.0); |
329 oas->Start(&source); | 343 oas->Start(&source); |
330 ::Sleep(500); | 344 ::Sleep(500); |
331 oas->Stop(); | 345 oas->Stop(); |
332 oas->Close(); | 346 oas->Close(); |
333 } | 347 } |
334 | 348 |
335 // This test produces actual audio for for .5 seconds on the default wave | 349 // This test produces actual audio for for .5 seconds on the default wave |
336 // device at 22K s/sec. Parameters have been chosen carefully so you should | 350 // device at 22K s/sec. Parameters have been chosen carefully so you should |
337 // not hear pops or noises while the sound is playing. The audio also should | 351 // not hear pops or noises while the sound is playing. The audio also should |
338 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 352 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
339 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 353 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
340 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 354 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
341 if (!audio_man->HasAudioOutputDevices()) { | 355 if (!audio_man->HasAudioOutputDevices()) { |
342 LOG(WARNING) << "No output device detected."; | 356 LOG(WARNING) << "No output device detected."; |
343 return; | 357 return; |
344 } | 358 } |
345 | 359 |
346 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 360 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
347 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 361 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
348 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 362 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
349 AudioParameters::kAudioCDSampleRate / 2, 16, | 363 AudioParameters::kAudioCDSampleRate / 2, 16, |
350 samples_100_ms)); | 364 samples_100_ms), |
| 365 std::string()); |
351 ASSERT_TRUE(NULL != oas); | 366 ASSERT_TRUE(NULL != oas); |
352 | 367 |
353 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); | 368 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); |
354 | 369 |
355 EXPECT_TRUE(oas->Open()); | 370 EXPECT_TRUE(oas->Open()); |
356 | 371 |
357 oas->SetVolume(0.5); | 372 oas->SetVolume(0.5); |
358 oas->Start(&source); | 373 oas->Start(&source); |
359 ::Sleep(500); | 374 ::Sleep(500); |
360 | 375 |
(...skipping 18 matching lines...) Expand all Loading... |
379 | 394 |
380 static const int kSampleRate = 16000; | 395 static const int kSampleRate = 16000; |
381 SineWaveAudioSource source(1, 200.0, kSampleRate); | 396 SineWaveAudioSource source(1, 200.0, kSampleRate); |
382 // Compute buffer size for 100ms of audio. | 397 // Compute buffer size for 100ms of audio. |
383 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; | 398 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; |
384 // Restrict SineWaveAudioSource to 100ms of samples. | 399 // Restrict SineWaveAudioSource to 100ms of samples. |
385 source.CapSamples(kSamples100ms); | 400 source.CapSamples(kSamples100ms); |
386 | 401 |
387 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 402 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
388 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 403 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
389 kSampleRate, 16, kSamples100ms)); | 404 kSampleRate, 16, kSamples100ms), |
| 405 std::string()); |
390 ASSERT_TRUE(NULL != oas); | 406 ASSERT_TRUE(NULL != oas); |
391 | 407 |
392 EXPECT_TRUE(oas->Open()); | 408 EXPECT_TRUE(oas->Open()); |
393 | 409 |
394 oas->SetVolume(1.0); | 410 oas->SetVolume(1.0); |
395 oas->Start(&source); | 411 oas->Start(&source); |
396 | 412 |
397 // We buffer and play at the same time, buffering happens every ~10ms and the | 413 // We buffer and play at the same time, buffering happens every ~10ms and the |
398 // consuming of the buffer happens every ~100ms. We do 100 buffers which | 414 // consuming of the buffer happens every ~100ms. We do 100 buffers which |
399 // effectively wrap around the file more than once. | 415 // effectively wrap around the file more than once. |
(...skipping 15 matching lines...) Expand all Loading... |
415 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 431 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
416 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 432 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
417 if (!audio_man->HasAudioOutputDevices()) { | 433 if (!audio_man->HasAudioOutputDevices()) { |
418 LOG(WARNING) << "No output device detected."; | 434 LOG(WARNING) << "No output device detected."; |
419 return; | 435 return; |
420 } | 436 } |
421 | 437 |
422 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 438 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
423 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 439 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
424 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 440 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
425 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 441 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 442 std::string()); |
426 ASSERT_TRUE(NULL != oas); | 443 ASSERT_TRUE(NULL != oas); |
427 | 444 |
428 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 445 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
429 EXPECT_TRUE(oas->Open()); | 446 EXPECT_TRUE(oas->Open()); |
430 oas->SetVolume(1.0); | 447 oas->SetVolume(1.0); |
431 | 448 |
432 // Play the wave for .5 seconds. | 449 // Play the wave for .5 seconds. |
433 oas->Start(&source); | 450 oas->Start(&source); |
434 ::Sleep(500); | 451 ::Sleep(500); |
435 oas->Stop(); | 452 oas->Stop(); |
(...skipping 25 matching lines...) Expand all Loading... |
461 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 478 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
462 // Take the existing native sample rate into account. | 479 // Take the existing native sample rate into account. |
463 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); | 480 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); |
464 int sample_rate = params.sample_rate(); | 481 int sample_rate = params.sample_rate(); |
465 uint32 samples_10_ms = sample_rate / 100; | 482 uint32 samples_10_ms = sample_rate / 100; |
466 int n = 1; | 483 int n = 1; |
467 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 484 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
468 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 485 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
469 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 486 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
470 CHANNEL_LAYOUT_MONO, sample_rate, | 487 CHANNEL_LAYOUT_MONO, sample_rate, |
471 16, n * samples_10_ms)); | 488 16, n * samples_10_ms), |
| 489 std::string()); |
472 ASSERT_TRUE(NULL != oas); | 490 ASSERT_TRUE(NULL != oas); |
473 | 491 |
474 SineWaveAudioSource source(1, 200, sample_rate); | 492 SineWaveAudioSource source(1, 200, sample_rate); |
475 | 493 |
476 bool opened = oas->Open(); | 494 bool opened = oas->Open(); |
477 if (!opened) { | 495 if (!opened) { |
478 // It was not possible to open this audio device in mono. | 496 // It was not possible to open this audio device in mono. |
479 // No point in continuing the test so let's break here. | 497 // No point in continuing the test so let's break here. |
480 LOG(WARNING) << "Mono is not supported. Skipping test."; | 498 LOG(WARNING) << "Mono is not supported. Skipping test."; |
481 oas->Close(); | 499 oas->Close(); |
(...skipping 12 matching lines...) Expand all Loading... |
494 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 512 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
495 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 513 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
496 if (!audio_man->HasAudioOutputDevices()) { | 514 if (!audio_man->HasAudioOutputDevices()) { |
497 LOG(WARNING) << "No output device detected."; | 515 LOG(WARNING) << "No output device detected."; |
498 return; | 516 return; |
499 } | 517 } |
500 | 518 |
501 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 519 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
502 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 520 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
503 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 521 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
504 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 522 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
| 523 std::string()); |
505 ASSERT_TRUE(NULL != oas); | 524 ASSERT_TRUE(NULL != oas); |
506 | 525 |
507 NiceMock<MockAudioSource> source; | 526 NiceMock<MockAudioSource> source; |
508 EXPECT_TRUE(oas->Open()); | 527 EXPECT_TRUE(oas->Open()); |
509 | 528 |
510 uint32 bytes_100_ms = samples_100_ms * 2; | 529 uint32 bytes_100_ms = samples_100_ms * 2; |
511 | 530 |
512 // Audio output stream has either a double or triple buffer scheme. | 531 // Audio output stream has either a double or triple buffer scheme. |
513 // We expect the amount of pending bytes will reaching up to 2 times of | 532 // We expect the amount of pending bytes will reaching up to 2 times of |
514 // |bytes_100_ms| depending on number of buffers used. | 533 // |bytes_100_ms| depending on number of buffers used. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 LOG(WARNING) << "No output device detected."; | 672 LOG(WARNING) << "No output device detected."; |
654 return; | 673 return; |
655 } | 674 } |
656 | 675 |
657 static const int sample_rate = AudioParameters::kAudioCDSampleRate; | 676 static const int sample_rate = AudioParameters::kAudioCDSampleRate; |
658 static const uint32 kSamples20ms = sample_rate / 50; | 677 static const uint32 kSamples20ms = sample_rate / 50; |
659 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 678 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
660 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); | 679 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); |
661 | 680 |
662 | 681 |
663 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); | 682 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, |
| 683 std::string()); |
664 ASSERT_TRUE(NULL != oas); | 684 ASSERT_TRUE(NULL != oas); |
665 | 685 |
666 ASSERT_TRUE(oas->Open()); | 686 ASSERT_TRUE(oas->Open()); |
667 | 687 |
668 base::SyncSocket sockets[2]; | 688 base::SyncSocket sockets[2]; |
669 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); | 689 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); |
670 | 690 |
671 SyncSocketSource source(&sockets[0], params); | 691 SyncSocketSource source(&sockets[0], params); |
672 | 692 |
673 SyncThreadContext thread_context; | 693 SyncThreadContext thread_context; |
(...skipping 10 matching lines...) Expand all Loading... |
684 oas->Start(&source); | 704 oas->Start(&source); |
685 | 705 |
686 ::WaitForSingleObject(thread, INFINITE); | 706 ::WaitForSingleObject(thread, INFINITE); |
687 ::CloseHandle(thread); | 707 ::CloseHandle(thread); |
688 | 708 |
689 oas->Stop(); | 709 oas->Stop(); |
690 oas->Close(); | 710 oas->Close(); |
691 } | 711 } |
692 | 712 |
693 } // namespace media | 713 } // namespace media |
OLD | NEW |