• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sys/cdefs.h>
25 #include <sys/types.h>
26 
27 #include <cutils/bitops.h>
28 
29 #include "audio-base.h"
30 #include "audio-base-utils.h"
31 
32 __BEGIN_DECLS
33 
34 /* The enums were moved here mostly from
35  * frameworks/base/include/media/AudioSystem.h
36  */
37 
38 /* represents an invalid uid for tracks; the calling or client uid is often substituted. */
39 #define AUDIO_UID_INVALID ((uid_t)-1)
40 
41 /* device address used to refer to the standard remote submix */
42 #define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0"
43 
44 /* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */
45 typedef int audio_io_handle_t;
46 
47 typedef uint32_t audio_flags_mask_t;
48 
49 /* Do not change these values without updating their counterparts
50  * in frameworks/base/media/java/android/media/AudioAttributes.java
51  */
52 enum {
53     AUDIO_FLAG_NONE                       = 0x0,
54     AUDIO_FLAG_AUDIBILITY_ENFORCED        = 0x1,
55     AUDIO_FLAG_SECURE                     = 0x2,
56     AUDIO_FLAG_SCO                        = 0x4,
57     AUDIO_FLAG_BEACON                     = 0x8,
58     AUDIO_FLAG_HW_AV_SYNC                 = 0x10,
59     AUDIO_FLAG_HW_HOTWORD                 = 0x20,
60     AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY = 0x40,
61     AUDIO_FLAG_BYPASS_MUTE                = 0x80,
62     AUDIO_FLAG_LOW_LATENCY                = 0x100,
63     AUDIO_FLAG_DEEP_BUFFER                = 0x200,
64 };
65 
66 /* Audio attributes */
67 #define AUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256
68 typedef struct {
69     audio_content_type_t content_type;
70     audio_usage_t        usage;
71     audio_source_t       source;
72     audio_flags_mask_t   flags;
73     char                 tags[AUDIO_ATTRIBUTES_TAGS_MAX_SIZE]; /* UTF8 */
74 } __attribute__((packed)) audio_attributes_t; // sent through Binder;
75 
76 /* a unique ID allocated by AudioFlinger for use as an audio_io_handle_t, audio_session_t,
77  * effect ID (int), audio_module_handle_t, and audio_patch_handle_t.
78  * Audio port IDs (audio_port_handle_t) are allocated by AudioPolicy
79  * in a different namespace than AudioFlinger unique IDs.
80  */
81 typedef int audio_unique_id_t;
82 
83 /* Possible uses for an audio_unique_id_t */
84 typedef enum {
85     AUDIO_UNIQUE_ID_USE_UNSPECIFIED = 0,
86     AUDIO_UNIQUE_ID_USE_SESSION = 1,    // for allocated sessions, not special AUDIO_SESSION_*
87     AUDIO_UNIQUE_ID_USE_MODULE = 2,
88     AUDIO_UNIQUE_ID_USE_EFFECT = 3,
89     AUDIO_UNIQUE_ID_USE_PATCH = 4,
90     AUDIO_UNIQUE_ID_USE_OUTPUT = 5,
91     AUDIO_UNIQUE_ID_USE_INPUT = 6,
92     AUDIO_UNIQUE_ID_USE_PLAYER = 7,
93     AUDIO_UNIQUE_ID_USE_MAX = 8,  // must be a power-of-two
94     AUDIO_UNIQUE_ID_USE_MASK = AUDIO_UNIQUE_ID_USE_MAX - 1
95 } audio_unique_id_use_t;
96 
97 /* Return the use of an audio_unique_id_t */
audio_unique_id_get_use(audio_unique_id_t id)98 static inline audio_unique_id_use_t audio_unique_id_get_use(audio_unique_id_t id)
99 {
100     return (audio_unique_id_use_t) (id & AUDIO_UNIQUE_ID_USE_MASK);
101 }
102 
103 /* Reserved audio_unique_id_t values.  FIXME: not a complete list. */
104 #define AUDIO_UNIQUE_ID_ALLOCATE AUDIO_SESSION_ALLOCATE
105 
106 /* A channel mask per se only defines the presence or absence of a channel, not the order.
107  * But see AUDIO_INTERLEAVE_* below for the platform convention of order.
108  *
109  * audio_channel_mask_t is an opaque type and its internal layout should not
110  * be assumed as it may change in the future.
111  * Instead, always use the functions declared in this header to examine.
112  *
113  * These are the current representations:
114  *
115  *   AUDIO_CHANNEL_REPRESENTATION_POSITION
116  *     is a channel mask representation for position assignment.
117  *     Each low-order bit corresponds to the spatial position of a transducer (output),
118  *     or interpretation of channel (input).
119  *     The user of a channel mask needs to know the context of whether it is for output or input.
120  *     The constants AUDIO_CHANNEL_OUT_* or AUDIO_CHANNEL_IN_* apply to the bits portion.
121  *     It is not permitted for no bits to be set.
122  *
123  *   AUDIO_CHANNEL_REPRESENTATION_INDEX
124  *     is a channel mask representation for index assignment.
125  *     Each low-order bit corresponds to a selected channel.
126  *     There is no platform interpretation of the various bits.
127  *     There is no concept of output or input.
128  *     It is not permitted for no bits to be set.
129  *
130  * All other representations are reserved for future use.
131  *
132  * Warning: current representation distinguishes between input and output, but this will not the be
133  * case in future revisions of the platform. Wherever there is an ambiguity between input and output
134  * that is currently resolved by checking the channel mask, the implementer should look for ways to
135  * fix it with additional information outside of the mask.
136  */
137 typedef uint32_t audio_channel_mask_t;
138 
139 /* log(2) of maximum number of representations, not part of public API */
140 #define AUDIO_CHANNEL_REPRESENTATION_LOG2   2
141 
142 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_bits(audio_channel_mask_t channel)143 static inline uint32_t audio_channel_mask_get_bits(audio_channel_mask_t channel)
144 {
145     return channel & ((1 << AUDIO_CHANNEL_COUNT_MAX) - 1);
146 }
147 
148 typedef uint32_t audio_channel_representation_t;
149 
150 /* The return value is undefined if the channel mask is invalid. */
audio_channel_mask_get_representation(audio_channel_mask_t channel)151 static inline audio_channel_representation_t audio_channel_mask_get_representation(
152         audio_channel_mask_t channel)
153 {
154     // The right shift should be sufficient, but also "and" for safety in case mask is not 32 bits
155     return (audio_channel_representation_t)
156             ((channel >> AUDIO_CHANNEL_COUNT_MAX) & ((1 << AUDIO_CHANNEL_REPRESENTATION_LOG2) - 1));
157 }
158 
159 /* Returns true if the channel mask is valid,
160  * or returns false for AUDIO_CHANNEL_NONE, AUDIO_CHANNEL_INVALID, and other invalid values.
161  * This function is unable to determine whether a channel mask for position assignment
162  * is invalid because an output mask has an invalid output bit set,
163  * or because an input mask has an invalid input bit set.
164  * All other APIs that take a channel mask assume that it is valid.
165  */
audio_channel_mask_is_valid(audio_channel_mask_t channel)166 static inline bool audio_channel_mask_is_valid(audio_channel_mask_t channel)
167 {
168     uint32_t bits = audio_channel_mask_get_bits(channel);
169     audio_channel_representation_t representation = audio_channel_mask_get_representation(channel);
170     switch (representation) {
171     case AUDIO_CHANNEL_REPRESENTATION_POSITION:
172     case AUDIO_CHANNEL_REPRESENTATION_INDEX:
173         break;
174     default:
175         bits = 0;
176         break;
177     }
178     return bits != 0;
179 }
180 
181 /* Not part of public API */
audio_channel_mask_from_representation_and_bits(audio_channel_representation_t representation,uint32_t bits)182 static inline audio_channel_mask_t audio_channel_mask_from_representation_and_bits(
183         audio_channel_representation_t representation, uint32_t bits)
184 {
185     return (audio_channel_mask_t) ((representation << AUDIO_CHANNEL_COUNT_MAX) | bits);
186 }
187 
188 /**
189  * Expresses the convention when stereo audio samples are stored interleaved
190  * in an array.  This should improve readability by allowing code to use
191  * symbolic indices instead of hard-coded [0] and [1].
192  *
193  * For multi-channel beyond stereo, the platform convention is that channels
194  * are interleaved in order from least significant channel mask bit to most
195  * significant channel mask bit, with unused bits skipped.  Any exceptions
196  * to this convention will be noted at the appropriate API.
197  */
198 enum {
199     AUDIO_INTERLEAVE_LEFT = 0,
200     AUDIO_INTERLEAVE_RIGHT = 1,
201 };
202 
203 /* This enum is deprecated */
204 typedef enum {
205     AUDIO_IN_ACOUSTICS_NONE          = 0,
206     AUDIO_IN_ACOUSTICS_AGC_ENABLE    = 0x0001,
207     AUDIO_IN_ACOUSTICS_AGC_DISABLE   = 0,
208     AUDIO_IN_ACOUSTICS_NS_ENABLE     = 0x0002,
209     AUDIO_IN_ACOUSTICS_NS_DISABLE    = 0,
210     AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
211     AUDIO_IN_ACOUSTICS_TX_DISABLE    = 0,
212 } audio_in_acoustics_t;
213 
214 typedef uint32_t audio_devices_t;
215 /**
216  * Stub audio output device. Used in policy configuration file on platforms without audio outputs.
217  * This alias value to AUDIO_DEVICE_OUT_DEFAULT is only used in the audio policy context.
218  */
219 #define AUDIO_DEVICE_OUT_STUB AUDIO_DEVICE_OUT_DEFAULT
220 /**
221  * Stub audio input device. Used in policy configuration file on platforms without audio inputs.
222  * This alias value to AUDIO_DEVICE_IN_DEFAULT is only used in the audio policy context.
223  */
224 #define AUDIO_DEVICE_IN_STUB AUDIO_DEVICE_IN_DEFAULT
225 
226 /* Additional information about compressed streams offloaded to
227  * hardware playback
228  * The version and size fields must be initialized by the caller by using
229  * one of the constants defined here.
230  * Must be aligned to transmit as raw memory through Binder.
231  */
232 typedef struct {
233     uint16_t version;                   // version of the info structure
234     uint16_t size;                      // total size of the structure including version and size
235     uint32_t sample_rate;               // sample rate in Hz
236     audio_channel_mask_t channel_mask;  // channel mask
237     audio_format_t format;              // audio format
238     audio_stream_type_t stream_type;    // stream type
239     uint32_t bit_rate;                  // bit rate in bits per second
240     int64_t duration_us;                // duration in microseconds, -1 if unknown
241     bool has_video;                     // true if stream is tied to a video stream
242     bool is_streaming;                  // true if streaming, false if local playback
243     uint32_t bit_width;
244     uint32_t offload_buffer_size;       // offload fragment size
245     audio_usage_t usage;
246 } __attribute__((aligned(8))) audio_offload_info_t;
247 
248 #define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \
249             ((((maj) & 0xff) << 8) | ((min) & 0xff))
250 
251 #define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1)
252 #define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1
253 
254 static const audio_offload_info_t AUDIO_INFO_INITIALIZER = {
255     /* .version = */ AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
256     /* .size = */ sizeof(audio_offload_info_t),
257     /* .sample_rate = */ 0,
258     /* .channel_mask = */ 0,
259     /* .format = */ AUDIO_FORMAT_DEFAULT,
260     /* .stream_type = */ AUDIO_STREAM_VOICE_CALL,
261     /* .bit_rate = */ 0,
262     /* .duration_us = */ 0,
263     /* .has_video = */ false,
264     /* .is_streaming = */ false,
265     /* .bit_width = */ 16,
266     /* .offload_buffer_size = */ 0,
267     /* .usage = */ AUDIO_USAGE_UNKNOWN
268 };
269 
270 /* common audio stream configuration parameters
271  * You should memset() the entire structure to zero before use to
272  * ensure forward compatibility
273  * Must be aligned to transmit as raw memory through Binder.
274  */
275 struct __attribute__((aligned(8))) audio_config {
276     uint32_t sample_rate;
277     audio_channel_mask_t channel_mask;
278     audio_format_t  format;
279     audio_offload_info_t offload_info;
280     uint32_t frame_count;
281 };
282 typedef struct audio_config audio_config_t;
283 
284 static const audio_config_t AUDIO_CONFIG_INITIALIZER = {
285     /* .sample_rate = */ 0,
286     /* .channel_mask = */ AUDIO_CHANNEL_NONE,
287     /* .format = */ AUDIO_FORMAT_DEFAULT,
288     /* .offload_info = */ {
289         /* .version = */ AUDIO_OFFLOAD_INFO_VERSION_CURRENT,
290         /* .size = */ sizeof(audio_offload_info_t),
291         /* .sample_rate = */ 0,
292         /* .channel_mask = */ 0,
293         /* .format = */ AUDIO_FORMAT_DEFAULT,
294         /* .stream_type = */ AUDIO_STREAM_VOICE_CALL,
295         /* .bit_rate = */ 0,
296         /* .duration_us = */ 0,
297         /* .has_video = */ false,
298         /* .is_streaming = */ false,
299         /* .bit_width = */ 16,
300         /* .offload_buffer_size = */ 0,
301         /* .usage = */ AUDIO_USAGE_UNKNOWN
302     },
303     /* .frame_count = */ 0,
304 };
305 
306 struct audio_config_base {
307     uint32_t sample_rate;
308     audio_channel_mask_t channel_mask;
309     audio_format_t  format;
310 };
311 
312 typedef struct audio_config_base audio_config_base_t;
313 
314 static const audio_config_base_t AUDIO_CONFIG_BASE_INITIALIZER = {
315     /* .sample_rate = */ 0,
316     /* .channel_mask = */ AUDIO_CHANNEL_NONE,
317     /* .format = */ AUDIO_FORMAT_DEFAULT
318 };
319 
320 /* audio hw module handle functions or structures referencing a module */
321 typedef int audio_module_handle_t;
322 
323 /******************************
324  *  Volume control
325  *****************************/
326 
327 /** 3 dB headroom are allowed on float samples (3db = 10^(3/20) = 1.412538).
328 * See: https://developer.android.com/reference/android/media/AudioTrack.html#write(float[], int, int, int)
329 */
330 #define FLOAT_NOMINAL_RANGE_HEADROOM 1.412538
331 
332 /* If the audio hardware supports gain control on some audio paths,
333  * the platform can expose them in the audio_policy.conf file. The audio HAL
334  * will then implement gain control functions that will use the following data
335  * structures. */
336 
337 typedef uint32_t audio_gain_mode_t;
338 
339 
340 /* An audio_gain struct is a representation of a gain stage.
341  * A gain stage is always attached to an audio port. */
342 struct audio_gain  {
343     audio_gain_mode_t    mode;          /* e.g. AUDIO_GAIN_MODE_JOINT */
344     audio_channel_mask_t channel_mask;  /* channels which gain an be controlled.
345                                            N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */
346     int                  min_value;     /* minimum gain value in millibels */
347     int                  max_value;     /* maximum gain value in millibels */
348     int                  default_value; /* default gain value in millibels */
349     unsigned int         step_value;    /* gain step in millibels */
350     unsigned int         min_ramp_ms;   /* minimum ramp duration in ms */
351     unsigned int         max_ramp_ms;   /* maximum ramp duration in ms */
352 };
353 
354 /* The gain configuration structure is used to get or set the gain values of a
355  * given port */
356 struct audio_gain_config  {
357     int                  index;             /* index of the corresponding audio_gain in the
358                                                audio_port gains[] table */
359     audio_gain_mode_t    mode;              /* mode requested for this command */
360     audio_channel_mask_t channel_mask;      /* channels which gain value follows.
361                                                N/A in joint mode */
362 
363     // note this "8" is not FCC_8, so it won't need to be changed for > 8 channels
364     int                  values[sizeof(audio_channel_mask_t) * 8]; /* gain values in millibels
365                                                for each channel ordered from LSb to MSb in
366                                                channel mask. The number of values is 1 in joint
367                                                mode or popcount(channel_mask) */
368     unsigned int         ramp_duration_ms; /* ramp duration in ms */
369 };
370 
371 /******************************
372  *  Routing control
373  *****************************/
374 
375 /* Types defined here are used to describe an audio source or sink at internal
376  * framework interfaces (audio policy, patch panel) or at the audio HAL.
377  * Sink and sources are grouped in a concept of “audio port” representing an
378  * audio end point at the edge of the system managed by the module exposing
379  * the interface. */
380 
381 /* Each port has a unique ID or handle allocated by policy manager */
382 typedef int audio_port_handle_t;
383 
384 /* the maximum length for the human-readable device name */
385 #define AUDIO_PORT_MAX_NAME_LEN 128
386 
387 /* maximum audio device address length */
388 #define AUDIO_DEVICE_MAX_ADDRESS_LEN 32
389 
390 /* extension for audio port configuration structure when the audio port is a
391  * hardware device */
392 struct audio_port_config_device_ext {
393     audio_module_handle_t hw_module;                /* module the device is attached to */
394     audio_devices_t       type;                     /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
395     char                  address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */
396 };
397 
398 /* extension for audio port configuration structure when the audio port is a
399  * sub mix */
400 struct audio_port_config_mix_ext {
401     audio_module_handle_t hw_module;    /* module the stream is attached to */
402     audio_io_handle_t handle;           /* I/O handle of the input/output stream */
403     union {
404         //TODO: change use case for output streams: use strategy and mixer attributes
405         audio_stream_type_t stream;
406         audio_source_t      source;
407     } usecase;
408 };
409 
410 /* extension for audio port configuration structure when the audio port is an
411  * audio session */
412 struct audio_port_config_session_ext {
413     audio_session_t   session; /* audio session */
414 };
415 
416 /* audio port configuration structure used to specify a particular configuration of
417  * an audio port */
418 struct audio_port_config {
419     audio_port_handle_t      id;           /* port unique ID */
420     audio_port_role_t        role;         /* sink or source */
421     audio_port_type_t        type;         /* device, mix ... */
422     unsigned int             config_mask;  /* e.g AUDIO_PORT_CONFIG_ALL */
423     unsigned int             sample_rate;  /* sampling rate in Hz */
424     audio_channel_mask_t     channel_mask; /* channel mask if applicable */
425     audio_format_t           format;       /* format if applicable */
426     struct audio_gain_config gain;         /* gain to apply if applicable */
427     union {
428         struct audio_port_config_device_ext  device;  /* device specific info */
429         struct audio_port_config_mix_ext     mix;     /* mix specific info */
430         struct audio_port_config_session_ext session; /* session specific info */
431     } ext;
432 };
433 
434 
435 /* max number of sampling rates in audio port */
436 #define AUDIO_PORT_MAX_SAMPLING_RATES 32
437 /* max number of channel masks in audio port */
438 #define AUDIO_PORT_MAX_CHANNEL_MASKS 32
439 /* max number of audio formats in audio port */
440 #define AUDIO_PORT_MAX_FORMATS 32
441 /* max number of gain controls in audio port */
442 #define AUDIO_PORT_MAX_GAINS 16
443 
444 /* extension for audio port structure when the audio port is a hardware device */
445 struct audio_port_device_ext {
446     audio_module_handle_t hw_module;    /* module the device is attached to */
447     audio_devices_t       type;         /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */
448     char                  address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
449 };
450 
451 /* extension for audio port structure when the audio port is a sub mix */
452 struct audio_port_mix_ext {
453     audio_module_handle_t     hw_module;     /* module the stream is attached to */
454     audio_io_handle_t         handle;        /* I/O handle of the input.output stream */
455     audio_mix_latency_class_t latency_class; /* latency class */
456     // other attributes: routing strategies
457 };
458 
459 /* extension for audio port structure when the audio port is an audio session */
460 struct audio_port_session_ext {
461     audio_session_t   session; /* audio session */
462 };
463 
464 struct audio_port {
465     audio_port_handle_t      id;                /* port unique ID */
466     audio_port_role_t        role;              /* sink or source */
467     audio_port_type_t        type;              /* device, mix ... */
468     char                     name[AUDIO_PORT_MAX_NAME_LEN];
469     unsigned int             num_sample_rates;  /* number of sampling rates in following array */
470     unsigned int             sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES];
471     unsigned int             num_channel_masks; /* number of channel masks in following array */
472     audio_channel_mask_t     channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS];
473     unsigned int             num_formats;       /* number of formats in following array */
474     audio_format_t           formats[AUDIO_PORT_MAX_FORMATS];
475     unsigned int             num_gains;         /* number of gains in following array */
476     struct audio_gain        gains[AUDIO_PORT_MAX_GAINS];
477     struct audio_port_config active_config;     /* current audio port configuration */
478     union {
479         struct audio_port_device_ext  device;
480         struct audio_port_mix_ext     mix;
481         struct audio_port_session_ext session;
482     } ext;
483 };
484 
485 /* An audio patch represents a connection between one or more source ports and
486  * one or more sink ports. Patches are connected and disconnected by audio policy manager or by
487  * applications via framework APIs.
488  * Each patch is identified by a handle at the interface used to create that patch. For instance,
489  * when a patch is created by the audio HAL, the HAL allocates and returns a handle.
490  * This handle is unique to a given audio HAL hardware module.
491  * But the same patch receives another system wide unique handle allocated by the framework.
492  * This unique handle is used for all transactions inside the framework.
493  */
494 typedef int audio_patch_handle_t;
495 
496 #define AUDIO_PATCH_PORTS_MAX   16
497 
498 struct audio_patch {
499     audio_patch_handle_t id;            /* patch unique ID */
500     unsigned int      num_sources;      /* number of sources in following array */
501     struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX];
502     unsigned int      num_sinks;        /* number of sinks in following array */
503     struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX];
504 };
505 
506 
507 
508 /* a HW synchronization source returned by the audio HAL */
509 typedef uint32_t audio_hw_sync_t;
510 
511 /* an invalid HW synchronization source indicating an error */
512 #define AUDIO_HW_SYNC_INVALID 0
513 
514 /**
515  * Mmap buffer descriptor returned by audio_stream->create_mmap_buffer().
516  * note\ Used by streams opened in mmap mode.
517  */
518 struct audio_mmap_buffer_info {
519     void*   shared_memory_address;  /**< base address of mmap memory buffer.
520                                          For use by local process only */
521     int32_t shared_memory_fd;       /**< FD for mmap memory buffer */
522     int32_t buffer_size_frames;     /**< total buffer size in frames */
523     int32_t burst_size_frames;      /**< transfer size granularity in frames */
524 };
525 
526 /**
527  * Mmap buffer read/write position returned by audio_stream->get_mmap_position().
528  * note\ Used by streams opened in mmap mode.
529  */
530 struct audio_mmap_position {
531     int64_t  time_nanoseconds; /**< timestamp in ns, CLOCK_MONOTONIC */
532     int32_t  position_frames;  /**< increasing 32 bit frame count reset when stream->stop()
533                                     is called */
534 };
535 
536 /** Metadata of a record track for an in stream. */
537 typedef struct playback_track_metadata {
538     audio_usage_t usage;
539     audio_content_type_t content_type;
540     float gain; // Normalized linear volume. 0=silence, 1=0dbfs...
541 } playback_track_metadata_t;
542 
543 /** Metadata of a playback track for an out stream. */
544 typedef struct record_track_metadata {
545     audio_source_t source;
546     float gain; // Normalized linear volume. 0=silence, 1=0dbfs...
547 } record_track_metadata_t;
548 
549 
550 /******************************
551  *  Helper functions
552  *****************************/
553 
audio_is_output_device(audio_devices_t device)554 static inline bool audio_is_output_device(audio_devices_t device)
555 {
556     if (((device & AUDIO_DEVICE_BIT_IN) == 0) &&
557             (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
558         return true;
559     else
560         return false;
561 }
562 
audio_is_input_device(audio_devices_t device)563 static inline bool audio_is_input_device(audio_devices_t device)
564 {
565     if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
566         device &= ~AUDIO_DEVICE_BIT_IN;
567         if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
568             return true;
569     }
570     return false;
571 }
572 
audio_is_output_devices(audio_devices_t device)573 static inline bool audio_is_output_devices(audio_devices_t device)
574 {
575     return (device & AUDIO_DEVICE_BIT_IN) == 0;
576 }
577 
audio_is_a2dp_in_device(audio_devices_t device)578 static inline bool audio_is_a2dp_in_device(audio_devices_t device)
579 {
580     if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
581         device &= ~AUDIO_DEVICE_BIT_IN;
582         if ((popcount(device) == 1) && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP))
583             return true;
584     }
585     return false;
586 }
587 
audio_is_a2dp_out_device(audio_devices_t device)588 static inline bool audio_is_a2dp_out_device(audio_devices_t device)
589 {
590     if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
591         return true;
592     else
593         return false;
594 }
595 
596 // Deprecated - use audio_is_a2dp_out_device() instead
audio_is_a2dp_device(audio_devices_t device)597 static inline bool audio_is_a2dp_device(audio_devices_t device)
598 {
599     return audio_is_a2dp_out_device(device);
600 }
601 
audio_is_bluetooth_sco_device(audio_devices_t device)602 static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
603 {
604     if ((device & AUDIO_DEVICE_BIT_IN) == 0) {
605         if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0))
606             return true;
607     } else {
608         device &= ~AUDIO_DEVICE_BIT_IN;
609         if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0))
610             return true;
611     }
612 
613     return false;
614 }
615 
audio_is_hearing_aid_out_device(audio_devices_t device)616 static inline bool audio_is_hearing_aid_out_device(audio_devices_t device)
617 {
618     return device == AUDIO_DEVICE_OUT_HEARING_AID;
619 }
620 
audio_is_usb_out_device(audio_devices_t device)621 static inline bool audio_is_usb_out_device(audio_devices_t device)
622 {
623     return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB));
624 }
625 
audio_is_usb_in_device(audio_devices_t device)626 static inline bool audio_is_usb_in_device(audio_devices_t device)
627 {
628     if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
629         device &= ~AUDIO_DEVICE_BIT_IN;
630         if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0)
631             return true;
632     }
633     return false;
634 }
635 
636 /* OBSOLETE - use audio_is_usb_out_device() instead. */
audio_is_usb_device(audio_devices_t device)637 static inline bool audio_is_usb_device(audio_devices_t device)
638 {
639     return audio_is_usb_out_device(device);
640 }
641 
audio_is_remote_submix_device(audio_devices_t device)642 static inline bool audio_is_remote_submix_device(audio_devices_t device)
643 {
644     if ((audio_is_output_devices(device) &&
645          (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
646         || (!audio_is_output_devices(device) &&
647          (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX))
648         return true;
649     else
650         return false;
651 }
652 
653 /* Returns true if:
654  *  representation is valid, and
655  *  there is at least one channel bit set which _could_ correspond to an input channel, and
656  *  there are no channel bits set which could _not_ correspond to an input channel.
657  * Otherwise returns false.
658  */
audio_is_input_channel(audio_channel_mask_t channel)659 static inline bool audio_is_input_channel(audio_channel_mask_t channel)
660 {
661     uint32_t bits = audio_channel_mask_get_bits(channel);
662     switch (audio_channel_mask_get_representation(channel)) {
663     case AUDIO_CHANNEL_REPRESENTATION_POSITION:
664         if (bits & ~AUDIO_CHANNEL_IN_ALL) {
665             bits = 0;
666         }
667         // fall through
668     case AUDIO_CHANNEL_REPRESENTATION_INDEX:
669         return bits != 0;
670     default:
671         return false;
672     }
673 }
674 
675 /* Returns true if:
676  *  representation is valid, and
677  *  there is at least one channel bit set which _could_ correspond to an output channel, and
678  *  there are no channel bits set which could _not_ correspond to an output channel.
679  * Otherwise returns false.
680  */
audio_is_output_channel(audio_channel_mask_t channel)681 static inline bool audio_is_output_channel(audio_channel_mask_t channel)
682 {
683     uint32_t bits = audio_channel_mask_get_bits(channel);
684     switch (audio_channel_mask_get_representation(channel)) {
685     case AUDIO_CHANNEL_REPRESENTATION_POSITION:
686         if (bits & ~AUDIO_CHANNEL_OUT_ALL) {
687             bits = 0;
688         }
689         // fall through
690     case AUDIO_CHANNEL_REPRESENTATION_INDEX:
691         return bits != 0;
692     default:
693         return false;
694     }
695 }
696 
697 /* Returns the number of channels from an input channel mask,
698  * used in the context of audio input or recording.
699  * If a channel bit is set which could _not_ correspond to an input channel,
700  * it is excluded from the count.
701  * Returns zero if the representation is invalid.
702  */
audio_channel_count_from_in_mask(audio_channel_mask_t channel)703 static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel)
704 {
705     uint32_t bits = audio_channel_mask_get_bits(channel);
706     switch (audio_channel_mask_get_representation(channel)) {
707     case AUDIO_CHANNEL_REPRESENTATION_POSITION:
708         // TODO: We can now merge with from_out_mask and remove anding
709         bits &= AUDIO_CHANNEL_IN_ALL;
710         // fall through
711     case AUDIO_CHANNEL_REPRESENTATION_INDEX:
712         return popcount(bits);
713     default:
714         return 0;
715     }
716 }
717 
718 /* Returns the number of channels from an output channel mask,
719  * used in the context of audio output or playback.
720  * If a channel bit is set which could _not_ correspond to an output channel,
721  * it is excluded from the count.
722  * Returns zero if the representation is invalid.
723  */
audio_channel_count_from_out_mask(audio_channel_mask_t channel)724 static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel)
725 {
726     uint32_t bits = audio_channel_mask_get_bits(channel);
727     switch (audio_channel_mask_get_representation(channel)) {
728     case AUDIO_CHANNEL_REPRESENTATION_POSITION:
729         // TODO: We can now merge with from_in_mask and remove anding
730         bits &= AUDIO_CHANNEL_OUT_ALL;
731         // fall through
732     case AUDIO_CHANNEL_REPRESENTATION_INDEX:
733         return popcount(bits);
734     default:
735         return 0;
736     }
737 }
738 
739 /* Derive a channel mask for index assignment from a channel count.
740  * Returns the matching channel mask,
741  * or AUDIO_CHANNEL_NONE if the channel count is zero,
742  * or AUDIO_CHANNEL_INVALID if the channel count exceeds AUDIO_CHANNEL_COUNT_MAX.
743  */
audio_channel_mask_for_index_assignment_from_count(uint32_t channel_count)744 static inline audio_channel_mask_t audio_channel_mask_for_index_assignment_from_count(
745         uint32_t channel_count)
746 {
747     if (channel_count == 0) {
748         return AUDIO_CHANNEL_NONE;
749     }
750     if (channel_count > AUDIO_CHANNEL_COUNT_MAX) {
751         return AUDIO_CHANNEL_INVALID;
752     }
753     uint32_t bits = (1 << channel_count) - 1;
754     return audio_channel_mask_from_representation_and_bits(
755             AUDIO_CHANNEL_REPRESENTATION_INDEX, bits);
756 }
757 
758 /* Derive an output channel mask for position assignment from a channel count.
759  * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
760  * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
761  * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
762  * for continuity with stereo.
763  * Returns the matching channel mask,
764  * or AUDIO_CHANNEL_NONE if the channel count is zero,
765  * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
766  * configurations for which a default output channel mask is defined.
767  */
audio_channel_out_mask_from_count(uint32_t channel_count)768 static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count)
769 {
770     uint32_t bits;
771     switch (channel_count) {
772     case 0:
773         return AUDIO_CHANNEL_NONE;
774     case 1:
775         bits = AUDIO_CHANNEL_OUT_MONO;
776         break;
777     case 2:
778         bits = AUDIO_CHANNEL_OUT_STEREO;
779         break;
780     case 3:
781         bits = AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER;
782         break;
783     case 4: // 4.0
784         bits = AUDIO_CHANNEL_OUT_QUAD;
785         break;
786     case 5: // 5.0
787         bits = AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER;
788         break;
789     case 6: // 5.1
790         bits = AUDIO_CHANNEL_OUT_5POINT1;
791         break;
792     case 7: // 6.1
793         bits = AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER;
794         break;
795     case 8:
796         bits = AUDIO_CHANNEL_OUT_7POINT1;
797         break;
798     // FIXME FCC_8
799     default:
800         return AUDIO_CHANNEL_INVALID;
801     }
802     return audio_channel_mask_from_representation_and_bits(
803             AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
804 }
805 
806 /* Derive a default input channel mask from a channel count.
807  * Assumes a position mask for mono and stereo, or an index mask for channel counts > 2.
808  * Returns the matching channel mask,
809  * or AUDIO_CHANNEL_NONE if the channel count is zero,
810  * or AUDIO_CHANNEL_INVALID if the channel count exceeds that of the
811  * configurations for which a default input channel mask is defined.
812  */
audio_channel_in_mask_from_count(uint32_t channel_count)813 static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count)
814 {
815     uint32_t bits;
816     switch (channel_count) {
817     case 0:
818         return AUDIO_CHANNEL_NONE;
819     case 1:
820         bits = AUDIO_CHANNEL_IN_MONO;
821         break;
822     case 2:
823         bits = AUDIO_CHANNEL_IN_STEREO;
824         break;
825     case 3:
826     case 4:
827     case 5:
828     case 6:
829     case 7:
830     case 8:
831         // FIXME FCC_8
832         return audio_channel_mask_for_index_assignment_from_count(channel_count);
833     default:
834         return AUDIO_CHANNEL_INVALID;
835     }
836     return audio_channel_mask_from_representation_and_bits(
837             AUDIO_CHANNEL_REPRESENTATION_POSITION, bits);
838 }
839 
audio_channel_mask_in_to_out(audio_channel_mask_t in)840 static inline audio_channel_mask_t audio_channel_mask_in_to_out(audio_channel_mask_t in)
841 {
842     switch (in) {
843     case AUDIO_CHANNEL_IN_MONO:
844         return AUDIO_CHANNEL_OUT_MONO;
845     case AUDIO_CHANNEL_IN_STEREO:
846         return AUDIO_CHANNEL_OUT_STEREO;
847     case AUDIO_CHANNEL_IN_5POINT1:
848         return AUDIO_CHANNEL_OUT_5POINT1;
849     case AUDIO_CHANNEL_IN_3POINT1POINT2:
850         return AUDIO_CHANNEL_OUT_3POINT1POINT2;
851     case AUDIO_CHANNEL_IN_3POINT0POINT2:
852         return AUDIO_CHANNEL_OUT_3POINT0POINT2;
853     case AUDIO_CHANNEL_IN_2POINT1POINT2:
854         return AUDIO_CHANNEL_OUT_2POINT1POINT2;
855     case AUDIO_CHANNEL_IN_2POINT0POINT2:
856         return AUDIO_CHANNEL_OUT_2POINT0POINT2;
857     default:
858         return AUDIO_CHANNEL_INVALID;
859     }
860 }
861 
audio_is_valid_format(audio_format_t format)862 static inline bool audio_is_valid_format(audio_format_t format)
863 {
864     switch (format & AUDIO_FORMAT_MAIN_MASK) {
865     case AUDIO_FORMAT_PCM:
866         switch (format) {
867         case AUDIO_FORMAT_PCM_16_BIT:
868         case AUDIO_FORMAT_PCM_8_BIT:
869         case AUDIO_FORMAT_PCM_32_BIT:
870         case AUDIO_FORMAT_PCM_8_24_BIT:
871         case AUDIO_FORMAT_PCM_FLOAT:
872         case AUDIO_FORMAT_PCM_24_BIT_PACKED:
873             return true;
874         default:
875             return false;
876         }
877         /* not reached */
878     case AUDIO_FORMAT_MP3:
879     case AUDIO_FORMAT_AMR_NB:
880     case AUDIO_FORMAT_AMR_WB:
881     case AUDIO_FORMAT_AAC:
882     case AUDIO_FORMAT_AAC_ADTS:
883     case AUDIO_FORMAT_HE_AAC_V1:
884     case AUDIO_FORMAT_HE_AAC_V2:
885     case AUDIO_FORMAT_AAC_ELD:
886     case AUDIO_FORMAT_AAC_XHE:
887     case AUDIO_FORMAT_VORBIS:
888     case AUDIO_FORMAT_OPUS:
889     case AUDIO_FORMAT_AC3:
890     case AUDIO_FORMAT_E_AC3:
891     case AUDIO_FORMAT_DTS:
892     case AUDIO_FORMAT_DTS_HD:
893     case AUDIO_FORMAT_IEC61937:
894     case AUDIO_FORMAT_DOLBY_TRUEHD:
895     case AUDIO_FORMAT_QCELP:
896     case AUDIO_FORMAT_EVRC:
897     case AUDIO_FORMAT_EVRCB:
898     case AUDIO_FORMAT_EVRCWB:
899     case AUDIO_FORMAT_AAC_ADIF:
900     case AUDIO_FORMAT_AMR_WB_PLUS:
901     case AUDIO_FORMAT_MP2:
902     case AUDIO_FORMAT_EVRCNW:
903     case AUDIO_FORMAT_FLAC:
904     case AUDIO_FORMAT_ALAC:
905     case AUDIO_FORMAT_APE:
906     case AUDIO_FORMAT_WMA:
907     case AUDIO_FORMAT_WMA_PRO:
908     case AUDIO_FORMAT_DSD:
909     case AUDIO_FORMAT_AC4:
910     case AUDIO_FORMAT_LDAC:
911     case AUDIO_FORMAT_E_AC3_JOC:
912     case AUDIO_FORMAT_MAT_1_0:
913     case AUDIO_FORMAT_MAT_2_0:
914     case AUDIO_FORMAT_MAT_2_1:
915         return true;
916     default:
917         return false;
918     }
919 }
920 
921 /**
922  * Extract the primary format, eg. PCM, AC3, etc.
923  */
audio_get_main_format(audio_format_t format)924 static inline audio_format_t audio_get_main_format(audio_format_t format)
925 {
926     return (audio_format_t)(format & AUDIO_FORMAT_MAIN_MASK);
927 }
928 
929 /**
930  * Is the data plain PCM samples that can be scaled and mixed?
931  */
audio_is_linear_pcm(audio_format_t format)932 static inline bool audio_is_linear_pcm(audio_format_t format)
933 {
934     return (audio_get_main_format(format) == AUDIO_FORMAT_PCM);
935 }
936 
937 /**
938  * For this format, is the number of PCM audio frames directly proportional
939  * to the number of data bytes?
940  *
941  * In other words, is the format transported as PCM audio samples,
942  * but not necessarily scalable or mixable.
943  * This returns true for real PCM, but also for AUDIO_FORMAT_IEC61937,
944  * which is transported as 16 bit PCM audio, but where the encoded data
945  * cannot be mixed or scaled.
946  */
audio_has_proportional_frames(audio_format_t format)947 static inline bool audio_has_proportional_frames(audio_format_t format)
948 {
949     audio_format_t mainFormat = audio_get_main_format(format);
950     return (mainFormat == AUDIO_FORMAT_PCM
951             || mainFormat == AUDIO_FORMAT_IEC61937);
952 }
953 
audio_bytes_per_sample(audio_format_t format)954 static inline size_t audio_bytes_per_sample(audio_format_t format)
955 {
956     size_t size = 0;
957 
958     switch (format) {
959     case AUDIO_FORMAT_PCM_32_BIT:
960     case AUDIO_FORMAT_PCM_8_24_BIT:
961         size = sizeof(int32_t);
962         break;
963     case AUDIO_FORMAT_PCM_24_BIT_PACKED:
964         size = sizeof(uint8_t) * 3;
965         break;
966     case AUDIO_FORMAT_PCM_16_BIT:
967     case AUDIO_FORMAT_IEC61937:
968         size = sizeof(int16_t);
969         break;
970     case AUDIO_FORMAT_PCM_8_BIT:
971         size = sizeof(uint8_t);
972         break;
973     case AUDIO_FORMAT_PCM_FLOAT:
974         size = sizeof(float);
975         break;
976     default:
977         break;
978     }
979     return size;
980 }
981 
audio_bytes_per_frame(uint32_t channel_count,audio_format_t format)982 static inline size_t audio_bytes_per_frame(uint32_t channel_count, audio_format_t format)
983 {
984     // cannot overflow for reasonable channel_count
985     return channel_count * audio_bytes_per_sample(format);
986 }
987 
988 /* converts device address to string sent to audio HAL via set_parameters */
audio_device_address_to_parameter(audio_devices_t device,const char * address)989 static inline char *audio_device_address_to_parameter(audio_devices_t device, const char *address)
990 {
991     const size_t kSize = AUDIO_DEVICE_MAX_ADDRESS_LEN + sizeof("a2dp_sink_address=");
992     char param[kSize];
993 
994     if (device & AUDIO_DEVICE_OUT_ALL_A2DP)
995         snprintf(param, kSize, "%s=%s", "a2dp_sink_address", address);
996     else if (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
997         snprintf(param, kSize, "%s=%s", "mix", address);
998     else
999         snprintf(param, kSize, "%s", address);
1000 
1001     return strdup(param);
1002 }
1003 
audio_device_is_digital(audio_devices_t device)1004 static inline bool audio_device_is_digital(audio_devices_t device) {
1005     if ((device & AUDIO_DEVICE_BIT_IN) != 0) {
1006         // input
1007         return (~AUDIO_DEVICE_BIT_IN & device & (AUDIO_DEVICE_IN_ALL_USB |
1008                           AUDIO_DEVICE_IN_HDMI |
1009                           AUDIO_DEVICE_IN_SPDIF |
1010                           AUDIO_DEVICE_IN_IP |
1011                           AUDIO_DEVICE_IN_BUS)) != 0;
1012     } else {
1013         // output
1014         return (device & (AUDIO_DEVICE_OUT_ALL_USB |
1015                           AUDIO_DEVICE_OUT_HDMI |
1016                           AUDIO_DEVICE_OUT_HDMI_ARC |
1017                           AUDIO_DEVICE_OUT_SPDIF |
1018                           AUDIO_DEVICE_OUT_IP |
1019                           AUDIO_DEVICE_OUT_BUS)) != 0;
1020     }
1021 }
1022 
1023 // Unique effect ID (can be generated from the following site:
1024 //  http://www.itu.int/ITU-T/asn1/uuid.html)
1025 // This struct is used for effects identification and in soundtrigger.
1026 typedef struct audio_uuid_s {
1027     uint32_t timeLow;
1028     uint16_t timeMid;
1029     uint16_t timeHiAndVersion;
1030     uint16_t clockSeq;
1031     uint8_t node[6];
1032 } audio_uuid_t;
1033 
1034 //TODO: audio_microphone_location_t need to move to HAL v4.0
1035 typedef enum {
1036     AUDIO_MICROPHONE_LOCATION_UNKNOWN = 0,
1037     AUDIO_MICROPHONE_LOCATION_MAINBODY = 1,
1038     AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE = 2,
1039     AUDIO_MICROPHONE_LOCATION_PERIPHERAL = 3,
1040     AUDIO_MICROPHONE_LOCATION_CNT = 4,
1041 } audio_microphone_location_t;
1042 
1043 //TODO: audio_microphone_directionality_t need to move to HAL v4.0
1044 typedef enum {
1045     AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN = 0,
1046     AUDIO_MICROPHONE_DIRECTIONALITY_OMNI = 1,
1047     AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL = 2,
1048     AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID = 3,
1049     AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID = 4,
1050     AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID = 5,
1051     AUDIO_MICROPHONE_DIRECTIONALITY_CNT = 6,
1052 } audio_microphone_directionality_t;
1053 
1054 /* A 3D point which could be used to represent geometric location
1055  * or orientation of a microphone.
1056  */
1057 struct audio_microphone_coordinate {
1058     float x;
1059     float y;
1060     float z;
1061 };
1062 
1063 /* An number to indicate which group the microphone locate. Main body is
1064  * usually group 0. Developer could use this value to group the microphones
1065  * that locate on the same peripheral or attachments.
1066  */
1067 typedef int audio_microphone_group_t;
1068 
1069 typedef enum {
1070     AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED = 0,
1071     AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT = 1,
1072     AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED = 2,
1073     AUDIO_MICROPHONE_CHANNEL_MAPPING_CNT = 3,
1074 } audio_microphone_channel_mapping_t;
1075 
1076 /* the maximum length for the microphone id */
1077 #define AUDIO_MICROPHONE_ID_MAX_LEN 32
1078 /* max number of frequency responses in a frequency response table */
1079 #define AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES 256
1080 /* max number of microphone */
1081 #define AUDIO_MICROPHONE_MAX_COUNT 32
1082 /* the value of unknown spl */
1083 #define AUDIO_MICROPHONE_SPL_UNKNOWN -FLT_MAX
1084 /* the value of unknown sensitivity */
1085 #define AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN -FLT_MAX
1086 /* the value of unknown coordinate */
1087 #define AUDIO_MICROPHONE_COORDINATE_UNKNOWN -FLT_MAX
1088 /* the value used as address when the address of bottom microphone is empty */
1089 #define AUDIO_BOTTOM_MICROPHONE_ADDRESS "bottom"
1090 /* the value used as address when the address of back microphone is empty */
1091 #define AUDIO_BACK_MICROPHONE_ADDRESS "back"
1092 
1093 struct audio_microphone_characteristic_t {
1094     char                               device_id[AUDIO_MICROPHONE_ID_MAX_LEN];
1095     audio_port_handle_t                id;
1096     audio_devices_t                    device;
1097     char                               address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
1098     audio_microphone_channel_mapping_t channel_mapping[AUDIO_CHANNEL_COUNT_MAX];
1099     audio_microphone_location_t        location;
1100     audio_microphone_group_t           group;
1101     unsigned int                       index_in_the_group;
1102     float                              sensitivity;
1103     float                              max_spl;
1104     float                              min_spl;
1105     audio_microphone_directionality_t  directionality;
1106     unsigned int                       num_frequency_responses;
1107     float frequency_responses[2][AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES];
1108     struct audio_microphone_coordinate geometric_location;
1109     struct audio_microphone_coordinate orientation;
1110 };
1111 
1112 __END_DECLS
1113 
1114 /**
1115  * List of known audio HAL modules. This is the base name of the audio HAL
1116  * library composed of the "audio." prefix, one of the base names below and
1117  * a suffix specific to the device.
1118  * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
1119  *
1120  * The same module names are used in audio policy configuration files.
1121  */
1122 
1123 #define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
1124 #define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
1125 #define AUDIO_HARDWARE_MODULE_ID_USB "usb"
1126 #define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
1127 #define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
1128 #define AUDIO_HARDWARE_MODULE_ID_STUB "stub"
1129 #define AUDIO_HARDWARE_MODULE_ID_HEARING_AID "hearing_aid"
1130 
1131 /**
1132  * Multi-Stream Decoder (MSD) HAL service name. MSD HAL is used to mix
1133  * encoded streams together with PCM streams, producing re-encoded
1134  * streams or PCM streams.
1135  *
1136  * The service must register itself using this name, and audioserver
1137  * tries to instantiate a device factory using this name as well.
1138  * Note that the HIDL implementation library file name *must* have the
1139  * suffix "msd" in order to be picked up by HIDL that is:
1140  *
1141  *   android.hardware.audio@x.x-implmsd.so
1142  */
1143 #define AUDIO_HAL_SERVICE_NAME_MSD "msd"
1144 
1145 /**
1146  * Parameter definitions.
1147  * Note that in the framework code it's recommended to use AudioParameter.h
1148  * instead of these preprocessor defines, and for sure avoid just copying
1149  * the constant values.
1150  */
1151 
1152 #define AUDIO_PARAMETER_VALUE_ON "on"
1153 #define AUDIO_PARAMETER_VALUE_OFF "off"
1154 
1155 /**
1156  *  audio device parameters
1157  */
1158 
1159 /* BT SCO Noise Reduction + Echo Cancellation parameters */
1160 #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
1161 
1162 /* Get a new HW synchronization source identifier.
1163  * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
1164  * or no HW sync is available. */
1165 #define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync"
1166 
1167 /* Screen state */
1168 #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
1169 
1170 /**
1171  *  audio stream parameters
1172  */
1173 
1174 #define AUDIO_PARAMETER_STREAM_ROUTING "routing"             /* audio_devices_t */
1175 #define AUDIO_PARAMETER_STREAM_FORMAT "format"               /* audio_format_t */
1176 #define AUDIO_PARAMETER_STREAM_CHANNELS "channels"           /* audio_channel_mask_t */
1177 #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count"     /* size_t */
1178 #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source"   /* audio_source_t */
1179 #define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
1180 
1181 /* Request the presentation id to be decoded by a next gen audio decoder */
1182 #define AUDIO_PARAMETER_STREAM_PRESENTATION_ID "presentation_id" /* int32_t */
1183 
1184 /* Request the program id to be decoded by a next gen audio decoder */
1185 #define AUDIO_PARAMETER_STREAM_PROGRAM_ID "program_id"           /* int32_t */
1186 
1187 #define AUDIO_PARAMETER_DEVICE_CONNECT "connect"            /* audio_devices_t */
1188 #define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect"      /* audio_devices_t */
1189 
1190 /* Enable mono audio playback if 1, else should be 0. */
1191 #define AUDIO_PARAMETER_MONO_OUTPUT "mono_output"
1192 
1193 /* Set the HW synchronization source for an output stream. */
1194 #define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
1195 
1196 /* Query supported formats. The response is a '|' separated list of strings from
1197  * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
1198 #define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
1199 /* Query supported channel masks. The response is a '|' separated list of strings from
1200  * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
1201 #define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
1202 /* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
1203  * "sup_sampling_rates=44100|48000" */
1204 #define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
1205 
1206 #define AUDIO_PARAMETER_VALUE_LIST_SEPARATOR "|"
1207 
1208 /* Reconfigure offloaded A2DP codec */
1209 #define AUDIO_PARAMETER_RECONFIG_A2DP "reconfigA2dp"
1210 /* Query if HwModule supports reconfiguration of offloaded A2DP codec */
1211 #define AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED "isReconfigA2dpSupported"
1212 
1213 /**
1214  * audio codec parameters
1215  */
1216 
1217 #define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
1218 #define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
1219 #define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
1220 #define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
1221 #define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
1222 #define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
1223 #define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
1224 #define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
1225 #define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL  "music_offload_num_channels"
1226 #define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING  "music_offload_down_sampling"
1227 #define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES  "delay_samples"
1228 #define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES  "padding_samples"
1229 
1230 #endif  // ANDROID_AUDIO_CORE_H
1231