observers_.RemoveObserver(observer);
}
+bool CrasAudioHandler::HasKeyboardMic() {
+ return GetKeyboardMic() != NULL;
+}
+
bool CrasAudioHandler::IsOutputMuted() {
return output_mute_on_;
}
const AudioDevice* device = GetDeviceFromId(device_id);
if (!device)
return false;
+ DCHECK(!device->is_input);
return audio_pref_handler_->GetMuteValue(*device);
}
-bool CrasAudioHandler::IsOutputVolumeBelowDefaultMuteLvel() {
+bool CrasAudioHandler::IsOutputVolumeBelowDefaultMuteLevel() {
return output_volume_ <= kMuteThresholdPercent;
}
const AudioDevice* device = GetDeviceFromId(device_id);
if (!device)
return false;
- return audio_pref_handler_->GetMuteValue(*device);
+ DCHECK(device->is_input);
+ // We don't record input mute state for each device in the prefs,
+ // for any non-active input device, we assume mute is off.
+ if (device->id == active_input_node_id_)
+ return input_mute_on_;
+ return false;
+}
+
+int CrasAudioHandler::GetOutputDefaultVolumeMuteThreshold() {
+ return kMuteThresholdPercent;
}
int CrasAudioHandler::GetOutputVolumePercent() {
return true;
}
+void CrasAudioHandler::SetKeyboardMicActive(bool active) {
+ const AudioDevice* keyboard_mic = GetKeyboardMic();
+ if (!keyboard_mic)
+ return;
+ if (active) {
+ chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
+ AddActiveInputNode(keyboard_mic->id);
+ } else {
+ chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
+ RemoveActiveInputNode(keyboard_mic->id);
+ }
+}
+
bool CrasAudioHandler::has_alternative_input() const {
return has_alternative_input_;
}
if (!SetOutputMuteInternal(mute_on))
return;
- if (const AudioDevice* device = GetDeviceFromId(active_output_node_id_))
+ if (const AudioDevice* device = GetDeviceFromId(active_output_node_id_)) {
+ DCHECK(!device->is_input);
audio_pref_handler_->SetMuteValue(*device, output_mute_on_);
+ }
FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputMuteChanged());
}
if (!SetInputMuteInternal(mute_on))
return;
- AudioDevice device;
- if (const AudioDevice* device = GetDeviceFromId(active_input_node_id_))
- audio_pref_handler_->SetMuteValue(*device, input_mute_on_);
-
-
FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged());
}
SetOutputMute(mute_on);
return;
} else if (device_id == active_input_node_id_) {
+ VLOG(1) << "SetMuteForDevice sets active input device id="
+ << "0x" << std::hex << device_id << " mute=" << mute_on;
SetInputMute(mute_on);
return;
}
- AudioDevice device;
- if (const AudioDevice* device = GetDeviceFromId(device_id))
+ const AudioDevice* device = GetDeviceFromId(device_id);
+ // Input device's mute state is not recorded in the pref. crbug.com/365050.
+ if (device && !device->is_input)
audio_pref_handler_->SetMuteValue(*device, mute_on);
}
return &(it->second);
}
+const AudioDevice* CrasAudioHandler::GetKeyboardMic() const {
+ for (AudioDeviceMap::const_iterator it = audio_devices_.begin();
+ it != audio_devices_.end(); it++) {
+ if (it->second.is_input && it->second.type == AUDIO_TYPE_KEYBOARD_MIC)
+ return &(it->second);
+ }
+ return NULL;
+}
+
void CrasAudioHandler::SetupAudioInputState() {
// Set the initial audio state to the ones read from audio prefs.
const AudioDevice* device = GetDeviceFromId(active_input_node_id_);
<< "0x" << std::hex << active_input_node_id_;
return;
}
- input_mute_on_ = audio_pref_handler_->GetMuteValue(*device);
input_gain_ = audio_pref_handler_->GetInputGainValue(device);
+ VLOG(1) << "SetupAudioInputState for active device id="
+ << "0x" << std::hex << device->id << " mute=" << input_mute_on_;
SetInputMuteInternal(input_mute_on_);
// TODO(rkc,jennyz): Set input gain once we decide on how to store
// the gain values since the range and step are both device specific.
<< "0x" << std::hex << active_output_node_id_;
return;
}
+ DCHECK(!device->is_input);
output_mute_on_ = audio_pref_handler_->GetMuteValue(*device);
output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device);
input_mute_locked_ = false;
if (audio_pref_handler_->GetAudioCaptureAllowedValue()) {
- // Set input mute if we have discovered active input device.
- const AudioDevice* device = GetDeviceFromId(active_input_node_id_);
- if (device)
- SetInputMuteInternal(false);
+ VLOG(1) << "Audio input allowed by policy, sets input id="
+ << "0x" << std::hex << active_input_node_id_ << " mute=false";
+ SetInputMuteInternal(false);
} else {
- SetInputMute(true);
+ VLOG(0) << "Audio input NOT allowed by policy, sets input id="
+ << "0x" << std::hex << active_input_node_id_ << " mute=true";
+ SetInputMuteInternal(true);
input_mute_locked_ = true;
}
}
if (input_mute_locked_)
return false;
+ VLOG(1) << "SetInputMuteInternal sets active input device id="
+ << "0x" << std::hex << active_input_node_id_ << " mute=" << mute_on;
input_mute_on_ = mute_on;
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
SetInputMute(mute_on);
if (!has_alternative_input_ &&
device.is_input &&
- device.type != AUDIO_TYPE_INTERNAL_MIC) {
+ device.type != AUDIO_TYPE_INTERNAL_MIC &&
+ device.type != AUDIO_TYPE_KEYBOARD_MIC) {
has_alternative_input_ = true;
} else if (!has_alternative_output_ &&
!device.is_input &&