Chromium Code Reviews| Index: chrome/browser/chromeos/audio_mixer_alsa.cc |
| diff --git a/chrome/browser/chromeos/audio_mixer_alsa.cc b/chrome/browser/chromeos/audio_mixer_alsa.cc |
| index a84ffeb519be7b51dc30805aebca216a9f8675a6..4b324de4048d5cd93e09ac0ad35eeb4d9c679e9a 100644 |
| --- a/chrome/browser/chromeos/audio_mixer_alsa.cc |
| +++ b/chrome/browser/chromeos/audio_mixer_alsa.cc |
| @@ -1,10 +1,11 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 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. |
| #include "chrome/browser/chromeos/audio_mixer_alsa.h" |
| #include <cmath> |
| +#include <unistd.h> |
| #include <alsa/asoundlib.h> |
| @@ -40,6 +41,14 @@ const int kPrefMuteOff = 0; |
| const int kPrefMuteOn = 1; |
| const int kPrefMuteInvalid = 2; |
| +// Maximum number of times that we'll attempt to initialize the mixer. |
| +// We'll fail until the ALSA modules have been loaded; see |
| +// http://crosbug.com/13162. |
| +const int kMaxInitAttempts = 20; |
| + |
| +// Number of seconds that we'll sleep between each initialization attempt. |
| +const int kInitRetrySleepSec = 1; |
| + |
| } // namespace |
| AudioMixerAlsa::AudioMixerAlsa() |
| @@ -198,7 +207,14 @@ void AudioMixerAlsa::RegisterPrefs(PrefService* local_state) { |
| // Private functions follow |
| void AudioMixerAlsa::DoInit(InitDoneCallback* callback) { |
| - bool success = InitializeAlsaMixer(); |
| + bool success = false; |
| + for (int num_attempts = 0; num_attempts < kMaxInitAttempts; ++num_attempts) { |
| + success = InitializeAlsaMixer(); |
| + if (success) |
| + break; |
| + else |
| + sleep(kInitRetrySleepSec); |
| + } |
|
davejcool
2011/03/29 17:50:55
There's a case where InitializeAlsaMixer() will re
Daniel Erat
2011/03/29 19:45:55
Thanks, that's a good point. But holding the lock
davejcool
2011/03/30 17:42:15
Ah, right - for this to work sleep() should be don
|
| if (success) { |
| BrowserThread::PostTask( |