blob: 813cade623e6ecb309215c9aab382335b39a4d5b [file] [log] [blame]
Dima Zavinf1504db2011-03-11 11:20:49 -08001/*
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>
Glenn Kasten841b9e82016-11-08 15:34:07 -080025#include <time.h>
Dima Zavinf1504db2011-03-11 11:20:49 -080026
27#include <cutils/bitops.h>
28
29#include <hardware/hardware.h>
Dima Zavinaa211722011-05-11 14:15:53 -070030#include <system/audio.h>
Eric Laurentf3008aa2011-06-17 16:53:12 -070031#include <hardware/audio_effect.h>
Dima Zavinf1504db2011-03-11 11:20:49 -080032
33__BEGIN_DECLS
34
35/**
36 * The id of this module
37 */
38#define AUDIO_HARDWARE_MODULE_ID "audio"
39
40/**
41 * Name of the audio devices to open
42 */
43#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
44
Eric Laurent55786bc2012-04-10 16:56:32 -070045
46/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
47 * hardcoded to 1. No audio module API change.
48 */
49#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
50#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
51
52/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
53 * will be considered of first generation API.
54 */
55#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
56#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
Eric Laurent85e08e22012-08-28 14:30:35 -070057#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eric Laurent73b8a742014-05-22 14:02:38 -070058#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
59#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
Eric Laurent447cae72014-05-22 13:45:55 -070060/* Minimal audio HAL version supported by the audio framework */
61#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
Eric Laurent55786bc2012-04-10 16:56:32 -070062
Dima Zavinf1504db2011-03-11 11:20:49 -080063/**************************************/
64
Eric Laurent70e81102011-08-07 10:05:40 -070065/**
66 * standard audio parameters that the HAL may need to handle
67 */
68
69/**
70 * audio device parameters
71 */
72
Eric Laurent70e81102011-08-07 10:05:40 -070073/* TTY mode selection */
74#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
75#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
76#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
77#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
78#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
79
Mikhail Naganovf7d1dff2016-10-17 17:13:10 -070080/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off */
Eric Laurentd1a1b1c2014-07-25 12:10:11 -050081#define AUDIO_PARAMETER_KEY_HAC "HACSetting"
82#define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
83#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
84
Eric Laurenta70c5d02012-03-07 18:59:47 -080085/* A2DP sink address set by framework */
86#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
87
Mike Lockwood2d4d9652014-05-28 11:09:54 -070088/* A2DP source address set by framework */
89#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
90
Glenn Kastend930d922014-04-29 13:35:57 -070091/* Bluetooth SCO wideband */
92#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
93
Eric Laurent70e81102011-08-07 10:05:40 -070094/**
95 * audio stream parameters
96 */
97
vivek mehta27258e52016-07-18 13:58:40 -070098/* Enable AANC */
99#define AUDIO_PARAMETER_KEY_AANC "aanc_enabled"
100
Eric Laurent70e81102011-08-07 10:05:40 -0700101/**************************************/
102
Dima Zavinf1504db2011-03-11 11:20:49 -0800103/* common audio stream parameters and operations */
104struct audio_stream {
105
106 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800107 * Return the sampling rate in Hz - eg. 44100.
Dima Zavinf1504db2011-03-11 11:20:49 -0800108 */
109 uint32_t (*get_sample_rate)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700110
111 /* currently unused - use set_parameters with key
112 * AUDIO_PARAMETER_STREAM_SAMPLING_RATE
113 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800114 int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
115
116 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800117 * Return size of input/output buffer in bytes for this stream - eg. 4800.
118 * It should be a multiple of the frame size. See also get_input_buffer_size.
Dima Zavinf1504db2011-03-11 11:20:49 -0800119 */
120 size_t (*get_buffer_size)(const struct audio_stream *stream);
121
122 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800123 * Return the channel mask -
Dima Zavinf1504db2011-03-11 11:20:49 -0800124 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
125 */
Eric Laurent55786bc2012-04-10 16:56:32 -0700126 audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
Dima Zavinf1504db2011-03-11 11:20:49 -0800127
128 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800129 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
Dima Zavinf1504db2011-03-11 11:20:49 -0800130 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800131 audio_format_t (*get_format)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700132
133 /* currently unused - use set_parameters with key
134 * AUDIO_PARAMETER_STREAM_FORMAT
135 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800136 int (*set_format)(struct audio_stream *stream, audio_format_t format);
Dima Zavinf1504db2011-03-11 11:20:49 -0800137
138 /**
139 * Put the audio hardware input/output into standby mode.
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800140 * Driver should exit from standby mode at the next I/O operation.
Dima Zavinf1504db2011-03-11 11:20:49 -0800141 * Returns 0 on success and <0 on failure.
142 */
143 int (*standby)(struct audio_stream *stream);
144
145 /** dump the state of the audio input/output device */
146 int (*dump)(const struct audio_stream *stream, int fd);
147
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800148 /** Return the set of device(s) which this stream is connected to */
Dima Zavinf1504db2011-03-11 11:20:49 -0800149 audio_devices_t (*get_device)(const struct audio_stream *stream);
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800150
151 /**
152 * Currently unused - set_device() corresponds to set_parameters() with key
153 * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
154 * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
155 * input streams only.
156 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800157 int (*set_device)(struct audio_stream *stream, audio_devices_t device);
158
159 /**
160 * set/get audio stream parameters. The function accepts a list of
161 * parameter key value pairs in the form: key1=value1;key2=value2;...
162 *
163 * Some keys are reserved for standard parameters (See AudioParameter class)
164 *
165 * If the implementation does not accept a parameter change while
166 * the output is active but the parameter is acceptable otherwise, it must
167 * return -ENOSYS.
168 *
169 * The audio flinger will put the stream in standby and then change the
170 * parameter value.
171 */
172 int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
173
174 /*
175 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800176 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800177 */
178 char * (*get_parameters)(const struct audio_stream *stream,
179 const char *keys);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700180 int (*add_audio_effect)(const struct audio_stream *stream,
181 effect_handle_t effect);
182 int (*remove_audio_effect)(const struct audio_stream *stream,
183 effect_handle_t effect);
Dima Zavinf1504db2011-03-11 11:20:49 -0800184};
185typedef struct audio_stream audio_stream_t;
186
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000187/* type of asynchronous write callback events. Mutually exclusive */
188typedef enum {
189 STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
Haynes Mathew George0d468762016-07-07 20:05:39 -0700190 STREAM_CBK_EVENT_DRAIN_READY, /* drain completed */
191 STREAM_CBK_EVENT_ERROR, /* stream hit some error, let AF take action */
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000192} stream_callback_event_t;
193
194typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
195
196/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
197typedef enum {
198 AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
199 AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
200 from the current track has been played to
201 give time for gapless track switch */
202} audio_drain_type_t;
203
Dima Zavinf1504db2011-03-11 11:20:49 -0800204/**
205 * audio_stream_out is the abstraction interface for the audio output hardware.
206 *
207 * It provides information about various properties of the audio output
208 * hardware driver.
209 */
210
211struct audio_stream_out {
Stewart Miles84d35492014-05-01 09:03:27 -0700212 /**
213 * Common methods of the audio stream out. This *must* be the first member of audio_stream_out
214 * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
215 * where it's known the audio_stream references an audio_stream_out.
216 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800217 struct audio_stream common;
218
219 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800220 * Return the audio hardware driver estimated latency in milliseconds.
Dima Zavinf1504db2011-03-11 11:20:49 -0800221 */
222 uint32_t (*get_latency)(const struct audio_stream_out *stream);
223
224 /**
225 * Use this method in situations where audio mixing is done in the
226 * hardware. This method serves as a direct interface with hardware,
227 * allowing you to directly set the volume as apposed to via the framework.
228 * This method might produce multiple PCM outputs or hardware accelerated
229 * codecs, such as MP3 or AAC.
230 */
231 int (*set_volume)(struct audio_stream_out *stream, float left, float right);
232
233 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800234 * Write audio buffer to driver. Returns number of bytes written, or a
235 * negative status_t. If at least one frame was written successfully prior to the error,
236 * it is suggested that the driver return that successful (short) byte count
237 * and then return an error in the subsequent call.
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000238 *
239 * If set_callback() has previously been called to enable non-blocking mode
240 * the write() is not allowed to block. It must write only the number of
241 * bytes that currently fit in the driver/hardware buffer and then return
242 * this byte count. If this is less than the requested write size the
243 * callback function must be called when more space is available in the
244 * driver/hardware buffer.
Dima Zavinf1504db2011-03-11 11:20:49 -0800245 */
246 ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
247 size_t bytes);
248
249 /* return the number of audio frames written by the audio dsp to DAC since
250 * the output has exited standby
251 */
252 int (*get_render_position)(const struct audio_stream_out *stream,
253 uint32_t *dsp_frames);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700254
255 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800256 * get the local time at which the next write to the audio driver will be presented.
257 * The units are microseconds, where the epoch is decided by the local audio HAL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700258 */
259 int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
260 int64_t *timestamp);
261
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000262 /**
263 * set the callback function for notifying completion of non-blocking
264 * write and drain.
265 * Calling this function implies that all future write() and drain()
266 * must be non-blocking and use the callback to signal completion.
267 */
268 int (*set_callback)(struct audio_stream_out *stream,
269 stream_callback_t callback, void *cookie);
270
271 /**
272 * Notifies to the audio driver to stop playback however the queued buffers are
273 * retained by the hardware. Useful for implementing pause/resume. Empty implementation
274 * if not supported however should be implemented for hardware with non-trivial
275 * latency. In the pause state audio hardware could still be using power. User may
276 * consider calling suspend after a timeout.
277 *
278 * Implementation of this function is mandatory for offloaded playback.
279 */
280 int (*pause)(struct audio_stream_out* stream);
281
282 /**
283 * Notifies to the audio driver to resume playback following a pause.
284 * Returns error if called without matching pause.
285 *
286 * Implementation of this function is mandatory for offloaded playback.
287 */
288 int (*resume)(struct audio_stream_out* stream);
289
290 /**
291 * Requests notification when data buffered by the driver/hardware has
292 * been played. If set_callback() has previously been called to enable
293 * non-blocking mode, the drain() must not block, instead it should return
294 * quickly and completion of the drain is notified through the callback.
295 * If set_callback() has not been called, the drain() must block until
296 * completion.
297 * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
298 * data has been played.
299 * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
300 * data for the current track has played to allow time for the framework
301 * to perform a gapless track switch.
302 *
303 * Drain must return immediately on stop() and flush() call
304 *
305 * Implementation of this function is mandatory for offloaded playback.
306 */
307 int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
308
309 /**
310 * Notifies to the audio driver to flush the queued data. Stream must already
311 * be paused before calling flush().
312 *
313 * Implementation of this function is mandatory for offloaded playback.
314 */
315 int (*flush)(struct audio_stream_out* stream);
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700316
317 /**
Glenn Kasten22a06b72013-09-10 09:23:07 -0700318 * Return a recent count of the number of audio frames presented to an external observer.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700319 * This excludes frames which have been written but are still in the pipeline.
320 * The count is not reset to zero when output enters standby.
321 * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
Glenn Kasten22a06b72013-09-10 09:23:07 -0700322 * The returned count is expected to be 'recent',
323 * but does not need to be the most recent possible value.
324 * However, the associated time should correspond to whatever count is returned.
325 * Example: assume that N+M frames have been presented, where M is a 'small' number.
326 * Then it is permissible to return N instead of N+M,
327 * and the timestamp should correspond to N rather than N+M.
328 * The terms 'recent' and 'small' are not defined.
329 * They reflect the quality of the implementation.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700330 *
331 * 3.0 and higher only.
332 */
333 int (*get_presentation_position)(const struct audio_stream_out *stream,
334 uint64_t *frames, struct timespec *timestamp);
335
Dima Zavinf1504db2011-03-11 11:20:49 -0800336};
337typedef struct audio_stream_out audio_stream_out_t;
338
339struct audio_stream_in {
Stewart Miles84d35492014-05-01 09:03:27 -0700340 /**
341 * Common methods of the audio stream in. This *must* be the first member of audio_stream_in
342 * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
343 * where it's known the audio_stream references an audio_stream_in.
344 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800345 struct audio_stream common;
346
347 /** set the input gain for the audio driver. This method is for
348 * for future use */
349 int (*set_gain)(struct audio_stream_in *stream, float gain);
350
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800351 /** Read audio buffer in from audio driver. Returns number of bytes read, or a
352 * negative status_t. If at least one frame was read prior to the error,
353 * read should return that byte count and then return an error in the subsequent call.
354 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800355 ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
356 size_t bytes);
357
358 /**
359 * Return the amount of input frames lost in the audio driver since the
360 * last call of this function.
361 * Audio driver is expected to reset the value to 0 and restart counting
362 * upon returning the current value by this function call.
363 * Such loss typically occurs when the user space process is blocked
364 * longer than the capacity of audio driver buffers.
365 *
366 * Unit: the number of input audio frames
367 */
368 uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
Andy Hung9904fab2016-01-15 17:42:36 -0800369
370 /**
371 * Return a recent count of the number of audio frames received and
372 * the clock time associated with that frame count.
373 *
374 * frames is the total frame count received. This should be as early in
375 * the capture pipeline as possible. In general,
376 * frames should be non-negative and should not go "backwards".
377 *
378 * time is the clock MONOTONIC time when frames was measured. In general,
379 * time should be a positive quantity and should not go "backwards".
380 *
381 * The status returned is 0 on success, -ENOSYS if the device is not
382 * ready/available, or -EINVAL if the arguments are null or otherwise invalid.
383 */
384 int (*get_capture_position)(const struct audio_stream_in *stream,
385 int64_t *frames, int64_t *time);
Dima Zavinf1504db2011-03-11 11:20:49 -0800386};
387typedef struct audio_stream_in audio_stream_in_t;
388
389/**
390 * return the frame size (number of bytes per sample).
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700391 *
392 * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
Dima Zavinf1504db2011-03-11 11:20:49 -0800393 */
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700394__attribute__((__deprecated__))
Glenn Kasten48915ac2012-02-20 12:08:57 -0800395static inline size_t audio_stream_frame_size(const struct audio_stream *s)
Dima Zavinf1504db2011-03-11 11:20:49 -0800396{
Glenn Kastena26cbac2012-01-13 14:53:35 -0800397 size_t chan_samp_sz;
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000398 audio_format_t format = s->get_format(s);
Dima Zavinf1504db2011-03-11 11:20:49 -0800399
Phil Burkc3385fc2016-01-19 12:21:55 -0800400 if (audio_has_proportional_frames(format)) {
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000401 chan_samp_sz = audio_bytes_per_sample(format);
402 return popcount(s->get_channels(s)) * chan_samp_sz;
Dima Zavinf1504db2011-03-11 11:20:49 -0800403 }
404
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000405 return sizeof(int8_t);
Dima Zavinf1504db2011-03-11 11:20:49 -0800406}
407
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700408/**
409 * return the frame size (number of bytes per sample) of an output stream.
410 */
411static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
412{
413 size_t chan_samp_sz;
414 audio_format_t format = s->common.get_format(&s->common);
415
Phil Burkc3385fc2016-01-19 12:21:55 -0800416 if (audio_has_proportional_frames(format)) {
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700417 chan_samp_sz = audio_bytes_per_sample(format);
418 return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
419 }
420
421 return sizeof(int8_t);
422}
423
424/**
425 * return the frame size (number of bytes per sample) of an input stream.
426 */
427static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
428{
429 size_t chan_samp_sz;
430 audio_format_t format = s->common.get_format(&s->common);
431
Phil Burkc3385fc2016-01-19 12:21:55 -0800432 if (audio_has_proportional_frames(format)) {
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700433 chan_samp_sz = audio_bytes_per_sample(format);
434 return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
435 }
436
437 return sizeof(int8_t);
438}
Dima Zavinf1504db2011-03-11 11:20:49 -0800439
440/**********************************************************************/
441
442/**
443 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
444 * and the fields of this data structure must begin with hw_module_t
445 * followed by module specific information.
446 */
447struct audio_module {
448 struct hw_module_t common;
449};
450
451struct audio_hw_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700452 /**
453 * Common methods of the audio device. This *must* be the first member of audio_hw_device
454 * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
455 * where it's known the hw_device_t references an audio_hw_device.
456 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800457 struct hw_device_t common;
458
459 /**
460 * used by audio flinger to enumerate what devices are supported by
461 * each audio_hw_device implementation.
462 *
463 * Return value is a bitmask of 1 or more values of audio_devices_t
Eric Laurent85e08e22012-08-28 14:30:35 -0700464 *
465 * NOTE: audio HAL implementations starting with
466 * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
467 * All supported devices should be listed in audio_policy.conf
468 * file and the audio policy manager must choose the appropriate
469 * audio module based on information in this file.
Dima Zavinf1504db2011-03-11 11:20:49 -0800470 */
471 uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
472
473 /**
474 * check to see if the audio hardware interface has been initialized.
475 * returns 0 on success, -ENODEV on failure.
476 */
477 int (*init_check)(const struct audio_hw_device *dev);
478
479 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
480 int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
481
482 /**
483 * set the audio volume for all audio activities other than voice call.
484 * Range between 0.0 and 1.0. If any value other than 0 is returned,
485 * the software mixer will emulate this capability.
486 */
487 int (*set_master_volume)(struct audio_hw_device *dev, float volume);
488
489 /**
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700490 * Get the current master volume value for the HAL, if the HAL supports
491 * master volume control. AudioFlinger will query this value from the
492 * primary audio HAL when the service starts and use the value for setting
493 * the initial master volume across all HALs. HALs which do not support
John Grossman47bf3d72012-07-17 11:54:04 -0700494 * this method may leave it set to NULL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700495 */
496 int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
497
498 /**
Glenn Kasten6df641e2012-01-09 10:41:30 -0800499 * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
Dima Zavinf1504db2011-03-11 11:20:49 -0800500 * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
501 * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
Dima Zavinf1504db2011-03-11 11:20:49 -0800502 */
Glenn Kasten6df641e2012-01-09 10:41:30 -0800503 int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
Dima Zavinf1504db2011-03-11 11:20:49 -0800504
505 /* mic mute */
506 int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
507 int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
508
509 /* set/get global audio parameters */
510 int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
511
512 /*
513 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800514 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800515 */
516 char * (*get_parameters)(const struct audio_hw_device *dev,
517 const char *keys);
518
519 /* Returns audio input buffer size according to parameters passed or
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800520 * 0 if one of the parameters is not supported.
521 * See also get_buffer_size which is for a particular stream.
Dima Zavinf1504db2011-03-11 11:20:49 -0800522 */
523 size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700524 const struct audio_config *config);
Dima Zavinf1504db2011-03-11 11:20:49 -0800525
Eric Laurentf5e24692014-07-27 16:14:57 -0700526 /** This method creates and opens the audio hardware output stream.
527 * The "address" parameter qualifies the "devices" audio device type if needed.
528 * The format format depends on the device type:
529 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
530 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
531 * - Other devices may use a number or any other string.
532 */
533
Eric Laurent55786bc2012-04-10 16:56:32 -0700534 int (*open_output_stream)(struct audio_hw_device *dev,
535 audio_io_handle_t handle,
536 audio_devices_t devices,
537 audio_output_flags_t flags,
538 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700539 struct audio_stream_out **stream_out,
540 const char *address);
Dima Zavinf1504db2011-03-11 11:20:49 -0800541
542 void (*close_output_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700543 struct audio_stream_out* stream_out);
Dima Zavinf1504db2011-03-11 11:20:49 -0800544
545 /** This method creates and opens the audio hardware input stream */
Eric Laurent55786bc2012-04-10 16:56:32 -0700546 int (*open_input_stream)(struct audio_hw_device *dev,
547 audio_io_handle_t handle,
548 audio_devices_t devices,
549 struct audio_config *config,
Glenn Kasten7d973ad2014-07-15 11:10:38 -0700550 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700551 audio_input_flags_t flags,
552 const char *address,
553 audio_source_t source);
Dima Zavinf1504db2011-03-11 11:20:49 -0800554
555 void (*close_input_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700556 struct audio_stream_in *stream_in);
Dima Zavinf1504db2011-03-11 11:20:49 -0800557
558 /** This method dumps the state of the audio hardware */
559 int (*dump)(const struct audio_hw_device *dev, int fd);
John Grossman47bf3d72012-07-17 11:54:04 -0700560
561 /**
562 * set the audio mute status for all audio activities. If any value other
563 * than 0 is returned, the software mixer will emulate this capability.
564 */
565 int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
566
567 /**
568 * Get the current master mute status for the HAL, if the HAL supports
569 * master mute control. AudioFlinger will query this value from the primary
570 * audio HAL when the service starts and use the value for setting the
571 * initial master mute across all HALs. HALs which do not support this
572 * method may leave it set to NULL.
573 */
574 int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
Eric Laurent73b8a742014-05-22 14:02:38 -0700575
576 /**
577 * Routing control
578 */
579
580 /* Creates an audio patch between several source and sink ports.
581 * The handle is allocated by the HAL and should be unique for this
582 * audio HAL module. */
583 int (*create_audio_patch)(struct audio_hw_device *dev,
584 unsigned int num_sources,
585 const struct audio_port_config *sources,
586 unsigned int num_sinks,
587 const struct audio_port_config *sinks,
588 audio_patch_handle_t *handle);
589
590 /* Release an audio patch */
591 int (*release_audio_patch)(struct audio_hw_device *dev,
592 audio_patch_handle_t handle);
593
594 /* Fills the list of supported attributes for a given audio port.
595 * As input, "port" contains the information (type, role, address etc...)
596 * needed by the HAL to identify the port.
597 * As output, "port" contains possible attributes (sampling rates, formats,
598 * channel masks, gain controllers...) for this port.
599 */
600 int (*get_audio_port)(struct audio_hw_device *dev,
601 struct audio_port *port);
602
603 /* Set audio port configuration */
604 int (*set_audio_port_config)(struct audio_hw_device *dev,
605 const struct audio_port_config *config);
606
Dima Zavinf1504db2011-03-11 11:20:49 -0800607};
608typedef struct audio_hw_device audio_hw_device_t;
609
610/** convenience API for opening and closing a supported device */
611
612static inline int audio_hw_device_open(const struct hw_module_t* module,
613 struct audio_hw_device** device)
614{
615 return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700616 TO_HW_DEVICE_T_OPEN(device));
Dima Zavinf1504db2011-03-11 11:20:49 -0800617}
618
619static inline int audio_hw_device_close(struct audio_hw_device* device)
620{
621 return device->common.close(&device->common);
622}
623
624
625__END_DECLS
626
627#endif // ANDROID_AUDIO_INTERFACE_H