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

Side by Side Diff: chrome/browser/chromeos/audio_mixer_alsa.cc

Issue 6760014: chromeos: Retry ALSA mixer initialization on failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge and update copyright year Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/audio_mixer_alsa.h" 5 #include "chrome/browser/chromeos/audio_mixer_alsa.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <unistd.h>
8 9
9 #include <alsa/asoundlib.h> 10 #include <alsa/asoundlib.h>
10 11
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/task.h" 14 #include "base/task.h"
14 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/prefs/pref_service.h" 17 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
(...skipping 15 matching lines...) Expand all
33 34
34 const char kMasterVolume[] = "Master"; 35 const char kMasterVolume[] = "Master";
35 const char kPCMVolume[] = "PCM"; 36 const char kPCMVolume[] = "PCM";
36 const double kDefaultMinVolume = -90.0; 37 const double kDefaultMinVolume = -90.0;
37 const double kDefaultMaxVolume = 0.0; 38 const double kDefaultMaxVolume = 0.0;
38 const double kPrefVolumeInvalid = -999.0; 39 const double kPrefVolumeInvalid = -999.0;
39 const int kPrefMuteOff = 0; 40 const int kPrefMuteOff = 0;
40 const int kPrefMuteOn = 1; 41 const int kPrefMuteOn = 1;
41 const int kPrefMuteInvalid = 2; 42 const int kPrefMuteInvalid = 2;
42 43
44 // Maximum number of times that we'll attempt to initialize the mixer.
45 // We'll fail until the ALSA modules have been loaded; see
46 // http://crosbug.com/13162.
47 const int kMaxInitAttempts = 20;
48
49 // Number of seconds that we'll sleep between each initialization attempt.
50 const int kInitRetrySleepSec = 1;
51
43 } // namespace 52 } // namespace
44 53
45 AudioMixerAlsa::AudioMixerAlsa() 54 AudioMixerAlsa::AudioMixerAlsa()
46 : min_volume_(kDefaultMinVolume), 55 : min_volume_(kDefaultMinVolume),
47 max_volume_(kDefaultMaxVolume), 56 max_volume_(kDefaultMaxVolume),
48 save_volume_(0), 57 save_volume_(0),
49 mixer_state_(UNINITIALIZED), 58 mixer_state_(UNINITIALIZED),
50 alsa_mixer_(NULL), 59 alsa_mixer_(NULL),
51 elem_master_(NULL), 60 elem_master_(NULL),
52 elem_pcm_(NULL), 61 elem_pcm_(NULL),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (!local_state->FindPreference(prefs::kAudioVolume)) 200 if (!local_state->FindPreference(prefs::kAudioVolume))
192 local_state->RegisterDoublePref(prefs::kAudioVolume, kPrefVolumeInvalid); 201 local_state->RegisterDoublePref(prefs::kAudioVolume, kPrefVolumeInvalid);
193 if (!local_state->FindPreference(prefs::kAudioMute)) 202 if (!local_state->FindPreference(prefs::kAudioMute))
194 local_state->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteInvalid); 203 local_state->RegisterIntegerPref(prefs::kAudioMute, kPrefMuteInvalid);
195 } 204 }
196 205
197 //////////////////////////////////////////////////////////////////////////////// 206 ////////////////////////////////////////////////////////////////////////////////
198 // Private functions follow 207 // Private functions follow
199 208
200 void AudioMixerAlsa::DoInit(InitDoneCallback* callback) { 209 void AudioMixerAlsa::DoInit(InitDoneCallback* callback) {
201 bool success = InitializeAlsaMixer(); 210 bool success = false;
211 for (int num_attempts = 0; num_attempts < kMaxInitAttempts; ++num_attempts) {
212 success = InitializeAlsaMixer();
213 if (success)
214 break;
215 else
216 sleep(kInitRetrySleepSec);
217 }
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
202 218
203 if (success) { 219 if (success) {
204 BrowserThread::PostTask( 220 BrowserThread::PostTask(
205 BrowserThread::UI, FROM_HERE, 221 BrowserThread::UI, FROM_HERE,
206 NewRunnableMethod(this, &AudioMixerAlsa::RestoreVolumeMuteOnUIThread)); 222 NewRunnableMethod(this, &AudioMixerAlsa::RestoreVolumeMuteOnUIThread));
207 } 223 }
208 224
209 if (callback) { 225 if (callback) {
210 callback->Run(success); 226 callback->Run(success);
211 delete callback; 227 delete callback;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (alsa_result != 0) { 538 if (alsa_result != 0) {
523 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: " 539 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: "
524 << snd_strerror(alsa_result); 540 << snd_strerror(alsa_result);
525 } else { 541 } else {
526 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) 542 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem)
527 << " to " << enabled; 543 << " to " << enabled;
528 } 544 }
529 } 545 }
530 546
531 } // namespace chromeos 547 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698