1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
#define CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
#include "base/callback.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/audio_node.h"
#include "chromeos/dbus/dbus_client.h"
#include "chromeos/dbus/volume_state.h"
namespace chromeos {
// CrasAudioClient is used to communicate with the cras audio dbus interface.
class CHROMEOS_EXPORT CrasAudioClient : public DBusClient {
public:
// Interface for observing changes from the cras audio changes.
class Observer {
public:
// Called when cras audio client starts or re-starts, which happens when
// cros device powers up or restarted.
virtual void AudioClientRestarted();
// Called when audio output mute state changed to new state of |mute_on|.
virtual void OutputMuteChanged(bool mute_on);
// Called when audio input mute state changed to new state of |mute_on|.
virtual void InputMuteChanged(bool mute_on);
// Called when audio nodes change.
virtual void NodesChanged();
// Called when active audio output node changed to new node with |node_id|.
virtual void ActiveOutputNodeChanged(uint64 node_id);
// Called when active audio input node changed to new node with |node_id|.
virtual void ActiveInputNodeChanged(uint64 node_id);
protected:
virtual ~Observer();
};
virtual ~CrasAudioClient();
// Adds and removes the observer.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Returns true if this object has the given observer.
virtual bool HasObserver(Observer* observer) = 0;
// GetVolumeStateCallback is used for GetVolumeState method. It receives
// 2 arguments, |volume_state| which containing both input and output volume
// state data, and |success| which indicates whether or not the request
// succeeded.
typedef base::Callback<void(const VolumeState&, bool)> GetVolumeStateCallback;
// GetNodesCallback is used for GetNodes method. It receives 2 arguments,
// |audio_nodes| which containing a list of audio nodes data and
// |success| which indicates whether or not the request succeeded.
typedef base::Callback<void(const AudioNodeList&, bool)> GetNodesCallback;
// ErrorCallback is used for cras dbus method error response. It receives 2
// arguments, |error_name| indicates the dbus error name, and |error_message|
// contains the detailed dbus error message.
typedef base::Callback<void(const std::string&,
const std::string&)> ErrorCallback;
// Gets the volume state, asynchronously.
virtual void GetVolumeState(const GetVolumeStateCallback& callback) = 0;
// Gets an array of audio input and output nodes.
virtual void GetNodes(const GetNodesCallback& callback,
const ErrorCallback& error_callback) = 0;
// Sets output volume of the given |node_id| to |volume|, in the rage of
// [0, 100].
virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) = 0;
// Sets output mute from user action.
virtual void SetOutputUserMute(bool mute_on) = 0;
// Sets input gain of the given |node_id| to |gain|, in the range of
// [0, 100].
virtual void SetInputNodeGain(uint64 node_id, int32 gain) = 0;
// Sets input mute state to |mute_on| value.
virtual void SetInputMute(bool mute_on) = 0;
// Sets the active output node to |node_id|.
virtual void SetActiveOutputNode(uint64 node_id) = 0;
// Sets the active input node to |node_id|.
virtual void SetActiveInputNode(uint64 node_id) = 0;
// Creates the instance.
static CrasAudioClient* Create();
protected:
// Create() should be used instead.
CrasAudioClient();
private:
DISALLOW_COPY_AND_ASSIGN(CrasAudioClient);
};
} // namespace chromeos
#endif // CHROMEOS_DBUS_CRAS_AUDIO_CLIENT_H_
|