Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 // Default value for unmuting, as a percent in the range [0, 100]. | 24 // Default value for unmuting, as a percent in the range [0, 100]. |
| 25 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. | 25 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. |
| 26 const int kDefaultUnmuteVolumePercent = 4; | 26 const int kDefaultUnmuteVolumePercent = 4; |
| 27 | 27 |
| 28 // Volume value which should be considered as muted in range [0, 100]. | 28 // Volume value which should be considered as muted in range [0, 100]. |
| 29 const int kMuteThresholdPercent = 1; | 29 const int kMuteThresholdPercent = 1; |
| 30 | 30 |
| 31 static CrasAudioHandler* g_cras_audio_handler = NULL; | 31 static CrasAudioHandler* g_cras_audio_handler = NULL; |
| 32 | 32 |
| 33 bool IsSameAudioDevice(const AudioDevice& a, const AudioDevice& b) { | |
| 34 return a.id == b.id && a.is_input == b.is_input && a.type == b.type | |
|
rkc
2013/09/16 22:38:11
Shouldn't just comparing the id's be enough? IIRC,
jennyz
2013/09/16 22:47:03
I am being extra careful here, after observing cra
| |
| 35 && a.device_name == b.device_name; | |
| 36 } | |
| 37 | |
| 33 } // namespace | 38 } // namespace |
| 34 | 39 |
| 35 CrasAudioHandler::AudioObserver::AudioObserver() { | 40 CrasAudioHandler::AudioObserver::AudioObserver() { |
| 36 } | 41 } |
| 37 | 42 |
| 38 CrasAudioHandler::AudioObserver::~AudioObserver() { | 43 CrasAudioHandler::AudioObserver::~AudioObserver() { |
| 39 } | 44 } |
| 40 | 45 |
| 41 void CrasAudioHandler::AudioObserver::OnOutputVolumeChanged() { | 46 void CrasAudioHandler::AudioObserver::OnOutputVolumeChanged() { |
| 42 } | 47 } |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 size_t num_old_devices = 0; | 560 size_t num_old_devices = 0; |
| 556 size_t num_new_devices = 0; | 561 size_t num_new_devices = 0; |
| 557 for (AudioDeviceMap::const_iterator it = audio_devices_.begin(); | 562 for (AudioDeviceMap::const_iterator it = audio_devices_.begin(); |
| 558 it != audio_devices_.end(); ++it) { | 563 it != audio_devices_.end(); ++it) { |
| 559 if (is_input == it->second.is_input) | 564 if (is_input == it->second.is_input) |
| 560 ++num_old_devices; | 565 ++num_old_devices; |
| 561 } | 566 } |
| 562 | 567 |
| 563 for (AudioNodeList::const_iterator it = new_nodes.begin(); | 568 for (AudioNodeList::const_iterator it = new_nodes.begin(); |
| 564 it != new_nodes.end(); ++it) { | 569 it != new_nodes.end(); ++it) { |
| 565 if (is_input == it->is_input) | 570 if (is_input == it->is_input) { |
| 566 ++num_new_devices; | 571 ++num_new_devices; |
| 572 // Look to see if the new device not in the old device list. | |
| 573 AudioDevice device(*it); | |
| 574 if (FoundNewDevice(device)) | |
| 575 return true; | |
| 576 } | |
| 567 } | 577 } |
| 568 return num_old_devices != num_new_devices; | 578 return num_old_devices != num_new_devices; |
| 569 } | 579 } |
| 570 | 580 |
| 581 bool CrasAudioHandler::FoundNewDevice(const AudioDevice& device) { | |
| 582 const AudioDevice* device_found = GetDeviceFromId(device.id); | |
| 583 if (!device_found) | |
| 584 return true; | |
| 585 | |
| 586 if (!IsSameAudioDevice(device, *device_found)) { | |
| 587 LOG(WARNING) << "Different Audio devices with same id:" | |
| 588 << " new device: " << device.ToString() | |
| 589 << " old device: " << device_found->ToString(); | |
| 590 return true; | |
| 591 } | |
| 592 return false; | |
| 593 } | |
| 594 | |
| 571 void CrasAudioHandler::UpdateDevicesAndSwitchActive( | 595 void CrasAudioHandler::UpdateDevicesAndSwitchActive( |
| 572 const AudioNodeList& nodes) { | 596 const AudioNodeList& nodes) { |
| 573 size_t old_audio_devices_size = audio_devices_.size(); | 597 size_t old_audio_devices_size = audio_devices_.size(); |
| 574 bool output_devices_changed = HasDeviceChange(nodes, false); | 598 bool output_devices_changed = HasDeviceChange(nodes, false); |
| 575 bool input_devices_changed = HasDeviceChange(nodes, true); | 599 bool input_devices_changed = HasDeviceChange(nodes, true); |
| 576 audio_devices_.clear(); | 600 audio_devices_.clear(); |
| 577 has_alternative_input_ = false; | 601 has_alternative_input_ = false; |
| 578 has_alternative_output_ = false; | 602 has_alternative_output_ = false; |
| 579 | 603 |
| 580 while (!input_devices_pq_.empty()) | 604 while (!input_devices_pq_.empty()) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 UpdateDevicesAndSwitchActive(node_list); | 654 UpdateDevicesAndSwitchActive(node_list); |
| 631 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); | 655 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
| 632 } | 656 } |
| 633 | 657 |
| 634 void CrasAudioHandler::HandleGetNodesError(const std::string& error_name, | 658 void CrasAudioHandler::HandleGetNodesError(const std::string& error_name, |
| 635 const std::string& error_msg) { | 659 const std::string& error_msg) { |
| 636 LOG_IF(ERROR, log_errors_) << "Failed to call GetNodes: " | 660 LOG_IF(ERROR, log_errors_) << "Failed to call GetNodes: " |
| 637 << error_name << ": " << error_msg; | 661 << error_name << ": " << error_msg; |
| 638 } | 662 } |
| 639 } // namespace chromeos | 663 } // namespace chromeos |
| OLD | NEW |