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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { | 168 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { |
169 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 169 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
170 if (!audio_man->HasAudioOutputDevices()) { | 170 if (!audio_man->HasAudioOutputDevices()) { |
171 LOG(WARNING) << "No output device detected."; | 171 LOG(WARNING) << "No output device detected."; |
172 return; | 172 return; |
173 } | 173 } |
174 | 174 |
175 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 175 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
176 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 176 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
177 8000, 16, 256), | 177 8000, 16, 256), |
178 std::string(), std::string()); | 178 std::string()); |
179 ASSERT_TRUE(NULL != oas); | 179 ASSERT_TRUE(NULL != oas); |
180 oas->Close(); | 180 oas->Close(); |
181 } | 181 } |
182 | 182 |
183 // Test that can it be cannot be created with invalid parameters. | 183 // Test that can it be cannot be created with invalid parameters. |
184 TEST(WinAudioTest, SanityOnMakeParams) { | 184 TEST(WinAudioTest, SanityOnMakeParams) { |
185 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 185 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
186 if (!audio_man->HasAudioOutputDevices()) { | 186 if (!audio_man->HasAudioOutputDevices()) { |
187 LOG(WARNING) << "No output device detected."; | 187 LOG(WARNING) << "No output device detected."; |
188 return; | 188 return; |
189 } | 189 } |
190 | 190 |
191 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; | 191 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; |
192 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 192 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
193 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), | 193 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
194 std::string(), std::string())); | 194 std::string())); |
195 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 195 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
196 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), | 196 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), |
197 std::string(), std::string())); | 197 std::string())); |
198 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 198 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
199 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), | 199 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), |
200 std::string(), std::string())); | 200 std::string())); |
201 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 201 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
202 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), | 202 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), |
203 std::string(), std::string())); | 203 std::string())); |
204 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 204 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
205 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256), | 205 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256), |
206 std::string(), std::string())); | 206 std::string())); |
207 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 207 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
208 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100), | 208 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100), |
209 std::string(), std::string())); | 209 std::string())); |
210 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 210 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
211 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0), | 211 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0), |
212 std::string(), std::string())); | 212 std::string())); |
213 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( | 213 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( |
214 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, | 214 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, |
215 media::limits::kMaxSamplesPerPacket + 1), | 215 media::limits::kMaxSamplesPerPacket + 1), |
216 std::string(), std::string())); | 216 std::string())); |
217 } | 217 } |
218 | 218 |
219 // Test that it can be opened and closed. | 219 // Test that it can be opened and closed. |
220 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { | 220 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { |
221 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 221 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
222 if (!audio_man->HasAudioOutputDevices()) { | 222 if (!audio_man->HasAudioOutputDevices()) { |
223 LOG(WARNING) << "No output device detected."; | 223 LOG(WARNING) << "No output device detected."; |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 227 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
228 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 228 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
229 8000, 16, 256), | 229 8000, 16, 256), |
230 std::string(), std::string()); | 230 std::string()); |
231 ASSERT_TRUE(NULL != oas); | 231 ASSERT_TRUE(NULL != oas); |
232 EXPECT_TRUE(oas->Open()); | 232 EXPECT_TRUE(oas->Open()); |
233 oas->Close(); | 233 oas->Close(); |
234 } | 234 } |
235 | 235 |
236 // Test that it has a maximum packet size. | 236 // Test that it has a maximum packet size. |
237 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { | 237 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { |
238 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 238 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
239 if (!audio_man->HasAudioOutputDevices()) { | 239 if (!audio_man->HasAudioOutputDevices()) { |
240 LOG(WARNING) << "No output device detected."; | 240 LOG(WARNING) << "No output device detected."; |
241 return; | 241 return; |
242 } | 242 } |
243 | 243 |
244 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 244 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
245 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, | 245 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, |
246 8000, 16, 1024 * 1024 * 1024), | 246 8000, 16, 1024 * 1024 * 1024), |
247 std::string(), std::string()); | 247 std::string()); |
248 EXPECT_TRUE(NULL == oas); | 248 EXPECT_TRUE(NULL == oas); |
249 if (oas) | 249 if (oas) |
250 oas->Close(); | 250 oas->Close(); |
251 } | 251 } |
252 | 252 |
253 // Test potential deadlock situation if the source is slow or blocks for some | 253 // Test potential deadlock situation if the source is slow or blocks for some |
254 // time. The actual EXPECT_GT are mostly meaningless and the real test is that | 254 // time. The actual EXPECT_GT are mostly meaningless and the real test is that |
255 // the test completes in reasonable time. | 255 // the test completes in reasonable time. |
256 TEST(WinAudioTest, PCMWaveSlowSource) { | 256 TEST(WinAudioTest, PCMWaveSlowSource) { |
257 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 257 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
258 if (!audio_man->HasAudioOutputDevices()) { | 258 if (!audio_man->HasAudioOutputDevices()) { |
259 LOG(WARNING) << "No output device detected."; | 259 LOG(WARNING) << "No output device detected."; |
260 return; | 260 return; |
261 } | 261 } |
262 | 262 |
263 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 263 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
264 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 264 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
265 16000, 16, 256), | 265 16000, 16, 256), |
266 std::string(), std::string()); | 266 std::string()); |
267 ASSERT_TRUE(NULL != oas); | 267 ASSERT_TRUE(NULL != oas); |
268 TestSourceLaggy test_laggy(2, 90); | 268 TestSourceLaggy test_laggy(2, 90); |
269 EXPECT_TRUE(oas->Open()); | 269 EXPECT_TRUE(oas->Open()); |
270 // The test parameters cause a callback every 32 ms and the source is | 270 // The test parameters cause a callback every 32 ms and the source is |
271 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. | 271 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. |
272 oas->Start(&test_laggy); | 272 oas->Start(&test_laggy); |
273 ::Sleep(500); | 273 ::Sleep(500); |
274 EXPECT_GT(test_laggy.callback_count(), 2); | 274 EXPECT_GT(test_laggy.callback_count(), 2); |
275 EXPECT_FALSE(test_laggy.had_error()); | 275 EXPECT_FALSE(test_laggy.had_error()); |
276 oas->Stop(); | 276 oas->Stop(); |
277 ::Sleep(500); | 277 ::Sleep(500); |
278 oas->Close(); | 278 oas->Close(); |
279 } | 279 } |
280 | 280 |
281 // Test another potential deadlock situation if the thread that calls Start() | 281 // Test another potential deadlock situation if the thread that calls Start() |
282 // gets paused. This test is best when run over RDP with audio enabled. See | 282 // gets paused. This test is best when run over RDP with audio enabled. See |
283 // bug 19276 for more details. | 283 // bug 19276 for more details. |
284 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { | 284 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { |
285 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 285 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
286 if (!audio_man->HasAudioOutputDevices()) { | 286 if (!audio_man->HasAudioOutputDevices()) { |
287 LOG(WARNING) << "No output device detected."; | 287 LOG(WARNING) << "No output device detected."; |
288 return; | 288 return; |
289 } | 289 } |
290 | 290 |
291 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 291 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
292 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 292 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
293 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 293 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
294 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 294 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
295 std::string(), std::string()); | 295 std::string()); |
296 ASSERT_TRUE(NULL != oas); | 296 ASSERT_TRUE(NULL != oas); |
297 | 297 |
298 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 298 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
299 | 299 |
300 EXPECT_TRUE(oas->Open()); | 300 EXPECT_TRUE(oas->Open()); |
301 oas->SetVolume(1.0); | 301 oas->SetVolume(1.0); |
302 | 302 |
303 for (int ix = 0; ix != 5; ++ix) { | 303 for (int ix = 0; ix != 5; ++ix) { |
304 oas->Start(&source); | 304 oas->Start(&source); |
305 ::Sleep(10); | 305 ::Sleep(10); |
(...skipping 10 matching lines...) Expand all Loading... |
316 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 316 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
317 if (!audio_man->HasAudioOutputDevices()) { | 317 if (!audio_man->HasAudioOutputDevices()) { |
318 LOG(WARNING) << "No output device detected."; | 318 LOG(WARNING) << "No output device detected."; |
319 return; | 319 return; |
320 } | 320 } |
321 | 321 |
322 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 322 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
323 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 323 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
324 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 324 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
325 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 325 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
326 std::string(), std::string()); | 326 std::string()); |
327 ASSERT_TRUE(NULL != oas); | 327 ASSERT_TRUE(NULL != oas); |
328 | 328 |
329 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 329 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
330 | 330 |
331 EXPECT_TRUE(oas->Open()); | 331 EXPECT_TRUE(oas->Open()); |
332 oas->SetVolume(1.0); | 332 oas->SetVolume(1.0); |
333 oas->Start(&source); | 333 oas->Start(&source); |
334 ::Sleep(500); | 334 ::Sleep(500); |
335 oas->Stop(); | 335 oas->Stop(); |
336 oas->Close(); | 336 oas->Close(); |
337 } | 337 } |
338 | 338 |
339 // This test produces actual audio for for .5 seconds on the default wave | 339 // This test produces actual audio for for .5 seconds on the default wave |
340 // device at 22K s/sec. Parameters have been chosen carefully so you should | 340 // device at 22K s/sec. Parameters have been chosen carefully so you should |
341 // not hear pops or noises while the sound is playing. The audio also should | 341 // not hear pops or noises while the sound is playing. The audio also should |
342 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. | 342 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. |
343 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { | 343 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { |
344 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 344 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
345 if (!audio_man->HasAudioOutputDevices()) { | 345 if (!audio_man->HasAudioOutputDevices()) { |
346 LOG(WARNING) << "No output device detected."; | 346 LOG(WARNING) << "No output device detected."; |
347 return; | 347 return; |
348 } | 348 } |
349 | 349 |
350 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; | 350 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; |
351 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 351 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
352 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 352 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
353 AudioParameters::kAudioCDSampleRate / 2, 16, | 353 AudioParameters::kAudioCDSampleRate / 2, 16, |
354 samples_100_ms), | 354 samples_100_ms), |
355 std::string(), std::string()); | 355 std::string()); |
356 ASSERT_TRUE(NULL != oas); | 356 ASSERT_TRUE(NULL != oas); |
357 | 357 |
358 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); | 358 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); |
359 | 359 |
360 EXPECT_TRUE(oas->Open()); | 360 EXPECT_TRUE(oas->Open()); |
361 | 361 |
362 oas->SetVolume(0.5); | 362 oas->SetVolume(0.5); |
363 oas->Start(&source); | 363 oas->Start(&source); |
364 ::Sleep(500); | 364 ::Sleep(500); |
365 | 365 |
(...skipping 19 matching lines...) Expand all Loading... |
385 static const int kSampleRate = 16000; | 385 static const int kSampleRate = 16000; |
386 SineWaveAudioSource source(1, 200.0, kSampleRate); | 386 SineWaveAudioSource source(1, 200.0, kSampleRate); |
387 // Compute buffer size for 100ms of audio. | 387 // Compute buffer size for 100ms of audio. |
388 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; | 388 const uint32 kSamples100ms = (kSampleRate / 1000) * 100; |
389 // Restrict SineWaveAudioSource to 100ms of samples. | 389 // Restrict SineWaveAudioSource to 100ms of samples. |
390 source.CapSamples(kSamples100ms); | 390 source.CapSamples(kSamples100ms); |
391 | 391 |
392 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 392 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
393 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 393 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
394 kSampleRate, 16, kSamples100ms), | 394 kSampleRate, 16, kSamples100ms), |
395 std::string(), std::string()); | 395 std::string()); |
396 ASSERT_TRUE(NULL != oas); | 396 ASSERT_TRUE(NULL != oas); |
397 | 397 |
398 EXPECT_TRUE(oas->Open()); | 398 EXPECT_TRUE(oas->Open()); |
399 | 399 |
400 oas->SetVolume(1.0); | 400 oas->SetVolume(1.0); |
401 oas->Start(&source); | 401 oas->Start(&source); |
402 | 402 |
403 // We buffer and play at the same time, buffering happens every ~10ms and the | 403 // We buffer and play at the same time, buffering happens every ~10ms and the |
404 // consuming of the buffer happens every ~100ms. We do 100 buffers which | 404 // consuming of the buffer happens every ~100ms. We do 100 buffers which |
405 // effectively wrap around the file more than once. | 405 // effectively wrap around the file more than once. |
(...skipping 16 matching lines...) Expand all Loading... |
422 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 422 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
423 if (!audio_man->HasAudioOutputDevices()) { | 423 if (!audio_man->HasAudioOutputDevices()) { |
424 LOG(WARNING) << "No output device detected."; | 424 LOG(WARNING) << "No output device detected."; |
425 return; | 425 return; |
426 } | 426 } |
427 | 427 |
428 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 428 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
429 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 429 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
430 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 430 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
431 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 431 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
432 std::string(), std::string()); | 432 std::string()); |
433 ASSERT_TRUE(NULL != oas); | 433 ASSERT_TRUE(NULL != oas); |
434 | 434 |
435 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); | 435 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); |
436 EXPECT_TRUE(oas->Open()); | 436 EXPECT_TRUE(oas->Open()); |
437 oas->SetVolume(1.0); | 437 oas->SetVolume(1.0); |
438 | 438 |
439 // Play the wave for .5 seconds. | 439 // Play the wave for .5 seconds. |
440 oas->Start(&source); | 440 oas->Start(&source); |
441 ::Sleep(500); | 441 ::Sleep(500); |
442 oas->Stop(); | 442 oas->Stop(); |
(...skipping 26 matching lines...) Expand all Loading... |
469 // Take the existing native sample rate into account. | 469 // Take the existing native sample rate into account. |
470 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); | 470 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); |
471 int sample_rate = params.sample_rate(); | 471 int sample_rate = params.sample_rate(); |
472 uint32 samples_10_ms = sample_rate / 100; | 472 uint32 samples_10_ms = sample_rate / 100; |
473 int n = 1; | 473 int n = 1; |
474 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 474 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
475 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 475 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
476 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 476 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
477 CHANNEL_LAYOUT_MONO, sample_rate, | 477 CHANNEL_LAYOUT_MONO, sample_rate, |
478 16, n * samples_10_ms), | 478 16, n * samples_10_ms), |
479 std::string(), std::string()); | 479 std::string()); |
480 ASSERT_TRUE(NULL != oas); | 480 ASSERT_TRUE(NULL != oas); |
481 | 481 |
482 SineWaveAudioSource source(1, 200, sample_rate); | 482 SineWaveAudioSource source(1, 200, sample_rate); |
483 | 483 |
484 bool opened = oas->Open(); | 484 bool opened = oas->Open(); |
485 if (!opened) { | 485 if (!opened) { |
486 // It was not possible to open this audio device in mono. | 486 // It was not possible to open this audio device in mono. |
487 // No point in continuing the test so let's break here. | 487 // No point in continuing the test so let's break here. |
488 LOG(WARNING) << "Mono is not supported. Skipping test."; | 488 LOG(WARNING) << "Mono is not supported. Skipping test."; |
489 oas->Close(); | 489 oas->Close(); |
(...skipping 13 matching lines...) Expand all Loading... |
503 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 503 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
504 if (!audio_man->HasAudioOutputDevices()) { | 504 if (!audio_man->HasAudioOutputDevices()) { |
505 LOG(WARNING) << "No output device detected."; | 505 LOG(WARNING) << "No output device detected."; |
506 return; | 506 return; |
507 } | 507 } |
508 | 508 |
509 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; | 509 uint32 samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; |
510 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 510 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
511 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 511 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
512 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), | 512 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), |
513 std::string(), std::string()); | 513 std::string()); |
514 ASSERT_TRUE(NULL != oas); | 514 ASSERT_TRUE(NULL != oas); |
515 | 515 |
516 NiceMock<MockAudioSourceCallback> source; | 516 NiceMock<MockAudioSourceCallback> source; |
517 EXPECT_TRUE(oas->Open()); | 517 EXPECT_TRUE(oas->Open()); |
518 | 518 |
519 uint32 bytes_100_ms = samples_100_ms * 2; | 519 uint32 bytes_100_ms = samples_100_ms * 2; |
520 | 520 |
521 // Audio output stream has either a double or triple buffer scheme. | 521 // Audio output stream has either a double or triple buffer scheme. |
522 // We expect the amount of pending bytes will reaching up to 2 times of | 522 // We expect the amount of pending bytes will reaching up to 2 times of |
523 // |bytes_100_ms| depending on number of buffers used. | 523 // |bytes_100_ms| depending on number of buffers used. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 return; | 657 return; |
658 } | 658 } |
659 | 659 |
660 static const int sample_rate = AudioParameters::kAudioCDSampleRate; | 660 static const int sample_rate = AudioParameters::kAudioCDSampleRate; |
661 static const uint32 kSamples20ms = sample_rate / 50; | 661 static const uint32 kSamples20ms = sample_rate / 50; |
662 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, | 662 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, |
663 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); | 663 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); |
664 | 664 |
665 | 665 |
666 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, | 666 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, |
667 std::string(), std::string()); | 667 std::string()); |
668 ASSERT_TRUE(NULL != oas); | 668 ASSERT_TRUE(NULL != oas); |
669 | 669 |
670 ASSERT_TRUE(oas->Open()); | 670 ASSERT_TRUE(oas->Open()); |
671 | 671 |
672 base::SyncSocket sockets[2]; | 672 base::SyncSocket sockets[2]; |
673 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); | 673 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); |
674 | 674 |
675 SyncSocketSource source(&sockets[0], params); | 675 SyncSocketSource source(&sockets[0], params); |
676 | 676 |
677 SyncThreadContext thread_context; | 677 SyncThreadContext thread_context; |
(...skipping 10 matching lines...) Expand all Loading... |
688 oas->Start(&source); | 688 oas->Start(&source); |
689 | 689 |
690 ::WaitForSingleObject(thread, INFINITE); | 690 ::WaitForSingleObject(thread, INFINITE); |
691 ::CloseHandle(thread); | 691 ::CloseHandle(thread); |
692 | 692 |
693 oas->Stop(); | 693 oas->Stop(); |
694 oas->Close(); | 694 oas->Close(); |
695 } | 695 } |
696 | 696 |
697 } // namespace media | 697 } // namespace media |
OLD | NEW |