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 void AudioHandler::OnMixerInitialized(bool success) { | 98 bool AudioHandler::IsValid() { |
99 connected_ = success; | 99 return mixer_->CheckState() == PulseAudioMixer::READY; |
100 DLOG(INFO) << "OnMixerInitialized, success = " << success; | |
101 } | 100 } |
102 | 101 |
103 AudioHandler::AudioHandler() | 102 AudioHandler::AudioHandler() |
104 : connected_(false), | 103 : reconnect_tries_(0) { |
105 reconnect_tries_(0) { | |
106 mixer_.reset(new PulseAudioMixer()); | 104 mixer_.reset(new PulseAudioMixer()); |
107 if (!mixer_->Init(NewCallback(this, &AudioHandler::OnMixerInitialized))) { | 105 connected_ = mixer_->InitSync(); |
108 LOG(ERROR) << "Unable to connect to PulseAudio"; | 106 DLOG(INFO) << "Mixer connected = " << connected_; |
109 } | |
110 } | 107 } |
111 | 108 |
112 AudioHandler::~AudioHandler() { | 109 AudioHandler::~AudioHandler() { |
113 }; | 110 }; |
114 | 111 |
115 bool AudioHandler::VerifyMixerConnection() { | 112 bool AudioHandler::VerifyMixerConnection() { |
116 PulseAudioMixer::State mixer_state = mixer_->CheckState(); | 113 PulseAudioMixer::State mixer_state = mixer_->CheckState(); |
117 if (mixer_state == PulseAudioMixer::READY) | 114 if (mixer_state == PulseAudioMixer::READY) |
118 return true; | 115 return true; |
119 if (connected_) { | 116 if (connected_) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 (kMaxVolumeDb - kMinVolumeDb), 1/kVolumeBias); | 158 (kMaxVolumeDb - kMinVolumeDb), 1/kVolumeBias); |
162 } | 159 } |
163 | 160 |
164 // static | 161 // static |
165 double AudioHandler::PercentToVolumeDb(double volume_percent) { | 162 double AudioHandler::PercentToVolumeDb(double volume_percent) { |
166 return pow(volume_percent / 100.0, kVolumeBias) * | 163 return pow(volume_percent / 100.0, kVolumeBias) * |
167 (kMaxVolumeDb - kMinVolumeDb) + kMinVolumeDb; | 164 (kMaxVolumeDb - kMinVolumeDb) + kMinVolumeDb; |
168 } | 165 } |
169 | 166 |
170 } // namespace chromeos | 167 } // namespace chromeos |
OLD | NEW |