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 #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 5 #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <queue> | 10 #include <queue> |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, | 32 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, |
33 public AudioPrefObserver, | 33 public AudioPrefObserver, |
34 public SessionManagerClient::Observer { | 34 public SessionManagerClient::Observer { |
35 public: | 35 public: |
36 typedef std::priority_queue<AudioDevice, | 36 typedef std::priority_queue<AudioDevice, |
37 std::vector<AudioDevice>, | 37 std::vector<AudioDevice>, |
38 AudioDeviceCompare> AudioDevicePriorityQueue; | 38 AudioDeviceCompare> AudioDevicePriorityQueue; |
39 typedef std::vector<uint64_t> NodeIdList; | 39 typedef std::vector<uint64_t> NodeIdList; |
40 | 40 |
| 41 // Volume change reasons that are not user-initiated. |
| 42 enum AutomatedVolumeChangeReason { |
| 43 // Indicates it is from intializaing audio state. |
| 44 VOLUME_CHANGE_INITIALIZING_AUDIO_STATE, |
| 45 |
| 46 // Indicates it is from restoring volume in maximimize mode screenshot. |
| 47 VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT, |
| 48 }; |
| 49 |
41 class AudioObserver { | 50 class AudioObserver { |
42 public: | 51 public: |
43 // Called when an active output volume changed. | 52 // Called when an active output volume changed. |
44 virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume); | 53 virtual void OnOutputNodeVolumeChanged(uint64_t node_id, int volume); |
45 | 54 |
46 // Called when output mute state changed. | 55 // Called when output mute state changed. |
47 // |mute_on|: True if output is muted. | 56 // |mute_on|: True if output is muted. |
48 // |system_adjust|: True if the mute state is adjusted by the system | 57 // |system_adjust|: True if the mute state is adjusted by the system |
49 // automatically(i.e. not by user). UI should reflect the system's mute | 58 // automatically(i.e. not by user). UI should reflect the system's mute |
50 // state, but it should not be too loud, e.g., the volume pop up window | 59 // state, but it should not be too loud, e.g., the volume pop up window |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // This call can be invoked from I/O thread or UI thread because | 157 // This call can be invoked from I/O thread or UI thread because |
149 // it does not need to access CrasAudioClient on DBus. | 158 // it does not need to access CrasAudioClient on DBus. |
150 virtual void GetAudioDevices(AudioDeviceList* device_list) const; | 159 virtual void GetAudioDevices(AudioDeviceList* device_list) const; |
151 | 160 |
152 virtual bool GetPrimaryActiveOutputDevice(AudioDevice* device) const; | 161 virtual bool GetPrimaryActiveOutputDevice(AudioDevice* device) const; |
153 | 162 |
154 // Whether there is alternative input/output audio device. | 163 // Whether there is alternative input/output audio device. |
155 virtual bool has_alternative_input() const; | 164 virtual bool has_alternative_input() const; |
156 virtual bool has_alternative_output() const; | 165 virtual bool has_alternative_output() const; |
157 | 166 |
158 // Sets all active output devices' volume level to |volume_percent|, whose | 167 // Sets all active output devices' volume levels to |volume_percent|, whose |
159 // range is from 0-100%. | 168 // range is from 0-100%. |
160 virtual void SetOutputVolumePercent(int volume_percent); | 169 virtual void SetOutputVolumePercent(int volume_percent); |
161 | 170 |
| 171 // Sets all active output devices' volume levels to |volume_percent|, whose |
| 172 // range is from 0-100%, without notifying observers. |
| 173 virtual void SetOutputVolumePercentWithoutNotifyingObservers( |
| 174 int volume_percent, |
| 175 AutomatedVolumeChangeReason reason); |
| 176 |
162 // Sets all active input devices' gain level to |gain_percent|, whose range is | 177 // Sets all active input devices' gain level to |gain_percent|, whose range is |
163 // from 0-100%. | 178 // from 0-100%. |
164 virtual void SetInputGainPercent(int gain_percent); | 179 virtual void SetInputGainPercent(int gain_percent); |
165 | 180 |
166 // Adjusts all active output devices' volume up (positive percentage) or down | 181 // Adjusts all active output devices' volume up (positive percentage) or down |
167 // (negative percentage). | 182 // (negative percentage). |
168 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); | 183 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); |
169 | 184 |
170 // Adjusts all active output devices' volume to a minimum audible level if it | 185 // Adjusts all active output devices' volume to a minimum audible level if it |
171 // is too low. | 186 // is too low. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 // Failures are not logged at startup, since CRAS may not be running yet. | 440 // Failures are not logged at startup, since CRAS may not be running yet. |
426 bool log_errors_; | 441 bool log_errors_; |
427 | 442 |
428 // Timer for HDMI re-discovering grace period. | 443 // Timer for HDMI re-discovering grace period. |
429 base::OneShotTimer hdmi_rediscover_timer_; | 444 base::OneShotTimer hdmi_rediscover_timer_; |
430 int hdmi_rediscover_grace_period_duration_in_ms_; | 445 int hdmi_rediscover_grace_period_duration_in_ms_; |
431 bool hdmi_rediscovering_; | 446 bool hdmi_rediscovering_; |
432 | 447 |
433 bool cras_service_available_ = false; | 448 bool cras_service_available_ = false; |
434 | 449 |
435 bool initializing_audio_state_ = false; | 450 std::deque<AutomatedVolumeChangeReason> automated_volume_change_reasons_; |
| 451 |
436 int init_volume_; | 452 int init_volume_; |
437 uint64_t init_node_id_; | 453 uint64_t init_node_id_; |
438 int init_volume_count_ = 0; | |
439 | 454 |
440 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; | 455 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; |
441 | 456 |
442 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); | 457 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); |
443 }; | 458 }; |
444 | 459 |
445 } // namespace chromeos | 460 } // namespace chromeos |
446 | 461 |
447 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 462 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
OLD | NEW |