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

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

Issue 14655010: Revert 198556 "Implement the rest of the audio API." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 "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"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "chromeos/audio/audio_device.h" 12 #include "chromeos/audio/audio_device.h"
13 #include "chromeos/audio/audio_pref_observer.h" 13 #include "chromeos/audio/audio_pref_observer.h"
14 #include "chromeos/dbus/audio_node.h" 14 #include "chromeos/dbus/audio_node.h"
15 #include "chromeos/dbus/cras_audio_client.h" 15 #include "chromeos/dbus/cras_audio_client.h"
16 #include "chromeos/dbus/volume_state.h" 16 #include "chromeos/dbus/volume_state.h"
17 17
18 class PrefRegistrySimple; 18 class PrefRegistrySimple;
19 class PrefService; 19 class PrefService;
20 20
21 namespace {
22
23 // Default value for the volume pref, as a percent in the range [0.0, 100.0].
24 const double kDefaultVolumeGainPercent = 75.0;
25
26 // Values used for muted preference.
27 const int kPrefMuteOff = 0;
28 const int kPrefMuteOn = 1;
29
30 } // namespace
31
32 namespace chromeos { 21 namespace chromeos {
33 22
34 class AudioDevicesPrefHandler; 23 class AudioDevicesPrefHandler;
35 24
36 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, 25 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
37 public AudioPrefObserver { 26 public AudioPrefObserver {
38 public: 27 public:
39 class AudioObserver { 28 class AudioObserver {
40 public: 29 public:
41 // Called when output volume changed. 30 // Called when output volume changed.
42 virtual void OnOutputVolumeChanged(); 31 virtual void OnOutputVolumeChanged();
43 32
44 // Called when output mute state changed. 33 // Called when output mute state changed.
45 virtual void OnOutputMuteChanged(); 34 virtual void OnOutputMuteChanged();
46 35
47 // Called when input mute state changed. 36 // Called when input mute state changed.
48 virtual void OnInputGainChanged();
49
50 // Called when input mute state changed.
51 virtual void OnInputMuteChanged(); 37 virtual void OnInputMuteChanged();
52 38
53 // Called when audio nodes changed. 39 // Called when audio nodes changed.
54 virtual void OnAudioNodesChanged(); 40 virtual void OnAudioNodesChanged();
55 41
56 // Called when active audio node changed. 42 // Called when active audio node changed.
57 virtual void OnActiveOutputNodeChanged(); 43 virtual void OnActiveOutputNodeChanged();
58 44
59 // Called when active audio input node changed. 45 // Called when active audio input node changed.
60 virtual void OnActiveInputNodeChanged(); 46 virtual void OnActiveInputNodeChanged();
(...skipping 25 matching lines...) Expand all
86 72
87 // Removes an audio observer. 73 // Removes an audio observer.
88 virtual void RemoveAudioObserver(AudioObserver* observer); 74 virtual void RemoveAudioObserver(AudioObserver* observer);
89 75
90 // Returns true if audio output is muted. 76 // Returns true if audio output is muted.
91 virtual bool IsOutputMuted(); 77 virtual bool IsOutputMuted();
92 78
93 // Returns true if audio input is muted. 79 // Returns true if audio input is muted.
94 virtual bool IsInputMuted(); 80 virtual bool IsInputMuted();
95 81
96 // Gets volume level in 0-100% range (0 being pure silence) for the current 82 // Gets volume level in 0-100% range, 0 being pure silence.
97 // active node.
98 virtual int GetOutputVolumePercent(); 83 virtual int GetOutputVolumePercent();
99 84
100 // Gets volume level in 0-100% range (0 being pure silence) for a device.
101 virtual int GetOutputVolumePercentForDevice(uint64 device_id);
102
103 // Gets gain level in 0-100% range (0 being pure silence) for the current
104 // active node.
105 virtual int GetInputGainPercent();
106
107 // Gets volume level in 0-100% range (0 being pure silence) for a device.
108 virtual int GetInputGainPercentForDevice(uint64 device_id);
109
110 // Returns node_id of the active output node. 85 // Returns node_id of the active output node.
111 virtual uint64 GetActiveOutputNode() const; 86 virtual uint64 GetActiveOutputNode() const;
112 87
113 // Returns the node_id of the active input node. 88 // Returns the node_id of the active input node.
114 virtual uint64 GetActiveInputNode() const; 89 virtual uint64 GetActiveInputNode() const;
115 90
116 // Gets the audio devices back in |device_list|. 91 // Gets the audio devices back in |device_list|.
117 virtual void GetAudioDevices(AudioDeviceList* device_list) const; 92 virtual void GetAudioDevices(AudioDeviceList* device_list) const;
118 93
119 virtual bool GetActiveOutputDevice(AudioDevice* device) const; 94 virtual bool GetActiveOutputDevice(AudioDevice* device) const;
120 95
121 // Whether there is alternative input/output audio device. 96 // Whether there is alternative input/output audio device.
122 virtual bool has_alternative_input() const; 97 virtual bool has_alternative_input() const;
123 virtual bool has_alternative_output() const; 98 virtual bool has_alternative_output() const;
124 99
125 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then 100 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then
126 // mutes the sound. If it was muted, and |volume_percent| is larger than 101 // mutes the sound. If it was muted, and |volume_percent| is larger than
127 // the threshold, then the sound is unmuted. 102 // the threshold, then the sound is unmuted.
128 virtual void SetOutputVolumePercent(int volume_percent); 103 virtual void SetOutputVolumePercent(int volume_percent);
129 104
130 // Sets gain level from 0-100%.
131 virtual void SetInputGainPercent(int gain_percent);
132
133 // Adjusts volume up (positive percentage) or down (negative percentage). 105 // Adjusts volume up (positive percentage) or down (negative percentage).
134 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent); 106 virtual void AdjustOutputVolumeByPercent(int adjust_by_percent);
135 107
136 // Mutes or unmutes audio output device. 108 // Mutes or unmutes audio output device.
137 virtual void SetOutputMute(bool mute_on); 109 virtual void SetOutputMute(bool mute_on);
138 110
139 // Mutes or unmutes audio input device. 111 // Mutes or unmutes audio input device.
140 virtual void SetInputMute(bool mute_on); 112 virtual void SetInputMute(bool mute_on);
141 113
142 // Sets the active audio output node to the node with |node_id|. 114 // Sets the active audio output node to the node with |node_id|.
143 virtual void SetActiveOutputNode(uint64 node_id); 115 virtual void SetActiveOutputNode(uint64 node_id);
144 116
145 // Sets the active audio input node to the node with |node_id|. 117 // Sets the active audio input node to the node with |node_id|.
146 virtual void SetActiveInputNode(uint64 node_id); 118 virtual void SetActiveInputNode(uint64 node_id);
147 119
148 // Sets volume/gain level from a device.
149 virtual void SetVolumeGainPercentForDevice(uint64 device_id, int value);
150
151 protected: 120 protected:
152 explicit CrasAudioHandler( 121 explicit CrasAudioHandler(
153 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler); 122 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler);
154 virtual ~CrasAudioHandler(); 123 virtual ~CrasAudioHandler();
155 124
156 private: 125 private:
157 // Overriden from CrasAudioClient::Observer. 126 // Overriden from CrasAudioHandler::Observer.
158 virtual void AudioClientRestarted() OVERRIDE; 127 virtual void AudioClientRestarted() OVERRIDE;
159 virtual void OutputVolumeChanged(int volume) OVERRIDE; 128 virtual void OutputVolumeChanged(int volume) OVERRIDE;
160 virtual void OutputMuteChanged(bool mute_on) OVERRIDE; 129 virtual void OutputMuteChanged(bool mute_on) OVERRIDE;
161 virtual void InputGainChanged(int gain) OVERRIDE;
162 virtual void InputMuteChanged(bool mute_on) OVERRIDE; 130 virtual void InputMuteChanged(bool mute_on) OVERRIDE;
163 virtual void NodesChanged() OVERRIDE; 131 virtual void NodesChanged() OVERRIDE;
164 virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE; 132 virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE;
165 virtual void ActiveInputNodeChanged(uint64 node_id) OVERRIDE; 133 virtual void ActiveInputNodeChanged(uint64 node_id) OVERRIDE;
166 134
167 // Overriden from AudioPrefObserver. 135 // Overriden from AudioPrefObserver.
168 virtual void OnAudioPolicyPrefChanged() OVERRIDE; 136 virtual void OnAudioPolicyPrefChanged() OVERRIDE;
169 137
170 // Sets up the audio device state based on audio policy and audio settings 138 // Sets up the audio device state based on audio policy and audio settings
171 // saved in prefs. 139 // saved in prefs.
172 void SetupAudioState(); 140 void SetupAudioState();
173 141
174 // Applies the audio muting policies whenever the user logs in or policy 142 // Applies the audio muting policies whenever the user logs in or policy
175 // change notification is received. 143 // change notification is received.
176 void ApplyAudioPolicy(); 144 void ApplyAudioPolicy();
177 145
178 // Sets output volume to specified value and notifies observers. 146 // Sets output volume to specified value and notifies observers.
179 void SetOutputVolumeInternal(int volume); 147 void SetOutputVolumeInternal(int volume);
180 148
181 // Sets output volume to specified value and notifies observers.
182 void SetInputGainInternal(int gain);
183
184 // Calling dbus to get nodes data. 149 // Calling dbus to get nodes data.
185 void GetNodes(); 150 void GetNodes();
186 151
187 // Handles dbus callback for GetNodes. 152 // Handles dbus callback for GetNodes.
188 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success); 153 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success);
189 154
190 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_; 155 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler_;
191 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; 156 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
192 ObserverList<AudioObserver> observers_; 157 ObserverList<AudioObserver> observers_;
193 158
194 // Audio data and state. 159 // Audio data and state.
195 AudioDeviceList audio_devices_; 160 AudioDeviceList audio_devices_;
196 VolumeState volume_state_; 161 VolumeState volume_state_;
197 bool output_mute_on_; 162 bool output_mute_on_;
198 bool input_mute_on_; 163 bool input_mute_on_;
199 int output_volume_; 164 int output_volume_;
200 int input_gain_;
201 uint64 active_output_node_id_; 165 uint64 active_output_node_id_;
202 uint64 active_input_node_id_; 166 uint64 active_input_node_id_;
203 bool has_alternative_input_; 167 bool has_alternative_input_;
204 bool has_alternative_output_; 168 bool has_alternative_output_;
205 169
206 bool output_mute_locked_; 170 bool output_mute_locked_;
207 bool input_mute_locked_; 171 bool input_mute_locked_;
208 172
209 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler); 173 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
210 }; 174 };
211 175
212 } // namespace chromeos 176 } // namespace chromeos
213 177
214 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_ 178 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
OLDNEW
« no previous file with comments | « trunk/src/chromeos/audio/audio_devices_pref_handler.h ('k') | trunk/src/chromeos/audio/cras_audio_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698