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/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 HANDLE fmap_; | 190 HANDLE fmap_; |
191 char* start_; | 191 char* start_; |
192 uint32 size_; | 192 uint32 size_; |
193 }; | 193 }; |
194 | 194 |
195 // ============================================================================ | 195 // ============================================================================ |
196 // Validate that the AudioManager::AUDIO_MOCK callbacks work. | 196 // Validate that the AudioManager::AUDIO_MOCK callbacks work. |
197 TEST(WinAudioTest, MockStreamBasicCallbacks) { | 197 TEST(WinAudioTest, MockStreamBasicCallbacks) { |
198 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 198 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
199 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 199 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
200 AudioParameters(AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_STEREO, 8000, | 200 AudioParameters(AudioParameters::AUDIO_MOCK, false, |
201 8, 128)); | 201 CHANNEL_LAYOUT_STEREO, 8000, 8, 128)); |
202 ASSERT_TRUE(NULL != oas); | 202 ASSERT_TRUE(NULL != oas); |
203 EXPECT_TRUE(oas->Open()); | 203 EXPECT_TRUE(oas->Open()); |
204 TestSourceBasic source; | 204 TestSourceBasic source; |
205 oas->Start(&source); | 205 oas->Start(&source); |
206 EXPECT_GT(source.callback_count(), 0); | 206 EXPECT_GT(source.callback_count(), 0); |
207 oas->Stop(); | 207 oas->Stop(); |
208 oas->Close(); | 208 oas->Close(); |
209 EXPECT_EQ(0, source.had_error()); | 209 EXPECT_EQ(0, source.had_error()); |
210 } | 210 } |
211 | 211 |
212 // =========================================================================== | 212 // =========================================================================== |
213 // Validation of AudioManager::AUDIO_PCM_LINEAR | 213 // Validation of AudioManager::AUDIO_PCM_LINEAR |
214 // | 214 // |
215 // NOTE: | 215 // NOTE: |
216 // The tests can fail on the build bots when somebody connects to them via | 216 // The tests can fail on the build bots when somebody connects to them via |
217 // remote-desktop and the rdp client installs an audio device that fails to open | 217 // remote-desktop and the rdp client installs an audio device that fails to open |
218 // at some point, possibly when the connection goes idle. | 218 // at some point, possibly when the connection goes idle. |
219 | 219 |
220 // Test that can it be created and closed. | 220 // Test that can it be created and closed. |
221 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 221 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
222 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 222 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
223 if (!audio_man->HasAudioOutputDevices()) { | 223 if (!audio_man->HasAudioOutputDevices()) { |
224 LOG(WARNING) << "No output device detected."; | 224 LOG(WARNING) << "No output device detected."; |
225 return; | 225 return; |
226 } | 226 } |
227 | 227 |
228 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 228 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
229 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 229 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
230 8000, 16, 256)); | 230 CHANNEL_LAYOUT_STEREO, 8000, 16, 256)); |
231 ASSERT_TRUE(NULL != oas); | 231 ASSERT_TRUE(NULL != oas); |
232 oas->Close(); | 232 oas->Close(); |
233 } | 233 } |
234 | 234 |
235 // Test that can it be cannot be created with invalid parameters. | 235 // Test that can it be cannot be created with invalid parameters. |
236 TEST(WinAudioTest, SanityOnMakeParams) { | 236 TEST(WinAudioTest, SanityOnMakeParams) { |
237 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 237 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
238 if (!audio_man->HasAudioOutputDevices()) { | 238 if (!audio_man->HasAudioOutputDevices()) { |
239 LOG(WARNING) << "No output device detected."; | 239 LOG(WARNING) << "No output device detected."; |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 243 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
244 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 244 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
245 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 245 AudioParameters(fmt, false, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); |
246 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 246 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
247 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); | 247 AudioParameters(fmt, false, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256))); |
248 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 248 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
249 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); | 249 AudioParameters(fmt, false, CHANNEL_LAYOUT_STEREO, 8000, 80, 256))); |
250 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 250 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
251 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); | 251 AudioParameters(fmt, false, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256))); |
252 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 252 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
253 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); | 253 AudioParameters(fmt, false, CHANNEL_LAYOUT_STEREO, -8000, 16, 256))); |
254 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 254 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
255 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); | 255 AudioParameters(fmt, false, CHANNEL_LAYOUT_MONO, 8000, 16, -100))); |
256 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 256 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
257 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); | 257 AudioParameters(fmt, false, CHANNEL_LAYOUT_MONO, 8000, 16, 0))); |
258 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 258 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
259 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 259 AudioParameters(fmt, false, CHANNEL_LAYOUT_MONO, 8000, 16, |
260 media::limits::kMaxSamplesPerPacket + 1))); | 260 media::limits::kMaxSamplesPerPacket + 1))); |
261 } | 261 } |
262 | 262 |
263 // Test that it can be opened and closed. | 263 // Test that it can be opened and closed. |
264 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 264 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
265 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 265 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
266 if (!audio_man->HasAudioOutputDevices()) { | 266 if (!audio_man->HasAudioOutputDevices()) { |
267 LOG(WARNING) << "No output device detected."; | 267 LOG(WARNING) << "No output device detected."; |
268 return; | 268 return; |
269 } | 269 } |
270 | 270 |
271 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 271 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
272 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 272 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
273 8000, 16, 256)); | 273 CHANNEL_LAYOUT_STEREO, 8000, 16, 256)); |
274 ASSERT_TRUE(NULL != oas); | 274 ASSERT_TRUE(NULL != oas); |
275 EXPECT_TRUE(oas->Open()); | 275 EXPECT_TRUE(oas->Open()); |
276 oas->Close(); | 276 oas->Close(); |
277 } | 277 } |
278 | 278 |
279 // Test that it has a maximum packet size. | 279 // Test that it has a maximum packet size. |
280 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 280 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
281 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 281 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
282 if (!audio_man->HasAudioOutputDevices()) { | 282 if (!audio_man->HasAudioOutputDevices()) { |
283 LOG(WARNING) << "No output device detected."; | 283 LOG(WARNING) << "No output device detected."; |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 287 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
288 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 288 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
289 8000, 16, 1024 * 1024 * 1024)); | 289 CHANNEL_LAYOUT_STEREO, 8000, 16, 1024 * 1024 * 1024)); |
290 EXPECT_TRUE(NULL == oas); | 290 EXPECT_TRUE(NULL == oas); |
291 if (oas) | 291 if (oas) |
292 oas->Close(); | 292 oas->Close(); |
293 } | 293 } |
294 | 294 |
295 // Test that it uses the triple buffers correctly. Because it uses the actual | 295 // Test that it uses the triple buffers correctly. Because it uses the actual |
296 // audio device, you might hear a short pop noise for a short time. | 296 // audio device, you might hear a short pop noise for a short time. |
297 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { | 297 TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { |
298 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 298 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
299 if (!audio_man->HasAudioOutputDevices()) { | 299 if (!audio_man->HasAudioOutputDevices()) { |
300 LOG(WARNING) << "No output device detected."; | 300 LOG(WARNING) << "No output device detected."; |
301 return; | 301 return; |
302 } | 302 } |
303 | 303 |
304 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 304 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
305 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 305 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
306 16000, 16, 256)); | 306 CHANNEL_LAYOUT_MONO, 16000, 16, 256)); |
307 ASSERT_TRUE(NULL != oas); | 307 ASSERT_TRUE(NULL != oas); |
308 TestSourceTripleBuffer test_triple_buffer; | 308 TestSourceTripleBuffer test_triple_buffer; |
309 EXPECT_TRUE(oas->Open()); | 309 EXPECT_TRUE(oas->Open()); |
310 oas->Start(&test_triple_buffer); | 310 oas->Start(&test_triple_buffer); |
311 ::Sleep(300); | 311 ::Sleep(300); |
312 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); | 312 EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); |
313 EXPECT_FALSE(test_triple_buffer.had_error()); | 313 EXPECT_FALSE(test_triple_buffer.had_error()); |
314 oas->Stop(); | 314 oas->Stop(); |
315 ::Sleep(500); | 315 ::Sleep(500); |
316 oas->Close(); | 316 oas->Close(); |
317 } | 317 } |
318 | 318 |
319 // Test potential deadlock situation if the source is slow or blocks for some | 319 // Test potential deadlock situation if the source is slow or blocks for some |
320 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 320 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
321 // the test completes in reasonable time. | 321 // the test completes in reasonable time. |
322 TEST(WinAudioTest, PCMWaveSlowSource) { | 322 TEST(WinAudioTest, PCMWaveSlowSource) { |
323 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 323 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
324 if (!audio_man->HasAudioOutputDevices()) { | 324 if (!audio_man->HasAudioOutputDevices()) { |
325 LOG(WARNING) << "No output device detected."; | 325 LOG(WARNING) << "No output device detected."; |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 329 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
330 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 330 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
331 16000, 16, 256)); | 331 CHANNEL_LAYOUT_MONO, 16000, 16, 256)); |
332 ASSERT_TRUE(NULL != oas); | 332 ASSERT_TRUE(NULL != oas); |
333 TestSourceLaggy test_laggy(2, 90); | 333 TestSourceLaggy test_laggy(2, 90); |
334 EXPECT_TRUE(oas->Open()); | 334 EXPECT_TRUE(oas->Open()); |
335 // The test parameters cause a callback every 32 ms and the source is | 335 // The test parameters cause a callback every 32 ms and the source is |
336 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 336 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
337 oas->Start(&test_laggy); | 337 oas->Start(&test_laggy); |
338 ::Sleep(500); | 338 ::Sleep(500); |
339 EXPECT_GT(test_laggy.callback_count(), 2); | 339 EXPECT_GT(test_laggy.callback_count(), 2); |
340 EXPECT_FALSE(test_laggy.had_error()); | 340 EXPECT_FALSE(test_laggy.had_error()); |
341 oas->Stop(); | 341 oas->Stop(); |
342 ::Sleep(500); | 342 ::Sleep(500); |
343 oas->Close(); | 343 oas->Close(); |
344 } | 344 } |
345 | 345 |
346 // Test another potential deadlock situation if the thread that calls Start() | 346 // Test another potential deadlock situation if the thread that calls Start() |
347 // gets paused. This test is best when run over RDP with audio enabled. See | 347 // gets paused. This test is best when run over RDP with audio enabled. See |
348 // bug 19276 for more details. | 348 // bug 19276 for more details. |
349 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 349 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
350 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 350 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
351 if (!audio_man->HasAudioOutputDevices()) { | 351 if (!audio_man->HasAudioOutputDevices()) { |
352 LOG(WARNING) << "No output device detected."; | 352 LOG(WARNING) << "No output device detected."; |
353 return; | 353 return; |
354 } | 354 } |
355 | 355 |
356 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 356 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
357 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 357 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
358 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 358 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 359 CHANNEL_LAYOUT_MONO, |
359 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 360 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
360 ASSERT_TRUE(NULL != oas); | 361 ASSERT_TRUE(NULL != oas); |
361 | 362 |
362 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 363 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
363 200.0, AudioParameters::kAudioCDSampleRate); | 364 200.0, AudioParameters::kAudioCDSampleRate); |
364 | 365 |
365 EXPECT_TRUE(oas->Open()); | 366 EXPECT_TRUE(oas->Open()); |
366 oas->SetVolume(1.0); | 367 oas->SetVolume(1.0); |
367 | 368 |
368 for (int ix = 0; ix != 5; ++ix) { | 369 for (int ix = 0; ix != 5; ++ix) { |
(...skipping 10 matching lines...) Expand all Loading... |
379 // not hear pops or noises while the sound is playing. | 380 // not hear pops or noises while the sound is playing. |
380 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { | 381 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { |
381 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 382 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
382 if (!audio_man->HasAudioOutputDevices()) { | 383 if (!audio_man->HasAudioOutputDevices()) { |
383 LOG(WARNING) << "No output device detected."; | 384 LOG(WARNING) << "No output device detected."; |
384 return; | 385 return; |
385 } | 386 } |
386 | 387 |
387 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 388 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
388 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 389 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
389 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 390 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 391 CHANNEL_LAYOUT_MONO, |
390 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 392 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
391 ASSERT_TRUE(NULL != oas); | 393 ASSERT_TRUE(NULL != oas); |
392 | 394 |
393 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 395 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
394 200.0, AudioParameters::kAudioCDSampleRate); | 396 200.0, AudioParameters::kAudioCDSampleRate); |
395 | 397 |
396 EXPECT_TRUE(oas->Open()); | 398 EXPECT_TRUE(oas->Open()); |
397 oas->SetVolume(1.0); | 399 oas->SetVolume(1.0); |
398 oas->Start(&source); | 400 oas->Start(&source); |
399 ::Sleep(500); | 401 ::Sleep(500); |
400 oas->Stop(); | 402 oas->Stop(); |
401 oas->Close(); | 403 oas->Close(); |
402 } | 404 } |
403 | 405 |
404 // This test produces actual audio for for .5 seconds on the default wave | 406 // This test produces actual audio for for .5 seconds on the default wave |
405 // device at 22K s/sec. Parameters have been chosen carefully so you should | 407 // device at 22K s/sec. Parameters have been chosen carefully so you should |
406 // not hear pops or noises while the sound is playing. The audio also should | 408 // not hear pops or noises while the sound is playing. The audio also should |
407 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 409 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
408 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 410 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
409 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 411 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
410 if (!audio_man->HasAudioOutputDevices()) { | 412 if (!audio_man->HasAudioOutputDevices()) { |
411 LOG(WARNING) << "No output device detected."; | 413 LOG(WARNING) << "No output device detected."; |
412 return; | 414 return; |
413 } | 415 } |
414 | 416 |
415 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 417 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
416 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 418 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
417 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 419 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 420 CHANNEL_LAYOUT_MONO, |
418 AudioParameters::kAudioCDSampleRate / 2, 16, | 421 AudioParameters::kAudioCDSampleRate / 2, 16, |
419 samples_100_ms)); | 422 samples_100_ms)); |
420 ASSERT_TRUE(NULL != oas); | 423 ASSERT_TRUE(NULL != oas); |
421 | 424 |
422 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 425 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
423 200.0, AudioParameters::kAudioCDSampleRate/2); | 426 200.0, AudioParameters::kAudioCDSampleRate/2); |
424 | 427 |
425 EXPECT_TRUE(oas->Open()); | 428 EXPECT_TRUE(oas->Open()); |
426 | 429 |
427 oas->SetVolume(0.5); | 430 oas->SetVolume(0.5); |
(...skipping 29 matching lines...) Expand all Loading... |
457 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); | 460 audio_file = audio_file.Append(kAudioFile1_16b_m_16K); |
458 // Map the entire file in memory. | 461 // Map the entire file in memory. |
459 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); | 462 ReadOnlyMappedFile file_reader(audio_file.value().c_str()); |
460 ASSERT_TRUE(file_reader.is_valid()); | 463 ASSERT_TRUE(file_reader.is_valid()); |
461 | 464 |
462 // Compute buffer size for 100ms of audio. | 465 // Compute buffer size for 100ms of audio. |
463 const uint32 kSamples100ms = (16000 / 1000) * 100; | 466 const uint32 kSamples100ms = (16000 / 1000) * 100; |
464 const uint32 kSize100ms = kSamples100ms * 2; | 467 const uint32 kSize100ms = kSamples100ms * 2; |
465 | 468 |
466 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 469 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
467 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 470 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 471 CHANNEL_LAYOUT_MONO, |
468 16000, 16, kSamples100ms)); | 472 16000, 16, kSamples100ms)); |
469 ASSERT_TRUE(NULL != oas); | 473 ASSERT_TRUE(NULL != oas); |
470 | 474 |
471 EXPECT_TRUE(oas->Open()); | 475 EXPECT_TRUE(oas->Open()); |
472 | 476 |
473 uint32 offset = 0; | 477 uint32 offset = 0; |
474 const uint32 kMaxStartOffset = file_reader.size() - kSize100ms; | 478 const uint32 kMaxStartOffset = file_reader.size() - kSize100ms; |
475 | 479 |
476 // We buffer and play at the same time, buffering happens every ~10ms and the | 480 // We buffer and play at the same time, buffering happens every ~10ms and the |
477 // consuming of the buffer happens every ~100ms. We do 100 buffers which | 481 // consuming of the buffer happens every ~100ms. We do 100 buffers which |
(...skipping 23 matching lines...) Expand all Loading... |
501 // of silence. | 505 // of silence. |
502 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { | 506 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { |
503 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 507 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
504 if (!audio_man->HasAudioOutputDevices()) { | 508 if (!audio_man->HasAudioOutputDevices()) { |
505 LOG(WARNING) << "No output device detected."; | 509 LOG(WARNING) << "No output device detected."; |
506 return; | 510 return; |
507 } | 511 } |
508 | 512 |
509 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 513 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
510 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 514 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
511 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 515 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 516 CHANNEL_LAYOUT_MONO, |
512 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 517 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
513 ASSERT_TRUE(NULL != oas); | 518 ASSERT_TRUE(NULL != oas); |
514 | 519 |
515 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 520 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
516 200.0, AudioParameters::kAudioCDSampleRate); | 521 200.0, AudioParameters::kAudioCDSampleRate); |
517 EXPECT_TRUE(oas->Open()); | 522 EXPECT_TRUE(oas->Open()); |
518 oas->SetVolume(1.0); | 523 oas->SetVolume(1.0); |
519 | 524 |
520 // Play the wave for .5 seconds. | 525 // Play the wave for .5 seconds. |
521 oas->Start(&source); | 526 oas->Start(&source); |
(...skipping 25 matching lines...) Expand all Loading... |
547 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 552 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
548 | 553 |
549 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 554 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
550 // Take the existing native sample rate into account. | 555 // Take the existing native sample rate into account. |
551 int sample_rate = static_cast<int>(media::GetAudioHardwareSampleRate()); | 556 int sample_rate = static_cast<int>(media::GetAudioHardwareSampleRate()); |
552 uint32 samples_10_ms = sample_rate / 100; | 557 uint32 samples_10_ms = sample_rate / 100; |
553 int n = 1; | 558 int n = 1; |
554 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 559 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
555 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 560 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
556 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 561 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
557 CHANNEL_LAYOUT_MONO, sample_rate, | 562 false, CHANNEL_LAYOUT_MONO, sample_rate, |
558 16, n * samples_10_ms)); | 563 16, n * samples_10_ms)); |
559 ASSERT_TRUE(NULL != oas); | 564 ASSERT_TRUE(NULL != oas); |
560 | 565 |
561 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 566 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
562 200.0, sample_rate); | 567 200.0, sample_rate); |
563 | 568 |
564 bool opened = oas->Open(); | 569 bool opened = oas->Open(); |
565 if (!opened) { | 570 if (!opened) { |
566 // It was not possible to open this audio device in mono. | 571 // It was not possible to open this audio device in mono. |
567 // No point in continuing the test so let's break here. | 572 // No point in continuing the test so let's break here. |
(...skipping 13 matching lines...) Expand all Loading... |
581 // Check that the pending bytes value is correct what the stream starts. | 586 // Check that the pending bytes value is correct what the stream starts. |
582 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { | 587 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { |
583 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 588 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
584 if (!audio_man->HasAudioOutputDevices()) { | 589 if (!audio_man->HasAudioOutputDevices()) { |
585 LOG(WARNING) << "No output device detected."; | 590 LOG(WARNING) << "No output device detected."; |
586 return; | 591 return; |
587 } | 592 } |
588 | 593 |
589 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 594 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
590 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 595 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
591 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 596 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
| 597 CHANNEL_LAYOUT_MONO, |
592 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); | 598 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms)); |
593 ASSERT_TRUE(NULL != oas); | 599 ASSERT_TRUE(NULL != oas); |
594 | 600 |
595 NiceMock<MockAudioSource> source; | 601 NiceMock<MockAudioSource> source; |
596 EXPECT_TRUE(oas->Open()); | 602 EXPECT_TRUE(oas->Open()); |
597 | 603 |
598 uint32 bytes_100_ms = samples_100_ms * 2; | 604 uint32 bytes_100_ms = samples_100_ms * 2; |
599 | 605 |
600 // We expect the amount of pending bytes will reaching 2 times of | 606 // We expect the amount of pending bytes will reaching 2 times of |
601 // |bytes_100_ms| because the audio output stream has a triple buffer scheme. | 607 // |bytes_100_ms| because the audio output stream has a triple buffer scheme. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 TEST(WinAudioTest, SyncSocketBasic) { | 715 TEST(WinAudioTest, SyncSocketBasic) { |
710 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); | 716 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); |
711 if (!audio_man->HasAudioOutputDevices()) { | 717 if (!audio_man->HasAudioOutputDevices()) { |
712 LOG(WARNING) << "No output device detected."; | 718 LOG(WARNING) << "No output device detected."; |
713 return; | 719 return; |
714 } | 720 } |
715 | 721 |
716 int sample_rate = AudioParameters::kAudioCDSampleRate; | 722 int sample_rate = AudioParameters::kAudioCDSampleRate; |
717 const uint32 kSamples20ms = sample_rate / 50; | 723 const uint32 kSamples20ms = sample_rate / 50; |
718 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 724 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
719 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, | 725 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, false, |
720 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); | 726 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms)); |
721 ASSERT_TRUE(NULL != oas); | 727 ASSERT_TRUE(NULL != oas); |
722 | 728 |
723 ASSERT_TRUE(oas->Open()); | 729 ASSERT_TRUE(oas->Open()); |
724 | 730 |
725 base::SyncSocket sockets[2]; | 731 base::SyncSocket sockets[2]; |
726 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); | 732 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); |
727 | 733 |
728 SyncSocketSource source(&sockets[0]); | 734 SyncSocketSource source(&sockets[0]); |
729 | 735 |
730 SyncThreadContext thread_context; | 736 SyncThreadContext thread_context; |
731 thread_context.sample_rate = sample_rate; | 737 thread_context.sample_rate = sample_rate; |
732 thread_context.sine_freq = 200.0; | 738 thread_context.sine_freq = 200.0; |
733 thread_context.packet_size_bytes = kSamples20ms * 2; | 739 thread_context.packet_size_bytes = kSamples20ms * 2; |
734 thread_context.socket = &sockets[1]; | 740 thread_context.socket = &sockets[1]; |
735 | 741 |
736 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, | 742 HANDLE thread = ::CreateThread(NULL, 0, SyncSocketThread, |
737 &thread_context, 0, NULL); | 743 &thread_context, 0, NULL); |
738 | 744 |
739 oas->Start(&source); | 745 oas->Start(&source); |
740 | 746 |
741 ::WaitForSingleObject(thread, INFINITE); | 747 ::WaitForSingleObject(thread, INFINITE); |
742 ::CloseHandle(thread); | 748 ::CloseHandle(thread); |
743 | 749 |
744 oas->Stop(); | 750 oas->Stop(); |
745 oas->Close(); | 751 oas->Close(); |
746 } | 752 } |
OLD | NEW |