| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Default value for unmuting, as a percent in the range [0, 100]. | 27 // Default value for unmuting, as a percent in the range [0, 100]. |
| 28 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. | 28 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. |
| 29 const int kDefaultUnmuteVolumePercent = 4; | 29 const int kDefaultUnmuteVolumePercent = 4; |
| 30 | 30 |
| 31 // Volume value which should be considered as muted in range [0, 100]. | 31 // Volume value which should be considered as muted in range [0, 100]. |
| 32 const int kMuteThresholdPercent = 1; | 32 const int kMuteThresholdPercent = 1; |
| 33 | 33 |
| 34 // The duration of HDMI output re-discover grace period in milliseconds. | 34 // The duration of HDMI output re-discover grace period in milliseconds. |
| 35 const int kHDMIRediscoverGracePeriodDurationInMs = 2000; | 35 const int kHDMIRediscoverGracePeriodDurationInMs = 2000; |
| 36 | 36 |
| 37 // Mixer matrix, [0.5, 0.5; 0.5, 0.5] |
| 38 const std::vector<double> kStereoToMono = {0.5, 0.5, 0.5, 0.5}; |
| 39 // Mixer matrix, [1, 0; 0, 1] |
| 40 const std::vector<double> kStereoToStereo = {1, 0, 0, 1}; |
| 41 |
| 37 static CrasAudioHandler* g_cras_audio_handler = NULL; | 42 static CrasAudioHandler* g_cras_audio_handler = NULL; |
| 38 | 43 |
| 39 bool IsSameAudioDevice(const AudioDevice& a, const AudioDevice& b) { | 44 bool IsSameAudioDevice(const AudioDevice& a, const AudioDevice& b) { |
| 40 return a.stable_device_id == b.stable_device_id && a.is_input == b.is_input && | 45 return a.stable_device_id == b.stable_device_id && a.is_input == b.is_input && |
| 41 a.type == b.type && a.device_name == b.device_name; | 46 a.type == b.type && a.device_name == b.device_name; |
| 42 } | 47 } |
| 43 | 48 |
| 44 bool IsInNodeList(uint64_t node_id, | 49 bool IsInNodeList(uint64_t node_id, |
| 45 const CrasAudioHandler::NodeIdList& id_list) { | 50 const CrasAudioHandler::NodeIdList& id_list) { |
| 46 return std::find(id_list.begin(), id_list.end(), node_id) != id_list.end(); | 51 return std::find(id_list.begin(), id_list.end(), node_id) != id_list.end(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 86 |
| 82 void CrasAudioHandler::AudioObserver::OnAudioNodesChanged() { | 87 void CrasAudioHandler::AudioObserver::OnAudioNodesChanged() { |
| 83 } | 88 } |
| 84 | 89 |
| 85 void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() { | 90 void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() { |
| 86 } | 91 } |
| 87 | 92 |
| 88 void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { | 93 void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { |
| 89 } | 94 } |
| 90 | 95 |
| 96 void CrasAudioHandler::AudioObserver::OnOuputChannelRemixingChanged( |
| 97 bool /* mono_on */) { |
| 98 } |
| 99 |
| 91 // static | 100 // static |
| 92 void CrasAudioHandler::Initialize( | 101 void CrasAudioHandler::Initialize( |
| 93 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { | 102 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { |
| 94 CHECK(!g_cras_audio_handler); | 103 CHECK(!g_cras_audio_handler); |
| 95 g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); | 104 g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); |
| 96 } | 105 } |
| 97 | 106 |
| 98 // static | 107 // static |
| 99 void CrasAudioHandler::InitializeForTesting() { | 108 void CrasAudioHandler::InitializeForTesting() { |
| 100 CHECK(!g_cras_audio_handler); | 109 CHECK(!g_cras_audio_handler); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 ++it) { | 330 ++it) { |
| 322 const AudioDevice& device = it->second; | 331 const AudioDevice& device = it->second; |
| 323 if (!device.is_input && device.type == AUDIO_TYPE_INTERNAL_SPEAKER) { | 332 if (!device.is_input && device.type == AUDIO_TYPE_INTERNAL_SPEAKER) { |
| 324 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->SwapLeftRight( | 333 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->SwapLeftRight( |
| 325 device.id, swap); | 334 device.id, swap); |
| 326 break; | 335 break; |
| 327 } | 336 } |
| 328 } | 337 } |
| 329 } | 338 } |
| 330 | 339 |
| 340 void CrasAudioHandler::SetOutputMono(bool mono_on) { |
| 341 output_mono_on_ = mono_on; |
| 342 if (mono_on) { |
| 343 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 344 SetGlobalOutputChannelRemix(output_channels_, kStereoToMono); |
| 345 } else { |
| 346 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 347 SetGlobalOutputChannelRemix(output_channels_, kStereoToStereo); |
| 348 } |
| 349 |
| 350 FOR_EACH_OBSERVER( |
| 351 AudioObserver, observers_, |
| 352 OnOuputChannelRemixingChanged(mono_on)); |
| 353 } |
| 354 |
| 355 bool CrasAudioHandler::IsOutputMonoEnabled() const { |
| 356 return output_mono_on_; |
| 357 } |
| 358 |
| 331 bool CrasAudioHandler::has_alternative_input() const { | 359 bool CrasAudioHandler::has_alternative_input() const { |
| 332 return has_alternative_input_; | 360 return has_alternative_input_; |
| 333 } | 361 } |
| 334 | 362 |
| 335 bool CrasAudioHandler::has_alternative_output() const { | 363 bool CrasAudioHandler::has_alternative_output() const { |
| 336 return has_alternative_output_; | 364 return has_alternative_output_; |
| 337 } | 365 } |
| 338 | 366 |
| 339 void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) { | 367 void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) { |
| 340 // Set all active devices to the same volume. | 368 // Set all active devices to the same volume. |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 : audio_pref_handler_(audio_pref_handler), | 534 : audio_pref_handler_(audio_pref_handler), |
| 507 output_mute_on_(false), | 535 output_mute_on_(false), |
| 508 input_mute_on_(false), | 536 input_mute_on_(false), |
| 509 output_volume_(0), | 537 output_volume_(0), |
| 510 input_gain_(0), | 538 input_gain_(0), |
| 511 active_output_node_id_(0), | 539 active_output_node_id_(0), |
| 512 active_input_node_id_(0), | 540 active_input_node_id_(0), |
| 513 has_alternative_input_(false), | 541 has_alternative_input_(false), |
| 514 has_alternative_output_(false), | 542 has_alternative_output_(false), |
| 515 output_mute_locked_(false), | 543 output_mute_locked_(false), |
| 544 output_channels_(2), |
| 545 output_mono_on_(false), |
| 516 log_errors_(false), | 546 log_errors_(false), |
| 517 hdmi_rediscover_grace_period_duration_in_ms_( | 547 hdmi_rediscover_grace_period_duration_in_ms_( |
| 518 kHDMIRediscoverGracePeriodDurationInMs), | 548 kHDMIRediscoverGracePeriodDurationInMs), |
| 519 hdmi_rediscovering_(false), | 549 hdmi_rediscovering_(false), |
| 520 weak_ptr_factory_(this) { | 550 weak_ptr_factory_(this) { |
| 521 if (!audio_pref_handler.get()) | 551 if (!audio_pref_handler.get()) |
| 522 return; | 552 return; |
| 523 // If the DBusThreadManager or the CrasAudioClient aren't available, there | 553 // If the DBusThreadManager or the CrasAudioClient aren't available, there |
| 524 // isn't much we can do. This should only happen when running tests. | 554 // isn't much we can do. This should only happen when running tests. |
| 525 if (!chromeos::DBusThreadManager::IsInitialized() || | 555 if (!chromeos::DBusThreadManager::IsInitialized() || |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 hdmi_rediscover_grace_period_duration_in_ms_), | 1308 hdmi_rediscover_grace_period_duration_in_ms_), |
| 1279 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); | 1309 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); |
| 1280 } | 1310 } |
| 1281 | 1311 |
| 1282 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( | 1312 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( |
| 1283 int duration_in_ms) { | 1313 int duration_in_ms) { |
| 1284 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; | 1314 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; |
| 1285 } | 1315 } |
| 1286 | 1316 |
| 1287 } // namespace chromeos | 1317 } // namespace chromeos |
| OLD | NEW |