Android-cuttlefish cvd tool
shm_layout.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <cstdint>
19
21
22namespace cuttlefish {
23// TODO (b/175151042): get these from the kernel headers when available
24
25enum class AudioCommandType : uint32_t {
26 /* jack control request types */
29
30 /* PCM control request types */
31 VIRTIO_SND_R_PCM_INFO = 0x0100,
37
38 /* channel map control request types */
40
41 /* control element request types */
42 VIRTIO_SND_R_CTL_INFO = 0x0300,
49};
50
51enum class AudioStatus : uint32_t {
52 /* common status codes */
53 VIRTIO_SND_S_OK = 0x8000,
57 // Not a virtio constant, but it's only used internally as an invalid value so
58 // it's safe.
59 NOT_SET = static_cast<uint32_t>(-1),
60};
61
62enum class AudioStreamDirection : uint8_t {
65};
66
67enum class AudioStreamFormat : uint8_t {
68 /* analog formats (width / physical width) */
69 VIRTIO_SND_PCM_FMT_IMA_ADPCM = 0, /* 4 / 4 bits */
70 VIRTIO_SND_PCM_FMT_MU_LAW, /* 8 / 8 bits */
71 VIRTIO_SND_PCM_FMT_A_LAW, /* 8 / 8 bits */
72 VIRTIO_SND_PCM_FMT_S8, /* 8 / 8 bits */
73 VIRTIO_SND_PCM_FMT_U8, /* 8 / 8 bits */
74 VIRTIO_SND_PCM_FMT_S16, /* 16 / 16 bits */
75 VIRTIO_SND_PCM_FMT_U16, /* 16 / 16 bits */
76 VIRTIO_SND_PCM_FMT_S18_3, /* 18 / 24 bits */
77 VIRTIO_SND_PCM_FMT_U18_3, /* 18 / 24 bits */
78 VIRTIO_SND_PCM_FMT_S20_3, /* 20 / 24 bits */
79 VIRTIO_SND_PCM_FMT_U20_3, /* 20 / 24 bits */
80 VIRTIO_SND_PCM_FMT_S24_3, /* 24 / 24 bits */
81 VIRTIO_SND_PCM_FMT_U24_3, /* 24 / 24 bits */
82 VIRTIO_SND_PCM_FMT_S20, /* 20 / 32 bits */
83 VIRTIO_SND_PCM_FMT_U20, /* 20 / 32 bits */
84 VIRTIO_SND_PCM_FMT_S24, /* 24 / 32 bits */
85 VIRTIO_SND_PCM_FMT_U24, /* 24 / 32 bits */
86 VIRTIO_SND_PCM_FMT_S32, /* 32 / 32 bits */
87 VIRTIO_SND_PCM_FMT_U32, /* 32 / 32 bits */
88 VIRTIO_SND_PCM_FMT_FLOAT, /* 32 / 32 bits */
89 VIRTIO_SND_PCM_FMT_FLOAT64, /* 64 / 64 bits */
90 /* digital formats (width / physical width) */
91 VIRTIO_SND_PCM_FMT_DSD_U8, /* 8 / 8 bits */
92 VIRTIO_SND_PCM_FMT_DSD_U16, /* 16 / 16 bits */
93 VIRTIO_SND_PCM_FMT_DSD_U32, /* 32 / 32 bits */
94 VIRTIO_SND_PCM_FMT_IEC958_SUBFRAME /* 32 / 32 bits */
95};
96
97/* supported PCM frame rates */
98enum AudioStreamRate : uint8_t {
114
115/* standard channel position definition */
116enum AudioChannelMap : uint8_t {
117 VIRTIO_SND_CHMAP_NONE = 0, /* undefined */
119 VIRTIO_SND_CHMAP_MONO, /* mono stream */
120 VIRTIO_SND_CHMAP_FL, /* front left */
121 VIRTIO_SND_CHMAP_FR, /* front right */
122 VIRTIO_SND_CHMAP_RL, /* rear left */
123 VIRTIO_SND_CHMAP_RR, /* rear right */
124 VIRTIO_SND_CHMAP_FC, /* front center */
125 VIRTIO_SND_CHMAP_LFE, /* low frequency (LFE) */
126 VIRTIO_SND_CHMAP_SL, /* side left */
127 VIRTIO_SND_CHMAP_SR, /* side right */
128 VIRTIO_SND_CHMAP_RC, /* rear center */
129 VIRTIO_SND_CHMAP_FLC, /* front left center */
130 VIRTIO_SND_CHMAP_FRC, /* front right center */
131 VIRTIO_SND_CHMAP_RLC, /* rear left center */
132 VIRTIO_SND_CHMAP_RRC, /* rear right center */
133 VIRTIO_SND_CHMAP_FLW, /* front left wide */
134 VIRTIO_SND_CHMAP_FRW, /* front right wide */
135 VIRTIO_SND_CHMAP_FLH, /* front left high */
136 VIRTIO_SND_CHMAP_FCH, /* front center high */
137 VIRTIO_SND_CHMAP_FRH, /* front right high */
138 VIRTIO_SND_CHMAP_TC, /* top center */
139 VIRTIO_SND_CHMAP_TFL, /* top front left */
140 VIRTIO_SND_CHMAP_TFR, /* top front right */
141 VIRTIO_SND_CHMAP_TFC, /* top front center */
142 VIRTIO_SND_CHMAP_TRL, /* top rear left */
143 VIRTIO_SND_CHMAP_TRR, /* top rear right */
144 VIRTIO_SND_CHMAP_TRC, /* top rear center */
145 VIRTIO_SND_CHMAP_TFLC, /* top front left center */
146 VIRTIO_SND_CHMAP_TFRC, /* top front right center */
147 VIRTIO_SND_CHMAP_TSL, /* top side left */
148 VIRTIO_SND_CHMAP_TSR, /* top side right */
149 VIRTIO_SND_CHMAP_LLFE, /* left LFE */
150 VIRTIO_SND_CHMAP_RLFE, /* right LFE */
151 VIRTIO_SND_CHMAP_BC, /* bottom center */
152 VIRTIO_SND_CHMAP_BLC, /* bottom left center */
153 VIRTIO_SND_CHMAP_BRC /* bottom right center */
155
157 Le32 code;
158};
159
163 Le32 count;
164 Le32 size; // unused
165};
166
169};
170
171/* supported jack features */
173
176 Le32 features; /* 1 << VIRTIO_SND_JACK_F_XXX */
179 uint8_t connected;
180
181 uint8_t padding[7];
182};
183
184constexpr uint8_t VIRTIO_SND_CHMAP_MAX_SIZE = 18;
187 uint8_t direction;
188 uint8_t channels;
190};
191
194 Le32 features; /* 1 << VIRTIO_SND_PCM_F_XXX */
195 Le64 formats; /* 1 << VIRTIO_SND_PCM_FMT_XXX */
196 Le64 rates; /* 1 << VIRTIO_SND_PCM_RATE_XXX */
197 uint8_t direction;
200
201 uint8_t padding[5];
202};
203
207};
208
213 Le32 features; /* 1 << VIRTIO_SND_PCM_F_XXX */
214 uint8_t channels;
215 uint8_t format;
216 uint8_t rate;
217 uint8_t padding;
218};
219
222};
223
225 Le32 status;
227};
228
229enum class AudioControlRole : uint8_t {
234};
235
236enum class AudioControlType : uint8_t {
243};
244
245enum AudioControlAccess : uint8_t {
254
257 Le32 role;
258 Le32 type;
259 Le32 access; // 1 << VIRTIO_SND_CTL_ACCESS_XXX
260 Le32 count;
261 Le32 index;
262 uint8_t name[44];
263 union {
264 struct {
265 Le32 min;
266 Le32 max;
267 Le32 step;
269 struct {
270 Le64 min;
271 Le64 max;
272 Le64 step;
274 struct {
275 Le32 items;
278};
279
283};
284
286 union {
287 Le32 integer[128];
288 Le64 integer64[64];
289 Le32 enumerated[128];
290 uint8_t bytes[512];
291 struct virtio_snd_ctl_iec958 {
292 uint8_t status[24]; /* AES/IEC958 channel status bits */
293 uint8_t subcode[147]; /* AES/IEC958 subcode bits */
294 uint8_t pad; /* nothing */
295 uint8_t dig_subframe[4]; /* AES/IEC958 subframe bits */
298};
299
303 Le16 mask;
304};
305
306inline constexpr uint32_t VIOS_VERSION = 3;
307
309 uint32_t version;
310 uint32_t jacks;
311 uint32_t streams;
312 uint32_t chmaps;
313 uint32_t controls;
314};
315
319 uint32_t buffer_len;
320};
321
326};
327
328// Ensure all message structs have predictable sizes
329#define ASSERT_VALID_MSG_TYPE(T, size) \
330 static_assert(sizeof(T) == (size), #T " has the wrong size")
342#undef ASSERT_VALID_MSG_TYPE
343
344} // namespace cuttlefish
Definition: alloc_driver.h:20
AudioChannelMap
Definition: shm_layout.h:116
@ VIRTIO_SND_CHMAP_BRC
Definition: shm_layout.h:153
@ VIRTIO_SND_CHMAP_TFC
Definition: shm_layout.h:141
@ VIRTIO_SND_CHMAP_RL
Definition: shm_layout.h:122
@ VIRTIO_SND_CHMAP_TSL
Definition: shm_layout.h:147
@ VIRTIO_SND_CHMAP_FRC
Definition: shm_layout.h:130
@ VIRTIO_SND_CHMAP_TFL
Definition: shm_layout.h:139
@ VIRTIO_SND_CHMAP_FLH
Definition: shm_layout.h:135
@ VIRTIO_SND_CHMAP_FCH
Definition: shm_layout.h:136
@ VIRTIO_SND_CHMAP_FRW
Definition: shm_layout.h:134
@ VIRTIO_SND_CHMAP_LLFE
Definition: shm_layout.h:149
@ VIRTIO_SND_CHMAP_TRL
Definition: shm_layout.h:142
@ VIRTIO_SND_CHMAP_FR
Definition: shm_layout.h:121
@ VIRTIO_SND_CHMAP_FLC
Definition: shm_layout.h:129
@ VIRTIO_SND_CHMAP_FC
Definition: shm_layout.h:124
@ VIRTIO_SND_CHMAP_BLC
Definition: shm_layout.h:152
@ VIRTIO_SND_CHMAP_FL
Definition: shm_layout.h:120
@ VIRTIO_SND_CHMAP_RRC
Definition: shm_layout.h:132
@ VIRTIO_SND_CHMAP_FRH
Definition: shm_layout.h:137
@ VIRTIO_SND_CHMAP_TC
Definition: shm_layout.h:138
@ VIRTIO_SND_CHMAP_RLC
Definition: shm_layout.h:131
@ VIRTIO_SND_CHMAP_TFR
Definition: shm_layout.h:140
@ VIRTIO_SND_CHMAP_MONO
Definition: shm_layout.h:119
@ VIRTIO_SND_CHMAP_RC
Definition: shm_layout.h:128
@ VIRTIO_SND_CHMAP_BC
Definition: shm_layout.h:151
@ VIRTIO_SND_CHMAP_NONE
Definition: shm_layout.h:117
@ VIRTIO_SND_CHMAP_LFE
Definition: shm_layout.h:125
@ VIRTIO_SND_CHMAP_TRC
Definition: shm_layout.h:144
@ VIRTIO_SND_CHMAP_TFRC
Definition: shm_layout.h:146
@ VIRTIO_SND_CHMAP_TRR
Definition: shm_layout.h:143
@ VIRTIO_SND_CHMAP_SL
Definition: shm_layout.h:126
@ VIRTIO_SND_CHMAP_SR
Definition: shm_layout.h:127
@ VIRTIO_SND_CHMAP_RR
Definition: shm_layout.h:123
@ VIRTIO_SND_CHMAP_FLW
Definition: shm_layout.h:133
@ VIRTIO_SND_CHMAP_NA
Definition: shm_layout.h:118
@ VIRTIO_SND_CHMAP_TFLC
Definition: shm_layout.h:145
@ VIRTIO_SND_CHMAP_TSR
Definition: shm_layout.h:148
@ VIRTIO_SND_CHMAP_RLFE
Definition: shm_layout.h:150
AudioCommandType
Definition: shm_layout.h:25
AudioStreamFormat
Definition: shm_layout.h:67
constexpr uint32_t VIOS_VERSION
Definition: shm_layout.h:306
constexpr uint8_t VIRTIO_SND_CHMAP_MAX_SIZE
Definition: shm_layout.h:184
AudioJackFeatures
Definition: shm_layout.h:172
@ VIRTIO_SND_JACK_F_REMAP
Definition: shm_layout.h:172
AudioControlAccess
Definition: shm_layout.h:245
@ VIRTIO_SND_CTL_ACCESS_VOLATILE
Definition: shm_layout.h:248
@ VIRTIO_SND_CTL_ACCESS_INACTIVE
Definition: shm_layout.h:249
@ VIRTIO_SND_CTL_ACCESS_TLV_COMMAND
Definition: shm_layout.h:252
@ VIRTIO_SND_CTL_ACCESS_TLV_WRITE
Definition: shm_layout.h:251
@ VIRTIO_SND_CTL_ACCESS_WRITE
Definition: shm_layout.h:247
@ VIRTIO_SND_CTL_ACCESS_TLV_READ
Definition: shm_layout.h:250
@ VIRTIO_SND_CTL_ACCESS_READ
Definition: shm_layout.h:246
AudioControlType
Definition: shm_layout.h:236
AudioControlRole
Definition: shm_layout.h:229
AudioStreamRate
Definition: shm_layout.h:98
@ VIRTIO_SND_PCM_RATE_88200
Definition: shm_layout.h:108
@ VIRTIO_SND_PCM_RATE_44100
Definition: shm_layout.h:105
@ VIRTIO_SND_PCM_RATE_11025
Definition: shm_layout.h:101
@ VIRTIO_SND_PCM_RATE_64000
Definition: shm_layout.h:107
@ VIRTIO_SND_PCM_RATE_192000
Definition: shm_layout.h:111
@ VIRTIO_SND_PCM_RATE_96000
Definition: shm_layout.h:109
@ VIRTIO_SND_PCM_RATE_22050
Definition: shm_layout.h:103
@ VIRTIO_SND_PCM_RATE_32000
Definition: shm_layout.h:104
@ VIRTIO_SND_PCM_RATE_176400
Definition: shm_layout.h:110
@ VIRTIO_SND_PCM_RATE_16000
Definition: shm_layout.h:102
@ VIRTIO_SND_PCM_RATE_8000
Definition: shm_layout.h:100
@ VIRTIO_SND_PCM_RATE_48000
Definition: shm_layout.h:106
@ VIRTIO_SND_PCM_RATE_5512
Definition: shm_layout.h:99
@ VIRTIO_SND_PCM_RATE_384000
Definition: shm_layout.h:112
AudioStatus
Definition: shm_layout.h:51
AudioStreamDirection
Definition: shm_layout.h:62
ASSERT_VALID_MSG_TYPE(virtio_snd_query_info, 16)
Definition: shm_layout.h:322
uint32_t consumed_length
Definition: shm_layout.h:325
virtio_snd_pcm_status status
Definition: shm_layout.h:323
uint32_t buffer_offset
Definition: shm_layout.h:324
Definition: shm_layout.h:316
uint32_t buffer_len
Definition: shm_layout.h:319
virtio_snd_pcm_xfer io_xfer
Definition: shm_layout.h:317
uint32_t buffer_offset
Definition: shm_layout.h:318
Definition: shm_layout.h:308
uint32_t version
Definition: shm_layout.h:309
uint32_t jacks
Definition: shm_layout.h:310
uint32_t controls
Definition: shm_layout.h:313
uint32_t streams
Definition: shm_layout.h:311
uint32_t chmaps
Definition: shm_layout.h:312
Definition: shm_layout.h:185
uint8_t direction
Definition: shm_layout.h:187
uint8_t channels
Definition: shm_layout.h:188
struct virtio_snd_info hdr
Definition: shm_layout.h:186
uint8_t positions[VIRTIO_SND_CHMAP_MAX_SIZE]
Definition: shm_layout.h:189
Definition: shm_layout.h:300
Le16 control_id
Definition: shm_layout.h:302
Le16 mask
Definition: shm_layout.h:303
struct virtio_snd_hdr hdr
Definition: shm_layout.h:301
Definition: shm_layout.h:280
struct virtio_snd_hdr hdr
Definition: shm_layout.h:281
Le32 control_id
Definition: shm_layout.h:282
Definition: shm_layout.h:255
struct virtio_snd_info hdr
Definition: shm_layout.h:256
uint8_t name[44]
Definition: shm_layout.h:262
struct cuttlefish::virtio_snd_ctl_info::@20::@22 integer64
Le32 min
Definition: shm_layout.h:265
Le32 items
Definition: shm_layout.h:275
Le32 index
Definition: shm_layout.h:261
Le32 max
Definition: shm_layout.h:266
Le64 max
Definition: shm_layout.h:271
Le32 step
Definition: shm_layout.h:267
Le32 access
Definition: shm_layout.h:259
Le32 count
Definition: shm_layout.h:260
Le32 type
Definition: shm_layout.h:258
struct cuttlefish::virtio_snd_ctl_info::@20::@21 integer
Le32 role
Definition: shm_layout.h:257
Le64 step
Definition: shm_layout.h:272
union cuttlefish::virtio_snd_ctl_info::@20 value
Le64 min
Definition: shm_layout.h:270
struct cuttlefish::virtio_snd_ctl_info::@20::@23 enumerated
Definition: shm_layout.h:285
uint8_t dig_subframe[4]
Definition: shm_layout.h:295
uint8_t subcode[147]
Definition: shm_layout.h:293
union cuttlefish::virtio_snd_ctl_value::@24 value
uint8_t status[24]
Definition: shm_layout.h:292
Le32 enumerated[128]
Definition: shm_layout.h:289
uint8_t bytes[512]
Definition: shm_layout.h:290
Le32 integer[128]
Definition: shm_layout.h:287
uint8_t pad
Definition: shm_layout.h:294
Le64 integer64[64]
Definition: shm_layout.h:288
struct cuttlefish::virtio_snd_ctl_value::@24::virtio_snd_ctl_iec958 iec958
Definition: shm_layout.h:156
Le32 code
Definition: shm_layout.h:157
Definition: shm_layout.h:167
Le32 hda_fn_nid
Definition: shm_layout.h:168
Definition: shm_layout.h:174
struct virtio_snd_info hdr
Definition: shm_layout.h:175
Le32 features
Definition: shm_layout.h:176
uint8_t padding[7]
Definition: shm_layout.h:181
uint8_t connected
Definition: shm_layout.h:179
Le32 hda_reg_caps
Definition: shm_layout.h:178
Le32 hda_reg_defconf
Definition: shm_layout.h:177
Definition: shm_layout.h:204
Le32 stream_id
Definition: shm_layout.h:206
struct virtio_snd_hdr hdr
Definition: shm_layout.h:205
Definition: shm_layout.h:192
Le32 features
Definition: shm_layout.h:194
Le64 formats
Definition: shm_layout.h:195
uint8_t channels_min
Definition: shm_layout.h:198
struct virtio_snd_info hdr
Definition: shm_layout.h:193
Le64 rates
Definition: shm_layout.h:196
uint8_t channels_max
Definition: shm_layout.h:199
uint8_t padding[5]
Definition: shm_layout.h:201
uint8_t direction
Definition: shm_layout.h:197
Definition: shm_layout.h:209
Le32 buffer_bytes
Definition: shm_layout.h:211
uint8_t format
Definition: shm_layout.h:215
Le32 features
Definition: shm_layout.h:213
uint8_t rate
Definition: shm_layout.h:216
uint8_t padding
Definition: shm_layout.h:217
uint8_t channels
Definition: shm_layout.h:214
Le32 period_bytes
Definition: shm_layout.h:212
struct virtio_snd_pcm_hdr hdr
Definition: shm_layout.h:210
Definition: shm_layout.h:224
Le32 status
Definition: shm_layout.h:225
Le32 latency_bytes
Definition: shm_layout.h:226
Definition: shm_layout.h:220
Le32 stream_id
Definition: shm_layout.h:221
Definition: shm_layout.h:160
Le32 start_id
Definition: shm_layout.h:162
Le32 count
Definition: shm_layout.h:163
struct virtio_snd_hdr hdr
Definition: shm_layout.h:161
Le32 size
Definition: shm_layout.h:164