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

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

Powered by Google App Engine
This is Rietveld 408576698