blob: 4c938ac6ac2a7bc5be1430a901c22f88127395f9 [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>
25
26#include <cutils/bitops.h>
27
28#include <hardware/hardware.h>
Dima Zavinaa211722011-05-11 14:15:53 -070029#include <system/audio.h>
Eric Laurentf3008aa2011-06-17 16:53:12 -070030#include <hardware/audio_effect.h>
Dima Zavinf1504db2011-03-11 11:20:49 -080031
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 Laurent55786bc2012-04-10 16:56:32 -070044
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 Laurent85e08e22012-08-28 14:30:35 -070056#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eric Laurent73b8a742014-05-22 14:02:38 -070057#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
58#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
Eric Laurent447cae72014-05-22 13:45:55 -070059/* Minimal audio HAL version supported by the audio framework */
60#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
Eric Laurent55786bc2012-04-10 16:56:32 -070061
Dima Zavinf1504db2011-03-11 11:20:49 -080062/**************************************/
63
Eric Laurent70e81102011-08-07 10:05:40 -070064/**
65 * standard audio parameters that the HAL may need to handle
66 */
67
68/**
69 * audio device parameters
70 */
71
Eric Laurent70e81102011-08-07 10:05:40 -070072/* TTY mode selection */
73#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
74#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
75#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
76#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
77#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
78
Mikhail Naganovf7d1dff2016-10-17 17:13:10 -070079/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off */
Eric Laurentd1a1b1c2014-07-25 12:10:11 -050080#define AUDIO_PARAMETER_KEY_HAC "HACSetting"
81#define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
82#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
83
Eric Laurenta70c5d02012-03-07 18:59:47 -080084/* A2DP sink address set by framework */
85#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
86
Mike Lockwood2d4d9652014-05-28 11:09:54 -070087/* A2DP source address set by framework */
88#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
89
Glenn Kastend930d922014-04-29 13:35:57 -070090/* Bluetooth SCO wideband */
91#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
92
Eric Laurent70e81102011-08-07 10:05:40 -070093/**
94 * audio stream parameters
95 */
96
vivek mehta27258e52016-07-18 13:58:40 -070097/* Enable AANC */
98#define AUDIO_PARAMETER_KEY_AANC "aanc_enabled"
99
Eric Laurent70e81102011-08-07 10:05:40 -0700100/**************************************/
101
Dima Zavinf1504db2011-03-11 11:20:49 -0800102/* common audio stream parameters and operations */
103struct audio_stream {
104
105 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800106 * Return the sampling rate in Hz - eg. 44100.
Dima Zavinf1504db2011-03-11 11:20:49 -0800107 */
108 uint32_t (*get_sample_rate)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700109
110 /* currently unused - use set_parameters with key
111 * AUDIO_PARAMETER_STREAM_SAMPLING_RATE
112 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800113 int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
114
115 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800116 * Return size of input/output buffer in bytes for this stream - eg. 4800.
117 * It should be a multiple of the frame size. See also get_input_buffer_size.
Dima Zavinf1504db2011-03-11 11:20:49 -0800118 */
119 size_t (*get_buffer_size)(const struct audio_stream *stream);
120
121 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800122 * Return the channel mask -
Dima Zavinf1504db2011-03-11 11:20:49 -0800123 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
124 */
Eric Laurent55786bc2012-04-10 16:56:32 -0700125 audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
Dima Zavinf1504db2011-03-11 11:20:49 -0800126
127 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800128 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
Dima Zavinf1504db2011-03-11 11:20:49 -0800129 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800130 audio_format_t (*get_format)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700131
132 /* currently unused - use set_parameters with key
133 * AUDIO_PARAMETER_STREAM_FORMAT
134 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800135 int (*set_format)(struct audio_stream *stream, audio_format_t format);
Dima Zavinf1504db2011-03-11 11:20:49 -0800136
137 /**
138 * Put the audio hardware input/output into standby mode.
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800139 * Driver should exit from standby mode at the next I/O operation.
Dima Zavinf1504db2011-03-11 11:20:49 -0800140 * Returns 0 on success and <0 on failure.
141 */
142 int (*standby)(struct audio_stream *stream);
143
144 /** dump the state of the audio input/output device */
145 int (*dump)(const struct audio_stream *stream, int fd);
146
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800147 /** Return the set of device(s) which this stream is connected to */
Dima Zavinf1504db2011-03-11 11:20:49 -0800148 audio_devices_t (*get_device)(const struct audio_stream *stream);
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800149
150 /**
151 * Currently unused - set_device() corresponds to set_parameters() with key
152 * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
153 * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
154 * input streams only.
155 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800156 int (*set_device)(struct audio_stream *stream, audio_devices_t device);
157
158 /**
159 * set/get audio stream parameters. The function accepts a list of
160 * parameter key value pairs in the form: key1=value1;key2=value2;...
161 *
162 * Some keys are reserved for standard parameters (See AudioParameter class)
163 *
164 * If the implementation does not accept a parameter change while
165 * the output is active but the parameter is acceptable otherwise, it must
166 * return -ENOSYS.
167 *
168 * The audio flinger will put the stream in standby and then change the
169 * parameter value.
170 */
171 int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
172
173 /*
174 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800175 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800176 */
177 char * (*get_parameters)(const struct audio_stream *stream,
178 const char *keys);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700179 int (*add_audio_effect)(const struct audio_stream *stream,
180 effect_handle_t effect);
181 int (*remove_audio_effect)(const struct audio_stream *stream,
182 effect_handle_t effect);
Dima Zavinf1504db2011-03-11 11:20:49 -0800183};
184typedef struct audio_stream audio_stream_t;
185
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000186/* type of asynchronous write callback events. Mutually exclusive */
187typedef enum {
188 STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
Haynes Mathew George0d468762016-07-07 20:05:39 -0700189 STREAM_CBK_EVENT_DRAIN_READY, /* drain completed */
190 STREAM_CBK_EVENT_ERROR, /* stream hit some error, let AF take action */
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000191} stream_callback_event_t;
192
193typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
194
195/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
196typedef enum {
197 AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
198 AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
199 from the current track has been played to
200 give time for gapless track switch */
201} audio_drain_type_t;
202
Dima Zavinf1504db2011-03-11 11:20:49 -0800203/**
204 * audio_stream_out is the abstraction interface for the audio output hardware.
205 *
206 * It provides information about various properties of the audio output
207 * hardware driver.
208 */
209
210struct audio_stream_out {
Stewart Miles84d35492014-05-01 09:03:27 -0700211 /**
212 * Common methods of the audio stream out. This *must* be the first member of audio_stream_out
213 * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
214 * where it's known the audio_stream references an audio_stream_out.
215 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800216 struct audio_stream common;
217
218 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800219 * Return the audio hardware driver estimated latency in milliseconds.
Dima Zavinf1504db2011-03-11 11:20:49 -0800220 */
221 uint32_t (*get_latency)(const struct audio_stream_out *stream);
222
223 /**
224 * Use this method in situations where audio mixing is done in the
225 * hardware. This method serves as a direct interface with hardware,
226 * allowing you to directly set the volume as apposed to via the framework.
227 * This method might produce multiple PCM outputs or hardware accelerated
228 * codecs, such as MP3 or AAC.
229 */
230 int (*set_volume)(struct audio_stream_out *stream, float left, float right);
231
232 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800233 * Write audio buffer to driver. Returns number of bytes written, or a
234 * negative status_t. If at least one frame was written successfully prior to the error,
235 * it is suggested that the driver return that successful (short) byte count
236 * and then return an error in the subsequent call.
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000237 *
238 * If set_callback() has previously been called to enable non-blocking mode
239 * the write() is not allowed to block. It must write only the number of
240 * bytes that currently fit in the driver/hardware buffer and then return
241 * this byte count. If this is less than the requested write size the
242 * callback function must be called when more space is available in the
243 * driver/hardware buffer.
Dima Zavinf1504db2011-03-11 11:20:49 -0800244 */
245 ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
246 size_t bytes);
247
248 /* return the number of audio frames written by the audio dsp to DAC since
249 * the output has exited standby
250 */
251 int (*get_render_position)(const struct audio_stream_out *stream,
252 uint32_t *dsp_frames);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700253
254 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800255 * get the local time at which the next write to the audio driver will be presented.
256 * The units are microseconds, where the epoch is decided by the local audio HAL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700257 */
258 int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
259 int64_t *timestamp);
260
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000261 /**
262 * set the callback function for notifying completion of non-blocking
263 * write and drain.
264 * Calling this function implies that all future write() and drain()
265 * must be non-blocking and use the callback to signal completion.
266 */
267 int (*set_callback)(struct audio_stream_out *stream,
268 stream_callback_t callback, void *cookie);
269
270 /**
271 * Notifies to the audio driver to stop playback however the queued buffers are
272 * retained by the hardware. Useful for implementing pause/resume. Empty implementation
273 * if not supported however should be implemented for hardware with non-trivial
274 * latency. In the pause state audio hardware could still be using power. User may
275 * consider calling suspend after a timeout.
276 *
277 * Implementation of this function is mandatory for offloaded playback.
278 */
279 int (*pause)(struct audio_stream_out* stream);
280
281 /**
282 * Notifies to the audio driver to resume playback following a pause.
283 * Returns error if called without matching pause.
284 *
285 * Implementation of this function is mandatory for offloaded playback.
286 */
287 int (*resume)(struct audio_stream_out* stream);
288
289 /**
290 * Requests notification when data buffered by the driver/hardware has
291 * been played. If set_callback() has previously been called to enable
292 * non-blocking mode, the drain() must not block, instead it should return
293 * quickly and completion of the drain is notified through the callback.
294 * If set_callback() has not been called, the drain() must block until
295 * completion.
296 * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
297 * data has been played.
298 * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
299 * data for the current track has played to allow time for the framework
300 * to perform a gapless track switch.
301 *
302 * Drain must return immediately on stop() and flush() call
303 *
304 * Implementation of this function is mandatory for offloaded playback.
305 */
306 int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
307
308 /**
309 * Notifies to the audio driver to flush the queued data. Stream must already
310 * be paused before calling flush().
311 *
312 * Implementation of this function is mandatory for offloaded playback.
313 */
314 int (*flush)(struct audio_stream_out* stream);
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700315
316 /**
Glenn Kasten22a06b72013-09-10 09:23:07 -0700317 * Return a recent count of the number of audio frames presented to an external observer.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700318 * This excludes frames which have been written but are still in the pipeline.
319 * The count is not reset to zero when output enters standby.
320 * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
Glenn Kasten22a06b72013-09-10 09:23:07 -0700321 * The returned count is expected to be 'recent',
322 * but does not need to be the most recent possible value.
323 * However, the associated time should correspond to whatever count is returned.
324 * Example: assume that N+M frames have been presented, where M is a 'small' number.
325 * Then it is permissible to return N instead of N+M,
326 * and the timestamp should correspond to N rather than N+M.
327 * The terms 'recent' and 'small' are not defined.
328 * They reflect the quality of the implementation.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700329 *
330 * 3.0 and higher only.
331 */
332 int (*get_presentation_position)(const struct audio_stream_out *stream,
333 uint64_t *frames, struct timespec *timestamp);
334
Dima Zavinf1504db2011-03-11 11:20:49 -0800335};
336typedef struct audio_stream_out audio_stream_out_t;
337
338struct audio_stream_in {
Stewart Miles84d35492014-05-01 09:03:27 -0700339 /**
340 * Common methods of the audio stream in. This *must* be the first member of audio_stream_in
341 * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
342 * where it's known the audio_stream references an audio_stream_in.
343 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800344 struct audio_stream common;
345
346 /** set the input gain for the audio driver. This method is for
347 * for future use */
348 int (*set_gain)(struct audio_stream_in *stream, float gain);
349
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800350 /** Read audio buffer in from audio driver. Returns number of bytes read, or a
351 * negative status_t. If at least one frame was read prior to the error,
352 * read should return that byte count and then return an error in the subsequent call.
353 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800354 ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
355 size_t bytes);
356
357 /**
358 * Return the amount of input frames lost in the audio driver since the
359 * last call of this function.
360 * Audio driver is expected to reset the value to 0 and restart counting
361 * upon returning the current value by this function call.
362 * Such loss typically occurs when the user space process is blocked
363 * longer than the capacity of audio driver buffers.
364 *
365 * Unit: the number of input audio frames
366 */
367 uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
Andy Hung9904fab2016-01-15 17:42:36 -0800368
369 /**
370 * Return a recent count of the number of audio frames received and
371 * the clock time associated with that frame count.
372 *
373 * frames is the total frame count received. This should be as early in
374 * the capture pipeline as possible. In general,
375 * frames should be non-negative and should not go "backwards".
376 *
377 * time is the clock MONOTONIC time when frames was measured. In general,
378 * time should be a positive quantity and should not go "backwards".
379 *
380 * The status returned is 0 on success, -ENOSYS if the device is not
381 * ready/available, or -EINVAL if the arguments are null or otherwise invalid.
382 */
383 int (*get_capture_position)(const struct audio_stream_in *stream,
384 int64_t *frames, int64_t *time);
Dima Zavinf1504db2011-03-11 11:20:49 -0800385};
386typedef struct audio_stream_in audio_stream_in_t;
387
388/**
389 * return the frame size (number of bytes per sample).
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700390 *
391 * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
Dima Zavinf1504db2011-03-11 11:20:49 -0800392 */
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700393__attribute__((__deprecated__))
Glenn Kasten48915ac2012-02-20 12:08:57 -0800394static inline size_t audio_stream_frame_size(const struct audio_stream *s)
Dima Zavinf1504db2011-03-11 11:20:49 -0800395{
Glenn Kastena26cbac2012-01-13 14:53:35 -0800396 size_t chan_samp_sz;
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000397 audio_format_t format = s->get_format(s);
Dima Zavinf1504db2011-03-11 11:20:49 -0800398
Phil Burkc3385fc2016-01-19 12:21:55 -0800399 if (audio_has_proportional_frames(format)) {
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000400 chan_samp_sz = audio_bytes_per_sample(format);
401 return popcount(s->get_channels(s)) * chan_samp_sz;
Dima Zavinf1504db2011-03-11 11:20:49 -0800402 }
403
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000404 return sizeof(int8_t);
Dima Zavinf1504db2011-03-11 11:20:49 -0800405}
406
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700407/**
408 * return the frame size (number of bytes per sample) of an output stream.
409 */
410static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
411{
412 size_t chan_samp_sz;
413 audio_format_t format = s->common.get_format(&s->common);
414
Phil Burkc3385fc2016-01-19 12:21:55 -0800415 if (audio_has_proportional_frames(format)) {
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700416 chan_samp_sz = audio_bytes_per_sample(format);
417 return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
418 }
419
420 return sizeof(int8_t);
421}
422
423/**
424 * return the frame size (number of bytes per sample) of an input stream.
425 */
426static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
427{
428 size_t chan_samp_sz;
429 audio_format_t format = s->common.get_format(&s->common);
430
Phil Burkc3385fc2016-01-19 12:21:55 -0800431 if (audio_has_proportional_frames(format)) {
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700432 chan_samp_sz = audio_bytes_per_sample(format);
433 return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
434 }
435
436 return sizeof(int8_t);
437}
Dima Zavinf1504db2011-03-11 11:20:49 -0800438
439/**********************************************************************/
440
441/**
442 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
443 * and the fields of this data structure must begin with hw_module_t
444 * followed by module specific information.
445 */
446struct audio_module {
447 struct hw_module_t common;
448};
449
450struct audio_hw_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700451 /**
452 * Common methods of the audio device. This *must* be the first member of audio_hw_device
453 * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
454 * where it's known the hw_device_t references an audio_hw_device.
455 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800456 struct hw_device_t common;
457
458 /**
459 * used by audio flinger to enumerate what devices are supported by
460 * each audio_hw_device implementation.
461 *
462 * Return value is a bitmask of 1 or more values of audio_devices_t
Eric Laurent85e08e22012-08-28 14:30:35 -0700463 *
464 * NOTE: audio HAL implementations starting with
465 * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
466 * All supported devices should be listed in audio_policy.conf
467 * file and the audio policy manager must choose the appropriate
468 * audio module based on information in this file.
Dima Zavinf1504db2011-03-11 11:20:49 -0800469 */
470 uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
471
472 /**
473 * check to see if the audio hardware interface has been initialized.
474 * returns 0 on success, -ENODEV on failure.
475 */
476 int (*init_check)(const struct audio_hw_device *dev);
477
478 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
479 int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
480
481 /**
482 * set the audio volume for all audio activities other than voice call.
483 * Range between 0.0 and 1.0. If any value other than 0 is returned,
484 * the software mixer will emulate this capability.
485 */
486 int (*set_master_volume)(struct audio_hw_device *dev, float volume);
487
488 /**
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700489 * Get the current master volume value for the HAL, if the HAL supports
490 * master volume control. AudioFlinger will query this value from the
491 * primary audio HAL when the service starts and use the value for setting
492 * the initial master volume across all HALs. HALs which do not support
John Grossman47bf3d72012-07-17 11:54:04 -0700493 * this method may leave it set to NULL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700494 */
495 int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
496
497 /**
Glenn Kasten6df641e2012-01-09 10:41:30 -0800498 * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
Dima Zavinf1504db2011-03-11 11:20:49 -0800499 * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
500 * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
Dima Zavinf1504db2011-03-11 11:20:49 -0800501 */
Glenn Kasten6df641e2012-01-09 10:41:30 -0800502 int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
Dima Zavinf1504db2011-03-11 11:20:49 -0800503
504 /* mic mute */
505 int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
506 int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
507
508 /* set/get global audio parameters */
509 int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
510
511 /*
512 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800513 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800514 */
515 char * (*get_parameters)(const struct audio_hw_device *dev,
516 const char *keys);
517
518 /* Returns audio input buffer size according to parameters passed or
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800519 * 0 if one of the parameters is not supported.
520 * See also get_buffer_size which is for a particular stream.
Dima Zavinf1504db2011-03-11 11:20:49 -0800521 */
522 size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700523 const struct audio_config *config);
Dima Zavinf1504db2011-03-11 11:20:49 -0800524
Eric Laurentf5e24692014-07-27 16:14:57 -0700525 /** This method creates and opens the audio hardware output stream.
526 * The "address" parameter qualifies the "devices" audio device type if needed.
527 * The format format depends on the device type:
528 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
529 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
530 * - Other devices may use a number or any other string.
531 */
532
Eric Laurent55786bc2012-04-10 16:56:32 -0700533 int (*open_output_stream)(struct audio_hw_device *dev,
534 audio_io_handle_t handle,
535 audio_devices_t devices,
536 audio_output_flags_t flags,
537 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700538 struct audio_stream_out **stream_out,
539 const char *address);
Dima Zavinf1504db2011-03-11 11:20:49 -0800540
541 void (*close_output_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700542 struct audio_stream_out* stream_out);
Dima Zavinf1504db2011-03-11 11:20:49 -0800543
544 /** This method creates and opens the audio hardware input stream */
Eric Laurent55786bc2012-04-10 16:56:32 -0700545 int (*open_input_stream)(struct audio_hw_device *dev,
546 audio_io_handle_t handle,
547 audio_devices_t devices,
548 struct audio_config *config,
Glenn Kasten7d973ad2014-07-15 11:10:38 -0700549 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700550 audio_input_flags_t flags,
551 const char *address,
552 audio_source_t source);
Dima Zavinf1504db2011-03-11 11:20:49 -0800553
554 void (*close_input_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700555 struct audio_stream_in *stream_in);
Dima Zavinf1504db2011-03-11 11:20:49 -0800556
557 /** This method dumps the state of the audio hardware */
558 int (*dump)(const struct audio_hw_device *dev, int fd);
John Grossman47bf3d72012-07-17 11:54:04 -0700559
560 /**
561 * set the audio mute status for all audio activities. If any value other
562 * than 0 is returned, the software mixer will emulate this capability.
563 */
564 int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
565
566 /**
567 * Get the current master mute status for the HAL, if the HAL supports
568 * master mute control. AudioFlinger will query this value from the primary
569 * audio HAL when the service starts and use the value for setting the
570 * initial master mute across all HALs. HALs which do not support this
571 * method may leave it set to NULL.
572 */
573 int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
Eric Laurent73b8a742014-05-22 14:02:38 -0700574
575 /**
576 * Routing control
577 */
578
579 /* Creates an audio patch between several source and sink ports.
580 * The handle is allocated by the HAL and should be unique for this
581 * audio HAL module. */
582 int (*create_audio_patch)(struct audio_hw_device *dev,
583 unsigned int num_sources,
584 const struct audio_port_config *sources,
585 unsigned int num_sinks,
586 const struct audio_port_config *sinks,
587 audio_patch_handle_t *handle);
588
589 /* Release an audio patch */
590 int (*release_audio_patch)(struct audio_hw_device *dev,
591 audio_patch_handle_t handle);
592
593 /* Fills the list of supported attributes for a given audio port.
594 * As input, "port" contains the information (type, role, address etc...)
595 * needed by the HAL to identify the port.
596 * As output, "port" contains possible attributes (sampling rates, formats,
597 * channel masks, gain controllers...) for this port.
598 */
599 int (*get_audio_port)(struct audio_hw_device *dev,
600 struct audio_port *port);
601
602 /* Set audio port configuration */
603 int (*set_audio_port_config)(struct audio_hw_device *dev,
604 const struct audio_port_config *config);
605
Dima Zavinf1504db2011-03-11 11:20:49 -0800606};
607typedef struct audio_hw_device audio_hw_device_t;
608
609/** convenience API for opening and closing a supported device */
610
611static inline int audio_hw_device_open(const struct hw_module_t* module,
612 struct audio_hw_device** device)
613{
614 return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
Colin Crosscc8d9f92016-10-06 16:44:23 -0700615 TO_HW_DEVICE_T_OPEN(device));
Dima Zavinf1504db2011-03-11 11:20:49 -0800616}
617
618static inline int audio_hw_device_close(struct audio_hw_device* device)
619{
620 return device->common.close(&device->common);
621}
622
623
624__END_DECLS
625
626#endif // ANDROID_AUDIO_INTERFACE_H