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

Unified Diff: chromeos/audio/cras_audio_handler.cc

Issue 23819034: Fix the wrong output device switching caused by an input device being plugged in. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « chromeos/audio/cras_audio_handler.h ('k') | 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 3fa81cbcdecf912aa55eedf8df7ad623aabf33b3..00ab2af440df80e14524817fefc417541da9dbb2 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -517,9 +517,29 @@ void CrasAudioHandler::SwitchToDevice(const AudioDevice& device) {
}
}
+bool CrasAudioHandler::HasDeviceChange(const AudioNodeList& new_nodes,
+ bool is_input) {
+ size_t num_old_devices = 0;
+ size_t num_new_devices = 0;
+ for (AudioDeviceMap::const_iterator it = audio_devices_.begin();
+ it != audio_devices_.end(); ++it) {
+ if (is_input == it->second.is_input)
+ ++num_old_devices;
+ }
+
+ for (AudioNodeList::const_iterator it = new_nodes.begin();
+ it != new_nodes.end(); ++it) {
+ if (is_input == it->is_input)
+ ++num_new_devices;
+ }
+ return num_old_devices != num_new_devices;
+}
+
void CrasAudioHandler::UpdateDevicesAndSwitchActive(
const AudioNodeList& nodes) {
size_t old_audio_devices_size = audio_devices_.size();
+ bool output_devices_changed = HasDeviceChange(nodes, false);
+ bool input_devices_changed = HasDeviceChange(nodes, true);
audio_devices_.clear();
has_alternative_input_ = false;
has_alternative_output_ = false;
@@ -552,12 +572,14 @@ void CrasAudioHandler::UpdateDevicesAndSwitchActive(
// If audio nodes change is caused by unplugging some non-active audio
// devices, the previously set active audio device will stay active.
// Otherwise, switch to a new active audio device according to their priority.
- if (!NonActiveDeviceUnplugged(old_audio_devices_size,
+ if (input_devices_changed &&
+ !NonActiveDeviceUnplugged(old_audio_devices_size,
audio_devices_.size(),
active_input_node_id_) &&
!input_devices_pq_.empty())
SwitchToDevice(input_devices_pq_.top());
- if (!NonActiveDeviceUnplugged(old_audio_devices_size,
+ if (output_devices_changed &&
+ !NonActiveDeviceUnplugged(old_audio_devices_size,
audio_devices_.size(),
active_output_node_id_) &&
!output_devices_pq_.empty()) {
« no previous file with comments | « chromeos/audio/cras_audio_handler.h ('k') | chromeos/audio/cras_audio_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698