| 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" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 LOG(ERROR) << "ALSA mixer " << card << " load error: %s" | 245 LOG(ERROR) << "ALSA mixer " << card << " load error: %s" |
| 246 << snd_strerror(err); | 246 << snd_strerror(err); |
| 247 snd_mixer_close(handle); | 247 snd_mixer_close(handle); |
| 248 return false; | 248 return false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 VLOG(1) << "Opened ALSA mixer " << card << " OK"; | 251 VLOG(1) << "Opened ALSA mixer " << card << " OK"; |
| 252 | 252 |
| 253 elem_master_ = FindElementWithName_Locked(handle, kMasterVolume); | 253 elem_master_ = FindElementWithName_Locked(handle, kMasterVolume); |
| 254 if (elem_master_) { | 254 if (elem_master_) { |
| 255 alsa_long_t long_lo, long_hi; | 255 alsa_long_t long_lo = static_cast<alsa_long_t>(kDefaultMinVolume * 100); |
| 256 alsa_long_t long_hi = static_cast<alsa_long_t>(kDefaultMaxVolume * 100); |
| 256 snd_mixer_selem_get_playback_dB_range(elem_master_, &long_lo, &long_hi); | 257 snd_mixer_selem_get_playback_dB_range(elem_master_, &long_lo, &long_hi); |
| 257 min_volume_ = static_cast<double>(long_lo) / 100.0; | 258 min_volume_ = static_cast<double>(long_lo) / 100.0; |
| 258 max_volume_ = static_cast<double>(long_hi) / 100.0; | 259 max_volume_ = static_cast<double>(long_hi) / 100.0; |
| 259 } else { | 260 } else { |
| 260 LOG(ERROR) << "Cannot find 'Master' ALSA mixer element on " << card; | 261 LOG(ERROR) << "Cannot find 'Master' ALSA mixer element on " << card; |
| 261 snd_mixer_close(handle); | 262 snd_mixer_close(handle); |
| 262 return false; | 263 return false; |
| 263 } | 264 } |
| 264 | 265 |
| 265 elem_pcm_ = FindElementWithName_Locked(handle, kPCMVolume); | 266 elem_pcm_ = FindElementWithName_Locked(handle, kPCMVolume); |
| 266 if (elem_pcm_) { | 267 if (elem_pcm_) { |
| 267 alsa_long_t long_lo, long_hi; | 268 alsa_long_t long_lo = static_cast<alsa_long_t>(kDefaultMinVolume * 100); |
| 269 alsa_long_t long_hi = static_cast<alsa_long_t>(kDefaultMaxVolume * 100); |
| 268 snd_mixer_selem_get_playback_dB_range(elem_pcm_, &long_lo, &long_hi); | 270 snd_mixer_selem_get_playback_dB_range(elem_pcm_, &long_lo, &long_hi); |
| 269 min_volume_ += static_cast<double>(long_lo) / 100.0; | 271 min_volume_ += static_cast<double>(long_lo) / 100.0; |
| 270 max_volume_ += static_cast<double>(long_hi) / 100.0; | 272 max_volume_ += static_cast<double>(long_hi) / 100.0; |
| 271 } | 273 } |
| 272 | 274 |
| 273 VLOG(1) << "ALSA volume range is " << min_volume_ << " dB to " | 275 VLOG(1) << "ALSA volume range is " << min_volume_ << " dB to " |
| 274 << max_volume_ << " dB"; | 276 << max_volume_ << " dB"; |
| 275 | 277 |
| 276 alsa_mixer_ = handle; | 278 alsa_mixer_ = handle; |
| 277 mixer_state_ = READY; | 279 mixer_state_ = READY; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 408 |
| 407 alsa_long_t value = static_cast<alsa_long_t>(rounding_bias + | 409 alsa_long_t value = static_cast<alsa_long_t>(rounding_bias + |
| 408 (new_vol - db_lo) / db_step) + vol_lo; | 410 (new_vol - db_lo) / db_step) + vol_lo; |
| 409 snd_mixer_selem_set_playback_volume_all(elem, value); | 411 snd_mixer_selem_set_playback_volume_all(elem, value); |
| 410 | 412 |
| 411 VLOG(1) << "Set volume " << snd_mixer_selem_get_name(elem) | 413 VLOG(1) << "Set volume " << snd_mixer_selem_get_name(elem) |
| 412 << " to " << new_vol << " ==> " << (value - vol_lo) * db_step + db_lo | 414 << " to " << new_vol << " ==> " << (value - vol_lo) * db_step + db_lo |
| 413 << " dB"; | 415 << " dB"; |
| 414 | 416 |
| 415 if (actual_vol) { | 417 if (actual_vol) { |
| 416 alsa_long_t volume; | 418 alsa_long_t volume = vol_lo; |
| 417 snd_mixer_selem_get_playback_volume( | 419 snd_mixer_selem_get_playback_volume( |
| 418 elem, | 420 elem, |
| 419 static_cast<snd_mixer_selem_channel_id_t>(0), | 421 static_cast<snd_mixer_selem_channel_id_t>(0), |
| 420 &volume); | 422 &volume); |
| 421 *actual_vol = db_lo + (volume - vol_lo) * db_step; | 423 *actual_vol = db_lo + (volume - vol_lo) * db_step; |
| 422 | 424 |
| 423 VLOG(1) << "Actual volume " << snd_mixer_selem_get_name(elem) | 425 VLOG(1) << "Actual volume " << snd_mixer_selem_get_name(elem) |
| 424 << " now " << *actual_vol << " dB"; | 426 << " now " << *actual_vol << " dB"; |
| 425 } | 427 } |
| 426 return true; | 428 return true; |
| 427 } | 429 } |
| 428 | 430 |
| 429 bool AudioMixerAlsa::GetElementMuted_Locked(snd_mixer_elem_t* elem) const { | 431 bool AudioMixerAlsa::GetElementMuted_Locked(snd_mixer_elem_t* elem) const { |
| 430 int enabled; | 432 int enabled = 0; |
| 431 snd_mixer_selem_get_playback_switch( | 433 snd_mixer_selem_get_playback_switch( |
| 432 elem, | 434 elem, |
| 433 static_cast<snd_mixer_selem_channel_id_t>(0), | 435 static_cast<snd_mixer_selem_channel_id_t>(0), |
| 434 &enabled); | 436 &enabled); |
| 435 return (enabled) ? false : true; | 437 return (enabled) ? false : true; |
| 436 } | 438 } |
| 437 | 439 |
| 438 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { | 440 void AudioMixerAlsa::SetElementMuted_Locked(snd_mixer_elem_t* elem, bool mute) { |
| 439 int enabled = mute ? 0 : 1; | 441 int enabled = mute ? 0 : 1; |
| 440 snd_mixer_selem_set_playback_switch_all(elem, enabled); | 442 snd_mixer_selem_set_playback_switch_all(elem, enabled); |
| 441 | 443 |
| 442 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) | 444 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) |
| 443 << " to " << enabled; | 445 << " to " << enabled; |
| 444 } | 446 } |
| 445 | 447 |
| 446 } // namespace chromeos | 448 } // namespace chromeos |
| 447 | 449 |
| OLD | NEW |