diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 35 | ||||
-rw-r--r-- | media/audio/win/waveout_output_win.cc | 18 |
2 files changed, 47 insertions, 6 deletions
diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index f47bd9c..bc5b61a 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -285,7 +285,7 @@ TEST(WinAudioTest, PCMWaveStreamDoubleBuffer) { oas->Close(); } -// Test potential deadlock situations if the source is slow or blocks for some +// Test potential deadlock situation if the source is slow or blocks for some // time. The actual EXPECT_GT are mostly meaningless and the real test is that // the test completes in reasonable time. TEST(WinAudioTest, PCMWaveSlowSource) { @@ -311,6 +311,37 @@ TEST(WinAudioTest, PCMWaveSlowSource) { oas->Close(); } +// Test another potential deadlock situation if the thread that calls Start() +// gets paused. This test is best when run over RDP with audio enabled. See +// bug 19276 for more details. +TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { + if (IsRunningHeadless()) + return; + AudioManager* audio_man = AudioManager::GetAudioManager(); + ASSERT_TRUE(NULL != audio_man); + if (!audio_man->HasAudioDevices()) + return; + AudioOutputStream* oas = + audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, + AudioManager::kAudioCDSampleRate, 16); + ASSERT_TRUE(NULL != oas); + + SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, + 200.0, AudioManager::kAudioCDSampleRate); + size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; + + EXPECT_TRUE(oas->Open(bytes_100_ms)); + oas->SetVolume(1.0, 1.0); + + for (int ix = 0; ix != 25; ++ix) { + oas->Start(&source); + ::Sleep(10); + oas->Stop(); + } + oas->Close(); +} + + // This test produces actual audio for 1.5 seconds on the default wave // device at 44.1K s/sec. Parameters have been chosen carefully so you should // not hear pops or noises while the sound is playing. diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc index 40d17d3..44bfb73 100644 --- a/media/audio/win/waveout_output_win.cc +++ b/media/audio/win/waveout_output_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -153,16 +153,26 @@ void PCMWaveOutAudioOutputStream::Start(AudioSourceCallback* callback) { buffer = GetNextBuffer(buffer); } buffer = buffer_; - - // Send the buffers to the audio driver. + MMRESULT result = ::waveOutPause(waveout_); + if (result != MMSYSERR_NOERROR) { + HandleError(result); + return; + } + // Send the buffers to the audio driver. Note that the device is paused + // so we avoid entering the callback method while still here. for (int ix = 0; ix != kNumBuffers; ++ix) { - MMRESULT result = ::waveOutWrite(waveout_, buffer, sizeof(WAVEHDR)); + result = ::waveOutWrite(waveout_, buffer, sizeof(WAVEHDR)); if (result != MMSYSERR_NOERROR) { HandleError(result); break; } buffer = GetNextBuffer(buffer); } + result = ::waveOutRestart(waveout_); + if (result != MMSYSERR_NOERROR) { + HandleError(result); + return; + } } // Stopping is tricky. First, no buffer should be locked by the audio driver |