| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <alsa/asoundlib.h> | 7 #include <alsa/asoundlib.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "base/threading/thread_restrictions.h" |
| 11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 | 16 |
| 16 namespace chromeos { | 17 namespace chromeos { |
| 17 | 18 |
| 18 // Connect to the ALSA mixer using their simple element API. Init is performed | 19 // Connect to the ALSA mixer using their simple element API. Init is performed |
| 19 // asynchronously on the worker thread. | 20 // asynchronously on the worker thread. |
| 20 // | 21 // |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 save_volume_(0), | 45 save_volume_(0), |
| 45 mixer_state_(UNINITIALIZED), | 46 mixer_state_(UNINITIALIZED), |
| 46 alsa_mixer_(NULL), | 47 alsa_mixer_(NULL), |
| 47 elem_master_(NULL), | 48 elem_master_(NULL), |
| 48 elem_pcm_(NULL) { | 49 elem_pcm_(NULL) { |
| 49 } | 50 } |
| 50 | 51 |
| 51 AudioMixerAlsa::~AudioMixerAlsa() { | 52 AudioMixerAlsa::~AudioMixerAlsa() { |
| 52 FreeAlsaMixer(); | 53 FreeAlsaMixer(); |
| 53 if (thread_ != NULL) { | 54 if (thread_ != NULL) { |
| 55 // A ScopedAllowIO object is required to join the thread when calling Stop. |
| 56 // The worker thread should be idle at this time. |
| 57 // See http://crosbug.com/11110 for discussion. |
| 58 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; |
| 59 |
| 54 thread_->Stop(); | 60 thread_->Stop(); |
| 55 thread_.reset(); | 61 thread_.reset(); |
| 56 } | 62 } |
| 57 } | 63 } |
| 58 | 64 |
| 59 void AudioMixerAlsa::Init(InitDoneCallback* callback) { | 65 void AudioMixerAlsa::Init(InitDoneCallback* callback) { |
| 60 DCHECK(callback); | 66 DCHECK(callback); |
| 61 if (!InitThread()) { | 67 if (!InitThread()) { |
| 62 callback->Run(false); | 68 callback->Run(false); |
| 63 delete callback; | 69 delete callback; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 mute = GetElementMuted_Locked(elem_master_); | 300 mute = GetElementMuted_Locked(elem_master_); |
| 295 else | 301 else |
| 296 mute = (pref_mute == kPrefMuteOn) ? true : false; | 302 mute = (pref_mute == kPrefMuteOn) ? true : false; |
| 297 | 303 |
| 298 VLOG(1) << "Setting volume to " << pref_volume << " and mute to " << mute; | 304 VLOG(1) << "Setting volume to " << pref_volume << " and mute to " << mute; |
| 299 | 305 |
| 300 if (mute) { | 306 if (mute) { |
| 301 save_volume_ = pref_volume; | 307 save_volume_ = pref_volume; |
| 302 DoSetVolumeDb_Locked(min_volume_); | 308 DoSetVolumeDb_Locked(min_volume_); |
| 303 } else { | 309 } else { |
| 304 DoSetVolumeDb_Locked(pref_volume); | 310 DoSetVolumeDb_Locked(pref_volume); |
| 305 } | 311 } |
| 306 | 312 |
| 307 SetElementMuted_Locked(elem_master_, mute); | 313 SetElementMuted_Locked(elem_master_, mute); |
| 308 if (elem_pcm_) | 314 if (elem_pcm_) |
| 309 SetElementMuted_Locked(elem_pcm_, mute); | 315 SetElementMuted_Locked(elem_pcm_, mute); |
| 310 } | 316 } |
| 311 | 317 |
| 312 void AudioMixerAlsa::RestoreVolumeMuteOnUIThread() { | 318 void AudioMixerAlsa::RestoreVolumeMuteOnUIThread() { |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 314 // This happens during init, so set the volume off the UI thread. | 320 // This happens during init, so set the volume off the UI thread. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { | 438 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { |
| 433 int enabled = mute ? 0 : 1; | 439 int enabled = mute ? 0 : 1; |
| 434 snd_mixer_selem_set_playback_switch_all(elem, enabled); | 440 snd_mixer_selem_set_playback_switch_all(elem, enabled); |
| 435 | 441 |
| 436 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) | 442 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) |
| 437 << " to " << enabled; | 443 << " to " << enabled; |
| 438 } | 444 } |
| 439 | 445 |
| 440 } // namespace chromeos | 446 } // namespace chromeos |
| 441 | 447 |
| OLD | NEW |