summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_util.cc
diff options
context:
space:
mode:
authorenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 06:29:16 +0000
committerenal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 06:29:16 +0000
commitd9893c848f639b31db18055d686d81008738b954 (patch)
tree2f8235bd0904bdf1bed7182935da361987f3c36b /media/audio/audio_util.cc
parent1582387e898ffc722d7f34768e257d1d25b9cde8 (diff)
downloadchromium_src-d9893c848f639b31db18055d686d81008738b954.zip
chromium_src-d9893c848f639b31db18055d686d81008738b954.tar.gz
chromium_src-d9893c848f639b31db18055d686d81008738b954.tar.bz2
Change the way we are sending audio data to driver when using WaveOut API.
Before, we were "feeding" the driver in the callback when OS returned audio buffer to us. MSDN disallows that, but We were avoiding deadlock when stopping the stream by using some clever tricks. Unfortunately, exactly the same deadlock happens when Windows were draining audio stream when switching the device, and our tricks did not help, as we were not controlling exact timing. Fix is to separate receiving freed buffer and "feeding" audio driver. Now we are using CALLBACK_EVENT wave out mode in which Windows signal event when buffer runs out of data, and using RegisterWaitForSingleObject() so our callback is called by one of thread pool threads. Stopping of playback became slower because now it is synchronous. If that ever become a problem we can use singleton that keeps track of the playing audio streams, than stopping can become instaneous, at a cost of more complex checks in the callback. Unfortunately, no automatic test, as there is no documented way to programmatically switch default audio device on Windows. People were able to figure it out (see http://www.daveamenta.com/2011-05/programmatically-or-command-line-change-the-default-sound-playback-device-in-windows-7/), but there is no guarantee it will continue to work in Win8, or even in next Service Pack for Win7. BUG=41036 TEST=Play any HTML5 audio/video on Windows and change default audio device TEST=using "Control Panel | Sound". There should be no hang, you should hear TEST=audio from the newly chosen device. Review URL: http://codereview.chromium.org/8591028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112147 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_util.cc')
-rw-r--r--media/audio/audio_util.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index 4aec30d..48be2db 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -293,6 +293,11 @@ size_t GetAudioHardwareBufferSize() {
#if defined(OS_MACOSX)
return 128;
#elif defined(OS_WIN)
+ if (base::win::GetVersion() <= base::win::VERSION_XP) {
+ // Fall back to Windows Wave implementation on Windows XP or lower
+ // and assume 48kHz as default sample rate.
+ return 2048;
+ }
// This call must be done on a COM thread configured as MTA.
// TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835.
int mixing_sample_rate =