Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chromeos/audio/cras_audio_handler.h

Issue 2605983002: Simplify logic behind chrome.audio.setActiveDevices (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chromeos/audio/cras_audio_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Destroys the global instance. 97 // Destroys the global instance.
98 static void Shutdown(); 98 static void Shutdown();
99 99
100 // Returns true if the global instance is initialized. 100 // Returns true if the global instance is initialized.
101 static bool IsInitialized(); 101 static bool IsInitialized();
102 102
103 // Gets the global instance. Initialize must be called first. 103 // Gets the global instance. Initialize must be called first.
104 static CrasAudioHandler* Get(); 104 static CrasAudioHandler* Get();
105 105
106 // Adds an audio observer. 106 // Adds an audio observer.
107 virtual void AddAudioObserver(AudioObserver* observer); 107 void AddAudioObserver(AudioObserver* observer);
108 108
109 // Removes an audio observer. 109 // Removes an audio observer.
110 virtual void RemoveAudioObserver(AudioObserver* observer); 110 void RemoveAudioObserver(AudioObserver* observer);
111 111
112 // Returns true if keyboard mic exists. 112 // Returns true if keyboard mic exists.
113 virtual bool HasKeyboardMic(); 113 bool HasKeyboardMic();
114 114
115 // Returns true if audio output is muted for the system. 115 // Returns true if audio output is muted for the system.
116 virtual bool IsOutputMuted(); 116 bool IsOutputMuted();
117 117
118 // Returns true if audio output is muted for a device. 118 // Returns true if audio output is muted for a device.
119 virtual bool IsOutputMutedForDevice(uint64_t device_id); 119 bool IsOutputMutedForDevice(uint64_t device_id);
120 120
121 // Returns true if audio input is muted. 121 // Returns true if audio input is muted.
122 virtual bool IsInputMuted(); 122 bool IsInputMuted();
123 123
124 // Returns true if audio input is muted for a device. 124 // Returns true if audio input is muted for a device.
125 virtual bool IsInputMutedForDevice(uint64_t device_id); 125 bool IsInputMutedForDevice(uint64_t device_id);
126 126
127 // Returns true if the output volume is below the default mute volume level. 127 // Returns true if the output volume is below the default mute volume level.
128 virtual bool IsOutputVolumeBelowDefaultMuteLevel(); 128 bool IsOutputVolumeBelowDefaultMuteLevel();
129 129
130 // Returns volume level in 0-100% range at which the volume should be muted. 130 // Returns volume level in 0-100% range at which the volume should be muted.
131 virtual int GetOutputDefaultVolumeMuteThreshold(); 131 int GetOutputDefaultVolumeMuteThreshold();
132 132
133 // Gets volume level in 0-100% range (0 being pure silence) for the current 133 // Gets volume level in 0-100% range (0 being pure silence) for the current
134 // active node. 134 // active node.
135 virtual int GetOutputVolumePercent(); 135 int GetOutputVolumePercent();
136 136
137 // Gets volume level in 0-100% range (0 being pure silence) for a device. 137 // Gets volume level in 0-100% range (0 being pure silence) for a device.
138 virtual int GetOutputVolumePercentForDevice(uint64_t device_id); 138 int GetOutputVolumePercentForDevice(uint64_t device_id);
139 139
140 // Gets gain level in 0-100% range (0 being pure silence) for the current 140 // Gets gain level in 0-100% range (0 being pure silence) for the current
141 // active node. 141 // active node.
142 virtual int GetInputGainPercent(); 142 int GetInputGainPercent();
143 143
144 // Gets volume level in 0-100% range (0 being pure silence) for a device. 144 // Gets volume level in 0-100% range (0 being pure silence) for a device.
145 virtual int GetInputGainPercentForDevice(uint64_t device_id); 145 int GetInputGainPercentForDevice(uint64_t device_id);
146 146
147 // Returns node_id of the primary active output node. 147 // Returns node_id of the primary active output node.
148 virtual uint64_t GetPrimaryActiveOutputNode() const; 148 uint64_t GetPrimaryActiveOutputNode() const;
149 149
150 // Returns the node_id of the primary active input node. 150 // Returns the node_id of the primary active input node.
151 virtual uint64_t GetPrimaryActiveInputNode() const; 151 uint64_t GetPrimaryActiveInputNode() const;
152 152
153 // Gets the audio devices back in |device_list|. 153 // Gets the audio devices back in |device_list|.
154 // This call can be invoked from I/O thread or UI thread because 154 // This call can be invoked from I/O thread or UI thread because
155 // it does not need to access CrasAudioClient on DBus. 155 // it does not need to access CrasAudioClient on DBus.
156 virtual void GetAudioDevices(AudioDeviceList* device_list) const; 156 void GetAudioDevices(AudioDeviceList* device_list) const;
157 157
158 virtual bool GetPrimaryActiveOutputDevice(AudioDevice* device) const; 158 bool GetPrimaryActiveOutputDevice(AudioDevice* device) const;
159 159
160 // Whether there is alternative input/output audio device. 160 // Whether there is alternative input/output audio device.
161 virtual bool has_alternative_input() const; 161 bool has_alternative_input() const;
162 virtual bool has_alternative_output() const; 162 bool has_alternative_output() const;
163 163
164 // Sets all active output devices' volume levels to |volume_percent|, whose 164 // Sets all active output devices' volume levels to |volume_percent|, whose
165 // range is from 0-100%. 165 // range is from 0-100%.
166 virtual void SetOutputVolumePercent(int volume_percent); 166 void SetOutputVolumePercent(int volume_percent);
167 167
168 // Sets all active output devices' volume levels to |volume_percent|, whose 168 // Sets all active output devices' volume levels to |volume_percent|, whose
169 // range is from 0-100%, without notifying observers. 169 // range is from 0-100%, without notifying observers.
170 virtual void SetOutputVolumePercentWithoutNotifyingObservers( 170 void SetOutputVolumePercentWithoutNotifyingObservers(
171 int volume_percent, 171 int volume_percent,
172 AutomatedVolumeChangeReason reason); 172 AutomatedVolumeChangeReason reason);
173 173
174 // Sets all active input devices' gain level to |gain_percent|, whose range is 174 // Sets all active input devices' gain level to |gain_percent|, whose range is
175 // from 0-100%. 175 // from 0-100%.
176 virtual void SetInputGainPercent(int gain_percent); 176 void SetInputGainPercent(int gain_percent);
177 177
178 // Adjusts all active output devices' volume up (positive percentage) or down 178 // Adjusts all active output devices' volume up (positive percentage) or down
179 // (negative percentage). 179 // (negative percentage).
180 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); 180 void AdjustOutputVolumeByPercent(int adjust_by_percent);
181 181
182 // Adjusts all active output devices' volume to a minimum audible level if it 182 // Adjusts all active output devices' volume to a minimum audible level if it
183 // is too low. 183 // is too low.
184 virtual void AdjustOutputVolumeToAudibleLevel(); 184 void AdjustOutputVolumeToAudibleLevel();
185 185
186 // Mutes or unmutes audio output device. 186 // Mutes or unmutes audio output device.
187 virtual void SetOutputMute(bool mute_on); 187 void SetOutputMute(bool mute_on);
188 188
189 // Mutes or unmutes audio input device. 189 // Mutes or unmutes audio input device.
190 virtual void SetInputMute(bool mute_on); 190 void SetInputMute(bool mute_on);
191 191
192 // Switches active audio device to |device|. |activate_by| indicates why 192 // Switches active audio device to |device|. |activate_by| indicates why
193 // the device is switched to active: by user's manual choice, by priority, 193 // the device is switched to active: by user's manual choice, by priority,
194 // or by restoring to its previous active state. 194 // or by restoring to its previous active state.
195 virtual void SwitchToDevice(const AudioDevice& device, 195 void SwitchToDevice(const AudioDevice& device,
196 bool notify, 196 bool notify,
197 DeviceActivateType activate_by); 197 DeviceActivateType activate_by);
198 198
199 // Sets volume/gain level for a device. 199 // Sets volume/gain level for a device.
200 virtual void SetVolumeGainPercentForDevice(uint64_t device_id, int value); 200 void SetVolumeGainPercentForDevice(uint64_t device_id, int value);
201 201
202 // Sets the mute for device. 202 // Sets the mute for device.
203 virtual void SetMuteForDevice(uint64_t device_id, bool mute_on); 203 void SetMuteForDevice(uint64_t device_id, bool mute_on);
204 204
205 // Activates or deactivates keyboard mic if there's one. 205 // Activates or deactivates keyboard mic if there's one.
206 virtual void SetKeyboardMicActive(bool active); 206 void SetKeyboardMicActive(bool active);
207 207
208 // Changes the active nodes to the nodes specified by |new_active_ids|. 208 // Changes the active nodes to the nodes specified by |new_active_ids|.
209 // The caller can pass in the "complete" active node list of either input 209 // The caller can pass in the "complete" active node list of either input
210 // nodes, or output nodes, or both. If only input nodes are passed in, 210 // nodes, or output nodes, or both. If only input nodes are passed in,
211 // it will only change the input nodes' active status, output nodes will NOT 211 // it will only change the input nodes' active status, output nodes will NOT
212 // be changed; similarly for the case if only output nodes are passed. 212 // be changed; similarly for the case if only output nodes are passed.
213 // If the nodes specified in |new_active_ids| are already active, they will 213 // If the nodes specified in |new_active_ids| are already active, they will
214 // remain active. Otherwise, the old active nodes will be de-activated before 214 // remain active. Otherwise, the old active nodes will be de-activated before
215 // we activate the new nodes with the same type(input/output). 215 // we activate the new nodes with the same type(input/output).
216 virtual void ChangeActiveNodes(const NodeIdList& new_active_ids); 216 // DEPRECATED in favor of |SetActiveInputNodes| and |SetActiveOutputNodes|.
217 void ChangeActiveNodes(const NodeIdList& new_active_ids);
218
219 // Sets the set of active input nodes. Empty |node_ids| will deactivate all
220 // input devices.
221 // |node_ids| is expected to contain only existing input node IDs - the
222 // method will fail if this is not the case.
223 // Returns whether the acive nodes were successfully set.
224 bool SetActiveInputNodes(const NodeIdList& node_ids);
225
226 // Sets the set of active output nodes. Empty |node_ids| will deactivate all
227 // output devices.
228 // |node_ids| is expected to contain only existing output node IDs - the
229 // method will fail if this is not the case.
230 // Returns whether the acive nodes were successfully set.
231 bool SetActiveOutputNodes(const NodeIdList& node_ids);
217 232
218 // Swaps the left and right channel of the internal speaker. 233 // Swaps the left and right channel of the internal speaker.
219 // Swap the left and right channel if |swap| is true; otherwise, swap the left 234 // Swap the left and right channel if |swap| is true; otherwise, swap the left
220 // and right channel back to the normal mode. 235 // and right channel back to the normal mode.
221 // If the feature is not supported on the device, nothing happens. 236 // If the feature is not supported on the device, nothing happens.
222 virtual void SwapInternalSpeakerLeftRightChannel(bool swap); 237 void SwapInternalSpeakerLeftRightChannel(bool swap);
223 238
224 // Accessibility audio setting: sets the output mono or not. 239 // Accessibility audio setting: sets the output mono or not.
225 virtual void SetOutputMono(bool mono_on); 240 void SetOutputMono(bool mono_on);
226 241
227 // Returns true if output mono is enabled. 242 // Returns true if output mono is enabled.
228 virtual bool IsOutputMonoEnabled() const; 243 bool IsOutputMonoEnabled() const;
229 244
230 // Enables error logging. 245 // Enables error logging.
231 virtual void LogErrors(); 246 void LogErrors();
232 247
233 // If necessary, sets the starting point for re-discovering the active HDMI 248 // If necessary, sets the starting point for re-discovering the active HDMI
234 // output device caused by device entering/exiting docking mode, HDMI display 249 // output device caused by device entering/exiting docking mode, HDMI display
235 // changing resolution, or chromeos device suspend/resume. If 250 // changing resolution, or chromeos device suspend/resume. If
236 // |force_rediscovering| is true, it will force to set the starting point for 251 // |force_rediscovering| is true, it will force to set the starting point for
237 // re-discovering the active HDMI output device again if it has been in the 252 // re-discovering the active HDMI output device again if it has been in the
238 // middle of rediscovering the HDMI active output device. 253 // middle of rediscovering the HDMI active output device.
239 virtual void SetActiveHDMIOutoutRediscoveringIfNecessary( 254 void SetActiveHDMIOutoutRediscoveringIfNecessary(bool force_rediscovering);
240 bool force_rediscovering);
241 255
242 virtual const AudioDevice* GetDeviceFromId(uint64_t device_id) const; 256 const AudioDevice* GetDeviceFromId(uint64_t device_id) const;
243 257
244 protected: 258 protected:
245 explicit CrasAudioHandler( 259 explicit CrasAudioHandler(
246 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 260 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler);
247 ~CrasAudioHandler() override; 261 ~CrasAudioHandler() override;
248 262
249 private: 263 private:
250 friend class CrasAudioHandlerTest; 264 friend class CrasAudioHandlerTest;
251 265
252 // CrasAudioClient::Observer overrides. 266 // CrasAudioClient::Observer overrides.
(...skipping 10 matching lines...) Expand all
263 void EmitLoginPromptVisibleCalled() override; 277 void EmitLoginPromptVisibleCalled() override;
264 278
265 // Sets the |active_device| to be active. 279 // Sets the |active_device| to be active.
266 // If |notify|, notifies Active*NodeChange. 280 // If |notify|, notifies Active*NodeChange.
267 // Saves device active states in prefs. |activate_by| indicates how 281 // Saves device active states in prefs. |activate_by| indicates how
268 // the device was activated. 282 // the device was activated.
269 void SetActiveDevice(const AudioDevice& active_device, 283 void SetActiveDevice(const AudioDevice& active_device,
270 bool notify, 284 bool notify,
271 DeviceActivateType activate_by); 285 DeviceActivateType activate_by);
272 286
287 // Shared implementation for |SetActiveInputNodes| and |SetActiveOutputNodes|.
288 bool SetActiveNodes(const NodeIdList& node_ids, bool is_input);
289
273 // Sets list of active input or output nodes to |devices|. 290 // Sets list of active input or output nodes to |devices|.
274 // If |is_input| is set, active input nodes will be set, otherwise active 291 // If |is_input| is set, active input nodes will be set, otherwise active
275 // output nodes will be set. 292 // output nodes will be set.
276 // For each device in |devices| it is expected device.is_input == is_input. 293 // For each device in |devices| it is expected device.is_input == is_input.
277 void SetActiveNodes(const AudioDeviceList& devices, bool is_input); 294 void SetActiveDevices(const AudioDeviceList& devices, bool is_input);
278 295
279 // Saves |device|'s state in pref. If |active| is true, |activate_by| 296 // Saves |device|'s state in pref. If |active| is true, |activate_by|
280 // indicates how |device| is activated. 297 // indicates how |device| is activated.
281 void SaveDeviceState(const AudioDevice& device, 298 void SaveDeviceState(const AudioDevice& device,
282 bool active, 299 bool active,
283 DeviceActivateType activate_by); 300 DeviceActivateType activate_by);
284 301
285 // Sets up the audio device state based on audio policy and audio settings 302 // Sets up the audio device state based on audio policy and audio settings
286 // saved in prefs. 303 // saved in prefs.
287 void SetupAudioInputState(); 304 void SetupAudioInputState();
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 uint64_t init_node_id_; 478 uint64_t init_node_id_;
462 479
463 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; 480 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
464 481
465 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); 482 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
466 }; 483 };
467 484
468 } // namespace chromeos 485 } // namespace chromeos
469 486
470 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ 487 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | chromeos/audio/cras_audio_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698