1 /*
2 * Copyright (C) 2011 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
17
18 #ifndef ANDROID_AUDIO_CORE_H
19 #define ANDROID_AUDIO_CORE_H
20
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/cdefs.h>
26 #include <sys/types.h>
27
28 // Remove in approximately 2021
29 #include <cutils/bitops.h>
30
31 #include "audio-base.h"
32 #include "audio-base-utils.h"
33
34 /*
35 * Annotation to tell clang that we intend to fall through from one case to
36 * another in a switch (for c++ files). Sourced from android-base/macros.h.
37 */
38 #ifndef FALLTHROUGH_INTENDED
39 #ifdef __cplusplus
40 #define FALLTHROUGH_INTENDED [[fallthrough]]
41 #elif __has_attribute(fallthrough)
42 #define FALLTHROUGH_INTENDED __attribute__((__fallthrough__))
43 #else
44 #define FALLTHROUGH_INTENDED
45 #endif // __cplusplus
46 #endif // FALLTHROUGH_INTENDED
47
48 __BEGIN_DECLS
49
50 /* The enums were moved here mostly from
51 * frameworks/base/include/media/AudioSystem.h
52 */
53
54 /* represents an invalid uid for tracks; the calling or client uid is often substituted. */
55 #define AUDIO_UID_INVALID ((uid_t)-1)
56
57 /* device address used to refer to the standard remote submix */
58 #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0"
59
60 /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */
61 typedef int audio_io_handle_t;
62
63 typedef uint32_t audio_flags_mask_t;
64
65 /* Do not change these values without updating their counterparts
66 * in frameworks/base/media/java/android/media/AudioAttributes.java
67 */
68 enum {
69 AUDIO_FLAG_NONE = 0x0,
70 AUDIO_FLAG_AUDIBILITY_ENFORCED = 0x1,
71 AUDIO_FLAG_SECURE = 0x2,
72 AUDIO_FLAG_SCO = 0x4,
73 AUDIO_FLAG_BEACON = 0x8,
74 AUDIO_FLAG_HW_AV_SYNC = 0x10,
75 AUDIO_FLAG_HW_HOTWORD = 0x20,
76 AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY = 0x40,
77 AUDIO_FLAG_BYPASS_MUTE = 0x80,
78 AUDIO_FLAG_LOW_LATENCY = 0x100,
79 AUDIO_FLAG_DEEP_BUFFER = 0x200,
80 AUDIO_FLAG_NO_MEDIA_PROJECTION = 0X400,
81 AUDIO_FLAG_MUTE_HAPTIC = 0x800,
82 AUDIO_FLAG_NO_SYSTEM_CAPTURE = 0X1000,
83 };
84
85 /* Audio attributes */
86 #define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
87 typedef struct {
88 audio_content_type_t content_type;
89 audio_usage_t usage;
90 audio_source_t source;
91 audio_flags_mask_t flags;
92 char tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
93 } __attribute__((packed)) audio_attributes_t; // sent through Binder;
94
95 static const audio_attributes_t AUDIO_ATTRIBUTES_INITIALIZER = {
96 /* .content_type = */ AUDIO_CONTENT_TYPE_UNKNOWN,
97 /* .usage = */ AUDIO_USAGE_UNKNOWN,
98 /* .source = */ AUDIO_SOURCE_DEFAULT,
99 /* .flags = */ AUDIO_FLAG_NONE,
100 /* .tags = */ ""
101 };
102
attributes_initializer(audio_usage_t usage)103 static inline audio_attributes_t attributes_initializer(audio_usage_t usage)
104 {
105 audio_attributes_t attributes = AUDIO_ATTRIBUTES_INITIALIZER;
106 attributes.usage = usage;
107 return attributes;
108 }
109
audio_flags_to_audio_output_flags(const audio_flags_mask_t audio_flags,audio_output_flags_t * flags)110 static inline void audio_flags_to_audio_output_flags(
111 const audio_flags_mask_t audio_flags,
112 audio_output_flags_t *flags)
113 {
114 if ((audio_flags & AUDIO_FLAG_HW_AV_SYNC) != 0) {
115 *flags = (audio_output_flags_t)(*flags |
116 AUDIO_OUTPUT_FLAG_HW_AV_SYNC | AUDIO_OUTPUT_FLAG_DIRECT);
117 }
118 if ((audio_flags & AUDIO_FLAG_LOW_LATENCY) != 0) {
119 *flags = (audio_output_flags_t)(*flags | AUDIO_OUTPUT_FLAG_FAST);
120 }
121 // check deep buffer after flags have been modified above
122 if (*flags == AUDIO_OUTPUT_FLAG_NONE && (audio_flags & AUDIO_FLAG_DEEP_BUFFER) != 0) {
123 *flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
124 }
125 }
126
127
128 /* a unique ID allocated by AudioFlinger for use as an audio_io_handle_t, audio_session_t,
129 * effect ID (int), audio_module_handle_t, and audio_patch_handle_t.
130 * Audio port IDs (audio_port_handle_t) are allocated by AudioPolicy
131 * in a different namespace than AudioFlinger unique IDs.
132 */
133 typedef int audio_unique_id_t;
134
135 /* Possible uses for an audio_unique_id_t */
136 typedef enum {
137 AUDIO_UNIQUE_ID_USE_UNSPECIFIED = 0,
138 AUDIO_UNIQUE_ID_USE_SESSION = 1, // for allocated sessions, not special AUDIO_SESSION_*
139 AUDIO_UNIQUE_ID_USE_MODULE = 2,
140 AUDIO_UNIQUE_ID_USE_EFFECT = 3,
141 AUDIO_UNIQUE_ID_USE_PATCH = 4,
142 AUDIO_UNIQUE_ID_USE_OUTPUT = 5,
143 AUDIO_UNIQUE_ID_USE_INPUT = 6,
144 AUDIO_UNIQUE_ID_USE_CLIENT = 7, // client-side players and recorders
145 AUDIO_UNIQUE_ID_USE_MAX = 8, // must be a power-of-two
146 AUDIO_UNIQUE_ID_USE_MASK = AUDIO_UNIQUE_ID_USE_MAX - 1
147 } audio_unique_id_use_t;
148
149 /* Return the use of an audio_unique_id_t */
audio_unique_id_get_use(audio_unique_id_t id)150 static inline audio_unique_id_use_t audio_unique_id_get_use(audio_unique_id_t id)
151 {
152 return (audio_unique_id_use_t) (id & AUDIO_UNIQUE_ID_USE_MASK);
153 }
154
155 /* Reserved audio_unique_id_t values. FIXME: not a complete list. */
156 #define AUDIO_UNIQUE_ID_ALLOCATE AUDIO_SESSION_ALLOCATE
157
158 /* returns true if the audio session ID corresponds to a global
159 * effect sessions (e.g. OUTPUT_MIX, OUTPUT_STAGE, or DEVICE).
160 */
audio_is_global_session(audio_session_t session)161 static inline bool audio_is_global_session(audio_session_t session) {
162 return session <= AUDIO_SESSION_OUTPUT_MIX;
163 }
164
165 /* A channel mask per se only defines the presence or absence of a channel, not the order.
166 * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
167 *
168 * audio_channel_mask_t is an opaque type and its internal layout should not
169 * be assumed as it may change in the future.
170 * Instead, always use the functions declared in this header to examine.
171 *
172 * These are the current representations:
173 *
174 * AUDIO_CHANNEL_REPRESENTATION_POSITION
175 * is a channel mask representation for position assignment.
176 * Each low-order bit corresponds to the spatial position of a transducer (output),
177 * or interpretation of channel (input).
178 * The user of a channel mask needs to know the context of whether it is for output or input.
179 * The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion.
180 * It is not permitted for no bits to be set.
181 *
182 * AUDIO_CHANNEL_REPRESENTATION_INDEX
183 * is a channel mask representation for index assignment.
184 * Each low-order bit corresponds to a selected channel.
185 * There is no platform interpretation of the various bits.
186 * There is no concept of output or input.
187 * It is not permitted for no bits to be set.
188 *
189 * All other representations are reserved for future use.
190 *
191 * Warning: current representation distinguishes between input and output, but this will not the be
192 * case in future revisions of the platform. Wherever there is an ambiguity between input and output
193 * that is currently resolved by checking the channel mask, the implementer should look for ways to
194 * fix it with additional information outside of the mask.
195 */
196 typedef uint32_t audio_channel_mask_t;
197
198 /* log(2) of maximum number of representations, not part of public API */
199 #define AUDIO_CHANNEL_REPRESENTATION_LOG2 2
200
201 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_bits(audio_channel_mask_t channel)202 static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel)
203 {
204 return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1);
205 }
206
207 typedef uint32_t audio_channel_representation_t;
208
209 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_representation(audio_channel_mask_t channel)210 static inline audio_channel_representation_t audio_channel_mask_get_representation(
211 audio_channel_mask_t channel)
212 {
213 // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits
214 return (audio_channel_representation_t)
215 ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1));
216 }
217
218 /* Returns true if the channel mask is valid,
219 * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values.
220 * This function is unable to determine whether a channel mask for position assignment
221 * is invalid because an output mask has an invalid output bit set,
222 * or because an input mask has an invalid input bit set.
223 * All other APIs that take a channel mask assume that it is valid.
224 */
audio_channel_mask_is_valid(audio_channel_mask_t channel)225 static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel)
226 {
227 uint32_t bits = audio_channel_mask_get_bits(channel);
228 audio_channel_representation_t representation = audio_channel_mask_get_representation(channel);
229 switch (representation) {
230 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
231 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
232 break;
233 default:
234 bits = 0;
235 break;
236 }
237 return bits != 0;
238 }
239
240 /* Not part of public API */
audio_channel_mask_from_representation_and_bits(audio_channel_representation_t representation,uint32_t bits)241 static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits(
242 audio_channel_representation_t representation, uint32_t bits)
243 {
244 return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits);
245 }
246
247 /**
248 * Expresses the convention when stereo audio samples are stored interleaved
249 * in an array. This should improve readability by allowing code to use
250 * symbolic indices instead of hard-coded [0] and [1].
251 *
252 * For multi-channel beyond stereo, the platform convention is that channels
253 * are interleaved in order from least significant channel mask bit to most
254 * significant channel mask bit, with unused bits skipped. Any exceptions
255 * to this convention will be noted at the appropriate API.
256 */
257 enum {
258 AUDIO_INTERLEAVE_LEFT = 0,
259 AUDIO_INTERLEAVE_RIGHT = 1,
260 };
261
262 /* This enum is deprecated */
263 typedef enum {
264 AUDIO_IN_ACOUSTICS_NONE = 0,
265 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
266 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
267 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
268 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
269 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
270 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
271 } audio_in_acoustics_t;
272
273 typedef uint32_t audio_devices_t;
274 /**
275 * Stub audio output device. Used in policy configuration file on platforms without audio outputs.
276 * This alias value to AUDIO_DEVICE_OUT_DEFAULT is only used in the audio policy context.
277 */
278 #define AUDIO_DEVICE_OUT_STUB AUDIO_DEVICE_OUT_DEFAULT
279 /**
280 * Stub audio input device. Used in policy configuration file on platforms without audio inputs.
281 * This alias value to AUDIO_DEVICE_IN_DEFAULT is only used in the audio policy context.
282 */
283 #define AUDIO_DEVICE_IN_STUB AUDIO_DEVICE_IN_DEFAULT
284
285 /* Additional information about compressed streams offloaded to
286 * hardware playback
287 * The version and size fields must be initialized by the caller by using
288 * one of the constants defined here.
289 * Must be aligned to transmit as raw memory through Binder.
290 */
291 typedef struct {
292 uint16_t version; // version of the info structure
293 uint16_t size; // total size of the structure including version and size
294 uint32_t sample_rate; // sample rate in Hz
295 audio_channel_mask_t channel_mask; // channel mask
296 audio_format_t format; // audio format
297 audio_stream_type_t stream_type; // stream type
298 uint32_t bit_rate; // bit rate in bits per second
299 int64_t duration_us; // duration in microseconds, -1 if unknown
300 bool has_video; // true if stream is tied to a video stream
301 bool is_streaming; // true if streaming, false if local playback
302 uint32_t bit_width;
303 uint32_t offload_buffer_size; // offload fragment size
304 audio_usage_t usage;
305 } __attribute__((aligned(8))) audio_offload_info_t;
306
307 #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
308 ((((maj) & 0xff) << 8) | ((min) & 0xff))
309
310 #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
311 #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
312
313 static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
314 /* .version = */ AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
315 /* .size = */ sizeof(audio_offload_info_t),
316 /* .sample_rate = */ 0,
317 /* .channel_mask = */ 0,
318 /* .format = */ AUDIO_FORMAT_DEFAULT,
319 /* .stream_type = */ AUDIO_STREAM_VOICE_CALL,
320 /* .bit_rate = */ 0,
321 /* .duration_us = */ 0,
322 /* .has_video = */ false,
323 /* .is_streaming = */ false,
324 /* .bit_width = */ 16,
325 /* .offload_buffer_size = */ 0,
326 /* .usage = */ AUDIO_USAGE_UNKNOWN
327 };
328
329 /* common audio stream configuration parameters
330 * You should memset() the entire structure to zero before use to
331 * ensure forward compatibility
332 * Must be aligned to transmit as raw memory through Binder.
333 */
334 struct __attribute__((aligned(8))) audio_config {
335 uint32_t sample_rate;
336 audio_channel_mask_t channel_mask;
337 audio_format_t format;
338 audio_offload_info_t offload_info;
339 uint32_t frame_count;
340 };
341 typedef struct audio_config audio_config_t;
342
343 static const audio_config_t AUDIO_CONFIG_INITIALIZER = {
344 /* .sample_rate = */ 0,
345 /* .channel_mask = */ AUDIO_CHANNEL_NONE,
346 /* .format = */ AUDIO_FORMAT_DEFAULT,
347 /* .offload_info = */ {
348 /* .version = */ AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
349 /* .size = */ sizeof(audio_offload_info_t),
350 /* .sample_rate = */ 0,
351 /* .channel_mask = */ 0,
352 /* .format = */ AUDIO_FORMAT_DEFAULT,
353 /* .stream_type = */ AUDIO_STREAM_VOICE_CALL,
354 /* .bit_rate = */ 0,
355 /* .duration_us = */ 0,
356 /* .has_video = */ false,
357 /* .is_streaming = */ false,
358 /* .bit_width = */ 16,
359 /* .offload_buffer_size = */ 0,
360 /* .usage = */ AUDIO_USAGE_UNKNOWN
361 },
362 /* .frame_count = */ 0,
363 };
364
365 struct audio_config_base {
366 uint32_t sample_rate;
367 audio_channel_mask_t channel_mask;
368 audio_format_t format;
369 };
370
371 typedef struct audio_config_base audio_config_base_t;
372
373 static const audio_config_base_t AUDIO_CONFIG_BASE_INITIALIZER = {
374 /* .sample_rate = */ 0,
375 /* .channel_mask = */ AUDIO_CHANNEL_NONE,
376 /* .format = */ AUDIO_FORMAT_DEFAULT
377 };
378
379 /* audio hw module handle functions or structures referencing a module */
380 typedef int audio_module_handle_t;
381
382 /******************************
383 * Volume control
384 *****************************/
385
386 /** 3 dB headroom are allowed on float samples (3db = 10^(3/20) = 1.412538).
387 * See: https://developer.android.com/reference/android/media/AudioTrack.html#write(float[], int, int, int)
388 */
389 #define FLOAT_NOMINAL_RANGE_HEADROOM 1.412538
390
391 /* If the audio hardware supports gain control on some audio paths,
392 * the platform can expose them in the audio_policy.conf file. The audio HAL
393 * will then implement gain control functions that will use the following data
394 * structures. */
395
396 typedef uint32_t audio_gain_mode_t;
397
398
399 /* An audio_gain struct is a representation of a gain stage.
400 * A gain stage is always attached to an audio port. */
401 struct audio_gain {
402 audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */
403 audio_channel_mask_t channel_mask; /* channels which gain an be controlled.
404 N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
405 int min_value; /* minimum gain value in millibels */
406 int max_value; /* maximum gain value in millibels */
407 int default_value; /* default gain value in millibels */
408 unsigned int step_value; /* gain step in millibels */
409 unsigned int min_ramp_ms; /* minimum ramp duration in ms */
410 unsigned int max_ramp_ms; /* maximum ramp duration in ms */
411 };
412
413 /* The gain configuration structure is used to get or set the gain values of a
414 * given port */
415 struct audio_gain_config {
416 int index; /* index of the corresponding audio_gain in the
417 audio_port gains[] table */
418 audio_gain_mode_t mode; /* mode requested for this command */
419 audio_channel_mask_t channel_mask; /* channels which gain value follows.
420 N/A in joint mode */
421
422 // note this "8" is not FCC_8, so it won't need to be changed for > 8 channels
423 int values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
424 for each channel ordered from LSb to MSb in
425 channel mask. The number of values is 1 in joint
426 mode or __builtin_popcount(channel_mask) */
427 unsigned int ramp_duration_ms; /* ramp duration in ms */
428 };
429
430 /******************************
431 * Routing control
432 *****************************/
433
434 /* Types defined here are used to describe an audio source or sink at internal
435 * framework interfaces (audio policy, patch panel) or at the audio HAL.
436 * Sink and sources are grouped in a concept of “audio port” representing an
437 * audio end point at the edge of the system managed by the module exposing
438 * the interface. */
439
440 /* Each port has a unique ID or handle allocated by policy manager */
441 typedef int audio_port_handle_t;
442
443 /* the maximum length for the human-readable device name */
444 #define AUDIO_PORT_MAX_NAME_LEN 128
445
446 /* a union to store port configuration flags. Declared as a type so can be reused
447 in framework code */
448 union audio_io_flags {
449 audio_input_flags_t input;
450 audio_output_flags_t output;
451 };
452
453 /* maximum audio device address length */
454 #define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
455
456 /* extension for audio port configuration structure when the audio port is a
457 * hardware device */
458 struct audio_port_config_device_ext {
459 audio_module_handle_t hw_module; /* module the device is attached to */
460 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
461 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
462 };
463
464 /* extension for audio port configuration structure when the audio port is a
465 * sub mix */
466 struct audio_port_config_mix_ext {
467 audio_module_handle_t hw_module; /* module the stream is attached to */
468 audio_io_handle_t handle; /* I/O handle of the input/output stream */
469 union {
470 //TODO: change use case for output streams: use strategy and mixer attributes
471 audio_stream_type_t stream;
472 audio_source_t source;
473 } usecase;
474 };
475
476 /* extension for audio port configuration structure when the audio port is an
477 * audio session */
478 struct audio_port_config_session_ext {
479 audio_session_t session; /* audio session */
480 };
481
482 /* audio port configuration structure used to specify a particular configuration of
483 * an audio port */
484 struct audio_port_config {
485 audio_port_handle_t id; /* port unique ID */
486 audio_port_role_t role; /* sink or source */
487 audio_port_type_t type; /* device, mix ... */
488 unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */
489 unsigned int sample_rate; /* sampling rate in Hz */
490 audio_channel_mask_t channel_mask; /* channel mask if applicable */
491 audio_format_t format; /* format if applicable */
492 struct audio_gain_config gain; /* gain to apply if applicable */
493 #ifndef AUDIO_NO_SYSTEM_DECLARATIONS
494 union audio_io_flags flags; /* framework only: HW_AV_SYNC, DIRECT, ... */
495 #endif
496 union {
497 struct audio_port_config_device_ext device; /* device specific info */
498 struct audio_port_config_mix_ext mix; /* mix specific info */
499 struct audio_port_config_session_ext session; /* session specific info */
500 } ext;
501 };
502
503
504 /* max number of sampling rates in audio port */
505 #define AUDIO_PORT_MAX_SAMPLING_RATES 32
506 /* max number of channel masks in audio port */
507 #define AUDIO_PORT_MAX_CHANNEL_MASKS 32
508 /* max number of audio formats in audio port */
509 #define AUDIO_PORT_MAX_FORMATS 32
510 /* max number of gain controls in audio port */
511 #define AUDIO_PORT_MAX_GAINS 16
512
513 /* extension for audio port structure when the audio port is a hardware device */
514 struct audio_port_device_ext {
515 audio_module_handle_t hw_module; /* module the device is attached to */
516 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
517 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
518 };
519
520 /* extension for audio port structure when the audio port is a sub mix */
521 struct audio_port_mix_ext {
522 audio_module_handle_t hw_module; /* module the stream is attached to */
523 audio_io_handle_t handle; /* I/O handle of the input.output stream */
524 audio_mix_latency_class_t latency_class; /* latency class */
525 // other attributes: routing strategies
526 };
527
528 /* extension for audio port structure when the audio port is an audio session */
529 struct audio_port_session_ext {
530 audio_session_t session; /* audio session */
531 };
532
533 struct audio_port {
534 audio_port_handle_t id; /* port unique ID */
535 audio_port_role_t role; /* sink or source */
536 audio_port_type_t type; /* device, mix ... */
537 char name[AUDIO_PORT_MAX_NAME_LEN];
538 unsigned int num_sample_rates; /* number of sampling rates in following array */
539 unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
540 unsigned int num_channel_masks; /* number of channel masks in following array */
541 audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
542 unsigned int num_formats; /* number of formats in following array */
543 audio_format_t formats[AUDIO_PORT_MAX_FORMATS];
544 unsigned int num_gains; /* number of gains in following array */
545 struct audio_gain gains[AUDIO_PORT_MAX_GAINS];
546 struct audio_port_config active_config; /* current audio port configuration */
547 union {
548 struct audio_port_device_ext device;
549 struct audio_port_mix_ext mix;
550 struct audio_port_session_ext session;
551 } ext;
552 };
553
554 /* An audio patch represents a connection between one or more source ports and
555 * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
556 * applications via framework APIs.
557 * Each patch is identified by a handle at the interface used to create that patch. For instance,
558 * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
559 * This handle is unique to a given audio HAL hardware module.
560 * But the same patch receives another system wide unique handle allocated by the framework.
561 * This unique handle is used for all transactions inside the framework.
562 */
563 typedef int audio_patch_handle_t;
564
565 #define AUDIO_PATCH_PORTS_MAX 16
566
567 struct audio_patch {
568 audio_patch_handle_t id; /* patch unique ID */
569 unsigned int num_sources; /* number of sources in following array */
570 struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
571 unsigned int num_sinks; /* number of sinks in following array */
572 struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
573 };
574
575
576
577 /* a HW synchronization source returned by the audio HAL */
578 typedef uint32_t audio_hw_sync_t;
579
580 /* an invalid HW synchronization source indicating an error */
581 #define AUDIO_HW_SYNC_INVALID 0
582
583 /** @TODO export from .hal */
584 typedef enum {
585 NONE = 0x0,
586 /**
587 * Only set this flag if applications can access the audio buffer memory
588 * shared with the backend (usually DSP) _without_ security issue.
589 *
590 * Setting this flag also implies that Binder will allow passing the shared memory FD
591 * to applications.
592 *
593 * That usually implies that the kernel will prevent any access to the
594 * memory surrounding the audio buffer as it could lead to a security breach.
595 *
596 * For example, a "/dev/snd/" file descriptor generally is not shareable,
597 * but an "anon_inode:dmabuffer" file descriptor is shareable.
598 * See also Linux kernel's dma_buf.
599 *
600 * This flag is required to support AAudio exclusive mode:
601 * See: https://source.android.com/devices/audio/aaudio
602 */
603 AUDIO_MMAP_APPLICATION_SHAREABLE = 0x1,
604 } audio_mmap_buffer_flag;
605
606 /**
607 * Mmap buffer descriptor returned by audio_stream->create_mmap_buffer().
608 * note\ Used by streams opened in mmap mode.
609 */
610 struct audio_mmap_buffer_info {
611 void* shared_memory_address; /**< base address of mmap memory buffer.
612 For use by local process only */
613 int32_t shared_memory_fd; /**< FD for mmap memory buffer */
614 int32_t buffer_size_frames; /**< total buffer size in frames */
615 int32_t burst_size_frames; /**< transfer size granularity in frames */
616 audio_mmap_buffer_flag flags; /**< Attributes describing the buffer. */
617 };
618
619 /**
620 * Mmap buffer read/write position returned by audio_stream->get_mmap_position().
621 * note\ Used by streams opened in mmap mode.
622 */
623 struct audio_mmap_position {
624 int64_t time_nanoseconds; /**< timestamp in ns, CLOCK_MONOTONIC */
625 int32_t position_frames; /**< increasing 32 bit frame count reset when stream->stop()
626 is called */
627 };
628
629 /** Metadata of a playback track for an in stream. */
630 typedef struct playback_track_metadata {
631 audio_usage_t usage;
632 audio_content_type_t content_type;
633 float gain; // Normalized linear volume. 0=silence, 1=0dbfs...
634 } playback_track_metadata_t;
635
636 /** Metadata of a record track for an out stream. */
637 typedef struct record_track_metadata {
638 audio_source_t source;
639 float gain; // Normalized linear volume. 0=silence, 1=0dbfs...
640 // For record tracks originating from a software patch, the dest_device
641 // fields provide information about the downstream device.
642 audio_devices_t dest_device;
643 char dest_device_address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
644 } record_track_metadata_t;
645
646
647 /******************************
648 * Helper functions
649 *****************************/
650
651 // see also: std::binary_search
652 // search range [left, right)
audio_binary_search_uint_array(const uint32_t audio_array[],size_t left,size_t right,uint32_t target)653 static inline bool audio_binary_search_uint_array(const uint32_t audio_array[], size_t left,
654 size_t right, uint32_t target)
655 {
656 if (right <= left || target < audio_array[left] || target > audio_array[right - 1]) {
657 return false;
658 }
659
660 while (left < right) {
661 const size_t mid = left + (right - left) / 2;
662 if (audio_array[mid] == target) {
663 return true;
664 } else if (audio_array[mid] < target) {
665 left = mid + 1;
666 } else {
667 right = mid;
668 }
669 }
670 return false;
671 }
672
audio_is_output_device(audio_devices_t device)673 static inline bool audio_is_output_device(audio_devices_t device)
674 {
675 switch (device) {
676 case AUDIO_DEVICE_OUT_SPEAKER_SAFE:
677 case AUDIO_DEVICE_OUT_SPEAKER:
678 case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
679 case AUDIO_DEVICE_OUT_WIRED_HEADSET:
680 case AUDIO_DEVICE_OUT_USB_HEADSET:
681 case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
682 case AUDIO_DEVICE_OUT_EARPIECE:
683 case AUDIO_DEVICE_OUT_REMOTE_SUBMIX:
684 case AUDIO_DEVICE_OUT_TELEPHONY_TX:
685 // Search the most common devices first as these devices are most likely
686 // to be used. Put the most common devices in the order of the likelihood
687 // of usage to get a quick return.
688 return true;
689 default:
690 // Binary seach all devices if the device is not a most common device.
691 return audio_binary_search_uint_array(
692 AUDIO_DEVICE_OUT_ALL_ARRAY, 0 /*left*/, AUDIO_DEVICE_OUT_CNT, device);
693 }
694 }
695
audio_is_input_device(audio_devices_t device)696 static inline bool audio_is_input_device(audio_devices_t device)
697 {
698 switch (device) {
699 case AUDIO_DEVICE_IN_BUILTIN_MIC:
700 case AUDIO_DEVICE_IN_BACK_MIC:
701 case AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET:
702 case AUDIO_DEVICE_IN_WIRED_HEADSET:
703 case AUDIO_DEVICE_IN_USB_HEADSET:
704 case AUDIO_DEVICE_IN_REMOTE_SUBMIX:
705 case AUDIO_DEVICE_IN_TELEPHONY_RX:
706 // Search the most common devices first as these devices are most likely
707 // to be used. Put the most common devices in the order of the likelihood
708 // of usage to get a quick return.
709 return true;
710 default:
711 // Binary seach all devices if the device is not a most common device.
712 return audio_binary_search_uint_array(
713 AUDIO_DEVICE_IN_ALL_ARRAY, 0 /*left*/, AUDIO_DEVICE_IN_CNT, device);
714 }
715 }
716
717 // TODO: this function expects a combination of audio device types as parameter. It should
718 // be deprecated as audio device types should not be use as bit mask any more since R.
audio_is_output_devices(audio_devices_t device)719 static inline bool audio_is_output_devices(audio_devices_t device)
720 {
721 return (device & AUDIO_DEVICE_BIT_IN) == 0;
722 }
723
audio_is_a2dp_in_device(audio_devices_t device)724 static inline bool audio_is_a2dp_in_device(audio_devices_t device)
725 {
726 return device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP;
727 }
728
audio_is_a2dp_out_device(audio_devices_t device)729 static inline bool audio_is_a2dp_out_device(audio_devices_t device)
730 {
731 return audio_binary_search_uint_array(
732 AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY, 0 /*left*/, AUDIO_DEVICE_OUT_A2DP_CNT, device);
733 }
734
735 // Deprecated - use audio_is_a2dp_out_device() instead
audio_is_a2dp_device(audio_devices_t device)736 static inline bool audio_is_a2dp_device(audio_devices_t device)
737 {
738 return audio_is_a2dp_out_device(device);
739 }
740
audio_is_bluetooth_out_sco_device(audio_devices_t device)741 static inline bool audio_is_bluetooth_out_sco_device(audio_devices_t device)
742 {
743 return audio_binary_search_uint_array(
744 AUDIO_DEVICE_OUT_ALL_SCO_ARRAY, 0 /*left*/, AUDIO_DEVICE_OUT_SCO_CNT, device);
745 }
746
audio_is_bluetooth_in_sco_device(audio_devices_t device)747 static inline bool audio_is_bluetooth_in_sco_device(audio_devices_t device)
748 {
749 return audio_binary_search_uint_array(
750 AUDIO_DEVICE_IN_ALL_SCO_ARRAY, 0 /*left*/, AUDIO_DEVICE_IN_SCO_CNT, device);
751 }
752
audio_is_bluetooth_sco_device(audio_devices_t device)753 static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
754 {
755 return audio_is_bluetooth_out_sco_device(device) ||
756 audio_is_bluetooth_in_sco_device(device);
757 }
758
audio_is_hearing_aid_out_device(audio_devices_t device)759 static inline bool audio_is_hearing_aid_out_device(audio_devices_t device)
760 {
761 return device == AUDIO_DEVICE_OUT_HEARING_AID;
762 }
763
audio_is_usb_out_device(audio_devices_t device)764 static inline bool audio_is_usb_out_device(audio_devices_t device)
765 {
766 return audio_binary_search_uint_array(
767 AUDIO_DEVICE_OUT_ALL_USB_ARRAY, 0 /*left*/, AUDIO_DEVICE_OUT_USB_CNT, device);
768 }
769
audio_is_usb_in_device(audio_devices_t device)770 static inline bool audio_is_usb_in_device(audio_devices_t device)
771 {
772 return audio_binary_search_uint_array(
773 AUDIO_DEVICE_IN_ALL_USB_ARRAY, 0 /*left*/, AUDIO_DEVICE_IN_USB_CNT, device);
774 }
775
776 /* OBSOLETE - use audio_is_usb_out_device() instead. */
audio_is_usb_device(audio_devices_t device)777 static inline bool audio_is_usb_device(audio_devices_t device)
778 {
779 return audio_is_usb_out_device(device);
780 }
781
audio_is_remote_submix_device(audio_devices_t device)782 static inline bool audio_is_remote_submix_device(audio_devices_t device)
783 {
784 return device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
785 device == AUDIO_DEVICE_IN_REMOTE_SUBMIX;
786 }
787
audio_is_digital_out_device(audio_devices_t device)788 static inline bool audio_is_digital_out_device(audio_devices_t device)
789 {
790 return audio_binary_search_uint_array(
791 AUDIO_DEVICE_OUT_ALL_DIGITAL_ARRAY, 0 /*left*/, AUDIO_DEVICE_OUT_DIGITAL_CNT, device);
792 }
793
audio_is_digital_in_device(audio_devices_t device)794 static inline bool audio_is_digital_in_device(audio_devices_t device)
795 {
796 return audio_binary_search_uint_array(
797 AUDIO_DEVICE_IN_ALL_DIGITAL_ARRAY, 0 /*left*/, AUDIO_DEVICE_IN_DIGITAL_CNT, device);
798 }
799
audio_device_is_digital(audio_devices_t device)800 static inline bool audio_device_is_digital(audio_devices_t device) {
801 return audio_is_digital_in_device(device) ||
802 audio_is_digital_out_device(device);
803 }
804
805 /* Returns true if:
806 * representation is valid, and
807 * there is at least one channel bit set which _could_ correspond to an input channel, and
808 * there are no channel bits set which could _not_ correspond to an input channel.
809 * Otherwise returns false.
810 */
audio_is_input_channel(audio_channel_mask_t channel)811 static inline bool audio_is_input_channel(audio_channel_mask_t channel)
812 {
813 uint32_t bits = audio_channel_mask_get_bits(channel);
814 switch (audio_channel_mask_get_representation(channel)) {
815 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
816 if (bits & ~AUDIO_CHANNEL_IN_ALL) {
817 bits = 0;
818 }
819 FALLTHROUGH_INTENDED;
820 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
821 return bits != 0;
822 default:
823 return false;
824 }
825 }
826
827 /* Returns true if:
828 * representation is valid, and
829 * there is at least one channel bit set which _could_ correspond to an output channel, and
830 * there are no channel bits set which could _not_ correspond to an output channel.
831 * Otherwise returns false.
832 */
audio_is_output_channel(audio_channel_mask_t channel)833 static inline bool audio_is_output_channel(audio_channel_mask_t channel)
834 {
835 uint32_t bits = audio_channel_mask_get_bits(channel);
836 switch (audio_channel_mask_get_representation(channel)) {
837 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
838 if (bits & ~AUDIO_CHANNEL_OUT_ALL) {
839 bits = 0;
840 }
841 FALLTHROUGH_INTENDED;
842 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
843 return bits != 0;
844 default:
845 return false;
846 }
847 }
848
849 /* Returns the number of channels from an input channel mask,
850 * used in the context of audio input or recording.
851 * If a channel bit is set which could _not_ correspond to an input channel,
852 * it is excluded from the count.
853 * Returns zero if the representation is invalid.
854 */
audio_channel_count_from_in_mask(audio_channel_mask_t channel)855 static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
856 {
857 uint32_t bits = audio_channel_mask_get_bits(channel);
858 switch (audio_channel_mask_get_representation(channel)) {
859 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
860 // TODO: We can now merge with from_out_mask and remove anding
861 bits &= AUDIO_CHANNEL_IN_ALL;
862 FALLTHROUGH_INTENDED;
863 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
864 return __builtin_popcount(bits);
865 default:
866 return 0;
867 }
868 }
869
870 /* Returns the number of channels from an output channel mask,
871 * used in the context of audio output or playback.
872 * If a channel bit is set which could _not_ correspond to an output channel,
873 * it is excluded from the count.
874 * Returns zero if the representation is invalid.
875 */
audio_channel_count_from_out_mask(audio_channel_mask_t channel)876 static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
877 {
878 uint32_t bits = audio_channel_mask_get_bits(channel);
879 switch (audio_channel_mask_get_representation(channel)) {
880 case AUDIO_CHANNEL_REPRESENTATION_POSITION:
881 // TODO: We can now merge with from_in_mask and remove anding
882 bits &= AUDIO_CHANNEL_OUT_ALL;
883 FALLTHROUGH_INTENDED;
884 case AUDIO_CHANNEL_REPRESENTATION_INDEX:
885 return __builtin_popcount(bits);
886 default:
887 return 0;
888 }
889 }
890
891 /* Derive a channel mask for index assignment from a channel count.
892 * Returns the matching channel mask,
893 * or AUDIO_CHANNEL_NONE if the channel count is zero,
894 * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX.
895 */
audio_channel_mask_for_index_assignment_from_count(uint32_t channel_count)896 static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count(
897 uint32_t channel_count)
898 {
899 if (channel_count == 0) {
900 return AUDIO_CHANNEL_NONE;
901 }
902 if (channel_count > AUDIO_CHANNEL_COUNT_MAX) {
903 return AUDIO_CHANNEL_INVALID;
904 }
905 uint32_t bits = (1 << channel_count) - 1;
906 return audio_channel_mask_from_representation_and_bits(
907 AUDIO_CHANNEL_REPRESENTATION_INDEX, bits);
908 }
909
910 /* Derive an output channel mask for position assignment from a channel count.
911 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
912 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
913 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
914 * for continuity with stereo.
915 * Returns the matching channel mask,
916 * or AUDIO_CHANNEL_NONE if the channel count is zero,
917 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
918 * configurations for which a default output channel mask is defined.
919 */
audio_channel_out_mask_from_count(uint32_t channel_count)920 static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
921 {
922 uint32_t bits;
923 switch (channel_count) {
924 case 0:
925 return AUDIO_CHANNEL_NONE;
926 case 1:
927 bits = AUDIO_CHANNEL_OUT_MONO;
928 break;
929 case 2:
930 bits = AUDIO_CHANNEL_OUT_STEREO;
931 break;
932 case 3: // 2.1
933 bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_LOW_FREQUENCY;
934 break;
935 case 4: // 4.0
936 bits = AUDIO_CHANNEL_OUT_QUAD;
937 break;
938 case 5: // 5.0
939 bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER;
940 break;
941 case 6: // 5.1
942 bits = AUDIO_CHANNEL_OUT_5POINT1;
943 break;
944 case 7: // 6.1
945 bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER;
946 break;
947 case 8:
948 bits = AUDIO_CHANNEL_OUT_7POINT1;
949 break;
950 // FIXME FCC_8
951 default:
952 return AUDIO_CHANNEL_INVALID;
953 }
954 return audio_channel_mask_from_representation_and_bits(
955 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
956 }
957
958 /* Derive a default input channel mask from a channel count.
959 * Assumes a position mask for mono and stereo, or an index mask for channel counts > 2.
960 * Returns the matching channel mask,
961 * or AUDIO_CHANNEL_NONE if the channel count is zero,
962 * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
963 * configurations for which a default input channel mask is defined.
964 */
audio_channel_in_mask_from_count(uint32_t channel_count)965 static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
966 {
967 uint32_t bits;
968 switch (channel_count) {
969 case 0:
970 return AUDIO_CHANNEL_NONE;
971 case 1:
972 bits = AUDIO_CHANNEL_IN_MONO;
973 break;
974 case 2:
975 bits = AUDIO_CHANNEL_IN_STEREO;
976 break;
977 case 3:
978 case 4:
979 case 5:
980 case 6:
981 case 7:
982 case 8:
983 // FIXME FCC_8
984 return audio_channel_mask_for_index_assignment_from_count(channel_count);
985 default:
986 return AUDIO_CHANNEL_INVALID;
987 }
988 return audio_channel_mask_from_representation_and_bits(
989 AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
990 }
991
992 /* Derive a default haptic channel mask from a channel count.
993 */
haptic_channel_mask_from_count(uint32_t channel_count)994 static inline audio_channel_mask_t haptic_channel_mask_from_count(uint32_t channel_count)
995 {
996 switch(channel_count) {
997 case 0:
998 return AUDIO_CHANNEL_NONE;
999 case 1:
1000 return AUDIO_CHANNEL_OUT_HAPTIC_A;
1001 case 2:
1002 return AUDIO_CHANNEL_OUT_HAPTIC_AB;
1003 default:
1004 return AUDIO_CHANNEL_INVALID;
1005 }
1006 }
1007
audio_channel_mask_in_to_out(audio_channel_mask_t in)1008 static inline audio_channel_mask_t audio_channel_mask_in_to_out(audio_channel_mask_t in)
1009 {
1010 switch (in) {
1011 case AUDIO_CHANNEL_IN_MONO:
1012 return AUDIO_CHANNEL_OUT_MONO;
1013 case AUDIO_CHANNEL_IN_STEREO:
1014 return AUDIO_CHANNEL_OUT_STEREO;
1015 case AUDIO_CHANNEL_IN_5POINT1:
1016 return AUDIO_CHANNEL_OUT_5POINT1;
1017 case AUDIO_CHANNEL_IN_3POINT1POINT2:
1018 return AUDIO_CHANNEL_OUT_3POINT1POINT2;
1019 case AUDIO_CHANNEL_IN_3POINT0POINT2:
1020 return AUDIO_CHANNEL_OUT_3POINT0POINT2;
1021 case AUDIO_CHANNEL_IN_2POINT1POINT2:
1022 return AUDIO_CHANNEL_OUT_2POINT1POINT2;
1023 case AUDIO_CHANNEL_IN_2POINT0POINT2:
1024 return AUDIO_CHANNEL_OUT_2POINT0POINT2;
1025 default:
1026 return AUDIO_CHANNEL_INVALID;
1027 }
1028 }
1029
audio_channel_mask_out_to_in(audio_channel_mask_t out)1030 static inline audio_channel_mask_t audio_channel_mask_out_to_in(audio_channel_mask_t out)
1031 {
1032 switch (out) {
1033 case AUDIO_CHANNEL_OUT_MONO:
1034 return AUDIO_CHANNEL_IN_MONO;
1035 case AUDIO_CHANNEL_OUT_STEREO:
1036 return AUDIO_CHANNEL_IN_STEREO;
1037 case AUDIO_CHANNEL_OUT_5POINT1:
1038 return AUDIO_CHANNEL_IN_5POINT1;
1039 case AUDIO_CHANNEL_OUT_3POINT1POINT2:
1040 return AUDIO_CHANNEL_IN_3POINT1POINT2;
1041 case AUDIO_CHANNEL_OUT_3POINT0POINT2:
1042 return AUDIO_CHANNEL_IN_3POINT0POINT2;
1043 case AUDIO_CHANNEL_OUT_2POINT1POINT2:
1044 return AUDIO_CHANNEL_IN_2POINT1POINT2;
1045 case AUDIO_CHANNEL_OUT_2POINT0POINT2:
1046 return AUDIO_CHANNEL_IN_2POINT0POINT2;
1047 default:
1048 return AUDIO_CHANNEL_INVALID;
1049 }
1050 }
1051
audio_channel_position_mask_is_out_canonical(audio_channel_mask_t channelMask)1052 static inline bool audio_channel_position_mask_is_out_canonical(audio_channel_mask_t channelMask)
1053 {
1054 if (audio_channel_mask_get_representation(channelMask)
1055 != AUDIO_CHANNEL_REPRESENTATION_POSITION) {
1056 return false;
1057 }
1058 const uint32_t audioChannelCount = audio_channel_count_from_out_mask(
1059 channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL);
1060 const uint32_t hapticChannelCount = audio_channel_count_from_out_mask(
1061 channelMask & AUDIO_CHANNEL_HAPTIC_ALL);
1062 return channelMask == (audio_channel_out_mask_from_count(audioChannelCount) |
1063 haptic_channel_mask_from_count(hapticChannelCount));
1064 }
1065
audio_is_valid_format(audio_format_t format)1066 static inline bool audio_is_valid_format(audio_format_t format)
1067 {
1068 switch (format & AUDIO_FORMAT_MAIN_MASK) {
1069 case AUDIO_FORMAT_PCM:
1070 switch (format) {
1071 case AUDIO_FORMAT_PCM_16_BIT:
1072 case AUDIO_FORMAT_PCM_8_BIT:
1073 case AUDIO_FORMAT_PCM_32_BIT:
1074 case AUDIO_FORMAT_PCM_8_24_BIT:
1075 case AUDIO_FORMAT_PCM_FLOAT:
1076 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1077 return true;
1078 default:
1079 return false;
1080 }
1081 /* not reached */
1082 case AUDIO_FORMAT_MP3:
1083 case AUDIO_FORMAT_AMR_NB:
1084 case AUDIO_FORMAT_AMR_WB:
1085 return true;
1086 case AUDIO_FORMAT_AAC:
1087 switch (format) {
1088 case AUDIO_FORMAT_AAC:
1089 case AUDIO_FORMAT_AAC_MAIN:
1090 case AUDIO_FORMAT_AAC_LC:
1091 case AUDIO_FORMAT_AAC_SSR:
1092 case AUDIO_FORMAT_AAC_LTP:
1093 case AUDIO_FORMAT_AAC_HE_V1:
1094 case AUDIO_FORMAT_AAC_SCALABLE:
1095 case AUDIO_FORMAT_AAC_ERLC:
1096 case AUDIO_FORMAT_AAC_LD:
1097 case AUDIO_FORMAT_AAC_HE_V2:
1098 case AUDIO_FORMAT_AAC_ELD:
1099 case AUDIO_FORMAT_AAC_XHE:
1100 return true;
1101 default:
1102 return false;
1103 }
1104 /* not reached */
1105 case AUDIO_FORMAT_HE_AAC_V1:
1106 case AUDIO_FORMAT_HE_AAC_V2:
1107 case AUDIO_FORMAT_VORBIS:
1108 case AUDIO_FORMAT_OPUS:
1109 case AUDIO_FORMAT_AC3:
1110 return true;
1111 case AUDIO_FORMAT_E_AC3:
1112 switch (format) {
1113 case AUDIO_FORMAT_E_AC3:
1114 case AUDIO_FORMAT_E_AC3_JOC:
1115 return true;
1116 default:
1117 return false;
1118 }
1119 /* not reached */
1120 case AUDIO_FORMAT_DTS:
1121 case AUDIO_FORMAT_DTS_HD:
1122 case AUDIO_FORMAT_IEC61937:
1123 case AUDIO_FORMAT_DOLBY_TRUEHD:
1124 case AUDIO_FORMAT_EVRC:
1125 case AUDIO_FORMAT_EVRCB:
1126 case AUDIO_FORMAT_EVRCWB:
1127 case AUDIO_FORMAT_EVRCNW:
1128 case AUDIO_FORMAT_AAC_ADIF:
1129 case AUDIO_FORMAT_WMA:
1130 case AUDIO_FORMAT_WMA_PRO:
1131 case AUDIO_FORMAT_AMR_WB_PLUS:
1132 case AUDIO_FORMAT_MP2:
1133 case AUDIO_FORMAT_QCELP:
1134 case AUDIO_FORMAT_DSD:
1135 case AUDIO_FORMAT_FLAC:
1136 case AUDIO_FORMAT_ALAC:
1137 case AUDIO_FORMAT_APE:
1138 return true;
1139 case AUDIO_FORMAT_AAC_ADTS:
1140 switch (format) {
1141 case AUDIO_FORMAT_AAC_ADTS:
1142 case AUDIO_FORMAT_AAC_ADTS_MAIN:
1143 case AUDIO_FORMAT_AAC_ADTS_LC:
1144 case AUDIO_FORMAT_AAC_ADTS_SSR:
1145 case AUDIO_FORMAT_AAC_ADTS_LTP:
1146 case AUDIO_FORMAT_AAC_ADTS_HE_V1:
1147 case AUDIO_FORMAT_AAC_ADTS_SCALABLE:
1148 case AUDIO_FORMAT_AAC_ADTS_ERLC:
1149 case AUDIO_FORMAT_AAC_ADTS_LD:
1150 case AUDIO_FORMAT_AAC_ADTS_HE_V2:
1151 case AUDIO_FORMAT_AAC_ADTS_ELD:
1152 case AUDIO_FORMAT_AAC_ADTS_XHE:
1153 return true;
1154 default:
1155 return false;
1156 }
1157 /* not reached */
1158 case AUDIO_FORMAT_SBC:
1159 case AUDIO_FORMAT_APTX:
1160 case AUDIO_FORMAT_APTX_HD:
1161 case AUDIO_FORMAT_AC4:
1162 case AUDIO_FORMAT_LDAC:
1163 return true;
1164 case AUDIO_FORMAT_MAT:
1165 switch (format) {
1166 case AUDIO_FORMAT_MAT:
1167 case AUDIO_FORMAT_MAT_1_0:
1168 case AUDIO_FORMAT_MAT_2_0:
1169 case AUDIO_FORMAT_MAT_2_1:
1170 return true;
1171 default:
1172 return false;
1173 }
1174 /* not reached */
1175 case AUDIO_FORMAT_AAC_LATM:
1176 switch (format) {
1177 case AUDIO_FORMAT_AAC_LATM:
1178 case AUDIO_FORMAT_AAC_LATM_LC:
1179 case AUDIO_FORMAT_AAC_LATM_HE_V1:
1180 case AUDIO_FORMAT_AAC_LATM_HE_V2:
1181 return true;
1182 default:
1183 return false;
1184 }
1185 /* not reached */
1186 case AUDIO_FORMAT_CELT:
1187 case AUDIO_FORMAT_APTX_ADAPTIVE:
1188 case AUDIO_FORMAT_LHDC:
1189 case AUDIO_FORMAT_LHDC_LL:
1190 case AUDIO_FORMAT_APTX_TWSP:
1191 return true;
1192 default:
1193 return false;
1194 }
1195 }
1196
audio_is_iec61937_compatible(audio_format_t format)1197 static inline bool audio_is_iec61937_compatible(audio_format_t format)
1198 {
1199 switch (format) {
1200 case AUDIO_FORMAT_AC3: // IEC 61937-3:2017
1201 case AUDIO_FORMAT_AC4: // IEC 61937-14:2017
1202 case AUDIO_FORMAT_E_AC3: // IEC 61937-3:2017
1203 case AUDIO_FORMAT_E_AC3_JOC: // IEC 61937-3:2017
1204 case AUDIO_FORMAT_MAT: // IEC 61937-9:2017
1205 case AUDIO_FORMAT_MAT_1_0: // IEC 61937-9:2017
1206 case AUDIO_FORMAT_MAT_2_0: // IEC 61937-9:2017
1207 case AUDIO_FORMAT_MAT_2_1: // IEC 61937-9:2017
1208 return true;
1209 default:
1210 return false;
1211 }
1212 }
1213
1214 /**
1215 * Extract the primary format, eg. PCM, AC3, etc.
1216 */
audio_get_main_format(audio_format_t format)1217 static inline audio_format_t audio_get_main_format(audio_format_t format)
1218 {
1219 return (audio_format_t)(format & AUDIO_FORMAT_MAIN_MASK);
1220 }
1221
1222 /**
1223 * Is the data plain PCM samples that can be scaled and mixed?
1224 */
audio_is_linear_pcm(audio_format_t format)1225 static inline bool audio_is_linear_pcm(audio_format_t format)
1226 {
1227 return (audio_get_main_format(format) == AUDIO_FORMAT_PCM);
1228 }
1229
1230 /**
1231 * For this format, is the number of PCM audio frames directly proportional
1232 * to the number of data bytes?
1233 *
1234 * In other words, is the format transported as PCM audio samples,
1235 * but not necessarily scalable or mixable.
1236 * This returns true for real PCM, but also for AUDIO_FORMAT_IEC61937,
1237 * which is transported as 16 bit PCM audio, but where the encoded data
1238 * cannot be mixed or scaled.
1239 */
audio_has_proportional_frames(audio_format_t format)1240 static inline bool audio_has_proportional_frames(audio_format_t format)
1241 {
1242 audio_format_t mainFormat = audio_get_main_format(format);
1243 return (mainFormat == AUDIO_FORMAT_PCM
1244 || mainFormat == AUDIO_FORMAT_IEC61937);
1245 }
1246
audio_bytes_per_sample(audio_format_t format)1247 static inline size_t audio_bytes_per_sample(audio_format_t format)
1248 {
1249 size_t size = 0;
1250
1251 switch (format) {
1252 case AUDIO_FORMAT_PCM_32_BIT:
1253 case AUDIO_FORMAT_PCM_8_24_BIT:
1254 size = sizeof(int32_t);
1255 break;
1256 case AUDIO_FORMAT_PCM_24_BIT_PACKED:
1257 size = sizeof(uint8_t) * 3;
1258 break;
1259 case AUDIO_FORMAT_PCM_16_BIT:
1260 case AUDIO_FORMAT_IEC61937:
1261 size = sizeof(int16_t);
1262 break;
1263 case AUDIO_FORMAT_PCM_8_BIT:
1264 size = sizeof(uint8_t);
1265 break;
1266 case AUDIO_FORMAT_PCM_FLOAT:
1267 size = sizeof(float);
1268 break;
1269 default:
1270 break;
1271 }
1272 return size;
1273 }
1274
audio_bytes_per_frame(uint32_t channel_count,audio_format_t format)1275 static inline size_t audio_bytes_per_frame(uint32_t channel_count, audio_format_t format)
1276 {
1277 // cannot overflow for reasonable channel_count
1278 return channel_count * audio_bytes_per_sample(format);
1279 }
1280
1281 /* converts device address to string sent to audio HAL via set_parameters */
audio_device_address_to_parameter(audio_devices_t device,const char * address)1282 static inline char *audio_device_address_to_parameter(audio_devices_t device, const char *address)
1283 {
1284 const size_t kSize = AUDIO_DEVICE_MAX_ADDRESS_LEN + sizeof("a2dp_source_address=");
1285 char param[kSize];
1286
1287 if (device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
1288 snprintf(param, kSize, "%s=%s", "a2dp_source_address", address);
1289 } else if (audio_is_a2dp_out_device(device)) {
1290 snprintf(param, kSize, "%s=%s", "a2dp_sink_address", address);
1291 } else if (audio_is_remote_submix_device(device)) {
1292 snprintf(param, kSize, "%s=%s", "mix", address);
1293 } else {
1294 snprintf(param, kSize, "%s", address);
1295 }
1296 return strdup(param);
1297 }
1298
1299 #ifndef AUDIO_NO_SYSTEM_DECLARATIONS
1300
audio_gain_config_are_equal(const struct audio_gain_config * lhs,const struct audio_gain_config * rhs)1301 static inline bool audio_gain_config_are_equal(
1302 const struct audio_gain_config *lhs, const struct audio_gain_config *rhs) {
1303 if (lhs->mode != rhs->mode) return false;
1304 switch (lhs->mode) {
1305 case AUDIO_GAIN_MODE_JOINT:
1306 if (lhs->values[0] != rhs->values[0]) return false;
1307 break;
1308 case AUDIO_GAIN_MODE_CHANNELS:
1309 case AUDIO_GAIN_MODE_RAMP:
1310 if (lhs->channel_mask != rhs->channel_mask) return false;
1311 for (int i = 0; i < __builtin_popcount(lhs->channel_mask); ++i) {
1312 if (lhs->values[i] != rhs->values[i]) return false;
1313 }
1314 break;
1315 default: return false;
1316 }
1317 return lhs->ramp_duration_ms == rhs->ramp_duration_ms;
1318 }
1319
audio_port_config_has_input_direction(const struct audio_port_config * port_cfg)1320 static inline bool audio_port_config_has_input_direction(const struct audio_port_config *port_cfg) {
1321 switch (port_cfg->type) {
1322 case AUDIO_PORT_TYPE_DEVICE:
1323 switch (port_cfg->role) {
1324 case AUDIO_PORT_ROLE_SOURCE: return true;
1325 case AUDIO_PORT_ROLE_SINK: return false;
1326 default: return false;
1327 }
1328 case AUDIO_PORT_TYPE_MIX:
1329 switch (port_cfg->role) {
1330 case AUDIO_PORT_ROLE_SOURCE: return false;
1331 case AUDIO_PORT_ROLE_SINK: return true;
1332 default: return false;
1333 }
1334 default: return false;
1335 }
1336 }
1337
audio_port_configs_are_equal(const struct audio_port_config * lhs,const struct audio_port_config * rhs)1338 static inline bool audio_port_configs_are_equal(
1339 const struct audio_port_config *lhs, const struct audio_port_config *rhs) {
1340 if (lhs->role != rhs->role || lhs->type != rhs->type) return false;
1341 switch (lhs->type) {
1342 case AUDIO_PORT_TYPE_NONE: break;
1343 case AUDIO_PORT_TYPE_DEVICE:
1344 if (lhs->ext.device.hw_module != rhs->ext.device.hw_module ||
1345 lhs->ext.device.type != rhs->ext.device.type ||
1346 strncmp(lhs->ext.device.address, rhs->ext.device.address,
1347 AUDIO_DEVICE_MAX_ADDRESS_LEN) != 0) {
1348 return false;
1349 }
1350 break;
1351 case AUDIO_PORT_TYPE_MIX:
1352 if (lhs->ext.mix.hw_module != rhs->ext.mix.hw_module ||
1353 lhs->ext.mix.handle != rhs->ext.mix.handle) return false;
1354 if (lhs->role == AUDIO_PORT_ROLE_SOURCE &&
1355 lhs->ext.mix.usecase.stream != rhs->ext.mix.usecase.stream) return false;
1356 else if (lhs->role == AUDIO_PORT_ROLE_SINK &&
1357 lhs->ext.mix.usecase.source != rhs->ext.mix.usecase.source) return false;
1358 break;
1359 case AUDIO_PORT_TYPE_SESSION:
1360 if (lhs->ext.session.session != rhs->ext.session.session) return false;
1361 break;
1362 default: return false;
1363 }
1364 return lhs->config_mask == rhs->config_mask &&
1365 ((lhs->config_mask & AUDIO_PORT_CONFIG_SAMPLE_RATE) == 0 ||
1366 lhs->sample_rate == rhs->sample_rate) &&
1367 ((lhs->config_mask & AUDIO_PORT_CONFIG_CHANNEL_MASK) == 0 ||
1368 lhs->channel_mask == rhs->channel_mask) &&
1369 ((lhs->config_mask & AUDIO_PORT_CONFIG_FORMAT) == 0 ||
1370 lhs->format == rhs->format) &&
1371 ((lhs->config_mask & AUDIO_PORT_CONFIG_GAIN) == 0 ||
1372 audio_gain_config_are_equal(&lhs->gain, &rhs->gain)) &&
1373 ((lhs->config_mask & AUDIO_PORT_CONFIG_FLAGS) == 0 ||
1374 (audio_port_config_has_input_direction(lhs) ?
1375 lhs->flags.input == rhs->flags.input :
1376 lhs->flags.output == rhs->flags.output));
1377 }
1378
audio_port_config_has_hw_av_sync(const struct audio_port_config * port_cfg)1379 static inline bool audio_port_config_has_hw_av_sync(const struct audio_port_config *port_cfg) {
1380 if (!(port_cfg->config_mask & AUDIO_PORT_CONFIG_FLAGS)) {
1381 return false;
1382 }
1383 return audio_port_config_has_input_direction(port_cfg) ?
1384 port_cfg->flags.input & AUDIO_INPUT_FLAG_HW_AV_SYNC
1385 : port_cfg->flags.output & AUDIO_OUTPUT_FLAG_HW_AV_SYNC;
1386 }
1387
audio_patch_has_hw_av_sync(const struct audio_patch * patch)1388 static inline bool audio_patch_has_hw_av_sync(const struct audio_patch *patch) {
1389 for (unsigned int i = 0; i < patch->num_sources; ++i) {
1390 if (audio_port_config_has_hw_av_sync(&patch->sources[i])) return true;
1391 }
1392 for (unsigned int i = 0; i < patch->num_sinks; ++i) {
1393 if (audio_port_config_has_hw_av_sync(&patch->sinks[i])) return true;
1394 }
1395 return false;
1396 }
1397
audio_patch_is_valid(const struct audio_patch * patch)1398 static inline bool audio_patch_is_valid(const struct audio_patch *patch) {
1399 // Note that patch can have no sinks.
1400 return patch->num_sources != 0 && patch->num_sources <= AUDIO_PATCH_PORTS_MAX &&
1401 patch->num_sinks <= AUDIO_PATCH_PORTS_MAX;
1402 }
1403
1404 // Note that when checking for equality the order of ports must match.
1405 // Patches will not be equivalent if they contain the same ports but they are permuted differently.
audio_patches_are_equal(const struct audio_patch * lhs,const struct audio_patch * rhs)1406 static inline bool audio_patches_are_equal(
1407 const struct audio_patch *lhs, const struct audio_patch *rhs) {
1408 if (!audio_patch_is_valid(lhs) || !audio_patch_is_valid(rhs)) return false;
1409 if (lhs->num_sources != rhs->num_sources || lhs->num_sinks != rhs->num_sinks) return false;
1410 for (unsigned int i = 0; i < lhs->num_sources; ++i) {
1411 if (!audio_port_configs_are_equal(&lhs->sources[i], &rhs->sources[i])) return false;
1412 }
1413 for (unsigned int i = 0; i < lhs->num_sinks; ++i) {
1414 if (!audio_port_configs_are_equal(&lhs->sinks[i], &rhs->sinks[i])) return false;
1415 }
1416 return true;
1417 }
1418
1419 #endif
1420
1421 // Unique effect ID (can be generated from the following site:
1422 // http://www.itu.int/ITU-T/asn1/uuid.html)
1423 // This struct is used for effects identification and in soundtrigger.
1424 typedef struct audio_uuid_s {
1425 uint32_t timeLow;
1426 uint16_t timeMid;
1427 uint16_t timeHiAndVersion;
1428 uint16_t clockSeq;
1429 uint8_t node[6];
1430 } audio_uuid_t;
1431
1432 //TODO: audio_microphone_location_t need to move to HAL v4.0
1433 typedef enum {
1434 AUDIO_MICROPHONE_LOCATION_UNKNOWN = 0,
1435 AUDIO_MICROPHONE_LOCATION_MAINBODY = 1,
1436 AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE = 2,
1437 AUDIO_MICROPHONE_LOCATION_PERIPHERAL = 3,
1438 AUDIO_MICROPHONE_LOCATION_CNT = 4,
1439 } audio_microphone_location_t;
1440
1441 //TODO: audio_microphone_directionality_t need to move to HAL v4.0
1442 typedef enum {
1443 AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN = 0,
1444 AUDIO_MICROPHONE_DIRECTIONALITY_OMNI = 1,
1445 AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL = 2,
1446 AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID = 3,
1447 AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID = 4,
1448 AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID = 5,
1449 AUDIO_MICROPHONE_DIRECTIONALITY_CNT = 6,
1450 } audio_microphone_directionality_t;
1451
1452 /* A 3D point which could be used to represent geometric location
1453 * or orientation of a microphone.
1454 */
1455 struct audio_microphone_coordinate {
1456 float x;
1457 float y;
1458 float z;
1459 };
1460
1461 /* An number to indicate which group the microphone locate. Main body is
1462 * usually group 0. Developer could use this value to group the microphones
1463 * that locate on the same peripheral or attachments.
1464 */
1465 typedef int audio_microphone_group_t;
1466
1467 typedef enum {
1468 AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED = 0,
1469 AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT = 1,
1470 AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED = 2,
1471 AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT = 3,
1472 } audio_microphone_channel_mapping_t;
1473
1474 /* the maximum length for the microphone id */
1475 #define AUDIO_MICROPHONE_ID_MAX_LEN 32
1476 /* max number of frequency responses in a frequency response table */
1477 #define AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES 256
1478 /* max number of microphone */
1479 #define AUDIO_MICROPHONE_MAX_COUNT 32
1480 /* the value of unknown spl */
1481 #define AUDIO_MICROPHONE_SPL_UNKNOWN -FLT_MAX
1482 /* the value of unknown sensitivity */
1483 #define AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN -FLT_MAX
1484 /* the value of unknown coordinate */
1485 #define AUDIO_MICROPHONE_COORDINATE_UNKNOWN -FLT_MAX
1486 /* the value used as address when the address of bottom microphone is empty */
1487 #define AUDIO_BOTTOM_MICROPHONE_ADDRESS "bottom"
1488 /* the value used as address when the address of back microphone is empty */
1489 #define AUDIO_BACK_MICROPHONE_ADDRESS "back"
1490
1491 struct audio_microphone_characteristic_t {
1492 char device_id[AUDIO_MICROPHONE_ID_MAX_LEN];
1493 audio_port_handle_t id;
1494 audio_devices_t device;
1495 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
1496 audio_microphone_channel_mapping_t channel_mapping[AUDIO_CHANNEL_COUNT_MAX];
1497 audio_microphone_location_t location;
1498 audio_microphone_group_t group;
1499 unsigned int index_in_the_group;
1500 float sensitivity;
1501 float max_spl;
1502 float min_spl;
1503 audio_microphone_directionality_t directionality;
1504 unsigned int num_frequency_responses;
1505 float frequency_responses[2][AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES];
1506 struct audio_microphone_coordinate geometric_location;
1507 struct audio_microphone_coordinate orientation;
1508 };
1509
1510 __END_DECLS
1511
1512 /**
1513 * List of known audio HAL modules. This is the base name of the audio HAL
1514 * library composed of the "audio." prefix, one of the base names below and
1515 * a suffix specific to the device.
1516 * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
1517 *
1518 * The same module names are used in audio policy configuration files.
1519 */
1520
1521 #define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
1522 #define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
1523 #define AUDIO_HARDWARE_MODULE_ID_USB "usb"
1524 #define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
1525 #define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
1526 #define AUDIO_HARDWARE_MODULE_ID_STUB "stub"
1527 #define AUDIO_HARDWARE_MODULE_ID_HEARING_AID "hearing_aid"
1528 #define AUDIO_HARDWARE_MODULE_ID_MSD "msd"
1529
1530 /**
1531 * Multi-Stream Decoder (MSD) HAL service name. MSD HAL is used to mix
1532 * encoded streams together with PCM streams, producing re-encoded
1533 * streams or PCM streams.
1534 *
1535 * The service must register itself using this name, and audioserver
1536 * tries to instantiate a device factory using this name as well.
1537 * Note that the HIDL implementation library file name *must* have the
1538 * suffix "msd" in order to be picked up by HIDL that is:
1539 *
1540 * android.hardware.audio@x.x-implmsd.so
1541 */
1542 #define AUDIO_HAL_SERVICE_NAME_MSD "msd"
1543
1544 /**
1545 * Parameter definitions.
1546 * Note that in the framework code it's recommended to use AudioParameter.h
1547 * instead of these preprocessor defines, and for sure avoid just copying
1548 * the constant values.
1549 */
1550
1551 #define AUDIO_PARAMETER_VALUE_ON "on"
1552 #define AUDIO_PARAMETER_VALUE_OFF "off"
1553
1554 /**
1555 * audio device parameters
1556 */
1557
1558 /* BT SCO Noise Reduction + Echo Cancellation parameters */
1559 #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
1560
1561 /* Get a new HW synchronization source identifier.
1562 * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
1563 * or no HW sync is available. */
1564 #define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync"
1565
1566 /* Screen state */
1567 #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
1568
1569 /* User's preferred audio language setting (in ISO 639-2/T three-letter string code)
1570 * used to select a specific language presentation for next generation audio codecs. */
1571 #define AUDIO_PARAMETER_KEY_AUDIO_LANGUAGE_PREFERRED "audio_language_preferred"
1572
1573 /**
1574 * audio stream parameters
1575 */
1576
1577 #define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */
1578 #define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */
1579 #define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */
1580 #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */
1581 #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */
1582 #define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
1583
1584 /* Request the presentation id to be decoded by a next gen audio decoder */
1585 #define AUDIO_PARAMETER_STREAM_PRESENTATION_ID "presentation_id" /* int32_t */
1586
1587 /* Request the program id to be decoded by a next gen audio decoder */
1588 #define AUDIO_PARAMETER_STREAM_PROGRAM_ID "program_id" /* int32_t */
1589
1590 #define AUDIO_PARAMETER_DEVICE_CONNECT "connect" /* audio_devices_t */
1591 #define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */
1592
1593 /* Enable mono audio playback if 1, else should be 0. */
1594 #define AUDIO_PARAMETER_MONO_OUTPUT "mono_output"
1595
1596 /* Set the HW synchronization source for an output stream. */
1597 #define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
1598
1599 /* Query supported formats. The response is a '|' separated list of strings from
1600 * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
1601 #define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
1602 /* Query supported channel masks. The response is a '|' separated list of strings from
1603 * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
1604 #define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
1605 /* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
1606 * "sup_sampling_rates=44100|48000" */
1607 #define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
1608
1609 #define AUDIO_PARAMETER_VALUE_LIST_SEPARATOR "|"
1610
1611 /* Reconfigure offloaded A2DP codec */
1612 #define AUDIO_PARAMETER_RECONFIG_A2DP "reconfigA2dp"
1613 /* Query if HwModule supports reconfiguration of offloaded A2DP codec */
1614 #define AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED "isReconfigA2dpSupported"
1615
1616 /**
1617 * audio codec parameters
1618 */
1619
1620 #define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
1621 #define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
1622 #define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
1623 #define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
1624 #define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
1625 #define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
1626 #define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
1627 #define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
1628 #define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels"
1629 #define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling"
1630 #define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples"
1631 #define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples"
1632
1633 #endif // ANDROID_AUDIO_CORE_H
1634