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> |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 31 | |
| 32 | __BEGIN_DECLS |
| 33 | |
| 34 | /** |
| 35 | * The id of this module |
| 36 | */ |
| 37 | #define AUDIO_HARDWARE_MODULE_ID "audio" |
| 38 | |
| 39 | /** |
| 40 | * Name of the audio devices to open |
| 41 | */ |
| 42 | #define AUDIO_HARDWARE_INTERFACE "audio_hw_if" |
| 43 | |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 44 | |
| 45 | /* Use version 0.1 to be compatible with first generation of audio hw module with version_major |
| 46 | * hardcoded to 1. No audio module API change. |
| 47 | */ |
| 48 | #define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 49 | #define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1 |
| 50 | |
| 51 | /* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0 |
| 52 | * will be considered of first generation API. |
| 53 | */ |
| 54 | #define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0) |
| 55 | #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] | 56 | #define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) |
| 57 | #define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_2_0 |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 58 | |
Eric Laurent | 431fc78 | 2012-04-03 12:07:02 -0700 | [diff] [blame] | 59 | /** |
| 60 | * List of known audio HAL modules. This is the base name of the audio HAL |
| 61 | * library composed of the "audio." prefix, one of the base names below and |
| 62 | * a suffix specific to the device. |
| 63 | * e.g: audio.primary.goldfish.so or audio.a2dp.default.so |
| 64 | */ |
| 65 | |
| 66 | #define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary" |
| 67 | #define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp" |
| 68 | #define AUDIO_HARDWARE_MODULE_ID_USB "usb" |
Jean-Michel Trivi | 88b79cb | 2012-08-16 13:56:03 -0700 | [diff] [blame] | 69 | #define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix" |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 70 | #define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload" |
Eric Laurent | 431fc78 | 2012-04-03 12:07:02 -0700 | [diff] [blame] | 71 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 72 | /**************************************/ |
| 73 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 74 | /** |
| 75 | * standard audio parameters that the HAL may need to handle |
| 76 | */ |
| 77 | |
| 78 | /** |
| 79 | * audio device parameters |
| 80 | */ |
| 81 | |
Eric Laurent | ed9928c | 2011-08-02 17:12:00 -0700 | [diff] [blame] | 82 | /* BT SCO Noise Reduction + Echo Cancellation parameters */ |
| 83 | #define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec" |
| 84 | #define AUDIO_PARAMETER_VALUE_ON "on" |
| 85 | #define AUDIO_PARAMETER_VALUE_OFF "off" |
| 86 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 87 | /* TTY mode selection */ |
| 88 | #define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode" |
| 89 | #define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off" |
| 90 | #define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco" |
| 91 | #define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco" |
| 92 | #define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full" |
| 93 | |
Eric Laurent | a70c5d0 | 2012-03-07 18:59:47 -0800 | [diff] [blame] | 94 | /* A2DP sink address set by framework */ |
| 95 | #define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address" |
| 96 | |
Glenn Kasten | 34afb68 | 2012-06-08 10:49:34 -0700 | [diff] [blame] | 97 | /* Screen state */ |
| 98 | #define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state" |
| 99 | |
Glenn Kasten | d930d92 | 2014-04-29 13:35:57 -0700 | [diff] [blame^] | 100 | /* Bluetooth SCO wideband */ |
| 101 | #define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs" |
| 102 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 103 | /** |
| 104 | * audio stream parameters |
| 105 | */ |
| 106 | |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 107 | #define AUDIO_PARAMETER_STREAM_ROUTING "routing" // audio_devices_t |
| 108 | #define AUDIO_PARAMETER_STREAM_FORMAT "format" // audio_format_t |
| 109 | #define AUDIO_PARAMETER_STREAM_CHANNELS "channels" // audio_channel_mask_t |
| 110 | #define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" // size_t |
| 111 | #define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" // audio_source_t |
| 112 | #define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" // uint32_t |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 113 | |
Eric Laurent | 41eeb4f | 2012-05-17 18:54:49 -0700 | [diff] [blame] | 114 | /* Query supported formats. The response is a '|' separated list of strings from |
| 115 | * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */ |
| 116 | #define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats" |
| 117 | /* Query supported channel masks. The response is a '|' separated list of strings from |
| 118 | * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */ |
| 119 | #define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels" |
| 120 | /* Query supported sampling rates. The response is a '|' separated list of integer values e.g: |
| 121 | * "sup_sampling_rates=44100|48000" */ |
| 122 | #define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates" |
| 123 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 124 | /** |
| 125 | * audio codec parameters |
| 126 | */ |
| 127 | |
| 128 | #define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param" |
| 129 | #define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample" |
| 130 | #define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate" |
| 131 | #define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate" |
| 132 | #define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id" |
| 133 | #define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align" |
| 134 | #define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate" |
| 135 | #define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option" |
| 136 | #define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels" |
| 137 | #define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling" |
| 138 | #define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples" |
| 139 | #define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples" |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 140 | |
Eric Laurent | 70e8110 | 2011-08-07 10:05:40 -0700 | [diff] [blame] | 141 | /**************************************/ |
| 142 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 143 | /* common audio stream configuration parameters |
| 144 | * You should memset() the entire structure to zero before use to |
| 145 | * ensure forward compatibility |
| 146 | */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 147 | struct audio_config { |
| 148 | uint32_t sample_rate; |
| 149 | audio_channel_mask_t channel_mask; |
| 150 | audio_format_t format; |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 151 | audio_offload_info_t offload_info; |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 152 | }; |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 153 | typedef struct audio_config audio_config_t; |
| 154 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 155 | /* common audio stream parameters and operations */ |
| 156 | struct audio_stream { |
| 157 | |
| 158 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 159 | * Return the sampling rate in Hz - eg. 44100. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 160 | */ |
| 161 | uint32_t (*get_sample_rate)(const struct audio_stream *stream); |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 162 | |
| 163 | /* currently unused - use set_parameters with key |
| 164 | * AUDIO_PARAMETER_STREAM_SAMPLING_RATE |
| 165 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 166 | int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate); |
| 167 | |
| 168 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 169 | * Return size of input/output buffer in bytes for this stream - eg. 4800. |
| 170 | * 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] | 171 | */ |
| 172 | size_t (*get_buffer_size)(const struct audio_stream *stream); |
| 173 | |
| 174 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 175 | * Return the channel mask - |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 176 | * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO |
| 177 | */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 178 | audio_channel_mask_t (*get_channels)(const struct audio_stream *stream); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 179 | |
| 180 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 181 | * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 182 | */ |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 183 | audio_format_t (*get_format)(const struct audio_stream *stream); |
Dima Zavin | 57dde28 | 2011-06-06 19:31:18 -0700 | [diff] [blame] | 184 | |
| 185 | /* currently unused - use set_parameters with key |
| 186 | * AUDIO_PARAMETER_STREAM_FORMAT |
| 187 | */ |
Glenn Kasten | fe79eb3 | 2012-01-12 14:55:57 -0800 | [diff] [blame] | 188 | int (*set_format)(struct audio_stream *stream, audio_format_t format); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Put the audio hardware input/output into standby mode. |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 192 | * Driver should exit from standby mode at the next I/O operation. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 193 | * Returns 0 on success and <0 on failure. |
| 194 | */ |
| 195 | int (*standby)(struct audio_stream *stream); |
| 196 | |
| 197 | /** dump the state of the audio input/output device */ |
| 198 | int (*dump)(const struct audio_stream *stream, int fd); |
| 199 | |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 200 | /** Return the set of device(s) which this stream is connected to */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 201 | audio_devices_t (*get_device)(const struct audio_stream *stream); |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Currently unused - set_device() corresponds to set_parameters() with key |
| 205 | * AUDIO_PARAMETER_STREAM_ROUTING for both input and output. |
| 206 | * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by |
| 207 | * input streams only. |
| 208 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 209 | int (*set_device)(struct audio_stream *stream, audio_devices_t device); |
| 210 | |
| 211 | /** |
| 212 | * set/get audio stream parameters. The function accepts a list of |
| 213 | * parameter key value pairs in the form: key1=value1;key2=value2;... |
| 214 | * |
| 215 | * Some keys are reserved for standard parameters (See AudioParameter class) |
| 216 | * |
| 217 | * If the implementation does not accept a parameter change while |
| 218 | * the output is active but the parameter is acceptable otherwise, it must |
| 219 | * return -ENOSYS. |
| 220 | * |
| 221 | * The audio flinger will put the stream in standby and then change the |
| 222 | * parameter value. |
| 223 | */ |
| 224 | int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs); |
| 225 | |
| 226 | /* |
| 227 | * Returns a pointer to a heap allocated string. The caller is responsible |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 228 | * for freeing the memory for it using free(). |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 229 | */ |
| 230 | char * (*get_parameters)(const struct audio_stream *stream, |
| 231 | const char *keys); |
Eric Laurent | f3008aa | 2011-06-17 16:53:12 -0700 | [diff] [blame] | 232 | int (*add_audio_effect)(const struct audio_stream *stream, |
| 233 | effect_handle_t effect); |
| 234 | int (*remove_audio_effect)(const struct audio_stream *stream, |
| 235 | effect_handle_t effect); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 236 | }; |
| 237 | typedef struct audio_stream audio_stream_t; |
| 238 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 239 | /* type of asynchronous write callback events. Mutually exclusive */ |
| 240 | typedef enum { |
| 241 | STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */ |
| 242 | STREAM_CBK_EVENT_DRAIN_READY /* drain completed */ |
| 243 | } stream_callback_event_t; |
| 244 | |
| 245 | typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie); |
| 246 | |
| 247 | /* type of drain requested to audio_stream_out->drain(). Mutually exclusive */ |
| 248 | typedef enum { |
| 249 | AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */ |
| 250 | AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data |
| 251 | from the current track has been played to |
| 252 | give time for gapless track switch */ |
| 253 | } audio_drain_type_t; |
| 254 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 255 | /** |
| 256 | * audio_stream_out is the abstraction interface for the audio output hardware. |
| 257 | * |
| 258 | * It provides information about various properties of the audio output |
| 259 | * hardware driver. |
| 260 | */ |
| 261 | |
| 262 | struct audio_stream_out { |
| 263 | struct audio_stream common; |
| 264 | |
| 265 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 266 | * Return the audio hardware driver estimated latency in milliseconds. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 267 | */ |
| 268 | uint32_t (*get_latency)(const struct audio_stream_out *stream); |
| 269 | |
| 270 | /** |
| 271 | * Use this method in situations where audio mixing is done in the |
| 272 | * hardware. This method serves as a direct interface with hardware, |
| 273 | * allowing you to directly set the volume as apposed to via the framework. |
| 274 | * This method might produce multiple PCM outputs or hardware accelerated |
| 275 | * codecs, such as MP3 or AAC. |
| 276 | */ |
| 277 | int (*set_volume)(struct audio_stream_out *stream, float left, float right); |
| 278 | |
| 279 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 280 | * Write audio buffer to driver. Returns number of bytes written, or a |
| 281 | * negative status_t. If at least one frame was written successfully prior to the error, |
| 282 | * it is suggested that the driver return that successful (short) byte count |
| 283 | * and then return an error in the subsequent call. |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 284 | * |
| 285 | * If set_callback() has previously been called to enable non-blocking mode |
| 286 | * the write() is not allowed to block. It must write only the number of |
| 287 | * bytes that currently fit in the driver/hardware buffer and then return |
| 288 | * this byte count. If this is less than the requested write size the |
| 289 | * callback function must be called when more space is available in the |
| 290 | * driver/hardware buffer. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 291 | */ |
| 292 | ssize_t (*write)(struct audio_stream_out *stream, const void* buffer, |
| 293 | size_t bytes); |
| 294 | |
| 295 | /* return the number of audio frames written by the audio dsp to DAC since |
| 296 | * the output has exited standby |
| 297 | */ |
| 298 | int (*get_render_position)(const struct audio_stream_out *stream, |
| 299 | uint32_t *dsp_frames); |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 300 | |
| 301 | /** |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 302 | * get the local time at which the next write to the audio driver will be presented. |
| 303 | * 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] | 304 | */ |
| 305 | int (*get_next_write_timestamp)(const struct audio_stream_out *stream, |
| 306 | int64_t *timestamp); |
| 307 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 308 | /** |
| 309 | * set the callback function for notifying completion of non-blocking |
| 310 | * write and drain. |
| 311 | * Calling this function implies that all future write() and drain() |
| 312 | * must be non-blocking and use the callback to signal completion. |
| 313 | */ |
| 314 | int (*set_callback)(struct audio_stream_out *stream, |
| 315 | stream_callback_t callback, void *cookie); |
| 316 | |
| 317 | /** |
| 318 | * Notifies to the audio driver to stop playback however the queued buffers are |
| 319 | * retained by the hardware. Useful for implementing pause/resume. Empty implementation |
| 320 | * if not supported however should be implemented for hardware with non-trivial |
| 321 | * latency. In the pause state audio hardware could still be using power. User may |
| 322 | * consider calling suspend after a timeout. |
| 323 | * |
| 324 | * Implementation of this function is mandatory for offloaded playback. |
| 325 | */ |
| 326 | int (*pause)(struct audio_stream_out* stream); |
| 327 | |
| 328 | /** |
| 329 | * Notifies to the audio driver to resume playback following a pause. |
| 330 | * Returns error if called without matching pause. |
| 331 | * |
| 332 | * Implementation of this function is mandatory for offloaded playback. |
| 333 | */ |
| 334 | int (*resume)(struct audio_stream_out* stream); |
| 335 | |
| 336 | /** |
| 337 | * Requests notification when data buffered by the driver/hardware has |
| 338 | * been played. If set_callback() has previously been called to enable |
| 339 | * non-blocking mode, the drain() must not block, instead it should return |
| 340 | * quickly and completion of the drain is notified through the callback. |
| 341 | * If set_callback() has not been called, the drain() must block until |
| 342 | * completion. |
| 343 | * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written |
| 344 | * data has been played. |
| 345 | * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all |
| 346 | * data for the current track has played to allow time for the framework |
| 347 | * to perform a gapless track switch. |
| 348 | * |
| 349 | * Drain must return immediately on stop() and flush() call |
| 350 | * |
| 351 | * Implementation of this function is mandatory for offloaded playback. |
| 352 | */ |
| 353 | int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type ); |
| 354 | |
| 355 | /** |
| 356 | * Notifies to the audio driver to flush the queued data. Stream must already |
| 357 | * be paused before calling flush(). |
| 358 | * |
| 359 | * Implementation of this function is mandatory for offloaded playback. |
| 360 | */ |
| 361 | int (*flush)(struct audio_stream_out* stream); |
Glenn Kasten | e25f9ed | 2013-08-22 16:27:22 -0700 | [diff] [blame] | 362 | |
| 363 | /** |
Glenn Kasten | 22a06b7 | 2013-09-10 09:23:07 -0700 | [diff] [blame] | 364 | * 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] | 365 | * This excludes frames which have been written but are still in the pipeline. |
| 366 | * The count is not reset to zero when output enters standby. |
| 367 | * Also returns the value of CLOCK_MONOTONIC as of this presentation count. |
Glenn Kasten | 22a06b7 | 2013-09-10 09:23:07 -0700 | [diff] [blame] | 368 | * The returned count is expected to be 'recent', |
| 369 | * but does not need to be the most recent possible value. |
| 370 | * However, the associated time should correspond to whatever count is returned. |
| 371 | * Example: assume that N+M frames have been presented, where M is a 'small' number. |
| 372 | * Then it is permissible to return N instead of N+M, |
| 373 | * and the timestamp should correspond to N rather than N+M. |
| 374 | * The terms 'recent' and 'small' are not defined. |
| 375 | * They reflect the quality of the implementation. |
Glenn Kasten | e25f9ed | 2013-08-22 16:27:22 -0700 | [diff] [blame] | 376 | * |
| 377 | * 3.0 and higher only. |
| 378 | */ |
| 379 | int (*get_presentation_position)(const struct audio_stream_out *stream, |
| 380 | uint64_t *frames, struct timespec *timestamp); |
| 381 | |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 382 | }; |
| 383 | typedef struct audio_stream_out audio_stream_out_t; |
| 384 | |
| 385 | struct audio_stream_in { |
| 386 | struct audio_stream common; |
| 387 | |
| 388 | /** set the input gain for the audio driver. This method is for |
| 389 | * for future use */ |
| 390 | int (*set_gain)(struct audio_stream_in *stream, float gain); |
| 391 | |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 392 | /** Read audio buffer in from audio driver. Returns number of bytes read, or a |
| 393 | * negative status_t. If at least one frame was read prior to the error, |
| 394 | * read should return that byte count and then return an error in the subsequent call. |
| 395 | */ |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 396 | ssize_t (*read)(struct audio_stream_in *stream, void* buffer, |
| 397 | size_t bytes); |
| 398 | |
| 399 | /** |
| 400 | * Return the amount of input frames lost in the audio driver since the |
| 401 | * last call of this function. |
| 402 | * Audio driver is expected to reset the value to 0 and restart counting |
| 403 | * upon returning the current value by this function call. |
| 404 | * Such loss typically occurs when the user space process is blocked |
| 405 | * longer than the capacity of audio driver buffers. |
| 406 | * |
| 407 | * Unit: the number of input audio frames |
| 408 | */ |
| 409 | uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream); |
| 410 | }; |
| 411 | typedef struct audio_stream_in audio_stream_in_t; |
| 412 | |
| 413 | /** |
| 414 | * return the frame size (number of bytes per sample). |
| 415 | */ |
Glenn Kasten | 48915ac | 2012-02-20 12:08:57 -0800 | [diff] [blame] | 416 | 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] | 417 | { |
Glenn Kasten | a26cbac | 2012-01-13 14:53:35 -0800 | [diff] [blame] | 418 | size_t chan_samp_sz; |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 419 | audio_format_t format = s->get_format(s); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 420 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 421 | if (audio_is_linear_pcm(format)) { |
| 422 | chan_samp_sz = audio_bytes_per_sample(format); |
| 423 | return popcount(s->get_channels(s)) * chan_samp_sz; |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Richard Fitzgerald | f37f187 | 2013-03-25 16:11:44 +0000 | [diff] [blame] | 426 | return sizeof(int8_t); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | |
| 430 | /**********************************************************************/ |
| 431 | |
| 432 | /** |
| 433 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 434 | * and the fields of this data structure must begin with hw_module_t |
| 435 | * followed by module specific information. |
| 436 | */ |
| 437 | struct audio_module { |
| 438 | struct hw_module_t common; |
| 439 | }; |
| 440 | |
| 441 | struct audio_hw_device { |
| 442 | struct hw_device_t common; |
| 443 | |
| 444 | /** |
| 445 | * used by audio flinger to enumerate what devices are supported by |
| 446 | * each audio_hw_device implementation. |
| 447 | * |
| 448 | * 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] | 449 | * |
| 450 | * NOTE: audio HAL implementations starting with |
| 451 | * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function. |
| 452 | * All supported devices should be listed in audio_policy.conf |
| 453 | * file and the audio policy manager must choose the appropriate |
| 454 | * audio module based on information in this file. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 455 | */ |
| 456 | uint32_t (*get_supported_devices)(const struct audio_hw_device *dev); |
| 457 | |
| 458 | /** |
| 459 | * check to see if the audio hardware interface has been initialized. |
| 460 | * returns 0 on success, -ENODEV on failure. |
| 461 | */ |
| 462 | int (*init_check)(const struct audio_hw_device *dev); |
| 463 | |
| 464 | /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */ |
| 465 | int (*set_voice_volume)(struct audio_hw_device *dev, float volume); |
| 466 | |
| 467 | /** |
| 468 | * set the audio volume for all audio activities other than voice call. |
| 469 | * Range between 0.0 and 1.0. If any value other than 0 is returned, |
| 470 | * the software mixer will emulate this capability. |
| 471 | */ |
| 472 | int (*set_master_volume)(struct audio_hw_device *dev, float volume); |
| 473 | |
| 474 | /** |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 475 | * Get the current master volume value for the HAL, if the HAL supports |
| 476 | * master volume control. AudioFlinger will query this value from the |
| 477 | * primary audio HAL when the service starts and use the value for setting |
| 478 | * the initial master volume across all HALs. HALs which do not support |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 479 | * this method may leave it set to NULL. |
Mike J. Chen | 5ad38a9 | 2011-08-15 12:05:00 -0700 | [diff] [blame] | 480 | */ |
| 481 | int (*get_master_volume)(struct audio_hw_device *dev, float *volume); |
| 482 | |
| 483 | /** |
Glenn Kasten | 6df641e | 2012-01-09 10:41:30 -0800 | [diff] [blame] | 484 | * 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] | 485 | * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is |
| 486 | * playing, and AUDIO_MODE_IN_CALL when a call is in progress. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 487 | */ |
Glenn Kasten | 6df641e | 2012-01-09 10:41:30 -0800 | [diff] [blame] | 488 | int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 489 | |
| 490 | /* mic mute */ |
| 491 | int (*set_mic_mute)(struct audio_hw_device *dev, bool state); |
| 492 | int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state); |
| 493 | |
| 494 | /* set/get global audio parameters */ |
| 495 | int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs); |
| 496 | |
| 497 | /* |
| 498 | * Returns a pointer to a heap allocated string. The caller is responsible |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 499 | * for freeing the memory for it using free(). |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 500 | */ |
| 501 | char * (*get_parameters)(const struct audio_hw_device *dev, |
| 502 | const char *keys); |
| 503 | |
| 504 | /* Returns audio input buffer size according to parameters passed or |
Glenn Kasten | 0cacd8d | 2012-02-10 13:42:44 -0800 | [diff] [blame] | 505 | * 0 if one of the parameters is not supported. |
| 506 | * See also get_buffer_size which is for a particular stream. |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 507 | */ |
| 508 | size_t (*get_input_buffer_size)(const struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 509 | const struct audio_config *config); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 510 | |
| 511 | /** This method creates and opens the audio hardware output stream */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 512 | int (*open_output_stream)(struct audio_hw_device *dev, |
| 513 | audio_io_handle_t handle, |
| 514 | audio_devices_t devices, |
| 515 | audio_output_flags_t flags, |
| 516 | struct audio_config *config, |
| 517 | struct audio_stream_out **stream_out); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 518 | |
| 519 | void (*close_output_stream)(struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 520 | struct audio_stream_out* stream_out); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 521 | |
| 522 | /** This method creates and opens the audio hardware input stream */ |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 523 | int (*open_input_stream)(struct audio_hw_device *dev, |
| 524 | audio_io_handle_t handle, |
| 525 | audio_devices_t devices, |
| 526 | struct audio_config *config, |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 527 | struct audio_stream_in **stream_in); |
| 528 | |
| 529 | void (*close_input_stream)(struct audio_hw_device *dev, |
Eric Laurent | 55786bc | 2012-04-10 16:56:32 -0700 | [diff] [blame] | 530 | struct audio_stream_in *stream_in); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 531 | |
| 532 | /** This method dumps the state of the audio hardware */ |
| 533 | int (*dump)(const struct audio_hw_device *dev, int fd); |
John Grossman | 47bf3d7 | 2012-07-17 11:54:04 -0700 | [diff] [blame] | 534 | |
| 535 | /** |
| 536 | * set the audio mute status for all audio activities. If any value other |
| 537 | * than 0 is returned, the software mixer will emulate this capability. |
| 538 | */ |
| 539 | int (*set_master_mute)(struct audio_hw_device *dev, bool mute); |
| 540 | |
| 541 | /** |
| 542 | * Get the current master mute status for the HAL, if the HAL supports |
| 543 | * master mute control. AudioFlinger will query this value from the primary |
| 544 | * audio HAL when the service starts and use the value for setting the |
| 545 | * initial master mute across all HALs. HALs which do not support this |
| 546 | * method may leave it set to NULL. |
| 547 | */ |
| 548 | int (*get_master_mute)(struct audio_hw_device *dev, bool *mute); |
Dima Zavin | f1504db | 2011-03-11 11:20:49 -0800 | [diff] [blame] | 549 | }; |
| 550 | typedef struct audio_hw_device audio_hw_device_t; |
| 551 | |
| 552 | /** convenience API for opening and closing a supported device */ |
| 553 | |
| 554 | static inline int audio_hw_device_open(const struct hw_module_t* module, |
| 555 | struct audio_hw_device** device) |
| 556 | { |
| 557 | return module->methods->open(module, AUDIO_HARDWARE_INTERFACE, |
| 558 | (struct hw_device_t**)device); |
| 559 | } |
| 560 | |
| 561 | static inline int audio_hw_device_close(struct audio_hw_device* device) |
| 562 | { |
| 563 | return device->common.close(&device->common); |
| 564 | } |
| 565 | |
| 566 | |
| 567 | __END_DECLS |
| 568 | |
| 569 | #endif // ANDROID_AUDIO_INTERFACE_H |