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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 protected: | 48 protected: |
49 AudioObserver(); | 49 AudioObserver(); |
50 virtual ~AudioObserver(); | 50 virtual ~AudioObserver(); |
51 DISALLOW_COPY_AND_ASSIGN(AudioObserver); | 51 DISALLOW_COPY_AND_ASSIGN(AudioObserver); |
52 }; | 52 }; |
53 | 53 |
54 // Sets the global instance. Must be called before any calls to Get(). | 54 // Sets the global instance. Must be called before any calls to Get(). |
55 static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler); | 55 static void Initialize(scoped_refptr<AudioPrefHandler> audio_pref_handler); |
56 | 56 |
| 57 // Sets the global instance for testing. |
| 58 static void InitializeForTesting(); |
| 59 |
57 // Destroys the global instance. | 60 // Destroys the global instance. |
58 static void Shutdown(); | 61 static void Shutdown(); |
59 | 62 |
60 // Returns true if the global instance is initialized. | 63 // Returns true if the global instance is initialized. |
61 static bool IsInitialized(); | 64 static bool IsInitialized(); |
62 | 65 |
63 // Gets the global instance. Initialize must be called first. | 66 // Gets the global instance. Initialize must be called first. |
64 static CrasAudioHandler* Get(); | 67 static CrasAudioHandler* Get(); |
65 | 68 |
66 // Adds an audio observer. | 69 // Adds an audio observer. |
67 void AddAudioObserver(AudioObserver* observer); | 70 virtual void AddAudioObserver(AudioObserver* observer); |
68 | 71 |
69 // Removes an audio observer. | 72 // Removes an audio observer. |
70 void RemoveAudioObserver(AudioObserver* observer); | 73 virtual void RemoveAudioObserver(AudioObserver* observer); |
71 | 74 |
72 // Returns true if audio output is muted. | 75 // Returns true if audio output is muted. |
73 bool IsOutputMuted(); | 76 virtual bool IsOutputMuted(); |
74 | 77 |
75 // Returns true if audio input is muted. | 78 // Returns true if audio input is muted. |
76 bool IsInputMuted(); | 79 virtual bool IsInputMuted(); |
77 | 80 |
78 // Gets volume level in 0-100% range, 0 being pure silence. | 81 // Gets volume level in 0-100% range, 0 being pure silence. |
79 int GetOutputVolumePercent(); | 82 virtual int GetOutputVolumePercent(); |
80 | 83 |
81 // Returns node_id of the active output node. | 84 // Returns node_id of the active output node. |
82 uint64 GetActiveOutputNode() const; | 85 virtual uint64 GetActiveOutputNode() const; |
83 | 86 |
84 // Returns the node_id of the active input node. | 87 // Returns the node_id of the active input node. |
85 uint64 GetActiveInputNode() const; | 88 virtual uint64 GetActiveInputNode() const; |
86 | 89 |
87 // Gets the audio devices back in |device_list|. | 90 // Gets the audio devices back in |device_list|. |
88 void GetAudioDevices(AudioDeviceList* device_list) const; | 91 virtual void GetAudioDevices(AudioDeviceList* device_list) const; |
89 | 92 |
90 bool GetActiveOutputDevice(AudioDevice* device) const; | 93 virtual bool GetActiveOutputDevice(AudioDevice* device) const; |
91 | 94 |
92 // Whether there is alternative input/output audio device. | 95 // Whether there is alternative input/output audio device. |
93 bool has_alternative_input() const { return has_alternative_input_; } | 96 virtual bool has_alternative_input() const; |
94 bool has_alternative_output() const { return has_alternative_output_; } | 97 virtual bool has_alternative_output() const; |
95 | 98 |
96 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then | 99 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then |
97 // mutes the sound. If it was muted, and |volume_percent| is larger than | 100 // mutes the sound. If it was muted, and |volume_percent| is larger than |
98 // the threshold, then the sound is unmuted. | 101 // the threshold, then the sound is unmuted. |
99 void SetOutputVolumePercent(int volume_percent); | 102 virtual void SetOutputVolumePercent(int volume_percent); |
100 | 103 |
101 // Adjusts volume up (positive percentage) or down (negative percentage). | 104 // Adjusts volume up (positive percentage) or down (negative percentage). |
102 void AdjustOutputVolumeByPercent(int adjust_by_percent); | 105 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); |
103 | 106 |
104 // Mutes or unmutes audio output device. | 107 // Mutes or unmutes audio output device. |
105 void SetOutputMute(bool mute_on); | 108 virtual void SetOutputMute(bool mute_on); |
106 | 109 |
107 // Mutes or unmutes audio input device. | 110 // Mutes or unmutes audio input device. |
108 void SetInputMute(bool mute_on); | 111 virtual void SetInputMute(bool mute_on); |
109 | 112 |
110 // Sets the active audio output node to the node with |node_id|. | 113 // Sets the active audio output node to the node with |node_id|. |
111 void SetActiveOutputNode(uint64 node_id); | 114 virtual void SetActiveOutputNode(uint64 node_id); |
112 | 115 |
113 // Sets the active audio input node to the node with |node_id|. | 116 // Sets the active audio input node to the node with |node_id|. |
114 void SetActiveInputNode(uint64 node_id); | 117 virtual void SetActiveInputNode(uint64 node_id); |
115 | 118 |
116 private: | 119 protected: |
117 explicit CrasAudioHandler(scoped_refptr<AudioPrefHandler> audio_pref_handler); | 120 explicit CrasAudioHandler(scoped_refptr<AudioPrefHandler> audio_pref_handler); |
118 virtual ~CrasAudioHandler(); | 121 virtual ~CrasAudioHandler(); |
119 | 122 |
| 123 private: |
120 // Overriden from CrasAudioHandler::Observer. | 124 // Overriden from CrasAudioHandler::Observer. |
121 virtual void AudioClientRestarted() OVERRIDE; | 125 virtual void AudioClientRestarted() OVERRIDE; |
122 virtual void OutputVolumeChanged(int volume) OVERRIDE; | 126 virtual void OutputVolumeChanged(int volume) OVERRIDE; |
123 virtual void OutputMuteChanged(bool mute_on) OVERRIDE; | 127 virtual void OutputMuteChanged(bool mute_on) OVERRIDE; |
124 virtual void InputMuteChanged(bool mute_on) OVERRIDE; | 128 virtual void InputMuteChanged(bool mute_on) OVERRIDE; |
125 virtual void NodesChanged() OVERRIDE; | 129 virtual void NodesChanged() OVERRIDE; |
126 virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE; | 130 virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE; |
127 virtual void ActiveInputNodeChanged(uint64 node_id) OVERRIDE; | 131 virtual void ActiveInputNodeChanged(uint64 node_id) OVERRIDE; |
128 | 132 |
129 // Overriden from AudioPrefObserver. | 133 // Overriden from AudioPrefObserver. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 167 |
164 bool output_mute_locked_; | 168 bool output_mute_locked_; |
165 bool input_mute_locked_; | 169 bool input_mute_locked_; |
166 | 170 |
167 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); | 171 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); |
168 }; | 172 }; |
169 | 173 |
170 } // namespace chromeos | 174 } // namespace chromeos |
171 | 175 |
172 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ | 176 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ |
OLD | NEW |