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

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

Issue 14314002: Implement new audio handler which talks to the new audio dbus apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
6 #define CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "chromeos/dbus/audio_node.h"
13 #include "chromeos/dbus/cras_audio_client.h"
14 #include "chromeos/dbus/volume_state.h"
15
16 class PrefRegistrySimple;
17 class PrefService;
18
19 namespace chromeos {
20
21 class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer {
22 public:
23 class AudioObserver {
24 public:
25 // Called when output volume changed.
26 virtual void OnOutputVolumeChanged();
27
28 // Called when output mute state changed.
29 virtual void OnOutputMuteChanged();
30
31 // Called when input mute state changed.
32 virtual void OnInputMuteChanged();
33
34 // Called when audio nodes changed.
35 virtual void OnAudioNodesChanged();
36
37 // Called when active audio node changed.
38 virtual void OnActiveOutputNodeChanged();
39
40 // Called when active audio input node changed.
41 virtual void OnActiveInputNodeChanged();
42
43 protected:
44 AudioObserver();
45 virtual ~AudioObserver();
46 DISALLOW_COPY_AND_ASSIGN(AudioObserver);
47 };
48
49 // Sets the global instance. Must be called before any calls to Get().
50 static void Initialize(PrefService* local_state);
51
52 // Destroys the global instance.
53 static void Shutdown();
54
55 // Returns true if the global instance is initialized.
56 static bool IsInitialized();
57
58 // Gets the global instance. Initialize must be called first.
59 static CrasAudioHandler* Get();
60
61 // Registers audio preferences.
62 static void RegisterPrefs(PrefRegistrySimple* registry);
63
64 // Adds an audio observer.
65 void AddAudioObserver(AudioObserver* observer);
66
67 // Removes an audio observer.
68 void RemoveAudioObserver(AudioObserver* observer);
69
70 // Returns true if audio output is muted.
71 bool IsOutputMuted();
72
73 // Returns true if audio input is muted.
74 bool IsInputMuted();
75
76 // Gets volume level in 0-100% range, 0 being pure silence.
77 int GetOutputVolumePercent();
78
79 // Returns node_id of the active output node.
80 uint64 GetActiveOutputNode() const;
81
82 // Returns the node_id of the active input node.
83 uint64 GetActiveInputNode() const;
84
85 // Sets volume level from 0-100%. If less than kMuteThresholdPercent, then
86 // mutes the sound. If it was muted, and |volume_percent| is larger than
87 // the threshold, then the sound is unmuted.
88 void SetOutputVolumePercent(int volume_percent);
89
90 // Adjusts volume up (positive percentage) or down (negative percentage).
91 void AdjustOutputVolumeByPercent(int adjust_by_percent);
92
93 // Mutes or unmutes audio output device.
94 void SetOutputMute(bool mute_on);
95
96 // Mutes or unmutes audio input device.
97 void SetInputMute(bool mute_on);
98
99 // Sets the active audio output node to the node with |node_id|.
100 void SetActiveOutputNode(uint64 node_id);
101
102 // Sets the active audio input node to the node with |node_id|.
103 void SetActiveInputNode(uint64 node_id);
104
105 private:
106 explicit CrasAudioHandler(PrefService* local_state);
107 virtual ~CrasAudioHandler();
108
109 // Overriden from CrasAuduiHandler::Observer.
stevenjb 2013/04/17 01:25:12 s/Audui/Audio
jennyz 2013/04/18 01:21:19 Done.
110 virtual void AudioClientRestarted() OVERRIDE;
111 virtual void OutputVolumeChanged(int volume) OVERRIDE;
112 virtual void OutputMuteChanged(bool mute_on) OVERRIDE;
113 virtual void InputMuteChanged(bool mute_on) OVERRIDE;
114 virtual void NodesChanged() OVERRIDE;
115 virtual void ActiveOutputNodeChanged(uint64 node_id) OVERRIDE;
116 virtual void ActiveInputNodeChanged(uint64 node_id) OVERRIDE;
117
118 // Initializes the observers for the policy prefs.
119 void InitializePrefObservers();
120
121 // Sets up the initial audio device state based on audio policy and
122 // audio settings saved in prefs.
123 void SetupInitialAudioState();
124
125 // Applies the audio muting policies whenever the user logs in or policy
126 // change notification is received.
127 void ApplyAudioPolicy();
128
129 // Sets output volume to specified value and notifies observers.
130 void SetOutputVolumeInternal(int volume);
131
132 // Calling dbus to get nodes data.
133 void GetNodes();
134
135 // Handles dbus callback for GetNodes.
136 void HandleGetNodes(const chromeos::AudioNodeList& node_list, bool success);
137
138 ObserverList<AudioObserver> observers_;
139
140 base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
stevenjb 2013/04/17 01:25:12 This should be after pref_change_registrar_ so tha
jennyz 2013/04/18 01:21:19 Done.
141 PrefService* local_state_; // not owned
142 PrefChangeRegistrar pref_change_registrar_;
143
144 // Audio data and state.
145 AudioNodeList audio_nodes_;
146 VolumeState volume_state_;
147 bool output_mute_on_;
148 bool input_mute_on_;
149 int output_volume_;
150 uint64 active_output_node_id_;
151 uint64 active_input_node_id_;
152
153 bool output_mute_locked_;
154 bool input_mute_locked_;
155
156 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandler);
157 };
158
159 } // namespace chromeos
160
161 #endif // CHROMEOS_AUDIO_CRAS_AUDIO_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698