Home | History | Annotate | Download | only in common
      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  * Messages sent between the server and clients.
      8  */
      9 #ifndef CRAS_MESSAGES_H_
     10 #define CRAS_MESSAGES_H_
     11 
     12 #include <stdint.h>
     13 
     14 #include "cras_iodev_info.h"
     15 #include "cras_types.h"
     16 
     17 /* Rev when message format changes. If new messages are added, or message ID
     18  * values change. */
     19 #define CRAS_PROTO_VER 1
     20 #define CRAS_SERV_MAX_MSG_SIZE 256
     21 #define CRAS_CLIENT_MAX_MSG_SIZE 256
     22 #define CRAS_HOTWORD_NAME_MAX_SIZE 8
     23 
     24 /* Message IDs. */
     25 enum CRAS_SERVER_MESSAGE_ID {
     26 	/* Client -> Server*/
     27 	CRAS_SERVER_CONNECT_STREAM,
     28 	CRAS_SERVER_DISCONNECT_STREAM,
     29 	CRAS_SERVER_SWITCH_STREAM_TYPE_IODEV, /* Unused */
     30 	CRAS_SERVER_SET_SYSTEM_VOLUME,
     31 	CRAS_SERVER_SET_SYSTEM_MUTE,
     32 	CRAS_SERVER_SET_USER_MUTE,
     33 	CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED,
     34 	CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN,
     35 	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE,
     36 	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED,
     37 	CRAS_SERVER_SET_NODE_ATTR,
     38 	CRAS_SERVER_SELECT_NODE,
     39 	CRAS_SERVER_RELOAD_DSP,
     40 	CRAS_SERVER_DUMP_DSP_INFO,
     41 	CRAS_SERVER_DUMP_AUDIO_THREAD,
     42 	CRAS_SERVER_ADD_ACTIVE_NODE,
     43 	CRAS_SERVER_RM_ACTIVE_NODE,
     44 	CRAS_SERVER_ADD_TEST_DEV,
     45 	CRAS_SERVER_TEST_DEV_COMMAND,
     46 	CRAS_SERVER_SUSPEND,
     47 	CRAS_SERVER_RESUME,
     48 	CRAS_CONFIG_GLOBAL_REMIX,
     49 	CRAS_SERVER_GET_HOTWORD_MODELS,
     50 	CRAS_SERVER_SET_HOTWORD_MODEL,
     51 	CRAS_SERVER_REGISTER_NOTIFICATION,
     52 };
     53 
     54 enum CRAS_CLIENT_MESSAGE_ID {
     55 	/* Server -> Client */
     56 	CRAS_CLIENT_CONNECTED,
     57 	CRAS_CLIENT_STREAM_CONNECTED,
     58 	CRAS_CLIENT_AUDIO_DEBUG_INFO_READY,
     59 	CRAS_CLIENT_GET_HOTWORD_MODELS_READY,
     60 	/* System status messages */
     61 	CRAS_CLIENT_OUTPUT_VOLUME_CHANGED,
     62 	CRAS_CLIENT_OUTPUT_MUTE_CHANGED,
     63 	CRAS_CLIENT_CAPTURE_GAIN_CHANGED,
     64 	CRAS_CLIENT_CAPTURE_MUTE_CHANGED,
     65 	CRAS_CLIENT_NODES_CHANGED,
     66 	CRAS_CLIENT_ACTIVE_NODE_CHANGED,
     67 	CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED,
     68 	CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
     69 	CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED,
     70 	CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED,
     71 };
     72 
     73 /* Messages that control the server. These are sent from the client to affect
     74  * and action on the server. */
     75 struct __attribute__ ((__packed__)) cras_server_message {
     76 	uint32_t length;
     77 	enum CRAS_SERVER_MESSAGE_ID id;
     78 };
     79 
     80 /* Messages that control the client. These are sent from the server to affect
     81  * and action on the client. */
     82 struct __attribute__ ((__packed__)) cras_client_message {
     83 	uint32_t length;
     84 	enum CRAS_CLIENT_MESSAGE_ID id;
     85 };
     86 
     87 /*
     88  * Messages from client to server.
     89  */
     90 
     91 /* Sent by a client to connect a stream to the server. */
     92 struct __attribute__ ((__packed__)) cras_connect_message {
     93 	struct cras_server_message header;
     94 	uint32_t proto_version;
     95 	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
     96 	cras_stream_id_t stream_id; /* unique id for this stream */
     97 	enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
     98 	uint32_t buffer_frames; /* Buffer size in frames. */
     99 	uint32_t cb_threshold; /* callback client when this much is left */
    100 	uint32_t flags;
    101 	struct cras_audio_format_packed format; /* rate, channel, sample size */
    102 	uint32_t dev_idx; /* device to attach stream, 0 if none */
    103 };
    104 static inline void cras_fill_connect_message(struct cras_connect_message *m,
    105 					   enum CRAS_STREAM_DIRECTION direction,
    106 					   cras_stream_id_t stream_id,
    107 					   enum CRAS_STREAM_TYPE stream_type,
    108 					   size_t buffer_frames,
    109 					   size_t cb_threshold,
    110 					   uint32_t flags,
    111 					   struct cras_audio_format format,
    112 					   uint32_t dev_idx)
    113 {
    114 	m->proto_version = CRAS_PROTO_VER;
    115 	m->direction = direction;
    116 	m->stream_id = stream_id;
    117 	m->stream_type = stream_type;
    118 	m->buffer_frames = buffer_frames;
    119 	m->cb_threshold = cb_threshold;
    120 	m->flags = flags;
    121 	pack_cras_audio_format(&m->format, &format);
    122 	m->dev_idx = dev_idx;
    123 	m->header.id = CRAS_SERVER_CONNECT_STREAM;
    124 	m->header.length = sizeof(struct cras_connect_message);
    125 }
    126 
    127 /* Sent by a client to remove a stream from the server. */
    128 struct __attribute__ ((__packed__)) cras_disconnect_stream_message {
    129 	struct cras_server_message header;
    130 	cras_stream_id_t stream_id;
    131 };
    132 static inline void cras_fill_disconnect_stream_message(
    133 		struct cras_disconnect_stream_message *m,
    134 		cras_stream_id_t stream_id)
    135 {
    136 	m->stream_id = stream_id;
    137 	m->header.id = CRAS_SERVER_DISCONNECT_STREAM;
    138 	m->header.length = sizeof(struct cras_disconnect_stream_message);
    139 }
    140 
    141 /* Move streams of "type" to the iodev at "iodev_idx". */
    142 struct __attribute__ ((__packed__)) cras_switch_stream_type_iodev {
    143 	struct cras_server_message header;
    144 	enum CRAS_STREAM_TYPE stream_type;
    145 	uint32_t iodev_idx;
    146 };
    147 
    148 /* Set the system volume. */
    149 struct __attribute__ ((__packed__)) cras_set_system_volume {
    150 	struct cras_server_message header;
    151 	uint32_t volume;
    152 };
    153 static inline void cras_fill_set_system_volume(
    154 		struct cras_set_system_volume *m,
    155 		size_t volume)
    156 {
    157 	m->volume = volume;
    158 	m->header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
    159 	m->header.length = sizeof(*m);
    160 }
    161 
    162 /* Sets the capture gain. */
    163 struct __attribute__ ((__packed__)) cras_set_system_capture_gain {
    164 	struct cras_server_message header;
    165 	int32_t gain;
    166 };
    167 static inline void cras_fill_set_system_capture_gain(
    168 		struct cras_set_system_capture_gain *m,
    169 		long gain)
    170 {
    171 	m->gain = gain;
    172 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
    173 	m->header.length = sizeof(*m);
    174 }
    175 
    176 /* Set the system mute state. */
    177 struct __attribute__ ((__packed__)) cras_set_system_mute {
    178 	struct cras_server_message header;
    179 	int32_t mute; /* 0 = un-mute, 1 = mute. */
    180 };
    181 static inline void cras_fill_set_system_mute(
    182 		struct cras_set_system_mute *m,
    183 		int mute)
    184 {
    185 	m->mute = mute;
    186 	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE;
    187 	m->header.length = sizeof(*m);
    188 }
    189 static inline void cras_fill_set_user_mute(
    190 		struct cras_set_system_mute *m,
    191 		int mute)
    192 {
    193 	m->mute = mute;
    194 	m->header.id = CRAS_SERVER_SET_USER_MUTE;
    195 	m->header.length = sizeof(*m);
    196 }
    197 static inline void cras_fill_set_system_mute_locked(
    198 		struct cras_set_system_mute *m,
    199 		int locked)
    200 {
    201 	m->mute = locked;
    202 	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED;
    203 	m->header.length = sizeof(*m);
    204 }
    205 static inline void cras_fill_set_system_capture_mute(
    206 		struct cras_set_system_mute *m,
    207 		int mute)
    208 {
    209 	m->mute = mute;
    210 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE;
    211 	m->header.length = sizeof(*m);
    212 }
    213 static inline void cras_fill_set_system_capture_mute_locked(
    214 		struct cras_set_system_mute *m,
    215 		int locked)
    216 {
    217 	m->mute = locked;
    218 	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED;
    219 	m->header.length = sizeof(*m);
    220 }
    221 
    222 /* Set an attribute of an ionode. */
    223 struct __attribute__ ((__packed__)) cras_set_node_attr {
    224 	struct cras_server_message header;
    225 	cras_node_id_t node_id;
    226 	enum ionode_attr attr;
    227 	int32_t value;
    228 };
    229 static inline void cras_fill_set_node_attr(
    230 		struct cras_set_node_attr *m,
    231 		cras_node_id_t node_id,
    232 		enum ionode_attr attr,
    233 		int value)
    234 {
    235 	m->header.id = CRAS_SERVER_SET_NODE_ATTR;
    236 	m->node_id = node_id;
    237 	m->attr = attr;
    238 	m->value = value;
    239 	m->header.length = sizeof(*m);
    240 }
    241 
    242 /* Set an attribute of an ionode. */
    243 struct __attribute__ ((__packed__)) cras_select_node {
    244 	struct cras_server_message header;
    245 	enum CRAS_STREAM_DIRECTION direction;
    246 	cras_node_id_t node_id;
    247 };
    248 static inline void cras_fill_select_node(
    249 		struct cras_select_node *m,
    250 		enum CRAS_STREAM_DIRECTION direction,
    251 		cras_node_id_t node_id)
    252 {
    253 	m->header.id = CRAS_SERVER_SELECT_NODE;
    254 	m->direction = direction;
    255 	m->node_id = node_id;
    256 	m->header.length = sizeof(*m);
    257 }
    258 
    259 /* Add an active ionode. */
    260 struct __attribute__ ((__packed__)) cras_add_active_node {
    261 	struct cras_server_message header;
    262 	enum CRAS_STREAM_DIRECTION direction;
    263 	cras_node_id_t node_id;
    264 };
    265 static inline void cras_fill_add_active_node(
    266 		struct cras_add_active_node *m,
    267 		enum CRAS_STREAM_DIRECTION direction,
    268 		cras_node_id_t node_id)
    269 {
    270 	m->header.id = CRAS_SERVER_ADD_ACTIVE_NODE;
    271 	m->direction = direction;
    272 	m->node_id = node_id;
    273 	m->header.length = sizeof(*m);
    274 }
    275 
    276 /* Remove an active ionode. */
    277 struct __attribute__ ((__packed__)) cras_rm_active_node {
    278 	struct cras_server_message header;
    279 	enum CRAS_STREAM_DIRECTION direction;
    280 	cras_node_id_t node_id;
    281 };
    282 static inline void cras_fill_rm_active_node(
    283 		struct cras_rm_active_node *m,
    284 		enum CRAS_STREAM_DIRECTION direction,
    285 		cras_node_id_t node_id)
    286 {
    287 	m->header.id = CRAS_SERVER_RM_ACTIVE_NODE;
    288 	m->direction = direction;
    289 	m->node_id = node_id;
    290 	m->header.length = sizeof(*m);
    291 }
    292 
    293 /* Reload the dsp configuration. */
    294 struct __attribute__ ((__packed__)) cras_reload_dsp {
    295 	struct cras_server_message header;
    296 };
    297 static inline void cras_fill_reload_dsp(
    298 		struct cras_reload_dsp *m)
    299 {
    300 	m->header.id = CRAS_SERVER_RELOAD_DSP;
    301 	m->header.length = sizeof(*m);
    302 }
    303 
    304 /* Dump current dsp information to syslog. */
    305 struct __attribute__ ((__packed__)) cras_dump_dsp_info {
    306 	struct cras_server_message header;
    307 };
    308 
    309 static inline void cras_fill_dump_dsp_info(
    310 		struct cras_dump_dsp_info *m)
    311 {
    312 	m->header.id = CRAS_SERVER_DUMP_DSP_INFO;
    313 	m->header.length = sizeof(*m);
    314 }
    315 
    316 /* Dump current audio thread information to syslog. */
    317 struct __attribute__ ((__packed__)) cras_dump_audio_thread {
    318 	struct cras_server_message header;
    319 };
    320 
    321 static inline void cras_fill_dump_audio_thread(
    322 		struct cras_dump_audio_thread *m)
    323 {
    324 	m->header.id = CRAS_SERVER_DUMP_AUDIO_THREAD;
    325 	m->header.length = sizeof(*m);
    326 }
    327 
    328 /* Add a test device. */
    329 struct __attribute__ ((__packed__)) cras_add_test_dev {
    330 	struct cras_server_message header;
    331 	enum TEST_IODEV_TYPE type;
    332 };
    333 
    334 static inline void cras_fill_add_test_dev(struct cras_add_test_dev *m,
    335 					  enum TEST_IODEV_TYPE type)
    336 {
    337 	m->header.id = CRAS_SERVER_ADD_TEST_DEV;
    338 	m->header.length = sizeof(*m);
    339 	m->type = type;
    340 }
    341 
    342 /* Command a test device. */
    343 struct __attribute__ ((__packed__)) cras_test_dev_command {
    344 	struct cras_server_message header;
    345 	unsigned int command;
    346 	unsigned int iodev_idx;
    347 	unsigned int data_len;
    348 	uint8_t data[];
    349 };
    350 
    351 static inline void cras_fill_test_dev_command(struct cras_test_dev_command *m,
    352 					      unsigned int iodev_idx,
    353 					      enum CRAS_TEST_IODEV_CMD command,
    354 					      unsigned int data_len,
    355 					      const uint8_t *data)
    356 {
    357 	m->header.id = CRAS_SERVER_TEST_DEV_COMMAND;
    358 	m->header.length = sizeof(*m) + data_len;
    359 	m->iodev_idx = iodev_idx;
    360 	m->command = command;
    361 	m->data_len = data_len;
    362 	memcpy(m->data, data, data_len);
    363 }
    364 
    365 static inline void cras_fill_suspend_message(struct cras_server_message *m,
    366 					     int is_suspend)
    367 {
    368 	m->id = is_suspend ? CRAS_SERVER_SUSPEND : CRAS_SERVER_RESUME;
    369 	m->length = sizeof(*m);
    370 }
    371 
    372 /* Configures the global remix converter. */
    373 struct __attribute__ ((__packed__)) cras_config_global_remix {
    374 	struct cras_server_message header;
    375 	unsigned int num_channels;
    376 	float coefficient[];
    377 };
    378 
    379 static inline void cras_fill_config_global_remix_command(
    380 		struct cras_config_global_remix *m,
    381 		unsigned int num_channels,
    382 		float *coeff,
    383 		unsigned int count)
    384 {
    385 	m->header.id = CRAS_CONFIG_GLOBAL_REMIX;
    386 	m->header.length = sizeof(*m) + count * sizeof(*coeff);
    387 	m->num_channels = num_channels;
    388 	memcpy(m->coefficient, coeff, count * sizeof(*coeff));
    389 }
    390 
    391 /* Get supported hotword models. */
    392 struct __attribute__ ((__packed__)) cras_get_hotword_models {
    393 	struct cras_server_message header;
    394 	cras_node_id_t node_id;
    395 };
    396 
    397 static inline void cras_fill_get_hotword_models_message(
    398 		struct cras_get_hotword_models *m,
    399 		cras_node_id_t node_id)
    400 {
    401 	m->header.id = CRAS_SERVER_GET_HOTWORD_MODELS;
    402 	m->header.length = sizeof(*m);
    403 	m->node_id = node_id;
    404 }
    405 
    406 /* Set desired hotword model. */
    407 struct __attribute__ ((__packed__)) cras_set_hotword_model {
    408 	struct cras_server_message header;
    409 	cras_node_id_t node_id;
    410 	char model_name[CRAS_HOTWORD_NAME_MAX_SIZE];
    411 };
    412 
    413 static inline void cras_fill_set_hotword_model_message(
    414 		struct cras_set_hotword_model *m,
    415 		cras_node_id_t node_id,
    416 		const char *model_name)
    417 {
    418 	m->header.id = CRAS_SERVER_SET_HOTWORD_MODEL;
    419 	m->header.length = sizeof(*m);
    420 	m->node_id = node_id;
    421 	memcpy(m->model_name, model_name, CRAS_HOTWORD_NAME_MAX_SIZE);
    422 }
    423 
    424 struct __attribute__ ((__packed__)) cras_register_notification {
    425 		struct cras_server_message header;
    426 		uint32_t msg_id;
    427 		int do_register;
    428 };
    429 static inline void cras_fill_register_notification_message(
    430 		struct cras_register_notification *m,
    431 		enum CRAS_CLIENT_MESSAGE_ID msg_id,
    432 		int do_register)
    433 {
    434 	m->header.id = CRAS_SERVER_REGISTER_NOTIFICATION;
    435 	m->header.length = sizeof(*m);
    436 	m->msg_id = msg_id;
    437 	m->do_register = do_register;
    438 }
    439 
    440 /*
    441  * Messages sent from server to client.
    442  */
    443 
    444 /* Reply from the server indicating that the client has connected. */
    445 struct __attribute__ ((__packed__)) cras_client_connected {
    446 	struct cras_client_message header;
    447 	uint32_t client_id;
    448 };
    449 static inline void cras_fill_client_connected(
    450 		struct cras_client_connected *m,
    451 		size_t client_id)
    452 {
    453 	m->client_id = client_id;
    454 	m->header.id = CRAS_CLIENT_CONNECTED;
    455 	m->header.length = sizeof(struct cras_client_connected);
    456 }
    457 
    458 /*
    459  * Reply from server that a stream has been successfully added.
    460  * Two file descriptors are added, input shm followed by out shm.
    461  */
    462 struct __attribute__ ((__packed__)) cras_client_stream_connected {
    463 	struct cras_client_message header;
    464 	int32_t err;
    465 	cras_stream_id_t stream_id;
    466 	struct cras_audio_format_packed format;
    467 	uint32_t shm_max_size;
    468 };
    469 static inline void cras_fill_client_stream_connected(
    470 		struct cras_client_stream_connected *m,
    471 		int err,
    472 		cras_stream_id_t stream_id,
    473 		struct cras_audio_format *format,
    474 		size_t shm_max_size)
    475 {
    476 	m->err = err;
    477 	m->stream_id = stream_id;
    478 	pack_cras_audio_format(&m->format, format);
    479 	m->shm_max_size = shm_max_size;
    480 	m->header.id = CRAS_CLIENT_STREAM_CONNECTED;
    481 	m->header.length = sizeof(struct cras_client_stream_connected);
    482 }
    483 
    484 /* Sent from server to client when audio debug information is requested. */
    485 struct cras_client_audio_debug_info_ready {
    486 	struct cras_client_message header;
    487 };
    488 static inline void cras_fill_client_audio_debug_info_ready(
    489 		struct cras_client_audio_debug_info_ready *m)
    490 {
    491 	m->header.id = CRAS_CLIENT_AUDIO_DEBUG_INFO_READY;
    492 	m->header.length = sizeof(*m);
    493 }
    494 
    495 /* Sent from server to client when hotword models info is ready. */
    496 struct cras_client_get_hotword_models_ready {
    497 	struct cras_client_message header;
    498 	int32_t hotword_models_size;
    499 	uint8_t hotword_models[0];
    500 };
    501 static inline void cras_fill_client_get_hotword_models_ready(
    502 		struct cras_client_get_hotword_models_ready *m,
    503 		const char *hotword_models,
    504 		size_t hotword_models_size)
    505 {
    506 	m->header.id = CRAS_CLIENT_GET_HOTWORD_MODELS_READY;
    507 	m->header.length = sizeof(*m) + hotword_models_size;
    508 	m->hotword_models_size = hotword_models_size;
    509 	memcpy(m->hotword_models, hotword_models, hotword_models_size);
    510 }
    511 
    512 /* System status messages sent from server to client when state changes. */
    513 struct __attribute__ ((__packed__)) cras_client_volume_changed {
    514 	struct cras_client_message header;
    515 	int32_t volume;
    516 };
    517 static inline void cras_fill_client_output_volume_changed(
    518 		struct cras_client_volume_changed *m, int32_t volume)
    519 {
    520 	m->header.id = CRAS_CLIENT_OUTPUT_VOLUME_CHANGED;
    521 	m->header.length = sizeof(*m);
    522 	m->volume = volume;
    523 }
    524 static inline void cras_fill_client_capture_gain_changed(
    525 		struct cras_client_volume_changed *m, int32_t gain)
    526 {
    527 	m->header.id = CRAS_CLIENT_CAPTURE_GAIN_CHANGED;
    528 	m->header.length = sizeof(*m);
    529 	m->volume = gain;
    530 }
    531 
    532 struct __attribute__ ((__packed__)) cras_client_mute_changed {
    533 	struct cras_client_message header;
    534 	int32_t muted;
    535 	int32_t user_muted;
    536 	int32_t mute_locked;
    537 };
    538 static inline void cras_fill_client_output_mute_changed(
    539 		struct cras_client_mute_changed *m, int32_t muted,
    540 		int32_t user_muted, int32_t mute_locked)
    541 {
    542 	m->header.id = CRAS_CLIENT_OUTPUT_MUTE_CHANGED;
    543 	m->header.length = sizeof(*m);
    544 	m->muted = muted;
    545 	m->user_muted = user_muted;
    546 	m->mute_locked = mute_locked;
    547 }
    548 static inline void cras_fill_client_capture_mute_changed(
    549 		struct cras_client_mute_changed *m, int32_t muted,
    550 		int32_t mute_locked)
    551 {
    552 	m->header.id = CRAS_CLIENT_CAPTURE_MUTE_CHANGED;
    553 	m->header.length = sizeof(*m);
    554 	m->muted = muted;
    555 	m->user_muted = 0;
    556 	m->mute_locked = mute_locked;
    557 }
    558 
    559 struct __attribute__ ((__packed__)) cras_client_nodes_changed {
    560 	struct cras_client_message header;
    561 };
    562 static inline void cras_fill_client_nodes_changed(
    563 		struct cras_client_nodes_changed *m)
    564 {
    565 	m->header.id = CRAS_CLIENT_NODES_CHANGED;
    566 	m->header.length = sizeof(*m);
    567 }
    568 
    569 struct __attribute__ ((__packed__)) cras_client_active_node_changed {
    570 	struct cras_client_message header;
    571 	uint32_t direction;
    572 	cras_node_id_t node_id;
    573 };
    574 static inline void cras_fill_client_active_node_changed (
    575 		struct cras_client_active_node_changed *m,
    576 		enum CRAS_STREAM_DIRECTION direction,
    577 		cras_node_id_t node_id)
    578 {
    579 	m->header.id = CRAS_CLIENT_ACTIVE_NODE_CHANGED;
    580 	m->header.length = sizeof(*m);
    581 	m->direction = direction;
    582 	m->node_id = node_id;
    583 };
    584 
    585 struct __attribute__ ((__packed__)) cras_client_node_value_changed {
    586 	struct cras_client_message header;
    587 	cras_node_id_t node_id;
    588 	int32_t value;
    589 };
    590 static inline void cras_fill_client_output_node_volume_changed (
    591 		struct cras_client_node_value_changed *m,
    592 		cras_node_id_t node_id,
    593 		int32_t volume)
    594 {
    595 	m->header.id = CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED;
    596 	m->header.length = sizeof(*m);
    597 	m->node_id = node_id;
    598 	m->value = volume;
    599 };
    600 static inline void cras_fill_client_node_left_right_swapped_changed (
    601 		struct cras_client_node_value_changed *m,
    602 		cras_node_id_t node_id,
    603 		int swapped)
    604 {
    605 	m->header.id = CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED;
    606 	m->header.length = sizeof(*m);
    607 	m->node_id = node_id;
    608 	m->value = swapped;
    609 };
    610 static inline void cras_fill_client_input_node_gain_changed (
    611 		struct cras_client_node_value_changed *m,
    612 		cras_node_id_t node_id,
    613 		int32_t gain)
    614 {
    615 	m->header.id = CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED;
    616 	m->header.length = sizeof(*m);
    617 	m->node_id = node_id;
    618 	m->value = gain;
    619 };
    620 
    621 struct __attribute__ ((__packed__)) cras_client_num_active_streams_changed {
    622 	struct cras_client_message header;
    623 	uint32_t direction;
    624 	uint32_t num_active_streams;
    625 };
    626 static inline void cras_fill_client_num_active_streams_changed (
    627 		struct cras_client_num_active_streams_changed *m,
    628 		enum CRAS_STREAM_DIRECTION direction,
    629 		uint32_t num_active_streams)
    630 {
    631 	m->header.id = CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED;
    632 	m->header.length = sizeof(*m);
    633 	m->direction = direction;
    634 	m->num_active_streams = num_active_streams;
    635 };
    636 
    637 /*
    638  * Messages specific to passing audio between client and server
    639  */
    640 enum CRAS_AUDIO_MESSAGE_ID {
    641 	AUDIO_MESSAGE_REQUEST_DATA,
    642 	AUDIO_MESSAGE_DATA_READY,
    643 	NUM_AUDIO_MESSAGES
    644 };
    645 
    646 struct __attribute__ ((__packed__)) audio_message {
    647 	enum CRAS_AUDIO_MESSAGE_ID id;
    648 	int32_t error;
    649 	uint32_t frames; /* number of samples per channel */
    650 };
    651 
    652 #endif /* CRAS_MESSAGES_H_ */
    653