| OLD | NEW |
| 1 // Copyright (c) 2011 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 <unistd.h> | 7 #include <unistd.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 base::AutoLock lock(lock_); | 135 base::AutoLock lock(lock_); |
| 136 if (isnan(volume_db)) { | 136 if (isnan(volume_db)) { |
| 137 LOG(WARNING) << "Got request to set volume to NaN"; | 137 LOG(WARNING) << "Got request to set volume to NaN"; |
| 138 volume_db = min_volume_db_; | 138 volume_db = min_volume_db_; |
| 139 } else { | 139 } else { |
| 140 volume_db = min(max(volume_db, min_volume_db_), max_volume_db_); | 140 volume_db = min(max(volume_db, min_volume_db_), max_volume_db_); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 prefs_->SetDouble(prefs::kAudioVolume, volume_db); | 144 prefs_->SetDouble(prefs::kAudioVolume, volume_db); |
| 145 prefs_->ScheduleSavePersistentPrefs(); | |
| 146 | 145 |
| 147 base::AutoLock lock(lock_); | 146 base::AutoLock lock(lock_); |
| 148 volume_db_ = volume_db; | 147 volume_db_ = volume_db; |
| 149 if (!apply_is_pending_) | 148 if (!apply_is_pending_) |
| 150 thread_->message_loop()->PostTask(FROM_HERE, | 149 thread_->message_loop()->PostTask(FROM_HERE, |
| 151 base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); | 150 base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| 152 } | 151 } |
| 153 | 152 |
| 154 bool AudioMixerAlsa::IsMuted() { | 153 bool AudioMixerAlsa::IsMuted() { |
| 155 base::AutoLock lock(lock_); | 154 base::AutoLock lock(lock_); |
| 156 return is_muted_; | 155 return is_muted_; |
| 157 } | 156 } |
| 158 | 157 |
| 159 void AudioMixerAlsa::SetMuted(bool muted) { | 158 void AudioMixerAlsa::SetMuted(bool muted) { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 prefs_->SetInteger(prefs::kAudioMute, muted ? kPrefMuteOn : kPrefMuteOff); | 160 prefs_->SetInteger(prefs::kAudioMute, muted ? kPrefMuteOn : kPrefMuteOff); |
| 162 prefs_->ScheduleSavePersistentPrefs(); | |
| 163 base::AutoLock lock(lock_); | 161 base::AutoLock lock(lock_); |
| 164 is_muted_ = muted; | 162 is_muted_ = muted; |
| 165 if (!apply_is_pending_) | 163 if (!apply_is_pending_) |
| 166 thread_->message_loop()->PostTask(FROM_HERE, | 164 thread_->message_loop()->PostTask(FROM_HERE, |
| 167 base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); | 165 base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| 168 } | 166 } |
| 169 | 167 |
| 170 // static | 168 // static |
| 171 void AudioMixerAlsa::RegisterPrefs(PrefService* local_state) { | 169 void AudioMixerAlsa::RegisterPrefs(PrefService* local_state) { |
| 172 // TODO(derat): Store audio volume percent instead of decibels. | 170 // TODO(derat): Store audio volume percent instead of decibels. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 if (alsa_result != 0) { | 447 if (alsa_result != 0) { |
| 450 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: " | 448 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: " |
| 451 << snd_strerror(alsa_result); | 449 << snd_strerror(alsa_result); |
| 452 } else { | 450 } else { |
| 453 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(element) | 451 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(element) |
| 454 << " to " << mute; | 452 << " to " << mute; |
| 455 } | 453 } |
| 456 } | 454 } |
| 457 | 455 |
| 458 } // namespace chromeos | 456 } // namespace chromeos |
| OLD | NEW |