Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1888)

Unified Diff: chromeos/audio/cras_audio_handler.cc

Issue 2087803003: Sync volume state using cras signal OutputNodeVolumeChanged. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromeos/audio/cras_audio_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/audio/cras_audio_handler.cc
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
index a6586bd742e074315df0dd69a113135595021f27..fef5c90b7498b23197a659f3a4703399a5d2b535 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -594,24 +594,25 @@ void CrasAudioHandler::NodesChanged() {
void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) {
const AudioDevice* device = this->GetDeviceFromId(node_id);
- int old_volume;
// If this is not an active output node, ignore this event. Because when this
// node set to active, it will be applied with the volume value stored in
// preference.
- if (!device || !device->active || device->is_input)
- return;
-
- // If this callback is triggered by a response to previous set volume command,
- // do nothing.
- old_volume =
- static_cast<int>(audio_pref_handler_->GetOutputVolumeValue(device));
- if (old_volume == volume)
+ if (!device || !device->active || device->is_input) {
+ LOG(ERROR) << "Unexpexted OutputNodeVolumeChanged received on node: 0x"
+ << std::hex << node_id;
return;
+ }
- // Otherwise another app or the hardware itself just changed volume, update
- // the new volume value to all active output nodes.
- SetOutputVolumePercent(volume);
+ // Sync internal volume state and notify UI for the change. We trust cras
+ // signal to report the volume state of the device, no matter which source
+ // set the volume, i.e., volume could be set from non-chrome source, like
+ // Bluetooth headset, etc. Assume all active output devices share a single
+ // volume.
+ output_volume_ = volume;
+ audio_pref_handler_->SetVolumeGainValue(*device, volume);
+ FOR_EACH_OBSERVER(AudioObserver, observers_,
+ OnOutputNodeVolumeChanged(node_id, volume));
}
void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) {
@@ -789,23 +790,20 @@ void CrasAudioHandler::SetOutputNodeVolume(uint64_t node_id, int volume) {
void CrasAudioHandler::SetOutputNodeVolumePercent(uint64_t node_id,
int volume_percent) {
- const AudioDevice* device = this->GetDeviceFromId(node_id);
+ const AudioDevice* device = GetDeviceFromId(node_id);
if (!device || device->is_input)
return;
volume_percent = min(max(volume_percent, 0), 100);
if (volume_percent <= kMuteThresholdPercent)
volume_percent = 0;
- if (node_id == active_output_node_id_)
- output_volume_ = volume_percent;
+ // Save the volume setting in pref in case this is called on non-active
+ // node for configuration.
audio_pref_handler_->SetVolumeGainValue(*device, volume_percent);
- if (device->active) {
+ if (device->active)
SetOutputNodeVolume(node_id, volume_percent);
- FOR_EACH_OBSERVER(AudioObserver, observers_,
- OnOutputNodeVolumeChanged(node_id, volume_percent));
- }
}
bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) {
« no previous file with comments | « no previous file | chromeos/audio/cras_audio_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698