Roll src/third_party/skia 726cf90:183b57f
[chromium-blink-merge.git] / chromeos / dbus / cras_audio_client.h
blob4b2d7eb37727e38efbd964d502ebed0ef7539f21
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.
5 #ifndef CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
6 #define CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
8 #include "base/callback.h"
9 #include "base/observer_list.h"
10 #include "chromeos/chromeos_export.h"
11 #include "chromeos/dbus/audio_node.h"
12 #include "chromeos/dbus/dbus_client.h"
13 #include "chromeos/dbus/volume_state.h"
15 namespace chromeos {
17 // CrasAudioClient is used to communicate with the cras audio dbus interface.
18 class CHROMEOS_EXPORT CrasAudioClient : public DBusClient {
19 public:
20 // Interface for observing changes from the cras audio changes.
21 class Observer {
22 public:
23 // Called when cras audio client starts or re-starts, which happens when
24 // cros device powers up or restarted.
25 virtual void AudioClientRestarted();
27 // Called when audio output mute state changed to new state of |mute_on|.
28 virtual void OutputMuteChanged(bool mute_on);
30 // Called when audio input mute state changed to new state of |mute_on|.
31 virtual void InputMuteChanged(bool mute_on);
33 // Called when audio nodes change.
34 virtual void NodesChanged();
36 // Called when active audio output node changed to new node with |node_id|.
37 virtual void ActiveOutputNodeChanged(uint64 node_id);
39 // Called when active audio input node changed to new node with |node_id|.
40 virtual void ActiveInputNodeChanged(uint64 node_id);
42 protected:
43 virtual ~Observer();
46 ~CrasAudioClient() override;
48 // Adds and removes the observer.
49 virtual void AddObserver(Observer* observer) = 0;
50 virtual void RemoveObserver(Observer* observer) = 0;
51 // Returns true if this object has the given observer.
52 virtual bool HasObserver(const Observer* observer) const = 0;
54 // GetVolumeStateCallback is used for GetVolumeState method. It receives
55 // 2 arguments, |volume_state| which containing both input and output volume
56 // state data, and |success| which indicates whether or not the request
57 // succeeded.
58 typedef base::Callback<void(const VolumeState&, bool)> GetVolumeStateCallback;
60 // GetNodesCallback is used for GetNodes method. It receives 2 arguments,
61 // |audio_nodes| which containing a list of audio nodes data and
62 // |success| which indicates whether or not the request succeeded.
63 typedef base::Callback<void(const AudioNodeList&, bool)> GetNodesCallback;
65 // ErrorCallback is used for cras dbus method error response. It receives 2
66 // arguments, |error_name| indicates the dbus error name, and |error_message|
67 // contains the detailed dbus error message.
68 typedef base::Callback<void(const std::string&,
69 const std::string&)> ErrorCallback;
71 // Gets the volume state, asynchronously.
72 virtual void GetVolumeState(const GetVolumeStateCallback& callback) = 0;
74 // Gets an array of audio input and output nodes.
75 virtual void GetNodes(const GetNodesCallback& callback,
76 const ErrorCallback& error_callback) = 0;
78 // Sets output volume of the given |node_id| to |volume|, in the rage of
79 // [0, 100].
80 virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) = 0;
82 // Sets output mute from user action.
83 virtual void SetOutputUserMute(bool mute_on) = 0;
85 // Sets input gain of the given |node_id| to |gain|, in the range of
86 // [0, 100].
87 virtual void SetInputNodeGain(uint64 node_id, int32 gain) = 0;
89 // Sets input mute state to |mute_on| value.
90 virtual void SetInputMute(bool mute_on) = 0;
92 // Sets the active output node to |node_id|.
93 virtual void SetActiveOutputNode(uint64 node_id) = 0;
95 // Sets the primary active input node to |node_id|.
96 virtual void SetActiveInputNode(uint64 node_id) = 0;
98 // Adds input node |node_id| to the active input list. This is used to add
99 // an additional active input node besides the one set by SetActiveInputNode.
100 // Note that this action will not trigger an ActiveInputNodeChanged event and
101 // nothing will happen if the |node_id| has already been set as active.
102 virtual void AddActiveInputNode(uint64 node_id) = 0;
104 // Removes input node |node_id| from the active input list. This is used for
105 // removing an active input node added by AddActiveInputNode.
106 virtual void RemoveActiveInputNode(uint64 node_id) = 0;
108 // Adds input node |node_id| to the active outputs list. This is used to add
109 // an additional active output node besides the one set by SetActiveInputNode.
110 // Note that this action will not trigger an ActiveOutputNodeChanged event
111 // and nothing will happen if the |node_id| has already been set as active.
112 virtual void AddActiveOutputNode(uint64 node_id) = 0;
114 // Removes output node |node_id| from the active output list. This is used for
115 // removing an active output node added by AddActiveOutputNode.
116 virtual void RemoveActiveOutputNode(uint64 node_id) = 0;
118 // Swaps the left and right channel of the primary active output device.
119 // Swap the left and right channel if |swap| is true; otherwise, swap the left
120 // and right channel back to the normal mode.
121 // The dbus message will be dropped if this feature is not supported on the
122 // |node_id|.
123 virtual void SwapLeftRight(uint64 node_id, bool swap) = 0;
125 // Creates the instance.
126 static CrasAudioClient* Create();
128 protected:
129 // Create() should be used instead.
130 CrasAudioClient();
132 private:
133 DISALLOW_COPY_AND_ASSIGN(CrasAudioClient);
136 } // namespace chromeos
138 #endif // CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_