Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: media/audio/win/audio_output_win_unittest.cc

Issue 1864483002: Forward output glitch information from stream WebRTC log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/win/audio_manager_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // remote-desktop and the rdp client installs an audio device that fails to open 171 // remote-desktop and the rdp client installs an audio device that fails to open
172 // at some point, possibly when the connection goes idle. 172 // at some point, possibly when the connection goes idle.
173 173
174 // Test that can it be created and closed. 174 // Test that can it be created and closed.
175 TEST_F(WinAudioTest, PCMWaveStreamGetAndClose) { 175 TEST_F(WinAudioTest, PCMWaveStreamGetAndClose) {
176 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 176 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
177 177
178 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 178 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
179 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 179 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
180 8000, 16, 256), 180 8000, 16, 256),
181 std::string()); 181 std::string(), AudioManager::LogCallback());
182 ASSERT_TRUE(NULL != oas); 182 ASSERT_TRUE(NULL != oas);
183 oas->Close(); 183 oas->Close();
184 } 184 }
185 185
186 // Test that can it be cannot be created with invalid parameters. 186 // Test that can it be cannot be created with invalid parameters.
187 TEST_F(WinAudioTest, SanityOnMakeParams) { 187 TEST_F(WinAudioTest, SanityOnMakeParams) {
188 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 188 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
189 189
190 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; 190 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR;
191 EXPECT_TRUE( 191 EXPECT_TRUE(
192 NULL == 192 NULL ==
193 audio_manager_->MakeAudioOutputStream( 193 audio_manager_->MakeAudioOutputStream(
194 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), 194 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256),
195 std::string())); 195 std::string(), AudioManager::LogCallback()));
196 EXPECT_TRUE( 196 EXPECT_TRUE(
197 NULL == 197 NULL ==
198 audio_manager_->MakeAudioOutputStream( 198 audio_manager_->MakeAudioOutputStream(
199 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), 199 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256),
200 std::string())); 200 std::string(), AudioManager::LogCallback()));
201 EXPECT_TRUE(NULL == 201 EXPECT_TRUE(NULL ==
202 audio_manager_->MakeAudioOutputStream( 202 audio_manager_->MakeAudioOutputStream(
203 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256), 203 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, 8000, 80, 256),
204 std::string())); 204 std::string(), AudioManager::LogCallback()));
205 EXPECT_TRUE( 205 EXPECT_TRUE(
206 NULL == 206 NULL ==
207 audio_manager_->MakeAudioOutputStream( 207 audio_manager_->MakeAudioOutputStream(
208 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), 208 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256),
209 std::string())); 209 std::string(), AudioManager::LogCallback()));
210 EXPECT_TRUE(NULL == 210 EXPECT_TRUE(NULL ==
211 audio_manager_->MakeAudioOutputStream( 211 audio_manager_->MakeAudioOutputStream(
212 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256), 212 AudioParameters(fmt, CHANNEL_LAYOUT_STEREO, -8000, 16, 256),
213 std::string())); 213 std::string(), AudioManager::LogCallback()));
214 EXPECT_TRUE(NULL == 214 EXPECT_TRUE(NULL ==
215 audio_manager_->MakeAudioOutputStream( 215 audio_manager_->MakeAudioOutputStream(
216 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100), 216 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, -100),
217 std::string())); 217 std::string(), AudioManager::LogCallback()));
218 EXPECT_TRUE(NULL == 218 EXPECT_TRUE(NULL ==
219 audio_manager_->MakeAudioOutputStream( 219 audio_manager_->MakeAudioOutputStream(
220 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0), 220 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0),
221 std::string())); 221 std::string(), AudioManager::LogCallback()));
222 EXPECT_TRUE(NULL == 222 EXPECT_TRUE(NULL ==
223 audio_manager_->MakeAudioOutputStream( 223 audio_manager_->MakeAudioOutputStream(
224 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 224 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16,
225 media::limits::kMaxSamplesPerPacket + 1), 225 media::limits::kMaxSamplesPerPacket + 1),
226 std::string())); 226 std::string(), AudioManager::LogCallback()));
227 } 227 }
228 228
229 // Test that it can be opened and closed. 229 // Test that it can be opened and closed.
230 TEST_F(WinAudioTest, PCMWaveStreamOpenAndClose) { 230 TEST_F(WinAudioTest, PCMWaveStreamOpenAndClose) {
231 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 231 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
232 232
233 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 233 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
234 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 234 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
235 8000, 16, 256), 235 8000, 16, 256),
236 std::string()); 236 std::string(), AudioManager::LogCallback());
237 ASSERT_TRUE(NULL != oas); 237 ASSERT_TRUE(NULL != oas);
238 EXPECT_TRUE(oas->Open()); 238 EXPECT_TRUE(oas->Open());
239 oas->Close(); 239 oas->Close();
240 } 240 }
241 241
242 // Test that it has a maximum packet size. 242 // Test that it has a maximum packet size.
243 TEST_F(WinAudioTest, PCMWaveStreamOpenLimit) { 243 TEST_F(WinAudioTest, PCMWaveStreamOpenLimit) {
244 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 244 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
245 245
246 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 246 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
247 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 247 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
248 8000, 16, 1024 * 1024 * 1024), 248 8000, 16, 1024 * 1024 * 1024),
249 std::string()); 249 std::string(), AudioManager::LogCallback());
250 EXPECT_TRUE(NULL == oas); 250 EXPECT_TRUE(NULL == oas);
251 if (oas) 251 if (oas)
252 oas->Close(); 252 oas->Close();
253 } 253 }
254 254
255 // Test potential deadlock situation if the source is slow or blocks for some 255 // Test potential deadlock situation if the source is slow or blocks for some
256 // time. The actual EXPECT_GT are mostly meaningless and the real test is that 256 // time. The actual EXPECT_GT are mostly meaningless and the real test is that
257 // the test completes in reasonable time. 257 // the test completes in reasonable time.
258 TEST_F(WinAudioTest, PCMWaveSlowSource) { 258 TEST_F(WinAudioTest, PCMWaveSlowSource) {
259 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 259 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
260 260
261 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 261 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
262 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 262 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
263 16000, 16, 256), 263 16000, 16, 256),
264 std::string()); 264 std::string(), AudioManager::LogCallback());
265 ASSERT_TRUE(NULL != oas); 265 ASSERT_TRUE(NULL != oas);
266 TestSourceLaggy test_laggy(90); 266 TestSourceLaggy test_laggy(90);
267 EXPECT_TRUE(oas->Open()); 267 EXPECT_TRUE(oas->Open());
268 // The test parameters cause a callback every 32 ms and the source is 268 // 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. 269 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers.
270 oas->Start(&test_laggy); 270 oas->Start(&test_laggy);
271 ::Sleep(500); 271 ::Sleep(500);
272 EXPECT_GT(test_laggy.callback_count(), 2); 272 EXPECT_GT(test_laggy.callback_count(), 2);
273 EXPECT_FALSE(test_laggy.had_error()); 273 EXPECT_FALSE(test_laggy.had_error());
274 oas->Stop(); 274 oas->Stop();
275 ::Sleep(500); 275 ::Sleep(500);
276 oas->Close(); 276 oas->Close();
277 } 277 }
278 278
279 // Test another potential deadlock situation if the thread that calls Start() 279 // 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 280 // gets paused. This test is best when run over RDP with audio enabled. See
281 // bug 19276 for more details. 281 // bug 19276 for more details.
282 TEST_F(WinAudioTest, PCMWaveStreamPlaySlowLoop) { 282 TEST_F(WinAudioTest, PCMWaveStreamPlaySlowLoop) {
283 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 283 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
284 284
285 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 285 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
286 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 286 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
287 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 287 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
288 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 288 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
289 std::string()); 289 std::string(), AudioManager::LogCallback());
290 ASSERT_TRUE(NULL != oas); 290 ASSERT_TRUE(NULL != oas);
291 291
292 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 292 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
293 293
294 EXPECT_TRUE(oas->Open()); 294 EXPECT_TRUE(oas->Open());
295 oas->SetVolume(1.0); 295 oas->SetVolume(1.0);
296 296
297 for (int ix = 0; ix != 5; ++ix) { 297 for (int ix = 0; ix != 5; ++ix) {
298 oas->Start(&source); 298 oas->Start(&source);
299 ::Sleep(10); 299 ::Sleep(10);
300 oas->Stop(); 300 oas->Stop();
301 } 301 }
302 oas->Close(); 302 oas->Close();
303 } 303 }
304 304
305 305
306 // This test produces actual audio for .5 seconds on the default wave 306 // This test produces actual audio for .5 seconds on the default wave
307 // device at 44.1K s/sec. Parameters have been chosen carefully so you should 307 // device at 44.1K s/sec. Parameters have been chosen carefully so you should
308 // not hear pops or noises while the sound is playing. 308 // not hear pops or noises while the sound is playing.
309 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { 309 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) {
310 if (!audio_manager_->HasAudioOutputDevices()) { 310 if (!audio_manager_->HasAudioOutputDevices()) {
311 LOG(WARNING) << "No output device detected."; 311 LOG(WARNING) << "No output device detected.";
312 return; 312 return;
313 } 313 }
314 314
315 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 315 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
316 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 316 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
317 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 317 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
318 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 318 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
319 std::string()); 319 std::string(), AudioManager::LogCallback());
320 ASSERT_TRUE(NULL != oas); 320 ASSERT_TRUE(NULL != oas);
321 321
322 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 322 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
323 323
324 EXPECT_TRUE(oas->Open()); 324 EXPECT_TRUE(oas->Open());
325 oas->SetVolume(1.0); 325 oas->SetVolume(1.0);
326 oas->Start(&source); 326 oas->Start(&source);
327 ::Sleep(500); 327 ::Sleep(500);
328 oas->Stop(); 328 oas->Stop();
329 oas->Close(); 329 oas->Close();
330 } 330 }
331 331
332 // This test produces actual audio for for .5 seconds on the default wave 332 // This test produces actual audio for for .5 seconds on the default wave
333 // device at 22K s/sec. Parameters have been chosen carefully so you should 333 // device at 22K s/sec. Parameters have been chosen carefully so you should
334 // not hear pops or noises while the sound is playing. The audio also should 334 // not hear pops or noises while the sound is playing. The audio also should
335 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. 335 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss.
336 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { 336 TEST_F(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) {
337 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 337 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
338 338
339 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; 339 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20;
340 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 340 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
341 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 341 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
342 AudioParameters::kAudioCDSampleRate / 2, 16, 342 AudioParameters::kAudioCDSampleRate / 2, 16,
343 samples_100_ms), 343 samples_100_ms),
344 std::string()); 344 std::string(), AudioManager::LogCallback());
345 ASSERT_TRUE(NULL != oas); 345 ASSERT_TRUE(NULL != oas);
346 346
347 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2); 347 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate/2);
348 348
349 EXPECT_TRUE(oas->Open()); 349 EXPECT_TRUE(oas->Open());
350 350
351 oas->SetVolume(0.5); 351 oas->SetVolume(0.5);
352 oas->Start(&source); 352 oas->Start(&source);
353 ::Sleep(500); 353 ::Sleep(500);
354 354
(...skipping 15 matching lines...) Expand all
370 static const int kSampleRate = 16000; 370 static const int kSampleRate = 16000;
371 SineWaveAudioSource source(1, 200.0, kSampleRate); 371 SineWaveAudioSource source(1, 200.0, kSampleRate);
372 // Compute buffer size for 100ms of audio. 372 // Compute buffer size for 100ms of audio.
373 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100; 373 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100;
374 // Restrict SineWaveAudioSource to 100ms of samples. 374 // Restrict SineWaveAudioSource to 100ms of samples.
375 source.CapSamples(kSamples100ms); 375 source.CapSamples(kSamples100ms);
376 376
377 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 377 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
378 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 378 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
379 kSampleRate, 16, kSamples100ms), 379 kSampleRate, 16, kSamples100ms),
380 std::string()); 380 std::string(), AudioManager::LogCallback());
381 ASSERT_TRUE(NULL != oas); 381 ASSERT_TRUE(NULL != oas);
382 382
383 EXPECT_TRUE(oas->Open()); 383 EXPECT_TRUE(oas->Open());
384 384
385 oas->SetVolume(1.0); 385 oas->SetVolume(1.0);
386 oas->Start(&source); 386 oas->Start(&source);
387 387
388 // We buffer and play at the same time, buffering happens every ~10ms and the 388 // We buffer and play at the same time, buffering happens every ~10ms and the
389 // consuming of the buffer happens every ~100ms. We do 100 buffers which 389 // consuming of the buffer happens every ~100ms. We do 100 buffers which
390 // effectively wrap around the file more than once. 390 // effectively wrap around the file more than once.
(...skipping 12 matching lines...) Expand all
403 // This test is to make sure an AudioOutputStream can be started after it was 403 // This test is to make sure an AudioOutputStream can be started after it was
404 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds 404 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds
405 // of silence. 405 // of silence.
406 TEST_F(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { 406 TEST_F(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) {
407 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 407 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
408 408
409 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 409 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
410 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 410 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
411 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 411 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
412 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 412 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
413 std::string()); 413 std::string(), AudioManager::LogCallback());
414 ASSERT_TRUE(NULL != oas); 414 ASSERT_TRUE(NULL != oas);
415 415
416 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 416 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
417 EXPECT_TRUE(oas->Open()); 417 EXPECT_TRUE(oas->Open());
418 oas->SetVolume(1.0); 418 oas->SetVolume(1.0);
419 419
420 // Play the wave for .5 seconds. 420 // Play the wave for .5 seconds.
421 oas->Start(&source); 421 oas->Start(&source);
422 ::Sleep(500); 422 ::Sleep(500);
423 oas->Stop(); 423 oas->Stop();
(...skipping 19 matching lines...) Expand all
443 // Take the existing native sample rate into account. 443 // Take the existing native sample rate into account.
444 const AudioParameters params = 444 const AudioParameters params =
445 audio_manager_->GetDefaultOutputStreamParameters(); 445 audio_manager_->GetDefaultOutputStreamParameters();
446 int sample_rate = params.sample_rate(); 446 int sample_rate = params.sample_rate();
447 uint32_t samples_10_ms = sample_rate / 100; 447 uint32_t samples_10_ms = sample_rate / 100;
448 int n = 1; 448 int n = 1;
449 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; 449 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1;
450 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 450 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
451 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 451 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
452 CHANNEL_LAYOUT_MONO, sample_rate, 16, n * samples_10_ms), 452 CHANNEL_LAYOUT_MONO, sample_rate, 16, n * samples_10_ms),
453 std::string()); 453 std::string(), AudioManager::LogCallback());
454 ASSERT_TRUE(NULL != oas); 454 ASSERT_TRUE(NULL != oas);
455 455
456 SineWaveAudioSource source(1, 200, sample_rate); 456 SineWaveAudioSource source(1, 200, sample_rate);
457 457
458 bool opened = oas->Open(); 458 bool opened = oas->Open();
459 if (!opened) { 459 if (!opened) {
460 // It was not possible to open this audio device in mono. 460 // It was not possible to open this audio device in mono.
461 // No point in continuing the test so let's break here. 461 // No point in continuing the test so let's break here.
462 LOG(WARNING) << "Mono is not supported. Skipping test."; 462 LOG(WARNING) << "Mono is not supported. Skipping test.";
463 oas->Close(); 463 oas->Close();
464 return; 464 return;
465 } 465 }
466 oas->SetVolume(1.0); 466 oas->SetVolume(1.0);
467 467
468 // Play the wave for .8 seconds. 468 // Play the wave for .8 seconds.
469 oas->Start(&source); 469 oas->Start(&source);
470 ::Sleep(800); 470 ::Sleep(800);
471 oas->Stop(); 471 oas->Stop();
472 oas->Close(); 472 oas->Close();
473 } 473 }
474 474
475 // Check that the pending bytes value is correct what the stream starts. 475 // Check that the pending bytes value is correct what the stream starts.
476 TEST_F(WinAudioTest, PCMWaveStreamPendingBytes) { 476 TEST_F(WinAudioTest, PCMWaveStreamPendingBytes) {
477 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 477 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
478 478
479 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 479 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
480 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream( 480 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
481 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 481 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
482 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 482 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
483 std::string()); 483 std::string(), AudioManager::LogCallback());
484 ASSERT_TRUE(NULL != oas); 484 ASSERT_TRUE(NULL != oas);
485 485
486 NiceMock<MockAudioSourceCallback> source; 486 NiceMock<MockAudioSourceCallback> source;
487 EXPECT_TRUE(oas->Open()); 487 EXPECT_TRUE(oas->Open());
488 488
489 uint32_t bytes_100_ms = samples_100_ms * 2; 489 uint32_t bytes_100_ms = samples_100_ms * 2;
490 490
491 // Audio output stream has either a double or triple buffer scheme. 491 // Audio output stream has either a double or triple buffer scheme.
492 // We expect the amount of pending bytes will reaching up to 2 times of 492 // We expect the amount of pending bytes will reaching up to 2 times of
493 // |bytes_100_ms| depending on number of buffers used. 493 // |bytes_100_ms| depending on number of buffers used.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. 605 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY.
606 // In this test you should hear a continuous 200Hz tone for 2 seconds. 606 // In this test you should hear a continuous 200Hz tone for 2 seconds.
607 TEST_F(WinAudioTest, SyncSocketBasic) { 607 TEST_F(WinAudioTest, SyncSocketBasic) {
608 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices()); 608 ABORT_AUDIO_TEST_IF_NOT(audio_manager_->HasAudioOutputDevices());
609 609
610 static const int sample_rate = AudioParameters::kAudioCDSampleRate; 610 static const int sample_rate = AudioParameters::kAudioCDSampleRate;
611 static const uint32_t kSamples20ms = sample_rate / 50; 611 static const uint32_t kSamples20ms = sample_rate / 50;
612 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 612 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
613 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); 613 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms);
614 614
615 AudioOutputStream* oas = 615 AudioOutputStream* oas = audio_manager_->MakeAudioOutputStream(
616 audio_manager_->MakeAudioOutputStream(params, std::string()); 616 params, std::string(), AudioManager::LogCallback());
617 ASSERT_TRUE(NULL != oas); 617 ASSERT_TRUE(NULL != oas);
618 618
619 ASSERT_TRUE(oas->Open()); 619 ASSERT_TRUE(oas->Open());
620 620
621 base::SyncSocket sockets[2]; 621 base::SyncSocket sockets[2];
622 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1])); 622 ASSERT_TRUE(base::SyncSocket::CreatePair(&sockets[0], &sockets[1]));
623 623
624 SyncSocketSource source(&sockets[0], params); 624 SyncSocketSource source(&sockets[0], params);
625 625
626 SyncThreadContext thread_context; 626 SyncThreadContext thread_context;
(...skipping 10 matching lines...) Expand all
637 oas->Start(&source); 637 oas->Start(&source);
638 638
639 ::WaitForSingleObject(thread, INFINITE); 639 ::WaitForSingleObject(thread, INFINITE);
640 ::CloseHandle(thread); 640 ::CloseHandle(thread);
641 641
642 oas->Stop(); 642 oas->Stop();
643 oas->Close(); 643 oas->Close();
644 } 644 }
645 645
646 } // namespace media 646 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_manager_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698