OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 int CrasAudioHandler::GetOutputVolumePercent() { | 128 int CrasAudioHandler::GetOutputVolumePercent() { |
129 return output_volume_; | 129 return output_volume_; |
130 } | 130 } |
131 | 131 |
132 int CrasAudioHandler::GetOutputVolumePercentForDevice(uint64 device_id) { | 132 int CrasAudioHandler::GetOutputVolumePercentForDevice(uint64 device_id) { |
133 if (device_id == active_output_node_id_) { | 133 if (device_id == active_output_node_id_) { |
134 return output_volume_; | 134 return output_volume_; |
135 } else { | 135 } else { |
136 const AudioDevice* device = GetDeviceFromId(device_id); | 136 const AudioDevice* device = GetDeviceFromId(device_id); |
137 if (!device) | 137 return static_cast<int>(audio_pref_handler_->GetOutputVolumeValue(device)); |
138 return kDefaultVolumeGainPercent; | |
139 return static_cast<int>(audio_pref_handler_->GetVolumeGainValue(*device)); | |
140 } | 138 } |
141 } | 139 } |
142 | 140 |
143 int CrasAudioHandler::GetInputGainPercent() { | 141 int CrasAudioHandler::GetInputGainPercent() { |
144 return input_gain_; | 142 return input_gain_; |
145 } | 143 } |
146 | 144 |
147 int CrasAudioHandler::GetInputGainPercentForDevice(uint64 device_id) { | 145 int CrasAudioHandler::GetInputGainPercentForDevice(uint64 device_id) { |
148 if (device_id == active_input_node_id_) { | 146 if (device_id == active_input_node_id_) { |
149 return input_gain_; | 147 return input_gain_; |
150 } else { | 148 } else { |
151 const AudioDevice* device = GetDeviceFromId(device_id); | 149 const AudioDevice* device = GetDeviceFromId(device_id); |
152 if (!device) | 150 return static_cast<int>(audio_pref_handler_->GetInputGainValue(device)); |
153 return kDefaultVolumeGainPercent; | |
154 return static_cast<int>(audio_pref_handler_->GetVolumeGainValue(*device)); | |
155 } | 151 } |
156 } | 152 } |
157 | 153 |
158 uint64 CrasAudioHandler::GetActiveOutputNode() const { | 154 uint64 CrasAudioHandler::GetActiveOutputNode() const { |
159 return active_output_node_id_; | 155 return active_output_node_id_; |
160 } | 156 } |
161 | 157 |
162 uint64 CrasAudioHandler::GetActiveInputNode() const { | 158 uint64 CrasAudioHandler::GetActiveInputNode() const { |
163 return active_input_node_id_; | 159 return active_input_node_id_; |
164 } | 160 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 368 |
373 void CrasAudioHandler::SetupAudioInputState() { | 369 void CrasAudioHandler::SetupAudioInputState() { |
374 // Set the initial audio state to the ones read from audio prefs. | 370 // Set the initial audio state to the ones read from audio prefs. |
375 const AudioDevice* device = GetDeviceFromId(active_input_node_id_); | 371 const AudioDevice* device = GetDeviceFromId(active_input_node_id_); |
376 if (!device) { | 372 if (!device) { |
377 LOG(ERROR) << "Can't set up audio state for unknow input device id =" | 373 LOG(ERROR) << "Can't set up audio state for unknow input device id =" |
378 << "0x" << std::hex << active_input_node_id_; | 374 << "0x" << std::hex << active_input_node_id_; |
379 return; | 375 return; |
380 } | 376 } |
381 input_mute_on_ = audio_pref_handler_->GetMuteValue(*device); | 377 input_mute_on_ = audio_pref_handler_->GetMuteValue(*device); |
382 input_gain_ = audio_pref_handler_->GetVolumeGainValue(*device); | 378 input_gain_ = audio_pref_handler_->GetInputGainValue(device); |
383 SetInputMuteInternal(input_mute_on_); | 379 SetInputMuteInternal(input_mute_on_); |
384 // TODO(rkc,jennyz): Set input gain once we decide on how to store | 380 // TODO(rkc,jennyz): Set input gain once we decide on how to store |
385 // the gain values since the range and step are both device specific. | 381 // the gain values since the range and step are both device specific. |
386 } | 382 } |
387 | 383 |
388 void CrasAudioHandler::SetupAudioOutputState() { | 384 void CrasAudioHandler::SetupAudioOutputState() { |
389 const AudioDevice* device = GetDeviceFromId(active_output_node_id_); | 385 const AudioDevice* device = GetDeviceFromId(active_output_node_id_); |
390 if (!device) { | 386 if (!device) { |
391 LOG(ERROR) << "Can't set up audio state for unknow output device id =" | 387 LOG(ERROR) << "Can't set up audio state for unknow output device id =" |
392 << "0x" << std::hex << active_output_node_id_; | 388 << "0x" << std::hex << active_output_node_id_; |
393 return; | 389 return; |
394 } | 390 } |
395 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); | 391 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); |
396 output_volume_ = audio_pref_handler_->GetVolumeGainValue(*device); | 392 output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device); |
397 | 393 |
398 SetOutputMuteInternal(output_mute_on_); | 394 SetOutputMuteInternal(output_mute_on_); |
399 SetOutputNodeVolume(active_output_node_id_, output_volume_); | 395 SetOutputNodeVolume(active_output_node_id_, output_volume_); |
400 } | 396 } |
401 | 397 |
402 void CrasAudioHandler::InitializeAudioState() { | 398 void CrasAudioHandler::InitializeAudioState() { |
403 ApplyAudioPolicy(); | 399 ApplyAudioPolicy(); |
404 GetNodes(); | 400 GetNodes(); |
405 } | 401 } |
406 | 402 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 if (!success) { | 566 if (!success) { |
571 LOG(ERROR) << "Failed to retrieve audio nodes data"; | 567 LOG(ERROR) << "Failed to retrieve audio nodes data"; |
572 return; | 568 return; |
573 } | 569 } |
574 | 570 |
575 UpdateDevicesAndSwitchActive(node_list); | 571 UpdateDevicesAndSwitchActive(node_list); |
576 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); | 572 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
577 } | 573 } |
578 | 574 |
579 } // namespace chromeos | 575 } // namespace chromeos |
OLD | NEW |