summaryrefslogtreecommitdiff
path: root/cras/src/server/cras_iodev_list.h
blob: d6e9ba5400e4e0350556c8c9b90975b8e2413b08 (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/*
 * IO list manages the list of inputs and outputs available.
 */
#ifndef CRAS_IODEV_LIST_H_
#define CRAS_IODEV_LIST_H_

#include <stdbool.h>
#include <stdint.h>

#include "cras_iodev.h"
#include "cras_types.h"

struct cras_rclient;
struct stream_list;

/* Device enabled/disabled callback. */
typedef void (*device_enabled_callback_t)(struct cras_iodev *dev,
					  void *cb_data);
typedef void (*device_disabled_callback_t)(struct cras_iodev *dev,
					   void *cb_data);

/* Initialize the list of iodevs. */
void cras_iodev_list_init();

/* Clean up any resources used by iodev. */
void cras_iodev_list_deinit();

/* Adds an output to the output list.
 * Args:
 *    output - the output to add.
 * Returns:
 *    0 on success, negative error on failure.
 */
int cras_iodev_list_add_output(struct cras_iodev *output);

/* Adds an input to the input list.
 * Args:
 *    input - the input to add.
 * Returns:
 *    0 on success, negative error on failure.
 */
int cras_iodev_list_add_input(struct cras_iodev *input);

/* Removes an output from the output list.
 * Args:
 *    output - the output to remove.
 * Returns:
 *    0 on success, negative error on failure.
 */
int cras_iodev_list_rm_output(struct cras_iodev *output);

/* Removes an input from the input list.
 * Args:
 *    output - the input to remove.
 * Returns:
 *    0 on success, negative error on failure.
 */
int cras_iodev_list_rm_input(struct cras_iodev *input);

/* Gets a list of outputs. Callee must free the list when finished.  If list_out
 * is NULL, this function can be used to return the number of outputs.
 * Args:
 *    list_out - This will be set to the malloc'd area containing the list of
 *        devices.  Ignored if NULL.
 * Returns:
 *    The number of devices on the list.
 */
int cras_iodev_list_get_outputs(struct cras_iodev_info **list_out);

/* Gets a list of inputs. Callee must free the list when finished.  If list_out
 * is NULL, this function can be used to return the number of inputs.
 * Args:
 *    list_out - This will be set to the malloc'd area containing the list of
 *        devices.  Ignored if NULL.
 * Returns:
 *    The number of devices on the list.
 */
int cras_iodev_list_get_inputs(struct cras_iodev_info **list_out);

/* Returns the first enabled device.
 * Args:
 *    direction - Playback or capture.
 * Returns:
 *    Pointer to the first enabled device of direction.
 */
struct cras_iodev *
cras_iodev_list_get_first_enabled_iodev(enum CRAS_STREAM_DIRECTION direction);

/* Returns SCO PCM device.
 * Args:
 *    direction - Playback or capture.
 * Returns:
 *    Pointer to the SCO PCM device of direction.
 */
struct cras_iodev *
cras_iodev_list_get_sco_pcm_iodev(enum CRAS_STREAM_DIRECTION direction);

/* Returns the active node id.
 * Args:
 *    direction - Playback or capture.
 * Returns:
 *    The id of the active node.
 */
cras_node_id_t
cras_iodev_list_get_active_node_id(enum CRAS_STREAM_DIRECTION direction);

/* Stores the following data to the shared memory server state region:
 * (1) device list
 * (2) node list
 * (3) selected nodes
 */
void cras_iodev_list_update_device_list();

/* Stores the node list in the shared memory server state region. */
void cras_iodev_list_update_node_list();

/* Gets the supported hotword models of an ionode. Caller should free
 * the returned string after use. */
char *cras_iodev_list_get_hotword_models(cras_node_id_t node_id);

/* Sets the desired hotword model to an ionode. */
int cras_iodev_list_set_hotword_model(cras_node_id_t id,
				      const char *model_name);

/* Notify that nodes are added/removed. */
void cras_iodev_list_notify_nodes_changed();

/* Notify that active node is changed for the given direction.
 * Args:
 *    direction - Direction of the node.
 */
void cras_iodev_list_notify_active_node_changed(
	enum CRAS_STREAM_DIRECTION direction);

/* Sets an attribute of an ionode on a device.
 * Args:
 *    id - the id of the ionode.
 *    node_index - Index of the ionode on the device.
 *    attr - the attribute we want to change.
 *    value - the value we want to set.
 */
int cras_iodev_list_set_node_attr(cras_node_id_t id, enum ionode_attr attr,
				  int value);

/* Select a node as the preferred node.
 * Args:
 *    direction - Playback or capture.
 *    node_id - the id of the ionode to be selected. As a special case, if
 *        node_id is 0, don't select any node in this direction.
 */
void cras_iodev_list_select_node(enum CRAS_STREAM_DIRECTION direction,
				 cras_node_id_t node_id);

/*
 * Checks if an iodev is enabled. By enabled we mean all default streams will
 * be routed to this iodev.
 */
int cras_iodev_list_dev_is_enabled(const struct cras_iodev *dev);

/* Enables an iodev. If the fallback device was already enabled, this
 * call will disable it. */
void cras_iodev_list_enable_dev(struct cras_iodev *dev);

/*
 * Suspends the connection of all types of stream attached to given iodev.
 * This call doesn't disable the given iodev.
 */
void cras_iodev_list_suspend_dev(unsigned int dev_idx);

/*
 * Resumes the connection of all types of stream attached to given iodev.
 * This call doesn't enable the given dev.
 */
void cras_iodev_list_resume_dev(unsigned int dev_idx);

/*
 * Sets mute state to device of given index.
 * Args:
 *    dev_idx - Index of the device to set mute state.
 */
void cras_iodev_list_set_dev_mute(unsigned int dev_idx);

/*
 * Disables an iodev. If this is the last device to disable, the
 * fallback devices will be enabled accordingly.
 * Set `foce_close` to true if the device must be closed regardless of having
 * pinned streams attached.
 */
void cras_iodev_list_disable_dev(struct cras_iodev *dev, bool force_close);

/* Adds a node to the active devices list.
 * Args:
 *    direction - Playback or capture.
 *    node_id - The id of the ionode to be added.
 */
void cras_iodev_list_add_active_node(enum CRAS_STREAM_DIRECTION direction,
				     cras_node_id_t node_id);

/* Removes a node from the active devices list.
 * Args:
 *    direction - Playback or capture.
 *    node_id - The id of the ionode to be removed.
 */
void cras_iodev_list_rm_active_node(enum CRAS_STREAM_DIRECTION direction,
				    cras_node_id_t node_id);

/* Returns 1 if the node is selected, 0 otherwise. */
int cras_iodev_list_node_selected(struct cras_ionode *node);

/* Notify the current volume of the given node. */
void cras_iodev_list_notify_node_volume(struct cras_ionode *node);

/* Notify the current capture gain of the given node. */
void cras_iodev_list_notify_node_capture_gain(struct cras_ionode *node);

/* Notify the current left right channel swapping state of the given node. */
void cras_iodev_list_notify_node_left_right_swapped(struct cras_ionode *node);

/* Handles the adding and removing of test iodevs. */
void cras_iodev_list_add_test_dev(enum TEST_IODEV_TYPE type);

/* Handles sending a command to a test iodev. */
void cras_iodev_list_test_dev_command(unsigned int iodev_idx,
				      enum CRAS_TEST_IODEV_CMD command,
				      unsigned int data_len,
				      const uint8_t *data);

/* Gets the audio thread used by the devices. */
struct audio_thread *cras_iodev_list_get_audio_thread();

/* Gets the list of all active audio streams attached to devices. */
struct stream_list *cras_iodev_list_get_stream_list();

/* Sets the function to call when a device is enabled or disabled. */
int cras_iodev_list_set_device_enabled_callback(
	device_enabled_callback_t enabled_cb,
	device_disabled_callback_t disabled_cb, void *cb_data);

/* Registers loopback to an output device.
 * Args:
 *    loopback_type - Pre or post software DSP.
 *    output_dev_idx - Index of the target output device.
 *    hook_data - Callback function to process loopback data.
 *    hook_start - Callback for starting or stopping loopback.
 *    loopback_dev_idx - Index of the loopback device that
 *        listens for output data.
 */
void cras_iodev_list_register_loopback(enum CRAS_LOOPBACK_TYPE loopback_type,
				       unsigned int output_dev_idx,
				       loopback_hook_data_t hook_data,
				       loopback_hook_control_t hook_start,
				       unsigned int loopback_dev_idx);

/* Unregisters loopback from an output device by matching
 * loopback type and loopback device index.
 * Args:
 *    loopback_type - Pre or post software DSP.
 *    output_dev_idx - Index of the target output device.
 *    loopback_dev_idx - Index of the loopback device that
 *        listens for output data.
 */
void cras_iodev_list_unregister_loopback(enum CRAS_LOOPBACK_TYPE loopback_type,
					 unsigned int output_dev_idx,
					 unsigned int loopback_dev_idx);

/* Suspends all hotwording streams. */
int cras_iodev_list_suspend_hotword_streams();

/* Resumes all hotwording streams. */
int cras_iodev_list_resume_hotword_stream();

/* Sets the state of noise cancellation for input devices which supports noise
 * cancellation by suspend, enable/disable, then resume.
 */
void cras_iodev_list_reset_for_noise_cancellation();

/* For unit test only. */
void cras_iodev_list_reset();

#endif /* CRAS_IODEV_LIST_H_ */