• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS 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 
6 /*
7  * Types commonly used in the client and server are defined here.
8  */
9 #ifndef CRAS_TYPES_H_
10 #define CRAS_TYPES_H_
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <stdlib.h>
15 
16 #include "cras_audio_format.h"
17 #include "cras_iodev_info.h"
18 
19 /* Architecture independent timespec */
20 struct __attribute__((__packed__)) cras_timespec {
21 	int64_t tv_sec;
22 	int64_t tv_nsec;
23 };
24 
25 /* Some special device index values. */
26 enum CRAS_SPECIAL_DEVICE {
27 	NO_DEVICE,
28 	SILENT_RECORD_DEVICE,
29 	SILENT_PLAYBACK_DEVICE,
30 	SILENT_HOTWORD_DEVICE,
31 	MAX_SPECIAL_DEVICE_IDX
32 };
33 
34 /*
35  * Types of test iodevs supported.
36  */
37 enum TEST_IODEV_TYPE {
38 	TEST_IODEV_HOTWORD,
39 };
40 
41 /* Commands for test iodevs. */
42 enum CRAS_TEST_IODEV_CMD {
43 	TEST_IODEV_CMD_HOTWORD_TRIGGER,
44 };
45 
46 /* CRAS client connection types. */
47 enum CRAS_CONNECTION_TYPE {
48 	CRAS_CONTROL, // For legacy client.
49 	CRAS_PLAYBACK, // For playback client.
50 	CRAS_CAPTURE, // For capture client.
51 	CRAS_NUM_CONN_TYPE,
52 };
53 
54 static inline bool
cras_validate_connection_type(enum CRAS_CONNECTION_TYPE conn_type)55 cras_validate_connection_type(enum CRAS_CONNECTION_TYPE conn_type)
56 {
57 	return 0 <= conn_type && conn_type < CRAS_NUM_CONN_TYPE;
58 }
59 
60 /* Directions of audio streams.
61  * Input, Output, or loopback.
62  *
63  * Note that we use enum CRAS_STREAM_DIRECTION to access the elements in
64  * num_active_streams in cras_server_state. For example,
65  * num_active_streams[CRAS_STREAM_OUTPUT] is the number of active
66  * streams with direction CRAS_STREAM_OUTPUT.
67  */
68 enum CRAS_STREAM_DIRECTION {
69 	CRAS_STREAM_OUTPUT,
70 	CRAS_STREAM_INPUT,
71 	CRAS_STREAM_UNDEFINED,
72 	CRAS_STREAM_POST_MIX_PRE_DSP,
73 	CRAS_NUM_DIRECTIONS
74 };
75 
76 /* Bitmask for supporting all CRAS_STREAM_DIRECTION. */
77 #define CRAS_STREAM_ALL_DIRECTION ((1 << CRAS_NUM_DIRECTIONS) - 1)
78 
79 /* Converts CRAS_STREAM_DIRECTION to bitmask.
80  * Args:
81  *   dir - An enum CRAS_STREAM_DIRECTION.
82  *
83  * Returns:
84  *   bitmask for the given direction on success, negative on failure.
85  */
86 static inline int
cras_stream_direction_mask(const enum CRAS_STREAM_DIRECTION dir)87 cras_stream_direction_mask(const enum CRAS_STREAM_DIRECTION dir)
88 {
89 	if (0 <= dir && dir < CRAS_NUM_DIRECTIONS)
90 		return (1 << dir);
91 	return -EINVAL;
92 }
93 
94 /*
95  * Flags for stream types.
96  *  BULK_AUDIO_OK - This stream is OK with receiving up to a full shm of samples
97  *      in a single callback.
98  *  USE_DEV_TIMING - Don't wake up based on stream timing.  Only wake when the
99  *      device is ready. Input streams only.
100  *  HOTWORD_STREAM - This stream is used only to listen for hotwords such as "OK
101  *      Google".  Hardware will wake the device when this phrase is heard.
102  *  TRIGGER_ONLY - This stream only wants to receive when the data is available
103  *      and does not want to receive data. Used with HOTWORD_STREAM.
104  *  SERVER_ONLY - This stream doesn't associate to a client. It's used mainly
105  *      for audio data to flow from hardware through iodev's dsp pipeline.
106  */
107 enum CRAS_INPUT_STREAM_FLAG {
108 	BULK_AUDIO_OK = 0x01,
109 	USE_DEV_TIMING = 0x02,
110 	HOTWORD_STREAM = BULK_AUDIO_OK | USE_DEV_TIMING,
111 	TRIGGER_ONLY = 0x04,
112 	SERVER_ONLY = 0x08,
113 };
114 
115 /*
116  * Types of Loopback stream.
117  */
118 enum CRAS_LOOPBACK_TYPE {
119 	LOOPBACK_POST_MIX_PRE_DSP,
120 	LOOPBACK_POST_DSP,
121 	LOOPBACK_NUM_TYPES,
122 };
123 
cras_stream_uses_output_hw(enum CRAS_STREAM_DIRECTION dir)124 static inline int cras_stream_uses_output_hw(enum CRAS_STREAM_DIRECTION dir)
125 {
126 	return dir == CRAS_STREAM_OUTPUT;
127 }
128 
cras_stream_uses_input_hw(enum CRAS_STREAM_DIRECTION dir)129 static inline int cras_stream_uses_input_hw(enum CRAS_STREAM_DIRECTION dir)
130 {
131 	return dir == CRAS_STREAM_INPUT;
132 }
133 
cras_stream_has_input(enum CRAS_STREAM_DIRECTION dir)134 static inline int cras_stream_has_input(enum CRAS_STREAM_DIRECTION dir)
135 {
136 	return dir != CRAS_STREAM_OUTPUT;
137 }
138 
cras_stream_is_loopback(enum CRAS_STREAM_DIRECTION dir)139 static inline int cras_stream_is_loopback(enum CRAS_STREAM_DIRECTION dir)
140 {
141 	return dir == CRAS_STREAM_POST_MIX_PRE_DSP;
142 }
143 
144 /* Types of audio streams. */
145 enum CRAS_STREAM_TYPE {
146 	CRAS_STREAM_TYPE_DEFAULT,
147 	CRAS_STREAM_TYPE_MULTIMEDIA,
148 	CRAS_STREAM_TYPE_VOICE_COMMUNICATION,
149 	CRAS_STREAM_TYPE_SPEECH_RECOGNITION,
150 	CRAS_STREAM_TYPE_PRO_AUDIO,
151 	CRAS_STREAM_TYPE_ACCESSIBILITY,
152 	CRAS_STREAM_NUM_TYPES,
153 };
154 
155 /* Types of audio clients. */
156 enum CRAS_CLIENT_TYPE {
157 	CRAS_CLIENT_TYPE_UNKNOWN, /* Unknown client */
158 	CRAS_CLIENT_TYPE_LEGACY, /* A client with old craslib (CRAS_PROTO_VER = 3) */
159 	CRAS_CLIENT_TYPE_TEST, /* cras_test_client */
160 	CRAS_CLIENT_TYPE_PCM, /* A client using CRAS via pcm, like aplay */
161 	CRAS_CLIENT_TYPE_CHROME, /* Chrome, UI */
162 	CRAS_CLIENT_TYPE_ARC, /* ARC++ */
163 	CRAS_CLIENT_TYPE_CROSVM, /* CROSVM */
164 	CRAS_CLIENT_TYPE_SERVER_STREAM, /* Server stream */
165 };
166 
167 #define ENUM_STR(x)                                                            \
168 	case x:                                                                \
169 		return #x;
170 
171 static inline const char *
cras_stream_type_str(enum CRAS_STREAM_TYPE stream_type)172 cras_stream_type_str(enum CRAS_STREAM_TYPE stream_type)
173 {
174 	// clang-format off
175 	switch (stream_type) {
176 	ENUM_STR(CRAS_STREAM_TYPE_DEFAULT)
177 	ENUM_STR(CRAS_STREAM_TYPE_MULTIMEDIA)
178 	ENUM_STR(CRAS_STREAM_TYPE_VOICE_COMMUNICATION)
179 	ENUM_STR(CRAS_STREAM_TYPE_SPEECH_RECOGNITION)
180 	ENUM_STR(CRAS_STREAM_TYPE_PRO_AUDIO)
181 	ENUM_STR(CRAS_STREAM_TYPE_ACCESSIBILITY)
182 	default:
183 		return "INVALID_STREAM_TYPE";
184 	}
185 	// clang-format on
186 }
187 
188 static inline const char *
cras_client_type_str(enum CRAS_CLIENT_TYPE client_type)189 cras_client_type_str(enum CRAS_CLIENT_TYPE client_type)
190 {
191 	// clang-format off
192 	switch (client_type) {
193 	ENUM_STR(CRAS_CLIENT_TYPE_UNKNOWN)
194 	ENUM_STR(CRAS_CLIENT_TYPE_LEGACY)
195 	ENUM_STR(CRAS_CLIENT_TYPE_TEST)
196 	ENUM_STR(CRAS_CLIENT_TYPE_PCM)
197 	ENUM_STR(CRAS_CLIENT_TYPE_CHROME)
198 	ENUM_STR(CRAS_CLIENT_TYPE_ARC)
199 	ENUM_STR(CRAS_CLIENT_TYPE_CROSVM)
200 	ENUM_STR(CRAS_CLIENT_TYPE_SERVER_STREAM)
201 	default:
202 		return "INVALID_CLIENT_TYPE";
203 	}
204 	// clang-format on
205 }
206 
207 /* Effects that can be enabled for a CRAS stream. */
208 enum CRAS_STREAM_EFFECT {
209 	APM_ECHO_CANCELLATION = (1 << 0),
210 	APM_NOISE_SUPRESSION = (1 << 1),
211 	APM_GAIN_CONTROL = (1 << 2),
212 	APM_VOICE_DETECTION = (1 << 3),
213 };
214 
215 /* Information about a client attached to the server. */
216 struct __attribute__((__packed__)) cras_attached_client_info {
217 	uint32_t id;
218 	int32_t pid;
219 	uint32_t uid;
220 	uint32_t gid;
221 };
222 
223 /* Each ionode has a unique id. The top 32 bits are the device index, lower 32
224  * are the node index. */
225 typedef uint64_t cras_node_id_t;
226 
cras_make_node_id(uint32_t dev_index,uint32_t node_index)227 static inline cras_node_id_t cras_make_node_id(uint32_t dev_index,
228 					       uint32_t node_index)
229 {
230 	cras_node_id_t id = dev_index;
231 	return (id << 32) | node_index;
232 }
233 
dev_index_of(cras_node_id_t id)234 static inline uint32_t dev_index_of(cras_node_id_t id)
235 {
236 	return (uint32_t)(id >> 32);
237 }
238 
node_index_of(cras_node_id_t id)239 static inline uint32_t node_index_of(cras_node_id_t id)
240 {
241 	return (uint32_t)id;
242 }
243 
244 #define CRAS_MAX_IODEVS 20
245 #define CRAS_MAX_IONODES 20
246 #define CRAS_MAX_ATTACHED_CLIENTS 20
247 #define CRAS_MAX_AUDIO_THREAD_SNAPSHOTS 10
248 #define CRAS_MAX_HOTWORD_MODEL_NAME_SIZE 12
249 #define MAX_DEBUG_DEVS 4
250 #define MAX_DEBUG_STREAMS 8
251 #define AUDIO_THREAD_EVENT_LOG_SIZE (1024 * 6)
252 #define CRAS_BT_EVENT_LOG_SIZE 1024
253 
254 /* There are 8 bits of space for events. */
255 enum AUDIO_THREAD_LOG_EVENTS {
256 	AUDIO_THREAD_WAKE,
257 	AUDIO_THREAD_SLEEP,
258 	AUDIO_THREAD_READ_AUDIO,
259 	AUDIO_THREAD_READ_AUDIO_TSTAMP,
260 	AUDIO_THREAD_READ_AUDIO_DONE,
261 	AUDIO_THREAD_READ_OVERRUN,
262 	AUDIO_THREAD_FILL_AUDIO,
263 	AUDIO_THREAD_FILL_AUDIO_TSTAMP,
264 	AUDIO_THREAD_FILL_AUDIO_DONE,
265 	AUDIO_THREAD_WRITE_STREAMS_WAIT,
266 	AUDIO_THREAD_WRITE_STREAMS_WAIT_TO,
267 	AUDIO_THREAD_WRITE_STREAMS_MIX,
268 	AUDIO_THREAD_WRITE_STREAMS_MIXED,
269 	AUDIO_THREAD_WRITE_STREAMS_STREAM,
270 	AUDIO_THREAD_FETCH_STREAM,
271 	AUDIO_THREAD_STREAM_ADDED,
272 	AUDIO_THREAD_STREAM_REMOVED,
273 	AUDIO_THREAD_A2DP_ENCODE,
274 	AUDIO_THREAD_A2DP_WRITE,
275 	AUDIO_THREAD_DEV_STREAM_MIX,
276 	AUDIO_THREAD_CAPTURE_POST,
277 	AUDIO_THREAD_CAPTURE_WRITE,
278 	AUDIO_THREAD_CONV_COPY,
279 	AUDIO_THREAD_STREAM_FETCH_PENDING,
280 	AUDIO_THREAD_STREAM_RESCHEDULE,
281 	AUDIO_THREAD_STREAM_SLEEP_TIME,
282 	AUDIO_THREAD_STREAM_SLEEP_ADJUST,
283 	AUDIO_THREAD_STREAM_SKIP_CB,
284 	AUDIO_THREAD_DEV_SLEEP_TIME,
285 	AUDIO_THREAD_SET_DEV_WAKE,
286 	AUDIO_THREAD_DEV_ADDED,
287 	AUDIO_THREAD_DEV_REMOVED,
288 	AUDIO_THREAD_IODEV_CB,
289 	AUDIO_THREAD_PB_MSG,
290 	AUDIO_THREAD_ODEV_NO_STREAMS,
291 	AUDIO_THREAD_ODEV_START,
292 	AUDIO_THREAD_ODEV_LEAVE_NO_STREAMS,
293 	AUDIO_THREAD_ODEV_DEFAULT_NO_STREAMS,
294 	AUDIO_THREAD_FILL_ODEV_ZEROS,
295 	AUDIO_THREAD_UNDERRUN,
296 	AUDIO_THREAD_SEVERE_UNDERRUN,
297 	AUDIO_THREAD_CAPTURE_DROP_TIME,
298 	AUDIO_THREAD_DEV_DROP_FRAMES,
299 };
300 
301 /* There are 8 bits of space for events. */
302 enum CRAS_BT_LOG_EVENTS {
303 	BT_ADAPTER_ADDED,
304 	BT_ADAPTER_REMOVED,
305 	BT_AUDIO_GATEWAY_INIT,
306 	BT_AUDIO_GATEWAY_START,
307 	BT_AVAILABLE_CODECS,
308 	BT_A2DP_CONFIGURED,
309 	BT_A2DP_START,
310 	BT_A2DP_SUSPENDED,
311 	BT_CODEC_SELECTION,
312 	BT_DEV_CONNECTED_CHANGE,
313 	BT_DEV_CONN_WATCH_CB,
314 	BT_DEV_SUSPEND_CB,
315 	BT_HFP_NEW_CONNECTION,
316 	BT_HFP_REQUEST_DISCONNECT,
317 	BT_HFP_SUPPORTED_FEATURES,
318 	BT_HSP_NEW_CONNECTION,
319 	BT_HSP_REQUEST_DISCONNECT,
320 	BT_NEW_AUDIO_PROFILE_AFTER_CONNECT,
321 	BT_RESET,
322 	BT_SCO_CONNECT,
323 	BT_TRANSPORT_ACQUIRE,
324 	BT_TRANSPORT_RELEASE,
325 };
326 
327 struct __attribute__((__packed__)) audio_thread_event {
328 	uint32_t tag_sec;
329 	uint32_t nsec;
330 	uint32_t data1;
331 	uint32_t data2;
332 	uint32_t data3;
333 };
334 
335 /* Ring buffer of log events from the audio thread. */
336 struct __attribute__((__packed__)) audio_thread_event_log {
337 	uint64_t write_pos;
338 	uint64_t sync_write_pos;
339 	uint32_t len;
340 	struct audio_thread_event log[AUDIO_THREAD_EVENT_LOG_SIZE];
341 };
342 
343 struct __attribute__((__packed__)) audio_dev_debug_info {
344 	char dev_name[CRAS_NODE_NAME_BUFFER_SIZE];
345 	uint32_t buffer_size;
346 	uint32_t min_buffer_level;
347 	uint32_t min_cb_level;
348 	uint32_t max_cb_level;
349 	uint32_t frame_rate;
350 	uint32_t num_channels;
351 	double est_rate_ratio;
352 	uint8_t direction;
353 	uint32_t num_underruns;
354 	uint32_t num_severe_underruns;
355 	uint32_t highest_hw_level;
356 	uint32_t runtime_sec;
357 	uint32_t runtime_nsec;
358 	uint32_t longest_wake_sec;
359 	uint32_t longest_wake_nsec;
360 	double software_gain_scaler;
361 };
362 
363 struct __attribute__((__packed__)) audio_stream_debug_info {
364 	uint64_t stream_id;
365 	uint32_t dev_idx;
366 	uint32_t direction;
367 	uint32_t stream_type;
368 	uint32_t client_type;
369 	uint32_t buffer_frames;
370 	uint32_t cb_threshold;
371 	uint64_t effects;
372 	uint32_t flags;
373 	uint32_t frame_rate;
374 	uint32_t num_channels;
375 	uint32_t longest_fetch_sec;
376 	uint32_t longest_fetch_nsec;
377 	uint32_t num_missed_cb;
378 	uint32_t num_overruns;
379 	uint32_t is_pinned;
380 	uint32_t pinned_dev_idx;
381 	uint32_t runtime_sec;
382 	uint32_t runtime_nsec;
383 	double stream_volume;
384 	int8_t channel_layout[CRAS_CH_MAX];
385 };
386 
387 /* Debug info shared from server to client. */
388 struct __attribute__((__packed__)) audio_debug_info {
389 	uint32_t num_streams;
390 	uint32_t num_devs;
391 	struct audio_dev_debug_info devs[MAX_DEBUG_DEVS];
392 	struct audio_stream_debug_info streams[MAX_DEBUG_STREAMS];
393 	struct audio_thread_event_log log;
394 };
395 
396 struct __attribute__((__packed__)) cras_bt_event {
397 	uint32_t tag_sec;
398 	uint32_t nsec;
399 	uint32_t data1;
400 	uint32_t data2;
401 };
402 
403 struct __attribute__((__packed__)) cras_bt_event_log {
404 	uint32_t write_pos;
405 	uint32_t len;
406 	struct cras_bt_event log[CRAS_BT_EVENT_LOG_SIZE];
407 };
408 
409 struct __attribute__((__packed__)) cras_bt_debug_info {
410 	struct cras_bt_event_log bt_log;
411 };
412 
413 /*
414  * All event enums should be less then AUDIO_THREAD_EVENT_TYPE_COUNT,
415  * or they will be ignored by the handler.
416  */
417 enum CRAS_AUDIO_THREAD_EVENT_TYPE {
418 	AUDIO_THREAD_EVENT_BUSYLOOP,
419 	AUDIO_THREAD_EVENT_DEBUG,
420 	AUDIO_THREAD_EVENT_SEVERE_UNDERRUN,
421 	AUDIO_THREAD_EVENT_UNDERRUN,
422 	AUDIO_THREAD_EVENT_DROP_SAMPLES,
423 	AUDIO_THREAD_EVENT_TYPE_COUNT,
424 };
425 
426 /*
427  * Structure of snapshot for audio thread.
428  */
429 struct __attribute__((__packed__)) cras_audio_thread_snapshot {
430 	struct timespec timestamp;
431 	enum CRAS_AUDIO_THREAD_EVENT_TYPE event_type;
432 	struct audio_debug_info audio_debug_info;
433 };
434 
435 /*
436  * Ring buffer for storing snapshots.
437  */
438 struct __attribute__((__packed__)) cras_audio_thread_snapshot_buffer {
439 	struct cras_audio_thread_snapshot
440 		snapshots[CRAS_MAX_AUDIO_THREAD_SNAPSHOTS];
441 	int pos;
442 };
443 
444 /* The server state that is shared with clients.
445  *    state_version - Version of this structure.
446  *    volume - index from 0-100.
447  *    min_volume_dBFS - volume in dB * 100 when volume = 1.
448  *    max_volume_dBFS - volume in dB * 100 when volume = max.
449  *    mute - 0 = unmuted, 1 = muted by system (device switch, suspend, etc).
450  *    user_mute - 0 = unmuted, 1 = muted by user.
451  *    mute_locked - 0 = unlocked, 1 = locked.
452  *    suspended - 1 = suspended, 0 = resumed.
453  *    capture_gain - Capture gain in dBFS * 100.
454  *    capture_gain_target - Target capture gain in dBFS * 100. The actual
455  *                          capture gain will be subjected to current
456  *                          supported range. When active device/node changes,
457  *                          supported range changes accordingly. System state
458  *                          should try to re-apply target gain subjected to new
459  *                          range.
460  *    capture_mute - 0 = unmuted, 1 = muted.
461  *    capture_mute_locked - 0 = unlocked, 1 = locked.
462  *    min_capture_gain - Min allowed capture gain in dBFS * 100.
463  *    max_capture_gain - Max allowed capture gain in dBFS * 100.
464  *    num_streams_attached - Total number of streams since server started.
465  *    num_output_devs - Number of available output devices.
466  *    num_input_devs - Number of available input devices.
467  *    output_devs - Output audio devices currently attached.
468  *    input_devs - Input audio devices currently attached.
469  *    num_output_nodes - Number of available output nodes.
470  *    num_input_nodes - Number of available input nodes.
471  *    output_nodes - Output nodes currently attached.
472  *    input_nodes - Input nodes currently attached.
473  *    num_attached_clients - Number of clients attached to server.
474  *    client_info - List of first 20 attached clients.
475  *    update_count - Incremented twice each time the struct is updated.  Odd
476  *        during updates.
477  *    num_active_streams - An array containing numbers or active
478  *        streams of different directions.
479  *    last_active_stream_time - Time the last stream was removed.  Can be used
480  *        to determine how long audio has been idle.
481  *    audio_debug_info - Debug data filled in when a client requests it. This
482  *        isn't protected against concurrent updating, only one client should
483  *        use it.
484  *    default_output_buffer_size - Default output buffer size in frames.
485  *    non_empty_status - Whether any non-empty audio is being
486  *        played/captured.
487  *    aec_supported - Flag to indicate if system aec is supported.
488  *    aec_group_id  - Group ID for the system aec to use for separating aec
489  *        tunings.
490  *    snapshot_buffer - ring buffer for storing audio thread snapshots.
491  *    bt_debug_info - ring buffer for storing bluetooth event logs.
492  *    bt_wbs_enabled - Whether or not bluetooth wideband speech is enabled.
493  */
494 #define CRAS_SERVER_STATE_VERSION 2
495 struct __attribute__((packed, aligned(4))) cras_server_state {
496 	uint32_t state_version;
497 	uint32_t volume;
498 	int32_t min_volume_dBFS;
499 	int32_t max_volume_dBFS;
500 	int32_t mute;
501 	int32_t user_mute;
502 	int32_t mute_locked;
503 	int32_t suspended;
504 	int32_t capture_gain;
505 	int32_t capture_gain_target;
506 	int32_t capture_mute;
507 	int32_t capture_mute_locked;
508 	int32_t min_capture_gain;
509 	int32_t max_capture_gain;
510 	uint32_t num_streams_attached;
511 	uint32_t num_output_devs;
512 	uint32_t num_input_devs;
513 	struct cras_iodev_info output_devs[CRAS_MAX_IODEVS];
514 	struct cras_iodev_info input_devs[CRAS_MAX_IODEVS];
515 	uint32_t num_output_nodes;
516 	uint32_t num_input_nodes;
517 	struct cras_ionode_info output_nodes[CRAS_MAX_IONODES];
518 	struct cras_ionode_info input_nodes[CRAS_MAX_IONODES];
519 	uint32_t num_attached_clients;
520 	struct cras_attached_client_info client_info[CRAS_MAX_ATTACHED_CLIENTS];
521 	uint32_t update_count;
522 	uint32_t num_active_streams[CRAS_NUM_DIRECTIONS];
523 	struct cras_timespec last_active_stream_time;
524 	struct audio_debug_info audio_debug_info;
525 	int32_t default_output_buffer_size;
526 	int32_t non_empty_status;
527 	int32_t aec_supported;
528 	int32_t aec_group_id;
529 	struct cras_audio_thread_snapshot_buffer snapshot_buffer;
530 	struct cras_bt_debug_info bt_debug_info;
531 	int32_t bt_wbs_enabled;
532 };
533 
534 /* Actions for card add/remove/change. */
535 enum cras_notify_device_action {
536 	/* Must match gavd action definitions.  */
537 	CRAS_DEVICE_ACTION_ADD = 0,
538 	CRAS_DEVICE_ACTION_REMOVE = 1,
539 	CRAS_DEVICE_ACTION_CHANGE = 2,
540 };
541 
542 /* Information about an ALSA card to be added to the system.
543  *    card_type - Either internal card or a USB sound card.
544  *    card_index - Index ALSA uses to refer to the card.  The X in "hw:X".
545  *    priority - Base priority to give devices found on this card. Zero is the
546  *      lowest priority.  Non-primary devices on the card will be given a
547  *      lowered priority.
548  *    usb_vendor_id - vendor ID if the device is on the USB bus.
549  *    usb_product_id - product ID if the device is on the USB bus.
550  *    usb_serial_number - serial number if the device is on the USB bus.
551  *    usb_desc_checksum - the checksum of the USB descriptors if the device
552  *      is on the USB bus.
553  */
554 enum CRAS_ALSA_CARD_TYPE {
555 	ALSA_CARD_TYPE_INTERNAL,
556 	ALSA_CARD_TYPE_USB,
557 };
558 #define USB_SERIAL_NUMBER_BUFFER_SIZE 64
559 struct __attribute__((__packed__)) cras_alsa_card_info {
560 	enum CRAS_ALSA_CARD_TYPE card_type;
561 	uint32_t card_index;
562 	uint32_t usb_vendor_id;
563 	uint32_t usb_product_id;
564 	char usb_serial_number[USB_SERIAL_NUMBER_BUFFER_SIZE];
565 	uint32_t usb_desc_checksum;
566 };
567 
568 /* Unique identifier for each active stream.
569  * The top 16 bits are the client number, lower 16 are the stream number.
570  */
571 typedef uint32_t cras_stream_id_t;
572 /* Generates a stream id for client stream. */
cras_get_stream_id(uint16_t client_id,uint16_t stream_id)573 static inline cras_stream_id_t cras_get_stream_id(uint16_t client_id,
574 						  uint16_t stream_id)
575 {
576 	return (cras_stream_id_t)(((client_id & 0x0000ffff) << 16) |
577 				  (stream_id & 0x0000ffff));
578 }
579 /* Verify if the stream_id fits the given client_id */
cras_valid_stream_id(cras_stream_id_t stream_id,uint16_t client_id)580 static inline bool cras_valid_stream_id(cras_stream_id_t stream_id,
581 					uint16_t client_id)
582 {
583 	return ((stream_id >> 16) ^ client_id) == 0;
584 }
585 
586 enum CRAS_NODE_TYPE {
587 	/* These value can be used for output nodes. */
588 	CRAS_NODE_TYPE_INTERNAL_SPEAKER,
589 	CRAS_NODE_TYPE_HEADPHONE,
590 	CRAS_NODE_TYPE_HDMI,
591 	CRAS_NODE_TYPE_HAPTIC,
592 	CRAS_NODE_TYPE_LINEOUT,
593 	/* These value can be used for input nodes. */
594 	CRAS_NODE_TYPE_MIC,
595 	CRAS_NODE_TYPE_HOTWORD,
596 	CRAS_NODE_TYPE_POST_MIX_PRE_DSP,
597 	CRAS_NODE_TYPE_POST_DSP,
598 	/* These value can be used for both output and input nodes. */
599 	CRAS_NODE_TYPE_USB,
600 	CRAS_NODE_TYPE_BLUETOOTH,
601 	CRAS_NODE_TYPE_FALLBACK_NORMAL,
602 	CRAS_NODE_TYPE_FALLBACK_ABNORMAL,
603 	CRAS_NODE_TYPE_UNKNOWN,
604 };
605 
606 /* Position values to described where a node locates on the system.
607  * NODE_POSITION_EXTERNAL - The node works only when peripheral
608  *     is plugged.
609  * NODE_POSITION_INTERNAL - The node lives on the system and doesn't
610  *     have specific direction.
611  * NODE_POSITION_FRONT - The node locates on the side of system that
612  *     faces user.
613  * NODE_POSITION_REAR - The node locates on the opposite side of
614  *     the system that faces user.
615  * NODE_POSITION_KEYBOARD - The node locates under the keyboard.
616  */
617 enum CRAS_NODE_POSITION {
618 	NODE_POSITION_EXTERNAL,
619 	NODE_POSITION_INTERNAL,
620 	NODE_POSITION_FRONT,
621 	NODE_POSITION_REAR,
622 	NODE_POSITION_KEYBOARD,
623 };
624 
625 #endif /* CRAS_TYPES_H_ */
626