| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 output_mute_on_(false), | 268 output_mute_on_(false), |
| 269 input_mute_on_(false), | 269 input_mute_on_(false), |
| 270 output_volume_(0), | 270 output_volume_(0), |
| 271 input_gain_(0), | 271 input_gain_(0), |
| 272 active_output_node_id_(0), | 272 active_output_node_id_(0), |
| 273 active_input_node_id_(0), | 273 active_input_node_id_(0), |
| 274 has_alternative_input_(false), | 274 has_alternative_input_(false), |
| 275 has_alternative_output_(false), | 275 has_alternative_output_(false), |
| 276 output_mute_locked_(false), | 276 output_mute_locked_(false), |
| 277 input_mute_locked_(false) { | 277 input_mute_locked_(false) { |
| 278 if (!audio_pref_handler) | 278 if (!audio_pref_handler.get()) |
| 279 return; | 279 return; |
| 280 // If the DBusThreadManager or the CrasAudioClient aren't available, there | 280 // If the DBusThreadManager or the CrasAudioClient aren't available, there |
| 281 // isn't much we can do. This should only happen when running tests. | 281 // isn't much we can do. This should only happen when running tests. |
| 282 if (!chromeos::DBusThreadManager::IsInitialized() || | 282 if (!chromeos::DBusThreadManager::IsInitialized() || |
| 283 !chromeos::DBusThreadManager::Get() || | 283 !chromeos::DBusThreadManager::Get() || |
| 284 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) | 284 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) |
| 285 return; | 285 return; |
| 286 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); | 286 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); |
| 287 audio_pref_handler_->AddAudioPrefObserver(this); | 287 audio_pref_handler_->AddAudioPrefObserver(this); |
| 288 InitializeAudioState(); | 288 InitializeAudioState(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 CrasAudioHandler::~CrasAudioHandler() { | 291 CrasAudioHandler::~CrasAudioHandler() { |
| 292 if (!chromeos::DBusThreadManager::IsInitialized() || | 292 if (!chromeos::DBusThreadManager::IsInitialized() || |
| 293 !chromeos::DBusThreadManager::Get() || | 293 !chromeos::DBusThreadManager::Get() || |
| 294 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) | 294 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) |
| 295 return; | 295 return; |
| 296 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 296 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 297 RemoveObserver(this); | 297 RemoveObserver(this); |
| 298 if (audio_pref_handler_) | 298 if (audio_pref_handler_.get()) |
| 299 audio_pref_handler_->RemoveAudioPrefObserver(this); | 299 audio_pref_handler_->RemoveAudioPrefObserver(this); |
| 300 audio_pref_handler_ = NULL; | 300 audio_pref_handler_ = NULL; |
| 301 } | 301 } |
| 302 | 302 |
| 303 void CrasAudioHandler::AudioClientRestarted() { | 303 void CrasAudioHandler::AudioClientRestarted() { |
| 304 InitializeAudioState(); | 304 InitializeAudioState(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void CrasAudioHandler::OutputVolumeChanged(int volume) { | 307 void CrasAudioHandler::OutputVolumeChanged(int volume) { |
| 308 if (output_volume_ != volume) { | 308 if (output_volume_ != volume) { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 if (!success) { | 541 if (!success) { |
| 542 LOG(ERROR) << "Failed to retrieve audio nodes data"; | 542 LOG(ERROR) << "Failed to retrieve audio nodes data"; |
| 543 return; | 543 return; |
| 544 } | 544 } |
| 545 | 545 |
| 546 UpdateDevicesAndSwitchActive(node_list); | 546 UpdateDevicesAndSwitchActive(node_list); |
| 547 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); | 547 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
| 548 } | 548 } |
| 549 | 549 |
| 550 } // namespace chromeos | 550 } // namespace chromeos |
| OLD | NEW |