summaryrefslogtreecommitdiff
path: root/cras/src/common/cras_messages.h
blob: 195965bbe9669d927b875e90757d6460607bda27 (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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/* 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.
 */

/*
 * Messages sent between the server and clients.
 */
#ifndef CRAS_MESSAGES_H_
#define CRAS_MESSAGES_H_

#include <stdint.h>

#include "cras_iodev_info.h"
#include "cras_types.h"

/* Rev when message format changes. If new messages are added, or message ID
 * values change. */
#define CRAS_PROTO_VER 5
#define CRAS_SERV_MAX_MSG_SIZE 256
#define CRAS_CLIENT_MAX_MSG_SIZE 256
#define CRAS_MAX_HOTWORD_MODELS 243
#define CRAS_MAX_REMIX_CHANNELS 32
#define CRAS_MAX_TEST_DATA_LEN 224
#define CRAS_AEC_DUMP_FILE_NAME_LEN 128

/* Message IDs. */
enum CRAS_SERVER_MESSAGE_ID {
	/* Client -> Server*/
	CRAS_SERVER_CONNECT_STREAM,
	CRAS_SERVER_DISCONNECT_STREAM,
	CRAS_SERVER_SWITCH_STREAM_TYPE_IODEV, /* Unused */
	CRAS_SERVER_SET_SYSTEM_VOLUME,
	CRAS_SERVER_SET_SYSTEM_MUTE,
	CRAS_SERVER_SET_USER_MUTE,
	CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED,
	CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN,
	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE,
	CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED,
	CRAS_SERVER_SET_NODE_ATTR,
	CRAS_SERVER_SELECT_NODE,
	CRAS_SERVER_RELOAD_DSP,
	CRAS_SERVER_DUMP_DSP_INFO,
	CRAS_SERVER_DUMP_AUDIO_THREAD,
	CRAS_SERVER_DUMP_SNAPSHOTS,
	CRAS_SERVER_ADD_ACTIVE_NODE,
	CRAS_SERVER_RM_ACTIVE_NODE,
	CRAS_SERVER_ADD_TEST_DEV,
	CRAS_SERVER_TEST_DEV_COMMAND,
	CRAS_SERVER_SUSPEND,
	CRAS_SERVER_RESUME,
	CRAS_CONFIG_GLOBAL_REMIX,
	CRAS_SERVER_GET_HOTWORD_MODELS,
	CRAS_SERVER_SET_HOTWORD_MODEL,
	CRAS_SERVER_REGISTER_NOTIFICATION,
	CRAS_SERVER_SET_AEC_DUMP,
	CRAS_SERVER_RELOAD_AEC_CONFIG,
	CRAS_SERVER_DUMP_BT,
	CRAS_SERVER_SET_BT_WBS_ENABLED,
	CRAS_SERVER_GET_ATLOG_FD,
};

enum CRAS_CLIENT_MESSAGE_ID {
	/* Server -> Client */
	CRAS_CLIENT_CONNECTED,
	CRAS_CLIENT_STREAM_CONNECTED,
	CRAS_CLIENT_AUDIO_DEBUG_INFO_READY,
	CRAS_CLIENT_GET_HOTWORD_MODELS_READY,
	/* System status messages */
	CRAS_CLIENT_OUTPUT_VOLUME_CHANGED,
	CRAS_CLIENT_OUTPUT_MUTE_CHANGED,
	CRAS_CLIENT_CAPTURE_GAIN_CHANGED,
	CRAS_CLIENT_CAPTURE_MUTE_CHANGED,
	CRAS_CLIENT_NODES_CHANGED,
	CRAS_CLIENT_ACTIVE_NODE_CHANGED,
	CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED,
	CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED,
	CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED,
	CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED,
	/* Server -> Client */
	CRAS_CLIENT_ATLOG_FD_READY,
};

/* Messages that control the server. These are sent from the client to affect
 * and action on the server. */
struct __attribute__((__packed__)) cras_server_message {
	uint32_t length;
	enum CRAS_SERVER_MESSAGE_ID id;
};

/* Messages that control the client. These are sent from the server to affect
 * and action on the client. */
struct __attribute__((__packed__)) cras_client_message {
	uint32_t length;
	enum CRAS_CLIENT_MESSAGE_ID id;
};

/*
 * Messages from client to server.
 */

/* Sent by a client to connect a stream to the server. */
struct __attribute__((__packed__)) cras_connect_message {
	struct cras_server_message header;
	uint32_t proto_version;
	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
	cras_stream_id_t stream_id; /* unique id for this stream */
	enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
	uint32_t buffer_frames; /* Buffer size in frames. */
	uint32_t cb_threshold; /* callback client when this much is left */
	uint32_t flags;
	struct cras_audio_format_packed format; /* rate, channel, sample size */
	uint32_t dev_idx; /* device to attach stream, 0 if none */
	uint64_t effects; /* Bit map of requested effects. */
	enum CRAS_CLIENT_TYPE client_type; /* chrome, or arc, etc. */
	uint32_t client_shm_size; /* Size of client-provided samples shm, if any */
};

/*
 * Old version of connect message without 'cras_type' and 'client_shm_size'
 * defined.
 * Used to check against when receiving invalid size of connect message.
 * Expected to have proto_version set to 3.
 * TODO(yuhsuan): remove when all clients migrate to latest libcras.
 */
struct __attribute__((__packed__)) cras_connect_message_old {
	struct cras_server_message header;
	uint32_t proto_version;
	enum CRAS_STREAM_DIRECTION direction; /* input/output/loopback */
	cras_stream_id_t stream_id; /* unique id for this stream */
	enum CRAS_STREAM_TYPE stream_type; /* media, or call, etc. */
	uint32_t buffer_frames; /* Buffer size in frames. */
	uint32_t cb_threshold; /* callback client when this much is left */
	uint32_t flags;
	struct cras_audio_format_packed format; /* rate, channel, sample size */
	uint32_t dev_idx; /* device to attach stream, 0 if none */
	uint64_t effects; /* Bit map of requested effects. */
};

static inline void cras_fill_connect_message(
	struct cras_connect_message *m, enum CRAS_STREAM_DIRECTION direction,
	cras_stream_id_t stream_id, enum CRAS_STREAM_TYPE stream_type,
	enum CRAS_CLIENT_TYPE client_type, size_t buffer_frames,
	size_t cb_threshold, uint32_t flags, uint64_t effects,
	struct cras_audio_format format, uint32_t dev_idx,
	uint32_t client_shm_size)
{
	m->proto_version = CRAS_PROTO_VER;
	m->direction = direction;
	m->stream_id = stream_id;
	m->stream_type = stream_type;
	m->buffer_frames = buffer_frames;
	m->cb_threshold = cb_threshold;
	m->flags = flags;
	m->effects = effects;
	pack_cras_audio_format(&m->format, &format);
	m->dev_idx = dev_idx;
	m->client_type = client_type;
	m->client_shm_size = client_shm_size;
	m->header.id = CRAS_SERVER_CONNECT_STREAM;
	m->header.length = sizeof(struct cras_connect_message);
}

/* Sent by a client to remove a stream from the server. */
struct __attribute__((__packed__)) cras_disconnect_stream_message {
	struct cras_server_message header;
	cras_stream_id_t stream_id;
};
static inline void
cras_fill_disconnect_stream_message(struct cras_disconnect_stream_message *m,
				    cras_stream_id_t stream_id)
{
	m->stream_id = stream_id;
	m->header.id = CRAS_SERVER_DISCONNECT_STREAM;
	m->header.length = sizeof(struct cras_disconnect_stream_message);
}

/* Move streams of "type" to the iodev at "iodev_idx". */
struct __attribute__((__packed__)) cras_switch_stream_type_iodev {
	struct cras_server_message header;
	enum CRAS_STREAM_TYPE stream_type;
	uint32_t iodev_idx;
};

/* Set the system volume. */
struct __attribute__((__packed__)) cras_set_system_volume {
	struct cras_server_message header;
	uint32_t volume;
};
static inline void cras_fill_set_system_volume(struct cras_set_system_volume *m,
					       size_t volume)
{
	m->volume = volume;
	m->header.id = CRAS_SERVER_SET_SYSTEM_VOLUME;
	m->header.length = sizeof(*m);
}

/* Sets the capture gain. */
struct __attribute__((__packed__)) cras_set_system_capture_gain {
	struct cras_server_message header;
	int32_t gain;
};
static inline void
cras_fill_set_system_capture_gain(struct cras_set_system_capture_gain *m,
				  long gain)
{
	m->gain = gain;
	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_GAIN;
	m->header.length = sizeof(*m);
}

/* Set the system mute state. */
struct __attribute__((__packed__)) cras_set_system_mute {
	struct cras_server_message header;
	int32_t mute; /* 0 = un-mute, 1 = mute. */
};
static inline void cras_fill_set_system_mute(struct cras_set_system_mute *m,
					     int mute)
{
	m->mute = mute;
	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE;
	m->header.length = sizeof(*m);
}
static inline void cras_fill_set_user_mute(struct cras_set_system_mute *m,
					   int mute)
{
	m->mute = mute;
	m->header.id = CRAS_SERVER_SET_USER_MUTE;
	m->header.length = sizeof(*m);
}
static inline void
cras_fill_set_system_mute_locked(struct cras_set_system_mute *m, int locked)
{
	m->mute = locked;
	m->header.id = CRAS_SERVER_SET_SYSTEM_MUTE_LOCKED;
	m->header.length = sizeof(*m);
}
static inline void
cras_fill_set_system_capture_mute(struct cras_set_system_mute *m, int mute)
{
	m->mute = mute;
	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE;
	m->header.length = sizeof(*m);
}
static inline void
cras_fill_set_system_capture_mute_locked(struct cras_set_system_mute *m,
					 int locked)
{
	m->mute = locked;
	m->header.id = CRAS_SERVER_SET_SYSTEM_CAPTURE_MUTE_LOCKED;
	m->header.length = sizeof(*m);
}

/* Set an attribute of an ionode. */
struct __attribute__((__packed__)) cras_set_node_attr {
	struct cras_server_message header;
	cras_node_id_t node_id;
	enum ionode_attr attr;
	int32_t value;
};
static inline void cras_fill_set_node_attr(struct cras_set_node_attr *m,
					   cras_node_id_t node_id,
					   enum ionode_attr attr, int value)
{
	m->header.id = CRAS_SERVER_SET_NODE_ATTR;
	m->node_id = node_id;
	m->attr = attr;
	m->value = value;
	m->header.length = sizeof(*m);
}

/* Set an attribute of an ionode. */
struct __attribute__((__packed__)) cras_select_node {
	struct cras_server_message header;
	enum CRAS_STREAM_DIRECTION direction;
	cras_node_id_t node_id;
};
static inline void cras_fill_select_node(struct cras_select_node *m,
					 enum CRAS_STREAM_DIRECTION direction,
					 cras_node_id_t node_id)
{
	m->header.id = CRAS_SERVER_SELECT_NODE;
	m->direction = direction;
	m->node_id = node_id;
	m->header.length = sizeof(*m);
}

/* Add an active ionode. */
struct __attribute__((__packed__)) cras_add_active_node {
	struct cras_server_message header;
	enum CRAS_STREAM_DIRECTION direction;
	cras_node_id_t node_id;
};
static inline void
cras_fill_add_active_node(struct cras_add_active_node *m,
			  enum CRAS_STREAM_DIRECTION direction,
			  cras_node_id_t node_id)
{
	m->header.id = CRAS_SERVER_ADD_ACTIVE_NODE;
	m->direction = direction;
	m->node_id = node_id;
	m->header.length = sizeof(*m);
}

/* Remove an active ionode. */
struct __attribute__((__packed__)) cras_rm_active_node {
	struct cras_server_message header;
	enum CRAS_STREAM_DIRECTION direction;
	cras_node_id_t node_id;
};
static inline void
cras_fill_rm_active_node(struct cras_rm_active_node *m,
			 enum CRAS_STREAM_DIRECTION direction,
			 cras_node_id_t node_id)
{
	m->header.id = CRAS_SERVER_RM_ACTIVE_NODE;
	m->direction = direction;
	m->node_id = node_id;
	m->header.length = sizeof(*m);
}

/* Reload the dsp configuration. */
struct __attribute__((__packed__)) cras_reload_dsp {
	struct cras_server_message header;
};
static inline void cras_fill_reload_dsp(struct cras_reload_dsp *m)
{
	m->header.id = CRAS_SERVER_RELOAD_DSP;
	m->header.length = sizeof(*m);
}

/* Dump current dsp information to syslog. */
struct __attribute__((__packed__)) cras_dump_dsp_info {
	struct cras_server_message header;
};

static inline void cras_fill_dump_dsp_info(struct cras_dump_dsp_info *m)
{
	m->header.id = CRAS_SERVER_DUMP_DSP_INFO;
	m->header.length = sizeof(*m);
}

/* Dump current audio thread information to syslog. */
struct __attribute__((__packed__)) cras_dump_audio_thread {
	struct cras_server_message header;
};

static inline void cras_fill_dump_audio_thread(struct cras_dump_audio_thread *m)
{
	m->header.id = CRAS_SERVER_DUMP_AUDIO_THREAD;
	m->header.length = sizeof(*m);
}

struct __attribute__((__packed__)) cras_get_atlog_fd {
	struct cras_server_message header;
};

static inline void cras_fill_get_atlog_fd(struct cras_get_atlog_fd *m)
{
	m->header.id = CRAS_SERVER_GET_ATLOG_FD;
	m->header.length = sizeof(*m);
}

/* Dump bluetooth events and state changes. */
struct __attribute__((__packed__)) cras_dump_bt {
	struct cras_server_message header;
};

static inline void cras_fill_dump_bt(struct cras_dump_bt *m)
{
	m->header.id = CRAS_SERVER_DUMP_BT;
	m->header.length = sizeof(*m);
}

/* Dump current audio thread snapshots to shard memory with the client. */
struct __attribute__((__packed__)) cras_dump_snapshots {
	struct cras_server_message header;
};

static inline void cras_fill_dump_snapshots(struct cras_dump_snapshots *m)
{
	m->header.id = CRAS_SERVER_DUMP_SNAPSHOTS;
	m->header.length = sizeof(*m);
}

/* Add a test device. */
struct __attribute__((__packed__)) cras_add_test_dev {
	struct cras_server_message header;
	enum TEST_IODEV_TYPE type;
};

static inline void cras_fill_add_test_dev(struct cras_add_test_dev *m,
					  enum TEST_IODEV_TYPE type)
{
	m->header.id = CRAS_SERVER_ADD_TEST_DEV;
	m->header.length = sizeof(*m);
	m->type = type;
}

/* Command a test device. */
struct __attribute__((__packed__)) cras_test_dev_command {
	struct cras_server_message header;
	unsigned int command;
	unsigned int iodev_idx;
	unsigned int data_len;
	uint8_t data[CRAS_MAX_TEST_DATA_LEN];
};

static inline void cras_fill_test_dev_command(struct cras_test_dev_command *m,
					      unsigned int iodev_idx,
					      enum CRAS_TEST_IODEV_CMD command,
					      unsigned int data_len,
					      const uint8_t *data)
{
	m->header.id = CRAS_SERVER_TEST_DEV_COMMAND;
	m->header.length = sizeof(*m) + data_len;
	m->iodev_idx = iodev_idx;
	m->command = command;
	m->data_len = data_len;
	memcpy(m->data, data, data_len);
}

static inline void cras_fill_suspend_message(struct cras_server_message *m,
					     int is_suspend)
{
	m->id = is_suspend ? CRAS_SERVER_SUSPEND : CRAS_SERVER_RESUME;
	m->length = sizeof(*m);
}

/*
 * Configures the global remix converter.
 * `num_channels` must be less than `CRAS_MAX_REMIX_CHANNELS`.
 */
struct __attribute__((__packed__)) cras_config_global_remix {
	struct cras_server_message header;
	unsigned int num_channels;
	float coefficient[CRAS_MAX_REMIX_CHANNELS];
};

static inline void
cras_fill_config_global_remix_command(struct cras_config_global_remix *m,
				      unsigned int num_channels, float *coeff,
				      unsigned int count)
{
	m->header.id = CRAS_CONFIG_GLOBAL_REMIX;
	m->header.length = sizeof(*m) + count * sizeof(*coeff);
	m->num_channels = num_channels;
	memcpy(m->coefficient, coeff, count * sizeof(*coeff));
}

/* Get supported hotword models. */
struct __attribute__((__packed__)) cras_get_hotword_models {
	struct cras_server_message header;
	cras_node_id_t node_id;
};

static inline void
cras_fill_get_hotword_models_message(struct cras_get_hotword_models *m,
				     cras_node_id_t node_id)
{
	m->header.id = CRAS_SERVER_GET_HOTWORD_MODELS;
	m->header.length = sizeof(*m);
	m->node_id = node_id;
}

/* Set desired hotword model. */
struct __attribute__((__packed__)) cras_set_hotword_model {
	struct cras_server_message header;
	cras_node_id_t node_id;
	char model_name[CRAS_MAX_HOTWORD_MODEL_NAME_SIZE];
};

static inline void
cras_fill_set_hotword_model_message(struct cras_set_hotword_model *m,
				    cras_node_id_t node_id,
				    const char *model_name)
{
	m->header.id = CRAS_SERVER_SET_HOTWORD_MODEL;
	m->header.length = sizeof(*m);
	m->node_id = node_id;
	memcpy(m->model_name, model_name, CRAS_MAX_HOTWORD_MODEL_NAME_SIZE);
}

/* Set aec dump to start or stop. */
struct __attribute__((__packed__)) cras_set_aec_dump {
	struct cras_server_message header;
	cras_stream_id_t stream_id;
	unsigned int start;
};

static inline void cras_fill_set_aec_dump_message(struct cras_set_aec_dump *m,
						  cras_stream_id_t stream_id,
						  unsigned int start)
{
	m->header.id = CRAS_SERVER_SET_AEC_DUMP;
	m->header.length = sizeof(*m);
	m->stream_id = stream_id;
	m->start = start;
}

/* Reload the aec configuration. */
struct __attribute__((__packed__)) cras_reload_aec_config {
	struct cras_server_message header;
};
static inline void cras_fill_reload_aec_config(struct cras_reload_aec_config *m)
{
	m->header.id = CRAS_SERVER_RELOAD_AEC_CONFIG;
	m->header.length = sizeof(*m);
}

/* Sets the flag to enable or disable bluetooth wideband speech feature. */
struct __attribute__((__packed__)) cras_set_bt_wbs_enabled {
	struct cras_server_message header;
	unsigned int enabled;
};
static inline void
cras_fill_set_bt_wbs_enabled(struct cras_set_bt_wbs_enabled *m,
			     unsigned int enabled)
{
	m->header.id = CRAS_SERVER_SET_BT_WBS_ENABLED;
	m->header.length = sizeof(*m);
	m->enabled = enabled;
}

struct __attribute__((__packed__)) cras_register_notification {
	struct cras_server_message header;
	uint32_t msg_id;
	int do_register;
};
static inline void
cras_fill_register_notification_message(struct cras_register_notification *m,
					enum CRAS_CLIENT_MESSAGE_ID msg_id,
					int do_register)
{
	m->header.id = CRAS_SERVER_REGISTER_NOTIFICATION;
	m->header.length = sizeof(*m);
	m->msg_id = msg_id;
	m->do_register = do_register;
}

/*
 * Messages sent from server to client.
 */

/* Reply from the server indicating that the client has connected. */
struct __attribute__((__packed__)) cras_client_connected {
	struct cras_client_message header;
	uint32_t client_id;
};
static inline void cras_fill_client_connected(struct cras_client_connected *m,
					      size_t client_id)
{
	m->client_id = client_id;
	m->header.id = CRAS_CLIENT_CONNECTED;
	m->header.length = sizeof(struct cras_client_connected);
}

/*
 * Reply from server that a stream has been successfully added.
 * Two file descriptors are added, input shm followed by out shm.
 *
 * samples_shm_size is shm_max_size for old clients.
 * TODO(fletcherw) remove comment once all clients are on CRAS_PROTO_VER >= 3.
 */
struct __attribute__((__packed__)) cras_client_stream_connected {
	struct cras_client_message header;
	int32_t err;
	cras_stream_id_t stream_id;
	struct cras_audio_format_packed format;
	uint32_t samples_shm_size;
	uint64_t effects;
};

static inline void
cras_fill_client_stream_connected(struct cras_client_stream_connected *m,
				  int err, cras_stream_id_t stream_id,
				  struct cras_audio_format *format,
				  size_t samples_shm_size, uint64_t effects)
{
	m->err = err;
	m->stream_id = stream_id;
	pack_cras_audio_format(&m->format, format);
	m->samples_shm_size = samples_shm_size;
	m->effects = effects;
	m->header.id = CRAS_CLIENT_STREAM_CONNECTED;
	m->header.length = sizeof(struct cras_client_stream_connected);
}

/* Sent from server to client when audio debug information is requested. */
struct __attribute__((__packed__)) cras_client_audio_debug_info_ready {
	struct cras_client_message header;
};
static inline void cras_fill_client_audio_debug_info_ready(
	struct cras_client_audio_debug_info_ready *m)
{
	m->header.id = CRAS_CLIENT_AUDIO_DEBUG_INFO_READY;
	m->header.length = sizeof(*m);
}

struct __attribute__((__packed__)) cras_client_atlog_fd_ready {
	struct cras_client_message header;
};

static inline void
cras_fill_client_atlog_fd_ready(struct cras_client_atlog_fd_ready *m)
{
	m->header.id = CRAS_CLIENT_ATLOG_FD_READY;
	m->header.length = sizeof(*m);
}

/* Sent from server to client when hotword models info is ready. */
struct __attribute__((__packed__)) cras_client_get_hotword_models_ready {
	struct cras_client_message header;
	int32_t hotword_models_size;
	uint8_t hotword_models[CRAS_MAX_HOTWORD_MODELS + 1];
};
static inline void cras_fill_client_get_hotword_models_ready(
	struct cras_client_get_hotword_models_ready *m,
	const char *hotword_models, size_t hotword_models_size)
{
	m->header.id = CRAS_CLIENT_GET_HOTWORD_MODELS_READY;
	m->header.length = sizeof(*m);
	m->hotword_models_size = hotword_models_size;
	/* Copy string data with terminator. */
	if (hotword_models) {
		strncpy((char *)m->hotword_models, hotword_models,
			CRAS_MAX_HOTWORD_MODELS);
		m->hotword_models[CRAS_MAX_HOTWORD_MODELS] = '\0';
	}
}

/* System status messages sent from server to client when state changes. */
struct __attribute__((__packed__)) cras_client_volume_changed {
	struct cras_client_message header;
	int32_t volume;
};
static inline void
cras_fill_client_output_volume_changed(struct cras_client_volume_changed *m,
				       int32_t volume)
{
	m->header.id = CRAS_CLIENT_OUTPUT_VOLUME_CHANGED;
	m->header.length = sizeof(*m);
	m->volume = volume;
}
static inline void
cras_fill_client_capture_gain_changed(struct cras_client_volume_changed *m,
				      int32_t gain)
{
	m->header.id = CRAS_CLIENT_CAPTURE_GAIN_CHANGED;
	m->header.length = sizeof(*m);
	m->volume = gain;
}

struct __attribute__((__packed__)) cras_client_mute_changed {
	struct cras_client_message header;
	int32_t muted;
	int32_t user_muted;
	int32_t mute_locked;
};
static inline void
cras_fill_client_output_mute_changed(struct cras_client_mute_changed *m,
				     int32_t muted, int32_t user_muted,
				     int32_t mute_locked)
{
	m->header.id = CRAS_CLIENT_OUTPUT_MUTE_CHANGED;
	m->header.length = sizeof(*m);
	m->muted = muted;
	m->user_muted = user_muted;
	m->mute_locked = mute_locked;
}
static inline void
cras_fill_client_capture_mute_changed(struct cras_client_mute_changed *m,
				      int32_t muted, int32_t mute_locked)
{
	m->header.id = CRAS_CLIENT_CAPTURE_MUTE_CHANGED;
	m->header.length = sizeof(*m);
	m->muted = muted;
	m->user_muted = 0;
	m->mute_locked = mute_locked;
}

struct __attribute__((__packed__)) cras_client_nodes_changed {
	struct cras_client_message header;
};
static inline void
cras_fill_client_nodes_changed(struct cras_client_nodes_changed *m)
{
	m->header.id = CRAS_CLIENT_NODES_CHANGED;
	m->header.length = sizeof(*m);
}

struct __attribute__((__packed__)) cras_client_active_node_changed {
	struct cras_client_message header;
	uint32_t direction;
	cras_node_id_t node_id;
};
static inline void
cras_fill_client_active_node_changed(struct cras_client_active_node_changed *m,
				     enum CRAS_STREAM_DIRECTION direction,
				     cras_node_id_t node_id)
{
	m->header.id = CRAS_CLIENT_ACTIVE_NODE_CHANGED;
	m->header.length = sizeof(*m);
	m->direction = direction;
	m->node_id = node_id;
};

struct __attribute__((__packed__)) cras_client_node_value_changed {
	struct cras_client_message header;
	cras_node_id_t node_id;
	int32_t value;
};
static inline void cras_fill_client_output_node_volume_changed(
	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
	int32_t volume)
{
	m->header.id = CRAS_CLIENT_OUTPUT_NODE_VOLUME_CHANGED;
	m->header.length = sizeof(*m);
	m->node_id = node_id;
	m->value = volume;
};
static inline void cras_fill_client_node_left_right_swapped_changed(
	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
	int swapped)
{
	m->header.id = CRAS_CLIENT_NODE_LEFT_RIGHT_SWAPPED_CHANGED;
	m->header.length = sizeof(*m);
	m->node_id = node_id;
	m->value = swapped;
};
static inline void cras_fill_client_input_node_gain_changed(
	struct cras_client_node_value_changed *m, cras_node_id_t node_id,
	int32_t gain)
{
	m->header.id = CRAS_CLIENT_INPUT_NODE_GAIN_CHANGED;
	m->header.length = sizeof(*m);
	m->node_id = node_id;
	m->value = gain;
};

struct __attribute__((__packed__)) cras_client_num_active_streams_changed {
	struct cras_client_message header;
	uint32_t direction;
	uint32_t num_active_streams;
};
static inline void cras_fill_client_num_active_streams_changed(
	struct cras_client_num_active_streams_changed *m,
	enum CRAS_STREAM_DIRECTION direction, uint32_t num_active_streams)
{
	m->header.id = CRAS_CLIENT_NUM_ACTIVE_STREAMS_CHANGED;
	m->header.length = sizeof(*m);
	m->direction = direction;
	m->num_active_streams = num_active_streams;
};

/*
 * Messages specific to passing audio between client and server
 */
enum CRAS_AUDIO_MESSAGE_ID {
	AUDIO_MESSAGE_REQUEST_DATA,
	AUDIO_MESSAGE_DATA_READY,
	AUDIO_MESSAGE_DATA_CAPTURED,
	NUM_AUDIO_MESSAGES
};

struct __attribute__((__packed__)) audio_message {
	enum CRAS_AUDIO_MESSAGE_ID id;
	int32_t error;
	uint32_t frames; /* number of samples per channel */
};

#endif /* CRAS_MESSAGES_H_ */