blob: cbcb9546a5e1981bdeb43f22235f8d044b275886 [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)
57#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_2_0
Eric Laurent447cae72014-05-22 13:45:55 -070058/* Minimal audio HAL version supported by the audio framework */
59#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
Eric Laurent55786bc2012-04-10 16:56:32 -070060
Eric Laurent431fc782012-04-03 12:07:02 -070061/**
62 * List of known audio HAL modules. This is the base name of the audio HAL
63 * library composed of the "audio." prefix, one of the base names below and
64 * a suffix specific to the device.
65 * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
66 */
67
68#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
69#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
70#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
Jean-Michel Trivi88b79cb2012-08-16 13:56:03 -070071#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +000072#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
Eric Laurent431fc782012-04-03 12:07:02 -070073
Dima Zavinf1504db2011-03-11 11:20:49 -080074/**************************************/
75
Eric Laurent70e81102011-08-07 10:05:40 -070076/**
77 * standard audio parameters that the HAL may need to handle
78 */
79
80/**
81 * audio device parameters
82 */
83
Eric Laurented9928c2011-08-02 17:12:00 -070084/* BT SCO Noise Reduction + Echo Cancellation parameters */
85#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
86#define AUDIO_PARAMETER_VALUE_ON "on"
87#define AUDIO_PARAMETER_VALUE_OFF "off"
88
Eric Laurent70e81102011-08-07 10:05:40 -070089/* TTY mode selection */
90#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
91#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
92#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
93#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
94#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
95
Eric Laurenta70c5d02012-03-07 18:59:47 -080096/* A2DP sink address set by framework */
97#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
98
Glenn Kasten34afb682012-06-08 10:49:34 -070099/* Screen state */
100#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
101
Glenn Kastend930d922014-04-29 13:35:57 -0700102/* Bluetooth SCO wideband */
103#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
104
Eric Laurent70e81102011-08-07 10:05:40 -0700105/**
106 * audio stream parameters
107 */
108
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800109#define AUDIO_PARAMETER_STREAM_ROUTING "routing" // audio_devices_t
110#define AUDIO_PARAMETER_STREAM_FORMAT "format" // audio_format_t
111#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" // audio_channel_mask_t
112#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" // size_t
113#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" // audio_source_t
114#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" // uint32_t
Dima Zavin57dde282011-06-06 19:31:18 -0700115
Eric Laurent41eeb4f2012-05-17 18:54:49 -0700116/* Query supported formats. The response is a '|' separated list of strings from
117 * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
118#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
119/* Query supported channel masks. The response is a '|' separated list of strings from
120 * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
121#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
122/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
123 * "sup_sampling_rates=44100|48000" */
124#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
125
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000126/**
127 * audio codec parameters
128 */
129
130#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
131#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
132#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
133#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
134#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
135#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
136#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
137#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
138#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels"
139#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling"
140#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples"
141#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples"
Eric Laurent55786bc2012-04-10 16:56:32 -0700142
Eric Laurent70e81102011-08-07 10:05:40 -0700143/**************************************/
144
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000145/* common audio stream configuration parameters
146 * You should memset() the entire structure to zero before use to
147 * ensure forward compatibility
148 */
Eric Laurent55786bc2012-04-10 16:56:32 -0700149struct audio_config {
150 uint32_t sample_rate;
151 audio_channel_mask_t channel_mask;
152 audio_format_t format;
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000153 audio_offload_info_t offload_info;
Eric Laurent55786bc2012-04-10 16:56:32 -0700154};
Eric Laurent55786bc2012-04-10 16:56:32 -0700155typedef struct audio_config audio_config_t;
156
Dima Zavinf1504db2011-03-11 11:20:49 -0800157/* common audio stream parameters and operations */
158struct audio_stream {
159
160 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800161 * Return the sampling rate in Hz - eg. 44100.
Dima Zavinf1504db2011-03-11 11:20:49 -0800162 */
163 uint32_t (*get_sample_rate)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700164
165 /* currently unused - use set_parameters with key
166 * AUDIO_PARAMETER_STREAM_SAMPLING_RATE
167 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800168 int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
169
170 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800171 * Return size of input/output buffer in bytes for this stream - eg. 4800.
172 * It should be a multiple of the frame size. See also get_input_buffer_size.
Dima Zavinf1504db2011-03-11 11:20:49 -0800173 */
174 size_t (*get_buffer_size)(const struct audio_stream *stream);
175
176 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800177 * Return the channel mask -
Dima Zavinf1504db2011-03-11 11:20:49 -0800178 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
179 */
Eric Laurent55786bc2012-04-10 16:56:32 -0700180 audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
Dima Zavinf1504db2011-03-11 11:20:49 -0800181
182 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800183 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
Dima Zavinf1504db2011-03-11 11:20:49 -0800184 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800185 audio_format_t (*get_format)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700186
187 /* currently unused - use set_parameters with key
188 * AUDIO_PARAMETER_STREAM_FORMAT
189 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800190 int (*set_format)(struct audio_stream *stream, audio_format_t format);
Dima Zavinf1504db2011-03-11 11:20:49 -0800191
192 /**
193 * Put the audio hardware input/output into standby mode.
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800194 * Driver should exit from standby mode at the next I/O operation.
Dima Zavinf1504db2011-03-11 11:20:49 -0800195 * Returns 0 on success and <0 on failure.
196 */
197 int (*standby)(struct audio_stream *stream);
198
199 /** dump the state of the audio input/output device */
200 int (*dump)(const struct audio_stream *stream, int fd);
201
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800202 /** Return the set of device(s) which this stream is connected to */
Dima Zavinf1504db2011-03-11 11:20:49 -0800203 audio_devices_t (*get_device)(const struct audio_stream *stream);
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800204
205 /**
206 * Currently unused - set_device() corresponds to set_parameters() with key
207 * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
208 * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
209 * input streams only.
210 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800211 int (*set_device)(struct audio_stream *stream, audio_devices_t device);
212
213 /**
214 * set/get audio stream parameters. The function accepts a list of
215 * parameter key value pairs in the form: key1=value1;key2=value2;...
216 *
217 * Some keys are reserved for standard parameters (See AudioParameter class)
218 *
219 * If the implementation does not accept a parameter change while
220 * the output is active but the parameter is acceptable otherwise, it must
221 * return -ENOSYS.
222 *
223 * The audio flinger will put the stream in standby and then change the
224 * parameter value.
225 */
226 int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
227
228 /*
229 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800230 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800231 */
232 char * (*get_parameters)(const struct audio_stream *stream,
233 const char *keys);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700234 int (*add_audio_effect)(const struct audio_stream *stream,
235 effect_handle_t effect);
236 int (*remove_audio_effect)(const struct audio_stream *stream,
237 effect_handle_t effect);
Dima Zavinf1504db2011-03-11 11:20:49 -0800238};
239typedef struct audio_stream audio_stream_t;
240
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000241/* type of asynchronous write callback events. Mutually exclusive */
242typedef enum {
243 STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
244 STREAM_CBK_EVENT_DRAIN_READY /* drain completed */
245} stream_callback_event_t;
246
247typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
248
249/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
250typedef enum {
251 AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
252 AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
253 from the current track has been played to
254 give time for gapless track switch */
255} audio_drain_type_t;
256
Dima Zavinf1504db2011-03-11 11:20:49 -0800257/**
258 * audio_stream_out is the abstraction interface for the audio output hardware.
259 *
260 * It provides information about various properties of the audio output
261 * hardware driver.
262 */
263
264struct audio_stream_out {
Stewart Miles84d35492014-05-01 09:03:27 -0700265 /**
266 * Common methods of the audio stream out. This *must* be the first member of audio_stream_out
267 * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
268 * where it's known the audio_stream references an audio_stream_out.
269 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800270 struct audio_stream common;
271
272 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800273 * Return the audio hardware driver estimated latency in milliseconds.
Dima Zavinf1504db2011-03-11 11:20:49 -0800274 */
275 uint32_t (*get_latency)(const struct audio_stream_out *stream);
276
277 /**
278 * Use this method in situations where audio mixing is done in the
279 * hardware. This method serves as a direct interface with hardware,
280 * allowing you to directly set the volume as apposed to via the framework.
281 * This method might produce multiple PCM outputs or hardware accelerated
282 * codecs, such as MP3 or AAC.
283 */
284 int (*set_volume)(struct audio_stream_out *stream, float left, float right);
285
286 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800287 * Write audio buffer to driver. Returns number of bytes written, or a
288 * negative status_t. If at least one frame was written successfully prior to the error,
289 * it is suggested that the driver return that successful (short) byte count
290 * and then return an error in the subsequent call.
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000291 *
292 * If set_callback() has previously been called to enable non-blocking mode
293 * the write() is not allowed to block. It must write only the number of
294 * bytes that currently fit in the driver/hardware buffer and then return
295 * this byte count. If this is less than the requested write size the
296 * callback function must be called when more space is available in the
297 * driver/hardware buffer.
Dima Zavinf1504db2011-03-11 11:20:49 -0800298 */
299 ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
300 size_t bytes);
301
302 /* return the number of audio frames written by the audio dsp to DAC since
303 * the output has exited standby
304 */
305 int (*get_render_position)(const struct audio_stream_out *stream,
306 uint32_t *dsp_frames);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700307
308 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800309 * get the local time at which the next write to the audio driver will be presented.
310 * The units are microseconds, where the epoch is decided by the local audio HAL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700311 */
312 int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
313 int64_t *timestamp);
314
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000315 /**
316 * set the callback function for notifying completion of non-blocking
317 * write and drain.
318 * Calling this function implies that all future write() and drain()
319 * must be non-blocking and use the callback to signal completion.
320 */
321 int (*set_callback)(struct audio_stream_out *stream,
322 stream_callback_t callback, void *cookie);
323
324 /**
325 * Notifies to the audio driver to stop playback however the queued buffers are
326 * retained by the hardware. Useful for implementing pause/resume. Empty implementation
327 * if not supported however should be implemented for hardware with non-trivial
328 * latency. In the pause state audio hardware could still be using power. User may
329 * consider calling suspend after a timeout.
330 *
331 * Implementation of this function is mandatory for offloaded playback.
332 */
333 int (*pause)(struct audio_stream_out* stream);
334
335 /**
336 * Notifies to the audio driver to resume playback following a pause.
337 * Returns error if called without matching pause.
338 *
339 * Implementation of this function is mandatory for offloaded playback.
340 */
341 int (*resume)(struct audio_stream_out* stream);
342
343 /**
344 * Requests notification when data buffered by the driver/hardware has
345 * been played. If set_callback() has previously been called to enable
346 * non-blocking mode, the drain() must not block, instead it should return
347 * quickly and completion of the drain is notified through the callback.
348 * If set_callback() has not been called, the drain() must block until
349 * completion.
350 * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
351 * data has been played.
352 * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
353 * data for the current track has played to allow time for the framework
354 * to perform a gapless track switch.
355 *
356 * Drain must return immediately on stop() and flush() call
357 *
358 * Implementation of this function is mandatory for offloaded playback.
359 */
360 int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
361
362 /**
363 * Notifies to the audio driver to flush the queued data. Stream must already
364 * be paused before calling flush().
365 *
366 * Implementation of this function is mandatory for offloaded playback.
367 */
368 int (*flush)(struct audio_stream_out* stream);
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700369
370 /**
Glenn Kasten22a06b72013-09-10 09:23:07 -0700371 * Return a recent count of the number of audio frames presented to an external observer.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700372 * This excludes frames which have been written but are still in the pipeline.
373 * The count is not reset to zero when output enters standby.
374 * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
Glenn Kasten22a06b72013-09-10 09:23:07 -0700375 * The returned count is expected to be 'recent',
376 * but does not need to be the most recent possible value.
377 * However, the associated time should correspond to whatever count is returned.
378 * Example: assume that N+M frames have been presented, where M is a 'small' number.
379 * Then it is permissible to return N instead of N+M,
380 * and the timestamp should correspond to N rather than N+M.
381 * The terms 'recent' and 'small' are not defined.
382 * They reflect the quality of the implementation.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700383 *
384 * 3.0 and higher only.
385 */
386 int (*get_presentation_position)(const struct audio_stream_out *stream,
387 uint64_t *frames, struct timespec *timestamp);
388
Dima Zavinf1504db2011-03-11 11:20:49 -0800389};
390typedef struct audio_stream_out audio_stream_out_t;
391
392struct audio_stream_in {
Stewart Miles84d35492014-05-01 09:03:27 -0700393 /**
394 * Common methods of the audio stream in. This *must* be the first member of audio_stream_in
395 * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
396 * where it's known the audio_stream references an audio_stream_in.
397 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800398 struct audio_stream common;
399
400 /** set the input gain for the audio driver. This method is for
401 * for future use */
402 int (*set_gain)(struct audio_stream_in *stream, float gain);
403
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800404 /** Read audio buffer in from audio driver. Returns number of bytes read, or a
405 * negative status_t. If at least one frame was read prior to the error,
406 * read should return that byte count and then return an error in the subsequent call.
407 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800408 ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
409 size_t bytes);
410
411 /**
412 * Return the amount of input frames lost in the audio driver since the
413 * last call of this function.
414 * Audio driver is expected to reset the value to 0 and restart counting
415 * upon returning the current value by this function call.
416 * Such loss typically occurs when the user space process is blocked
417 * longer than the capacity of audio driver buffers.
418 *
419 * Unit: the number of input audio frames
420 */
421 uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
422};
423typedef struct audio_stream_in audio_stream_in_t;
424
425/**
426 * return the frame size (number of bytes per sample).
427 */
Glenn Kasten48915ac2012-02-20 12:08:57 -0800428static inline size_t audio_stream_frame_size(const struct audio_stream *s)
Dima Zavinf1504db2011-03-11 11:20:49 -0800429{
Glenn Kastena26cbac2012-01-13 14:53:35 -0800430 size_t chan_samp_sz;
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000431 audio_format_t format = s->get_format(s);
Dima Zavinf1504db2011-03-11 11:20:49 -0800432
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000433 if (audio_is_linear_pcm(format)) {
434 chan_samp_sz = audio_bytes_per_sample(format);
435 return popcount(s->get_channels(s)) * chan_samp_sz;
Dima Zavinf1504db2011-03-11 11:20:49 -0800436 }
437
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000438 return sizeof(int8_t);
Dima Zavinf1504db2011-03-11 11:20:49 -0800439}
440
441
442/**********************************************************************/
443
444/**
445 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
446 * and the fields of this data structure must begin with hw_module_t
447 * followed by module specific information.
448 */
449struct audio_module {
450 struct hw_module_t common;
451};
452
453struct audio_hw_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700454 /**
455 * Common methods of the audio device. This *must* be the first member of audio_hw_device
456 * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
457 * where it's known the hw_device_t references an audio_hw_device.
458 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800459 struct hw_device_t common;
460
461 /**
462 * used by audio flinger to enumerate what devices are supported by
463 * each audio_hw_device implementation.
464 *
465 * Return value is a bitmask of 1 or more values of audio_devices_t
Eric Laurent85e08e22012-08-28 14:30:35 -0700466 *
467 * NOTE: audio HAL implementations starting with
468 * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
469 * All supported devices should be listed in audio_policy.conf
470 * file and the audio policy manager must choose the appropriate
471 * audio module based on information in this file.
Dima Zavinf1504db2011-03-11 11:20:49 -0800472 */
473 uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
474
475 /**
476 * check to see if the audio hardware interface has been initialized.
477 * returns 0 on success, -ENODEV on failure.
478 */
479 int (*init_check)(const struct audio_hw_device *dev);
480
481 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
482 int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
483
484 /**
485 * set the audio volume for all audio activities other than voice call.
486 * Range between 0.0 and 1.0. If any value other than 0 is returned,
487 * the software mixer will emulate this capability.
488 */
489 int (*set_master_volume)(struct audio_hw_device *dev, float volume);
490
491 /**
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700492 * Get the current master volume value for the HAL, if the HAL supports
493 * master volume control. AudioFlinger will query this value from the
494 * primary audio HAL when the service starts and use the value for setting
495 * the initial master volume across all HALs. HALs which do not support
John Grossman47bf3d72012-07-17 11:54:04 -0700496 * this method may leave it set to NULL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700497 */
498 int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
499
500 /**
Glenn Kasten6df641e2012-01-09 10:41:30 -0800501 * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
Dima Zavinf1504db2011-03-11 11:20:49 -0800502 * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
503 * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
Dima Zavinf1504db2011-03-11 11:20:49 -0800504 */
Glenn Kasten6df641e2012-01-09 10:41:30 -0800505 int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
Dima Zavinf1504db2011-03-11 11:20:49 -0800506
507 /* mic mute */
508 int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
509 int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
510
511 /* set/get global audio parameters */
512 int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
513
514 /*
515 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800516 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800517 */
518 char * (*get_parameters)(const struct audio_hw_device *dev,
519 const char *keys);
520
521 /* Returns audio input buffer size according to parameters passed or
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800522 * 0 if one of the parameters is not supported.
523 * See also get_buffer_size which is for a particular stream.
Dima Zavinf1504db2011-03-11 11:20:49 -0800524 */
525 size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700526 const struct audio_config *config);
Dima Zavinf1504db2011-03-11 11:20:49 -0800527
528 /** This method creates and opens the audio hardware output stream */
Eric Laurent55786bc2012-04-10 16:56:32 -0700529 int (*open_output_stream)(struct audio_hw_device *dev,
530 audio_io_handle_t handle,
531 audio_devices_t devices,
532 audio_output_flags_t flags,
533 struct audio_config *config,
534 struct audio_stream_out **stream_out);
Dima Zavinf1504db2011-03-11 11:20:49 -0800535
536 void (*close_output_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700537 struct audio_stream_out* stream_out);
Dima Zavinf1504db2011-03-11 11:20:49 -0800538
539 /** This method creates and opens the audio hardware input stream */
Eric Laurent55786bc2012-04-10 16:56:32 -0700540 int (*open_input_stream)(struct audio_hw_device *dev,
541 audio_io_handle_t handle,
542 audio_devices_t devices,
543 struct audio_config *config,
Dima Zavinf1504db2011-03-11 11:20:49 -0800544 struct audio_stream_in **stream_in);
545
546 void (*close_input_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700547 struct audio_stream_in *stream_in);
Dima Zavinf1504db2011-03-11 11:20:49 -0800548
549 /** This method dumps the state of the audio hardware */
550 int (*dump)(const struct audio_hw_device *dev, int fd);
John Grossman47bf3d72012-07-17 11:54:04 -0700551
552 /**
553 * set the audio mute status for all audio activities. If any value other
554 * than 0 is returned, the software mixer will emulate this capability.
555 */
556 int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
557
558 /**
559 * Get the current master mute status for the HAL, if the HAL supports
560 * master mute control. AudioFlinger will query this value from the primary
561 * audio HAL when the service starts and use the value for setting the
562 * initial master mute across all HALs. HALs which do not support this
563 * method may leave it set to NULL.
564 */
565 int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
Dima Zavinf1504db2011-03-11 11:20:49 -0800566};
567typedef struct audio_hw_device audio_hw_device_t;
568
569/** convenience API for opening and closing a supported device */
570
571static inline int audio_hw_device_open(const struct hw_module_t* module,
572 struct audio_hw_device** device)
573{
574 return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
575 (struct hw_device_t**)device);
576}
577
578static inline int audio_hw_device_close(struct audio_hw_device* device)
579{
580 return device->common.close(&device->common);
581}
582
583
584__END_DECLS
585
586#endif // ANDROID_AUDIO_INTERFACE_H