Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 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_HAL_INTERFACE_H |
| 19 | #define ANDROID_AUDIO_HAL_INTERFACE_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <strings.h> |
| 23 | #include <sys/cdefs.h> |
| 24 | #include <sys/types.h> |
| 25 | |
| 26 | #include <cutils/bitops.h> |
| 27 | |
| 28 | #include <hardware/hardware.h> |
Dima Zavin | aa21172 | 2011-05-11 14:15:53 -0700 | [diff] [blame] | 29 | #include <system/audio.h> |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 30 | #include <hardware/audio_effect.h> |
Kiran Kandi | 0efc9ff | 2013-10-17 15:49:54 -0700 | [diff] [blame] | 31 | #ifdef AUDIO_LISTEN_ENABLED |
| 32 | #include <listen_types.h> |
| 33 | #endif |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 34 | |
| 35 | __BEGIN_DECLS |
| 36 | |
| 37 | /** |
| 38 | * The id of this module |
| 39 | */ |
| 40 | #define AUDIO_HARDWARE_MODULE_ID "audio" |
| 41 | |
| 42 | /** |
| 43 | * Name of the audio devices to open |
| 44 | */ |
| 45 | #define AUDIO_HARDWARE_INTERFACE "audio_hw_if" |
| 46 | |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 47 | |
| 48 | /* Use version 0.1 to be compatible with first generation of audio hw module with version_major |
| 49 | * hardcoded to 1. No audio module API change. |
| 50 | */ |
| 51 | #define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 52 | #define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1 |
| 53 | |
| 54 | /* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0 |
| 55 | * will be considered of first generation API. |
| 56 | */ |
| 57 | #define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0) |
| 58 | #define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) |
Eric Laurent | 85e08e2 | 2012-08-28 14:30:35 -0700 | [diff] [blame] | 59 | #define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) |
Eric Laurent | 73b8a74 | 2014-05-22 14:02:38 -0700 | [diff] [blame] | 60 | #define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) |
| 61 | #define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0 |
Eric Laurent | 447cae7 | 2014-05-22 13:45:55 -0700 | [diff] [blame] | 62 | /* Minimal audio HAL version supported by the audio framework */ |
| 63 | #define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0 |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 64 | |
Eric Laurent | 431fc78 | 2012-04-03 12:07:02 -0700 | [diff] [blame] | 65 | /** |
| 66 | * List of known audio HAL modules. This is the base name of the audio HAL |
| 67 | * library composed of the "audio." prefix, one of the base names below and |
| 68 | * a suffix specific to the device. |
| 69 | * e.g: audio.primary.goldfish.so or audio.a2dp.default.so |
| 70 | */ |
| 71 | |
| 72 | #define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary" |
| 73 | #define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp" |
| 74 | #define AUDIO_HARDWARE_MODULE_ID_USB "usb" |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 75 | #define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix" |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 76 | #define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload" |
Eric Laurent | 431fc78 | 2012-04-03 12:07:02 -0700 | [diff] [blame] | 77 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 78 | /**************************************/ |
| 79 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 80 | /** |
| 81 | * standard audio parameters that the HAL may need to handle |
| 82 | */ |
| 83 | |
| 84 | /** |
| 85 | * audio device parameters |
| 86 | */ |
| 87 | |
Eric Laurent | ed9928c | 2011-08-02 17:12:00 -0700 | [diff] [blame] | 88 | /* BT SCO Noise Reduction + Echo Cancellation parameters */ |
| 89 | #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec" |
| 90 | #define AUDIO_PARAMETER_VALUE_ON "on" |
| 91 | #define AUDIO_PARAMETER_VALUE_OFF "off" |
| 92 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 93 | /* TTY mode selection */ |
| 94 | #define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode" |
| 95 | #define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off" |
| 96 | #define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco" |
| 97 | #define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco" |
| 98 | #define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full" |
| 99 | |
Eric Laurent | d1a1b1c | 2014-07-25 12:10:11 -0500 | [diff] [blame] | 100 | /* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off |
| 101 | Strings must be in sync with CallFeaturesSetting.java */ |
| 102 | #define AUDIO_PARAMETER_KEY_HAC "HACSetting" |
| 103 | #define AUDIO_PARAMETER_VALUE_HAC_ON "ON" |
| 104 | #define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF" |
| 105 | |
Eric Laurent | a70c5d0 | 2012-03-07 18:59:47 -0800 | [diff] [blame] | 106 | /* A2DP sink address set by framework */ |
| 107 | #define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address" |
| 108 | |
Mike Lockwood | 2d4d965 | 2014-05-28 11:09:54 -0700 | [diff] [blame] | 109 | /* A2DP source address set by framework */ |
| 110 | #define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address" |
| 111 | |
Glenn Kasten | 34afb68 | 2012-06-08 10:49:34 -0700 | [diff] [blame] | 112 | /* Screen state */ |
| 113 | #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state" |
| 114 | |
Glenn Kasten | d930d92 | 2014-04-29 13:35:57 -0700 | [diff] [blame] | 115 | /* Bluetooth SCO wideband */ |
| 116 | #define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs" |
| 117 | |
Bala Kishore Pati | 494ff16 | 2016-10-10 19:39:28 +0530 | [diff] [blame] | 118 | |
| 119 | /* Device state*/ |
| 120 | #define AUDIO_PARAMETER_KEY_DEV_SHUTDOWN "dev_shutdown" |
| 121 | |
Eric Laurent | bc19a3d | 2014-10-17 18:17:51 -0700 | [diff] [blame] | 122 | /* Get a new HW synchronization source identifier. |
| 123 | * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs |
| 124 | * or no HW sync is available. */ |
| 125 | #define AUDIO_PARAMETER_HW_AV_SYNC "hw_av_sync" |
Eric Laurent | 4ea9b95 | 2014-08-01 14:42:44 -0700 | [diff] [blame] | 126 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 127 | /** |
| 128 | * audio stream parameters |
| 129 | */ |
| 130 | |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 131 | #define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */ |
| 132 | #define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */ |
| 133 | #define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */ |
| 134 | #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */ |
| 135 | #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */ |
| 136 | #define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */ |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 137 | |
Haynes Mathew George | d5f7dbe | 2014-09-24 19:10:12 -0700 | [diff] [blame] | 138 | #define AUDIO_PARAMETER_DEVICE_CONNECT "connect" /* audio_devices_t */ |
Paul McLean | 2c6196f | 2014-08-20 16:50:25 -0700 | [diff] [blame] | 139 | #define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */ |
| 140 | |
Eric Laurent | 41eeb4f | 2012-05-17 18:54:49 -0700 | [diff] [blame] | 141 | /* Query supported formats. The response is a '|' separated list of strings from |
| 142 | * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */ |
| 143 | #define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats" |
| 144 | /* Query supported channel masks. The response is a '|' separated list of strings from |
| 145 | * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */ |
| 146 | #define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels" |
| 147 | /* Query supported sampling rates. The response is a '|' separated list of integer values e.g: |
| 148 | * "sup_sampling_rates=44100|48000" */ |
| 149 | #define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates" |
| 150 | |
Eric Laurent | bc19a3d | 2014-10-17 18:17:51 -0700 | [diff] [blame] | 151 | /* Set the HW synchronization source for an output stream. */ |
Eric Laurent | 4ea9b95 | 2014-08-01 14:42:44 -0700 | [diff] [blame] | 152 | #define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync" |
| 153 | |
Andy Hung | 89d567f | 2016-01-05 11:23:36 -0800 | [diff] [blame] | 154 | /* Enable mono audio playback if 1, else should be 0. */ |
| 155 | #define AUDIO_PARAMETER_MONO_OUTPUT "mono_output" |
| 156 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 157 | /** |
| 158 | * audio codec parameters |
| 159 | */ |
| 160 | |
| 161 | #define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param" |
| 162 | #define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample" |
| 163 | #define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate" |
| 164 | #define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate" |
| 165 | #define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id" |
| 166 | #define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align" |
| 167 | #define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate" |
| 168 | #define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option" |
| 169 | #define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels" |
| 170 | #define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling" |
| 171 | #define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples" |
| 172 | #define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples" |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 173 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 174 | /**************************************/ |
| 175 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 176 | /* common audio stream parameters and operations */ |
| 177 | struct audio_stream { |
| 178 | |
| 179 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 180 | * Return the sampling rate in Hz - eg. 44100. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 181 | */ |
| 182 | uint32_t (*get_sample_rate)(const struct audio_stream *stream); |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 183 | |
| 184 | /* currently unused - use set_parameters with key |
| 185 | * AUDIO_PARAMETER_STREAM_SAMPLING_RATE |
| 186 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 187 | int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate); |
| 188 | |
| 189 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 190 | * Return size of input/output buffer in bytes for this stream - eg. 4800. |
| 191 | * It should be a multiple of the frame size. See also get_input_buffer_size. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 192 | */ |
| 193 | size_t (*get_buffer_size)(const struct audio_stream *stream); |
| 194 | |
| 195 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 196 | * Return the channel mask - |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 197 | * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO |
| 198 | */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 199 | audio_channel_mask_t (*get_channels)(const struct audio_stream *stream); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 200 | |
| 201 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 202 | * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 203 | */ |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 204 | audio_format_t (*get_format)(const struct audio_stream *stream); |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 205 | |
| 206 | /* currently unused - use set_parameters with key |
| 207 | * AUDIO_PARAMETER_STREAM_FORMAT |
| 208 | */ |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 209 | int (*set_format)(struct audio_stream *stream, audio_format_t format); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * Put the audio hardware input/output into standby mode. |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 213 | * Driver should exit from standby mode at the next I/O operation. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 214 | * Returns 0 on success and <0 on failure. |
| 215 | */ |
| 216 | int (*standby)(struct audio_stream *stream); |
| 217 | |
| 218 | /** dump the state of the audio input/output device */ |
| 219 | int (*dump)(const struct audio_stream *stream, int fd); |
| 220 | |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 221 | /** Return the set of device(s) which this stream is connected to */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 222 | audio_devices_t (*get_device)(const struct audio_stream *stream); |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * Currently unused - set_device() corresponds to set_parameters() with key |
| 226 | * AUDIO_PARAMETER_STREAM_ROUTING for both input and output. |
| 227 | * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by |
| 228 | * input streams only. |
| 229 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 230 | int (*set_device)(struct audio_stream *stream, audio_devices_t device); |
| 231 | |
| 232 | /** |
| 233 | * set/get audio stream parameters. The function accepts a list of |
| 234 | * parameter key value pairs in the form: key1=value1;key2=value2;... |
| 235 | * |
| 236 | * Some keys are reserved for standard parameters (See AudioParameter class) |
| 237 | * |
| 238 | * If the implementation does not accept a parameter change while |
| 239 | * the output is active but the parameter is acceptable otherwise, it must |
| 240 | * return -ENOSYS. |
| 241 | * |
| 242 | * The audio flinger will put the stream in standby and then change the |
| 243 | * parameter value. |
| 244 | */ |
| 245 | int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs); |
| 246 | |
| 247 | /* |
| 248 | * Returns a pointer to a heap allocated string. The caller is responsible |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 249 | * for freeing the memory for it using free(). |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 250 | */ |
| 251 | char * (*get_parameters)(const struct audio_stream *stream, |
| 252 | const char *keys); |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 253 | int (*add_audio_effect)(const struct audio_stream *stream, |
| 254 | effect_handle_t effect); |
| 255 | int (*remove_audio_effect)(const struct audio_stream *stream, |
| 256 | effect_handle_t effect); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 257 | }; |
| 258 | typedef struct audio_stream audio_stream_t; |
| 259 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 260 | /* type of asynchronous write callback events. Mutually exclusive */ |
| 261 | typedef enum { |
| 262 | STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */ |
Haynes Mathew George | 0d46876 | 2016-07-07 20:05:39 -0700 | [diff] [blame] | 263 | STREAM_CBK_EVENT_DRAIN_READY, /* drain completed */ |
| 264 | STREAM_CBK_EVENT_ERROR, /* stream hit some error, let AF take action */ |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 265 | } stream_callback_event_t; |
| 266 | |
| 267 | typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie); |
| 268 | |
| 269 | /* type of drain requested to audio_stream_out->drain(). Mutually exclusive */ |
| 270 | typedef enum { |
| 271 | AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */ |
| 272 | AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data |
| 273 | from the current track has been played to |
| 274 | give time for gapless track switch */ |
| 275 | } audio_drain_type_t; |
| 276 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 277 | /** |
| 278 | * audio_stream_out is the abstraction interface for the audio output hardware. |
| 279 | * |
| 280 | * It provides information about various properties of the audio output |
| 281 | * hardware driver. |
| 282 | */ |
| 283 | |
| 284 | struct audio_stream_out { |
Stewart Miles | 84d3549 | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 285 | /** |
| 286 | * Common methods of the audio stream out. This *must* be the first member of audio_stream_out |
| 287 | * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts |
| 288 | * where it's known the audio_stream references an audio_stream_out. |
| 289 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 290 | struct audio_stream common; |
| 291 | |
| 292 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 293 | * Return the audio hardware driver estimated latency in milliseconds. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 294 | */ |
| 295 | uint32_t (*get_latency)(const struct audio_stream_out *stream); |
| 296 | |
| 297 | /** |
| 298 | * Use this method in situations where audio mixing is done in the |
| 299 | * hardware. This method serves as a direct interface with hardware, |
| 300 | * allowing you to directly set the volume as apposed to via the framework. |
| 301 | * This method might produce multiple PCM outputs or hardware accelerated |
| 302 | * codecs, such as MP3 or AAC. |
| 303 | */ |
| 304 | int (*set_volume)(struct audio_stream_out *stream, float left, float right); |
| 305 | |
| 306 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 307 | * Write audio buffer to driver. Returns number of bytes written, or a |
| 308 | * negative status_t. If at least one frame was written successfully prior to the error, |
| 309 | * it is suggested that the driver return that successful (short) byte count |
| 310 | * and then return an error in the subsequent call. |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 311 | * |
| 312 | * If set_callback() has previously been called to enable non-blocking mode |
| 313 | * the write() is not allowed to block. It must write only the number of |
| 314 | * bytes that currently fit in the driver/hardware buffer and then return |
| 315 | * this byte count. If this is less than the requested write size the |
| 316 | * callback function must be called when more space is available in the |
| 317 | * driver/hardware buffer. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 318 | */ |
| 319 | ssize_t (*write)(struct audio_stream_out *stream, const void* buffer, |
| 320 | size_t bytes); |
| 321 | |
| 322 | /* return the number of audio frames written by the audio dsp to DAC since |
| 323 | * the output has exited standby |
| 324 | */ |
| 325 | int (*get_render_position)(const struct audio_stream_out *stream, |
| 326 | uint32_t *dsp_frames); |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 327 | |
| 328 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 329 | * get the local time at which the next write to the audio driver will be presented. |
| 330 | * The units are microseconds, where the epoch is decided by the local audio HAL. |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 331 | */ |
| 332 | int (*get_next_write_timestamp)(const struct audio_stream_out *stream, |
| 333 | int64_t *timestamp); |
| 334 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 335 | /** |
| 336 | * set the callback function for notifying completion of non-blocking |
| 337 | * write and drain. |
| 338 | * Calling this function implies that all future write() and drain() |
| 339 | * must be non-blocking and use the callback to signal completion. |
| 340 | */ |
| 341 | int (*set_callback)(struct audio_stream_out *stream, |
| 342 | stream_callback_t callback, void *cookie); |
| 343 | |
| 344 | /** |
| 345 | * Notifies to the audio driver to stop playback however the queued buffers are |
| 346 | * retained by the hardware. Useful for implementing pause/resume. Empty implementation |
| 347 | * if not supported however should be implemented for hardware with non-trivial |
| 348 | * latency. In the pause state audio hardware could still be using power. User may |
| 349 | * consider calling suspend after a timeout. |
| 350 | * |
| 351 | * Implementation of this function is mandatory for offloaded playback. |
| 352 | */ |
| 353 | int (*pause)(struct audio_stream_out* stream); |
| 354 | |
| 355 | /** |
| 356 | * Notifies to the audio driver to resume playback following a pause. |
| 357 | * Returns error if called without matching pause. |
| 358 | * |
| 359 | * Implementation of this function is mandatory for offloaded playback. |
| 360 | */ |
| 361 | int (*resume)(struct audio_stream_out* stream); |
| 362 | |
| 363 | /** |
| 364 | * Requests notification when data buffered by the driver/hardware has |
| 365 | * been played. If set_callback() has previously been called to enable |
| 366 | * non-blocking mode, the drain() must not block, instead it should return |
| 367 | * quickly and completion of the drain is notified through the callback. |
| 368 | * If set_callback() has not been called, the drain() must block until |
| 369 | * completion. |
| 370 | * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written |
| 371 | * data has been played. |
| 372 | * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all |
| 373 | * data for the current track has played to allow time for the framework |
| 374 | * to perform a gapless track switch. |
| 375 | * |
| 376 | * Drain must return immediately on stop() and flush() call |
| 377 | * |
| 378 | * Implementation of this function is mandatory for offloaded playback. |
| 379 | */ |
| 380 | int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type ); |
| 381 | |
| 382 | /** |
| 383 | * Notifies to the audio driver to flush the queued data. Stream must already |
| 384 | * be paused before calling flush(). |
| 385 | * |
| 386 | * Implementation of this function is mandatory for offloaded playback. |
| 387 | */ |
| 388 | int (*flush)(struct audio_stream_out* stream); |
Glenn Kasten | e25f9ed | 2013-08-22 16:27:22 -0700 | [diff] [blame] | 389 | |
| 390 | /** |
Glenn Kasten | 22a06b7 | 2013-09-10 09:23:07 -0700 | [diff] [blame] | 391 | * Return a recent count of the number of audio frames presented to an external observer. |
Glenn Kasten | e25f9ed | 2013-08-22 16:27:22 -0700 | [diff] [blame] | 392 | * This excludes frames which have been written but are still in the pipeline. |
| 393 | * The count is not reset to zero when output enters standby. |
| 394 | * Also returns the value of CLOCK_MONOTONIC as of this presentation count. |
Glenn Kasten | 22a06b7 | 2013-09-10 09:23:07 -0700 | [diff] [blame] | 395 | * The returned count is expected to be 'recent', |
| 396 | * but does not need to be the most recent possible value. |
| 397 | * However, the associated time should correspond to whatever count is returned. |
| 398 | * Example: assume that N+M frames have been presented, where M is a 'small' number. |
| 399 | * Then it is permissible to return N instead of N+M, |
| 400 | * and the timestamp should correspond to N rather than N+M. |
| 401 | * The terms 'recent' and 'small' are not defined. |
| 402 | * They reflect the quality of the implementation. |
Glenn Kasten | e25f9ed | 2013-08-22 16:27:22 -0700 | [diff] [blame] | 403 | * |
| 404 | * 3.0 and higher only. |
| 405 | */ |
| 406 | int (*get_presentation_position)(const struct audio_stream_out *stream, |
| 407 | uint64_t *frames, struct timespec *timestamp); |
| 408 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 409 | }; |
| 410 | typedef struct audio_stream_out audio_stream_out_t; |
| 411 | |
| 412 | struct audio_stream_in { |
Stewart Miles | 84d3549 | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Common methods of the audio stream in. This *must* be the first member of audio_stream_in |
| 415 | * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts |
| 416 | * where it's known the audio_stream references an audio_stream_in. |
| 417 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 418 | struct audio_stream common; |
| 419 | |
| 420 | /** set the input gain for the audio driver. This method is for |
| 421 | * for future use */ |
| 422 | int (*set_gain)(struct audio_stream_in *stream, float gain); |
| 423 | |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 424 | /** Read audio buffer in from audio driver. Returns number of bytes read, or a |
| 425 | * negative status_t. If at least one frame was read prior to the error, |
| 426 | * read should return that byte count and then return an error in the subsequent call. |
| 427 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 428 | ssize_t (*read)(struct audio_stream_in *stream, void* buffer, |
| 429 | size_t bytes); |
| 430 | |
| 431 | /** |
| 432 | * Return the amount of input frames lost in the audio driver since the |
| 433 | * last call of this function. |
| 434 | * Audio driver is expected to reset the value to 0 and restart counting |
| 435 | * upon returning the current value by this function call. |
| 436 | * Such loss typically occurs when the user space process is blocked |
| 437 | * longer than the capacity of audio driver buffers. |
| 438 | * |
| 439 | * Unit: the number of input audio frames |
| 440 | */ |
| 441 | uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream); |
Andy Hung | 9904fab | 2016-01-15 17:42:36 -0800 | [diff] [blame] | 442 | |
| 443 | /** |
| 444 | * Return a recent count of the number of audio frames received and |
| 445 | * the clock time associated with that frame count. |
| 446 | * |
| 447 | * frames is the total frame count received. This should be as early in |
| 448 | * the capture pipeline as possible. In general, |
| 449 | * frames should be non-negative and should not go "backwards". |
| 450 | * |
| 451 | * time is the clock MONOTONIC time when frames was measured. In general, |
| 452 | * time should be a positive quantity and should not go "backwards". |
| 453 | * |
| 454 | * The status returned is 0 on success, -ENOSYS if the device is not |
| 455 | * ready/available, or -EINVAL if the arguments are null or otherwise invalid. |
| 456 | */ |
| 457 | int (*get_capture_position)(const struct audio_stream_in *stream, |
| 458 | int64_t *frames, int64_t *time); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 459 | }; |
| 460 | typedef struct audio_stream_in audio_stream_in_t; |
| 461 | |
| 462 | /** |
| 463 | * return the frame size (number of bytes per sample). |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 464 | * |
| 465 | * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 466 | */ |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 467 | __attribute__((__deprecated__)) |
Glenn Kasten | 48915ac | 2012-02-20 12:08:57 -0800 | [diff] [blame] | 468 | static inline size_t audio_stream_frame_size(const struct audio_stream *s) |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 469 | { |
Glenn Kasten | a26cbac | 2012-01-13 14:53:35 -0800 | [diff] [blame] | 470 | size_t chan_samp_sz; |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 471 | audio_format_t format = s->get_format(s); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 472 | |
Phil Burk | c3385fc | 2016-01-19 12:21:55 -0800 | [diff] [blame] | 473 | if (audio_has_proportional_frames(format)) { |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 474 | chan_samp_sz = audio_bytes_per_sample(format); |
| 475 | return popcount(s->get_channels(s)) * chan_samp_sz; |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 478 | return sizeof(int8_t); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 479 | } |
| 480 | |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 481 | /** |
| 482 | * return the frame size (number of bytes per sample) of an output stream. |
| 483 | */ |
| 484 | static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s) |
| 485 | { |
| 486 | size_t chan_samp_sz; |
| 487 | audio_format_t format = s->common.get_format(&s->common); |
| 488 | |
Phil Burk | c3385fc | 2016-01-19 12:21:55 -0800 | [diff] [blame] | 489 | if (audio_has_proportional_frames(format)) { |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 490 | chan_samp_sz = audio_bytes_per_sample(format); |
| 491 | return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz; |
| 492 | } |
| 493 | |
| 494 | return sizeof(int8_t); |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * return the frame size (number of bytes per sample) of an input stream. |
| 499 | */ |
| 500 | static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s) |
| 501 | { |
| 502 | size_t chan_samp_sz; |
| 503 | audio_format_t format = s->common.get_format(&s->common); |
| 504 | |
Phil Burk | c3385fc | 2016-01-19 12:21:55 -0800 | [diff] [blame] | 505 | if (audio_has_proportional_frames(format)) { |
Eric Laurent | c5ae6a0 | 2014-07-02 13:45:32 -0700 | [diff] [blame] | 506 | chan_samp_sz = audio_bytes_per_sample(format); |
| 507 | return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz; |
| 508 | } |
| 509 | |
| 510 | return sizeof(int8_t); |
| 511 | } |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 512 | |
| 513 | /**********************************************************************/ |
| 514 | |
| 515 | /** |
| 516 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 517 | * and the fields of this data structure must begin with hw_module_t |
| 518 | * followed by module specific information. |
| 519 | */ |
| 520 | struct audio_module { |
| 521 | struct hw_module_t common; |
| 522 | }; |
| 523 | |
| 524 | struct audio_hw_device { |
Stewart Miles | 84d3549 | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 525 | /** |
| 526 | * Common methods of the audio device. This *must* be the first member of audio_hw_device |
| 527 | * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts |
| 528 | * where it's known the hw_device_t references an audio_hw_device. |
| 529 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 530 | struct hw_device_t common; |
| 531 | |
| 532 | /** |
| 533 | * used by audio flinger to enumerate what devices are supported by |
| 534 | * each audio_hw_device implementation. |
| 535 | * |
| 536 | * Return value is a bitmask of 1 or more values of audio_devices_t |
Eric Laurent | 85e08e2 | 2012-08-28 14:30:35 -0700 | [diff] [blame] | 537 | * |
| 538 | * NOTE: audio HAL implementations starting with |
| 539 | * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function. |
| 540 | * All supported devices should be listed in audio_policy.conf |
| 541 | * file and the audio policy manager must choose the appropriate |
| 542 | * audio module based on information in this file. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 543 | */ |
| 544 | uint32_t (*get_supported_devices)(const struct audio_hw_device *dev); |
| 545 | |
| 546 | /** |
| 547 | * check to see if the audio hardware interface has been initialized. |
| 548 | * returns 0 on success, -ENODEV on failure. |
| 549 | */ |
| 550 | int (*init_check)(const struct audio_hw_device *dev); |
| 551 | |
| 552 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ |
| 553 | int (*set_voice_volume)(struct audio_hw_device *dev, float volume); |
| 554 | |
| 555 | /** |
| 556 | * set the audio volume for all audio activities other than voice call. |
| 557 | * Range between 0.0 and 1.0. If any value other than 0 is returned, |
| 558 | * the software mixer will emulate this capability. |
| 559 | */ |
| 560 | int (*set_master_volume)(struct audio_hw_device *dev, float volume); |
| 561 | |
| 562 | /** |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 563 | * Get the current master volume value for the HAL, if the HAL supports |
| 564 | * master volume control. AudioFlinger will query this value from the |
| 565 | * primary audio HAL when the service starts and use the value for setting |
| 566 | * the initial master volume across all HALs. HALs which do not support |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 567 | * this method may leave it set to NULL. |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 568 | */ |
| 569 | int (*get_master_volume)(struct audio_hw_device *dev, float *volume); |
| 570 | |
| 571 | /** |
Glenn Kasten | 6df641e | 2012-01-09 10:41:30 -0800 | [diff] [blame] | 572 | * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 573 | * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is |
| 574 | * playing, and AUDIO_MODE_IN_CALL when a call is in progress. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 575 | */ |
Glenn Kasten | 6df641e | 2012-01-09 10:41:30 -0800 | [diff] [blame] | 576 | int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 577 | |
| 578 | /* mic mute */ |
| 579 | int (*set_mic_mute)(struct audio_hw_device *dev, bool state); |
| 580 | int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state); |
| 581 | |
| 582 | /* set/get global audio parameters */ |
| 583 | int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs); |
| 584 | |
| 585 | /* |
| 586 | * Returns a pointer to a heap allocated string. The caller is responsible |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 587 | * for freeing the memory for it using free(). |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 588 | */ |
| 589 | char * (*get_parameters)(const struct audio_hw_device *dev, |
| 590 | const char *keys); |
| 591 | |
| 592 | /* Returns audio input buffer size according to parameters passed or |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 593 | * 0 if one of the parameters is not supported. |
| 594 | * See also get_buffer_size which is for a particular stream. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 595 | */ |
| 596 | size_t (*get_input_buffer_size)(const struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 597 | const struct audio_config *config); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 598 | |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 599 | /** This method creates and opens the audio hardware output stream. |
| 600 | * The "address" parameter qualifies the "devices" audio device type if needed. |
| 601 | * The format format depends on the device type: |
| 602 | * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC" |
| 603 | * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y" |
| 604 | * - Other devices may use a number or any other string. |
| 605 | */ |
| 606 | |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 607 | int (*open_output_stream)(struct audio_hw_device *dev, |
| 608 | audio_io_handle_t handle, |
| 609 | audio_devices_t devices, |
| 610 | audio_output_flags_t flags, |
| 611 | struct audio_config *config, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 612 | struct audio_stream_out **stream_out, |
| 613 | const char *address); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 614 | |
| 615 | void (*close_output_stream)(struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 616 | struct audio_stream_out* stream_out); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 617 | |
| 618 | /** This method creates and opens the audio hardware input stream */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 619 | int (*open_input_stream)(struct audio_hw_device *dev, |
| 620 | audio_io_handle_t handle, |
| 621 | audio_devices_t devices, |
| 622 | struct audio_config *config, |
Glenn Kasten | 7d973ad | 2014-07-15 11:10:38 -0700 | [diff] [blame] | 623 | struct audio_stream_in **stream_in, |
Eric Laurent | f5e2469 | 2014-07-27 16:14:57 -0700 | [diff] [blame] | 624 | audio_input_flags_t flags, |
| 625 | const char *address, |
| 626 | audio_source_t source); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 627 | |
| 628 | void (*close_input_stream)(struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 629 | struct audio_stream_in *stream_in); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 630 | |
| 631 | /** This method dumps the state of the audio hardware */ |
| 632 | int (*dump)(const struct audio_hw_device *dev, int fd); |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 633 | |
| 634 | /** |
| 635 | * set the audio mute status for all audio activities. If any value other |
| 636 | * than 0 is returned, the software mixer will emulate this capability. |
| 637 | */ |
| 638 | int (*set_master_mute)(struct audio_hw_device *dev, bool mute); |
| 639 | |
| 640 | /** |
| 641 | * Get the current master mute status for the HAL, if the HAL supports |
| 642 | * master mute control. AudioFlinger will query this value from the primary |
| 643 | * audio HAL when the service starts and use the value for setting the |
| 644 | * initial master mute across all HALs. HALs which do not support this |
| 645 | * method may leave it set to NULL. |
| 646 | */ |
| 647 | int (*get_master_mute)(struct audio_hw_device *dev, bool *mute); |
Eric Laurent | 73b8a74 | 2014-05-22 14:02:38 -0700 | [diff] [blame] | 648 | |
| 649 | /** |
| 650 | * Routing control |
| 651 | */ |
| 652 | |
| 653 | /* Creates an audio patch between several source and sink ports. |
| 654 | * The handle is allocated by the HAL and should be unique for this |
| 655 | * audio HAL module. */ |
| 656 | int (*create_audio_patch)(struct audio_hw_device *dev, |
| 657 | unsigned int num_sources, |
| 658 | const struct audio_port_config *sources, |
| 659 | unsigned int num_sinks, |
| 660 | const struct audio_port_config *sinks, |
| 661 | audio_patch_handle_t *handle); |
| 662 | |
| 663 | /* Release an audio patch */ |
| 664 | int (*release_audio_patch)(struct audio_hw_device *dev, |
| 665 | audio_patch_handle_t handle); |
| 666 | |
| 667 | /* Fills the list of supported attributes for a given audio port. |
| 668 | * As input, "port" contains the information (type, role, address etc...) |
| 669 | * needed by the HAL to identify the port. |
| 670 | * As output, "port" contains possible attributes (sampling rates, formats, |
| 671 | * channel masks, gain controllers...) for this port. |
| 672 | */ |
| 673 | int (*get_audio_port)(struct audio_hw_device *dev, |
| 674 | struct audio_port *port); |
| 675 | |
| 676 | /* Set audio port configuration */ |
| 677 | int (*set_audio_port_config)(struct audio_hw_device *dev, |
| 678 | const struct audio_port_config *config); |
| 679 | |
Kiran Kandi | 0efc9ff | 2013-10-17 15:49:54 -0700 | [diff] [blame] | 680 | #ifdef AUDIO_LISTEN_ENABLED |
| 681 | /** This method creates the listen session and returns handle */ |
| 682 | int (*open_listen_session)(struct audio_hw_device *dev, |
| 683 | listen_open_params_t *params, |
| 684 | struct listen_session** handle); |
| 685 | |
| 686 | /** This method closes the listen session */ |
| 687 | int (*close_listen_session)(struct audio_hw_device *dev, |
| 688 | struct listen_session* handle); |
| 689 | |
| 690 | /** This method sets the mad observer callback */ |
| 691 | int (*set_mad_observer)(struct audio_hw_device *dev, |
| 692 | listen_callback_t cb_func); |
| 693 | |
| 694 | /** |
| 695 | * This method is used for setting listen hal specfic parameters. |
| 696 | * If multiple paramets are set in one call and setting any one of them |
| 697 | * fails it will return failure. |
| 698 | */ |
| 699 | int (*listen_set_parameters)(struct audio_hw_device *dev, |
| 700 | const char *kv_pairs); |
| 701 | #endif |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 702 | }; |
| 703 | typedef struct audio_hw_device audio_hw_device_t; |
| 704 | |
| 705 | /** convenience API for opening and closing a supported device */ |
| 706 | |
| 707 | static inline int audio_hw_device_open(const struct hw_module_t* module, |
| 708 | struct audio_hw_device** device) |
| 709 | { |
| 710 | return module->methods->open(module, AUDIO_HARDWARE_INTERFACE, |
| 711 | (struct hw_device_t**)device); |
| 712 | } |
| 713 | |
| 714 | static inline int audio_hw_device_close(struct audio_hw_device* device) |
| 715 | { |
| 716 | return device->common.close(&device->common); |
| 717 | } |
| 718 | |
| 719 | |
| 720 | __END_DECLS |
| 721 | |
| 722 | #endif // ANDROID_AUDIO_INTERFACE_H |