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_handler.h" | 5 #include "chrome/browser/chromeos/audio_handler.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/chromeos/pulse_audio_mixer.h" | 10 #include "chrome/browser/chromeos/pulse_audio_mixer.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void AudioHandler::SetMute(bool do_mute) { | 89 void AudioHandler::SetMute(bool do_mute) { |
90 if (!VerifyMixerConnection()) | 90 if (!VerifyMixerConnection()) |
91 return; | 91 return; |
92 | 92 |
93 DLOG(INFO) << "Setting Mute to " << do_mute; | 93 DLOG(INFO) << "Setting Mute to " << do_mute; |
94 | 94 |
95 mixer_->SetMute(do_mute); | 95 mixer_->SetMute(do_mute); |
96 } | 96 } |
97 | 97 |
98 bool AudioHandler::IsValid() { | 98 void AudioHandler::OnMixerInitialized(bool success) { |
99 return mixer_->CheckState() == PulseAudioMixer::READY; | 99 connected_ = success; |
| 100 DLOG(INFO) << "OnMixerInitialized, success = " << success; |
100 } | 101 } |
101 | 102 |
102 AudioHandler::AudioHandler() | 103 AudioHandler::AudioHandler() |
103 : reconnect_tries_(0) { | 104 : connected_(false), |
| 105 reconnect_tries_(0) { |
104 mixer_.reset(new PulseAudioMixer()); | 106 mixer_.reset(new PulseAudioMixer()); |
105 connected_ = mixer_->InitSync(); | 107 if (!mixer_->Init(NewCallback(this, &AudioHandler::OnMixerInitialized))) { |
106 DLOG(INFO) << "Mixer connected = " << connected_; | 108 LOG(ERROR) << "Unable to connect to PulseAudio"; |
| 109 } |
107 } | 110 } |
108 | 111 |
109 AudioHandler::~AudioHandler() { | 112 AudioHandler::~AudioHandler() { |
110 }; | 113 }; |
111 | 114 |
112 bool AudioHandler::VerifyMixerConnection() { | 115 bool AudioHandler::VerifyMixerConnection() { |
113 PulseAudioMixer::State mixer_state = mixer_->CheckState(); | 116 PulseAudioMixer::State mixer_state = mixer_->CheckState(); |
114 if (mixer_state == PulseAudioMixer::READY) | 117 if (mixer_state == PulseAudioMixer::READY) |
115 return true; | 118 return true; |
116 if (connected_) { | 119 if (connected_) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 (kMaxVolumeDb - kMinVolumeDb), 1/kVolumeBias); | 161 (kMaxVolumeDb - kMinVolumeDb), 1/kVolumeBias); |
159 } | 162 } |
160 | 163 |
161 // static | 164 // static |
162 double AudioHandler::PercentToVolumeDb(double volume_percent) { | 165 double AudioHandler::PercentToVolumeDb(double volume_percent) { |
163 return pow(volume_percent / 100.0, kVolumeBias) * | 166 return pow(volume_percent / 100.0, kVolumeBias) * |
164 (kMaxVolumeDb - kMinVolumeDb) + kMinVolumeDb; | 167 (kMaxVolumeDb - kMinVolumeDb) + kMinVolumeDb; |
165 } | 168 } |
166 | 169 |
167 } // namespace chromeos | 170 } // namespace chromeos |
OLD | NEW |