blob: 10669569b7bd8655b8ec90fa8761dc36c9721218 [file] [log] [blame]
Dima Zavinf1504db2011-03-11 11:20:49 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
Bharath Ramachandramurthye41db452014-01-14 07:28:09 -08003 * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
4 * Not a Contribution.
Dima Zavinf1504db2011-03-11 11:20:49 -08005 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19
20#ifndef ANDROID_AUDIO_HAL_INTERFACE_H
21#define ANDROID_AUDIO_HAL_INTERFACE_H
22
23#include <stdint.h>
24#include <strings.h>
25#include <sys/cdefs.h>
26#include <sys/types.h>
27
28#include <cutils/bitops.h>
29
30#include <hardware/hardware.h>
Dima Zavinaa211722011-05-11 14:15:53 -070031#include <system/audio.h>
Eric Laurentf3008aa2011-06-17 16:53:12 -070032#include <hardware/audio_effect.h>
Kiran Kandi807edfa2013-10-17 15:49:54 -070033#ifdef AUDIO_LISTEN_ENABLED
34#include <listen_types.h>
35#endif
Dima Zavinf1504db2011-03-11 11:20:49 -080036
37__BEGIN_DECLS
38
39/**
40 * The id of this module
41 */
42#define AUDIO_HARDWARE_MODULE_ID "audio"
43
44/**
45 * Name of the audio devices to open
46 */
47#define AUDIO_HARDWARE_INTERFACE "audio_hw_if"
48
Eric Laurent55786bc2012-04-10 16:56:32 -070049
50/* Use version 0.1 to be compatible with first generation of audio hw module with version_major
51 * hardcoded to 1. No audio module API change.
52 */
53#define AUDIO_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
54#define AUDIO_MODULE_API_VERSION_CURRENT AUDIO_MODULE_API_VERSION_0_1
55
56/* First generation of audio devices had version hardcoded to 0. all devices with versions < 1.0
57 * will be considered of first generation API.
58 */
59#define AUDIO_DEVICE_API_VERSION_0_0 HARDWARE_DEVICE_API_VERSION(0, 0)
60#define AUDIO_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0)
Eric Laurent85e08e22012-08-28 14:30:35 -070061#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
Eric Laurent73b8a742014-05-22 14:02:38 -070062#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
63#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_0
Eric Laurent447cae72014-05-22 13:45:55 -070064/* Minimal audio HAL version supported by the audio framework */
65#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
Eric Laurent55786bc2012-04-10 16:56:32 -070066
Eric Laurent431fc782012-04-03 12:07:02 -070067/**
68 * List of known audio HAL modules. This is the base name of the audio HAL
69 * library composed of the "audio." prefix, one of the base names below and
70 * a suffix specific to the device.
71 * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
72 */
73
74#define AUDIO_HARDWARE_MODULE_ID_PRIMARY "primary"
75#define AUDIO_HARDWARE_MODULE_ID_A2DP "a2dp"
76#define AUDIO_HARDWARE_MODULE_ID_USB "usb"
Jean-Michel Trivi88b79cb2012-08-16 13:56:03 -070077#define AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX "r_submix"
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +000078#define AUDIO_HARDWARE_MODULE_ID_CODEC_OFFLOAD "codec_offload"
Eric Laurent431fc782012-04-03 12:07:02 -070079
Dima Zavinf1504db2011-03-11 11:20:49 -080080/**************************************/
81
Eric Laurent70e81102011-08-07 10:05:40 -070082/**
83 * standard audio parameters that the HAL may need to handle
84 */
85
86/**
87 * audio device parameters
88 */
89
Eric Laurented9928c2011-08-02 17:12:00 -070090/* BT SCO Noise Reduction + Echo Cancellation parameters */
91#define AUDIO_PARAMETER_KEY_BT_NREC "bt_headset_nrec"
92#define AUDIO_PARAMETER_VALUE_ON "on"
93#define AUDIO_PARAMETER_VALUE_OFF "off"
94
Eric Laurent70e81102011-08-07 10:05:40 -070095/* TTY mode selection */
96#define AUDIO_PARAMETER_KEY_TTY_MODE "tty_mode"
97#define AUDIO_PARAMETER_VALUE_TTY_OFF "tty_off"
98#define AUDIO_PARAMETER_VALUE_TTY_VCO "tty_vco"
99#define AUDIO_PARAMETER_VALUE_TTY_HCO "tty_hco"
100#define AUDIO_PARAMETER_VALUE_TTY_FULL "tty_full"
101
Eric Laurentd1a1b1c2014-07-25 12:10:11 -0500102/* Hearing Aid Compatibility - Telecoil (HAC-T) mode on/off
103 Strings must be in sync with CallFeaturesSetting.java */
104#define AUDIO_PARAMETER_KEY_HAC "HACSetting"
105#define AUDIO_PARAMETER_VALUE_HAC_ON "ON"
106#define AUDIO_PARAMETER_VALUE_HAC_OFF "OFF"
107
Eric Laurenta70c5d02012-03-07 18:59:47 -0800108/* A2DP sink address set by framework */
109#define AUDIO_PARAMETER_A2DP_SINK_ADDRESS "a2dp_sink_address"
110
Mike Lockwood2d4d9652014-05-28 11:09:54 -0700111/* A2DP source address set by framework */
112#define AUDIO_PARAMETER_A2DP_SOURCE_ADDRESS "a2dp_source_address"
113
Glenn Kasten34afb682012-06-08 10:49:34 -0700114/* Screen state */
115#define AUDIO_PARAMETER_KEY_SCREEN_STATE "screen_state"
116
Glenn Kastend930d922014-04-29 13:35:57 -0700117/* Bluetooth SCO wideband */
118#define AUDIO_PARAMETER_KEY_BT_SCO_WB "bt_wbs"
119
Eric Laurent4ea9b952014-08-01 14:42:44 -0700120
Eric Laurent70e81102011-08-07 10:05:40 -0700121/**
122 * audio stream parameters
123 */
124
Eric Laurentf5e24692014-07-27 16:14:57 -0700125#define AUDIO_PARAMETER_STREAM_ROUTING "routing" /* audio_devices_t */
126#define AUDIO_PARAMETER_STREAM_FORMAT "format" /* audio_format_t */
127#define AUDIO_PARAMETER_STREAM_CHANNELS "channels" /* audio_channel_mask_t */
128#define AUDIO_PARAMETER_STREAM_FRAME_COUNT "frame_count" /* size_t */
129#define AUDIO_PARAMETER_STREAM_INPUT_SOURCE "input_source" /* audio_source_t */
130#define AUDIO_PARAMETER_STREAM_SAMPLING_RATE "sampling_rate" /* uint32_t */
Dima Zavin57dde282011-06-06 19:31:18 -0700131
Paul McLean2c6196f2014-08-20 16:50:25 -0700132#define AUDIO_PARAMETER_DEVICE_DISCONNECT "disconnect" /* audio_devices_t */
133
Eric Laurent41eeb4f2012-05-17 18:54:49 -0700134/* Query supported formats. The response is a '|' separated list of strings from
135 * audio_format_t enum e.g: "sup_formats=AUDIO_FORMAT_PCM_16_BIT" */
136#define AUDIO_PARAMETER_STREAM_SUP_FORMATS "sup_formats"
137/* Query supported channel masks. The response is a '|' separated list of strings from
138 * audio_channel_mask_t enum e.g: "sup_channels=AUDIO_CHANNEL_OUT_STEREO|AUDIO_CHANNEL_OUT_MONO" */
139#define AUDIO_PARAMETER_STREAM_SUP_CHANNELS "sup_channels"
140/* Query supported sampling rates. The response is a '|' separated list of integer values e.g:
141 * "sup_sampling_rates=44100|48000" */
142#define AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES "sup_sampling_rates"
143
Eric Laurent4ea9b952014-08-01 14:42:44 -0700144/* Get the HW synchronization source used for an output stream.
145 * Return a valid source (positive integer) or AUDIO_HW_SYNC_INVALID if an error occurs
146 * or no HW sync source is used. */
147#define AUDIO_PARAMETER_STREAM_HW_AV_SYNC "hw_av_sync"
148
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000149/**
150 * audio codec parameters
151 */
152
153#define AUDIO_OFFLOAD_CODEC_PARAMS "music_offload_codec_param"
154#define AUDIO_OFFLOAD_CODEC_BIT_PER_SAMPLE "music_offload_bit_per_sample"
155#define AUDIO_OFFLOAD_CODEC_BIT_RATE "music_offload_bit_rate"
156#define AUDIO_OFFLOAD_CODEC_AVG_BIT_RATE "music_offload_avg_bit_rate"
157#define AUDIO_OFFLOAD_CODEC_ID "music_offload_codec_id"
158#define AUDIO_OFFLOAD_CODEC_BLOCK_ALIGN "music_offload_block_align"
159#define AUDIO_OFFLOAD_CODEC_SAMPLE_RATE "music_offload_sample_rate"
160#define AUDIO_OFFLOAD_CODEC_ENCODE_OPTION "music_offload_encode_option"
161#define AUDIO_OFFLOAD_CODEC_NUM_CHANNEL "music_offload_num_channels"
162#define AUDIO_OFFLOAD_CODEC_DOWN_SAMPLING "music_offload_down_sampling"
163#define AUDIO_OFFLOAD_CODEC_DELAY_SAMPLES "delay_samples"
164#define AUDIO_OFFLOAD_CODEC_PADDING_SAMPLES "padding_samples"
Eric Laurent55786bc2012-04-10 16:56:32 -0700165
Eric Laurent70e81102011-08-07 10:05:40 -0700166/**************************************/
167
Dima Zavinf1504db2011-03-11 11:20:49 -0800168/* common audio stream parameters and operations */
169struct audio_stream {
170
171 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800172 * Return the sampling rate in Hz - eg. 44100.
Dima Zavinf1504db2011-03-11 11:20:49 -0800173 */
174 uint32_t (*get_sample_rate)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700175
176 /* currently unused - use set_parameters with key
177 * AUDIO_PARAMETER_STREAM_SAMPLING_RATE
178 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800179 int (*set_sample_rate)(struct audio_stream *stream, uint32_t rate);
180
181 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800182 * Return size of input/output buffer in bytes for this stream - eg. 4800.
183 * It should be a multiple of the frame size. See also get_input_buffer_size.
Dima Zavinf1504db2011-03-11 11:20:49 -0800184 */
185 size_t (*get_buffer_size)(const struct audio_stream *stream);
186
187 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800188 * Return the channel mask -
Dima Zavinf1504db2011-03-11 11:20:49 -0800189 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
190 */
Eric Laurent55786bc2012-04-10 16:56:32 -0700191 audio_channel_mask_t (*get_channels)(const struct audio_stream *stream);
Dima Zavinf1504db2011-03-11 11:20:49 -0800192
193 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800194 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
Dima Zavinf1504db2011-03-11 11:20:49 -0800195 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800196 audio_format_t (*get_format)(const struct audio_stream *stream);
Dima Zavin57dde282011-06-06 19:31:18 -0700197
198 /* currently unused - use set_parameters with key
199 * AUDIO_PARAMETER_STREAM_FORMAT
200 */
Glenn Kastenfe79eb32012-01-12 14:55:57 -0800201 int (*set_format)(struct audio_stream *stream, audio_format_t format);
Dima Zavinf1504db2011-03-11 11:20:49 -0800202
203 /**
204 * Put the audio hardware input/output into standby mode.
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800205 * Driver should exit from standby mode at the next I/O operation.
Dima Zavinf1504db2011-03-11 11:20:49 -0800206 * Returns 0 on success and <0 on failure.
207 */
208 int (*standby)(struct audio_stream *stream);
209
210 /** dump the state of the audio input/output device */
211 int (*dump)(const struct audio_stream *stream, int fd);
212
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800213 /** Return the set of device(s) which this stream is connected to */
Dima Zavinf1504db2011-03-11 11:20:49 -0800214 audio_devices_t (*get_device)(const struct audio_stream *stream);
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800215
216 /**
217 * Currently unused - set_device() corresponds to set_parameters() with key
218 * AUDIO_PARAMETER_STREAM_ROUTING for both input and output.
219 * AUDIO_PARAMETER_STREAM_INPUT_SOURCE is an additional information used by
220 * input streams only.
221 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800222 int (*set_device)(struct audio_stream *stream, audio_devices_t device);
223
224 /**
225 * set/get audio stream parameters. The function accepts a list of
226 * parameter key value pairs in the form: key1=value1;key2=value2;...
227 *
228 * Some keys are reserved for standard parameters (See AudioParameter class)
229 *
230 * If the implementation does not accept a parameter change while
231 * the output is active but the parameter is acceptable otherwise, it must
232 * return -ENOSYS.
233 *
234 * The audio flinger will put the stream in standby and then change the
235 * parameter value.
236 */
237 int (*set_parameters)(struct audio_stream *stream, const char *kv_pairs);
238
239 /*
240 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800241 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800242 */
243 char * (*get_parameters)(const struct audio_stream *stream,
244 const char *keys);
Eric Laurentf3008aa2011-06-17 16:53:12 -0700245 int (*add_audio_effect)(const struct audio_stream *stream,
246 effect_handle_t effect);
247 int (*remove_audio_effect)(const struct audio_stream *stream,
248 effect_handle_t effect);
Dima Zavinf1504db2011-03-11 11:20:49 -0800249};
250typedef struct audio_stream audio_stream_t;
251
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000252/* type of asynchronous write callback events. Mutually exclusive */
253typedef enum {
254 STREAM_CBK_EVENT_WRITE_READY, /* non blocking write completed */
255 STREAM_CBK_EVENT_DRAIN_READY /* drain completed */
256} stream_callback_event_t;
257
258typedef int (*stream_callback_t)(stream_callback_event_t event, void *param, void *cookie);
259
260/* type of drain requested to audio_stream_out->drain(). Mutually exclusive */
261typedef enum {
262 AUDIO_DRAIN_ALL, /* drain() returns when all data has been played */
263 AUDIO_DRAIN_EARLY_NOTIFY /* drain() returns a short time before all data
264 from the current track has been played to
265 give time for gapless track switch */
266} audio_drain_type_t;
267
Dima Zavinf1504db2011-03-11 11:20:49 -0800268/**
269 * audio_stream_out is the abstraction interface for the audio output hardware.
270 *
271 * It provides information about various properties of the audio output
272 * hardware driver.
273 */
274
275struct audio_stream_out {
Stewart Miles84d35492014-05-01 09:03:27 -0700276 /**
277 * Common methods of the audio stream out. This *must* be the first member of audio_stream_out
278 * as users of this structure will cast a audio_stream to audio_stream_out pointer in contexts
279 * where it's known the audio_stream references an audio_stream_out.
280 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800281 struct audio_stream common;
282
283 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800284 * Return the audio hardware driver estimated latency in milliseconds.
Dima Zavinf1504db2011-03-11 11:20:49 -0800285 */
286 uint32_t (*get_latency)(const struct audio_stream_out *stream);
287
288 /**
289 * Use this method in situations where audio mixing is done in the
290 * hardware. This method serves as a direct interface with hardware,
291 * allowing you to directly set the volume as apposed to via the framework.
292 * This method might produce multiple PCM outputs or hardware accelerated
293 * codecs, such as MP3 or AAC.
294 */
295 int (*set_volume)(struct audio_stream_out *stream, float left, float right);
296
297 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800298 * Write audio buffer to driver. Returns number of bytes written, or a
299 * negative status_t. If at least one frame was written successfully prior to the error,
300 * it is suggested that the driver return that successful (short) byte count
301 * and then return an error in the subsequent call.
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000302 *
303 * If set_callback() has previously been called to enable non-blocking mode
304 * the write() is not allowed to block. It must write only the number of
305 * bytes that currently fit in the driver/hardware buffer and then return
306 * this byte count. If this is less than the requested write size the
307 * callback function must be called when more space is available in the
308 * driver/hardware buffer.
Dima Zavinf1504db2011-03-11 11:20:49 -0800309 */
310 ssize_t (*write)(struct audio_stream_out *stream, const void* buffer,
311 size_t bytes);
312
313 /* return the number of audio frames written by the audio dsp to DAC since
314 * the output has exited standby
315 */
316 int (*get_render_position)(const struct audio_stream_out *stream,
317 uint32_t *dsp_frames);
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700318
319 /**
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800320 * get the local time at which the next write to the audio driver will be presented.
321 * The units are microseconds, where the epoch is decided by the local audio HAL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700322 */
323 int (*get_next_write_timestamp)(const struct audio_stream_out *stream,
324 int64_t *timestamp);
325
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000326 /**
327 * set the callback function for notifying completion of non-blocking
328 * write and drain.
329 * Calling this function implies that all future write() and drain()
330 * must be non-blocking and use the callback to signal completion.
331 */
332 int (*set_callback)(struct audio_stream_out *stream,
333 stream_callback_t callback, void *cookie);
334
335 /**
336 * Notifies to the audio driver to stop playback however the queued buffers are
337 * retained by the hardware. Useful for implementing pause/resume. Empty implementation
338 * if not supported however should be implemented for hardware with non-trivial
339 * latency. In the pause state audio hardware could still be using power. User may
340 * consider calling suspend after a timeout.
341 *
342 * Implementation of this function is mandatory for offloaded playback.
343 */
344 int (*pause)(struct audio_stream_out* stream);
345
346 /**
347 * Notifies to the audio driver to resume playback following a pause.
348 * Returns error if called without matching pause.
349 *
350 * Implementation of this function is mandatory for offloaded playback.
351 */
352 int (*resume)(struct audio_stream_out* stream);
353
354 /**
355 * Requests notification when data buffered by the driver/hardware has
356 * been played. If set_callback() has previously been called to enable
357 * non-blocking mode, the drain() must not block, instead it should return
358 * quickly and completion of the drain is notified through the callback.
359 * If set_callback() has not been called, the drain() must block until
360 * completion.
361 * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
362 * data has been played.
363 * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
364 * data for the current track has played to allow time for the framework
365 * to perform a gapless track switch.
366 *
367 * Drain must return immediately on stop() and flush() call
368 *
369 * Implementation of this function is mandatory for offloaded playback.
370 */
371 int (*drain)(struct audio_stream_out* stream, audio_drain_type_t type );
372
373 /**
374 * Notifies to the audio driver to flush the queued data. Stream must already
375 * be paused before calling flush().
376 *
377 * Implementation of this function is mandatory for offloaded playback.
378 */
379 int (*flush)(struct audio_stream_out* stream);
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700380
381 /**
Glenn Kasten22a06b72013-09-10 09:23:07 -0700382 * Return a recent count of the number of audio frames presented to an external observer.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700383 * This excludes frames which have been written but are still in the pipeline.
384 * The count is not reset to zero when output enters standby.
385 * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
Glenn Kasten22a06b72013-09-10 09:23:07 -0700386 * The returned count is expected to be 'recent',
387 * but does not need to be the most recent possible value.
388 * However, the associated time should correspond to whatever count is returned.
389 * Example: assume that N+M frames have been presented, where M is a 'small' number.
390 * Then it is permissible to return N instead of N+M,
391 * and the timestamp should correspond to N rather than N+M.
392 * The terms 'recent' and 'small' are not defined.
393 * They reflect the quality of the implementation.
Glenn Kastene25f9ed2013-08-22 16:27:22 -0700394 *
395 * 3.0 and higher only.
396 */
397 int (*get_presentation_position)(const struct audio_stream_out *stream,
398 uint64_t *frames, struct timespec *timestamp);
399
Dima Zavinf1504db2011-03-11 11:20:49 -0800400};
401typedef struct audio_stream_out audio_stream_out_t;
402
403struct audio_stream_in {
Stewart Miles84d35492014-05-01 09:03:27 -0700404 /**
405 * Common methods of the audio stream in. This *must* be the first member of audio_stream_in
406 * as users of this structure will cast a audio_stream to audio_stream_in pointer in contexts
407 * where it's known the audio_stream references an audio_stream_in.
408 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800409 struct audio_stream common;
410
411 /** set the input gain for the audio driver. This method is for
412 * for future use */
413 int (*set_gain)(struct audio_stream_in *stream, float gain);
414
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800415 /** Read audio buffer in from audio driver. Returns number of bytes read, or a
416 * negative status_t. If at least one frame was read prior to the error,
417 * read should return that byte count and then return an error in the subsequent call.
418 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800419 ssize_t (*read)(struct audio_stream_in *stream, void* buffer,
420 size_t bytes);
421
422 /**
423 * Return the amount of input frames lost in the audio driver since the
424 * last call of this function.
425 * Audio driver is expected to reset the value to 0 and restart counting
426 * upon returning the current value by this function call.
427 * Such loss typically occurs when the user space process is blocked
428 * longer than the capacity of audio driver buffers.
429 *
430 * Unit: the number of input audio frames
431 */
432 uint32_t (*get_input_frames_lost)(struct audio_stream_in *stream);
433};
434typedef struct audio_stream_in audio_stream_in_t;
435
436/**
437 * return the frame size (number of bytes per sample).
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700438 *
439 * Deprecated: use audio_stream_out_frame_size() or audio_stream_in_frame_size() instead.
Dima Zavinf1504db2011-03-11 11:20:49 -0800440 */
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700441__attribute__((__deprecated__))
Glenn Kasten48915ac2012-02-20 12:08:57 -0800442static inline size_t audio_stream_frame_size(const struct audio_stream *s)
Dima Zavinf1504db2011-03-11 11:20:49 -0800443{
Glenn Kastena26cbac2012-01-13 14:53:35 -0800444 size_t chan_samp_sz;
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000445 audio_format_t format = s->get_format(s);
Dima Zavinf1504db2011-03-11 11:20:49 -0800446
Mingming Yinb9966742014-05-22 15:37:22 -0700447 if (audio_is_linear_pcm(format) &&
448 format != AUDIO_FORMAT_PCM_8_24_BIT) {
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000449 chan_samp_sz = audio_bytes_per_sample(format);
450 return popcount(s->get_channels(s)) * chan_samp_sz;
Dima Zavinf1504db2011-03-11 11:20:49 -0800451 }
452
Richard Fitzgeraldf37f1872013-03-25 16:11:44 +0000453 return sizeof(int8_t);
Dima Zavinf1504db2011-03-11 11:20:49 -0800454}
455
Eric Laurentc5ae6a02014-07-02 13:45:32 -0700456/**
457 * return the frame size (number of bytes per sample) of an output stream.
458 */
459static inline size_t audio_stream_out_frame_size(const struct audio_stream_out *s)
460{
461 size_t chan_samp_sz;
462 audio_format_t format = s->common.get_format(&s->common);
463
464 if (audio_is_linear_pcm(format)) {
465 chan_samp_sz = audio_bytes_per_sample(format);
466 return audio_channel_count_from_out_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
467 }
468
469 return sizeof(int8_t);
470}
471
472/**
473 * return the frame size (number of bytes per sample) of an input stream.
474 */
475static inline size_t audio_stream_in_frame_size(const struct audio_stream_in *s)
476{
477 size_t chan_samp_sz;
478 audio_format_t format = s->common.get_format(&s->common);
479
480 if (audio_is_linear_pcm(format)) {
481 chan_samp_sz = audio_bytes_per_sample(format);
482 return audio_channel_count_from_in_mask(s->common.get_channels(&s->common)) * chan_samp_sz;
483 }
484
485 return sizeof(int8_t);
486}
Dima Zavinf1504db2011-03-11 11:20:49 -0800487
488/**********************************************************************/
489
490/**
491 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
492 * and the fields of this data structure must begin with hw_module_t
493 * followed by module specific information.
494 */
495struct audio_module {
496 struct hw_module_t common;
497};
498
499struct audio_hw_device {
Stewart Miles84d35492014-05-01 09:03:27 -0700500 /**
501 * Common methods of the audio device. This *must* be the first member of audio_hw_device
502 * as users of this structure will cast a hw_device_t to audio_hw_device pointer in contexts
503 * where it's known the hw_device_t references an audio_hw_device.
504 */
Dima Zavinf1504db2011-03-11 11:20:49 -0800505 struct hw_device_t common;
506
507 /**
508 * used by audio flinger to enumerate what devices are supported by
509 * each audio_hw_device implementation.
510 *
511 * Return value is a bitmask of 1 or more values of audio_devices_t
Eric Laurent85e08e22012-08-28 14:30:35 -0700512 *
513 * NOTE: audio HAL implementations starting with
514 * AUDIO_DEVICE_API_VERSION_2_0 do not implement this function.
515 * All supported devices should be listed in audio_policy.conf
516 * file and the audio policy manager must choose the appropriate
517 * audio module based on information in this file.
Dima Zavinf1504db2011-03-11 11:20:49 -0800518 */
519 uint32_t (*get_supported_devices)(const struct audio_hw_device *dev);
520
521 /**
522 * check to see if the audio hardware interface has been initialized.
523 * returns 0 on success, -ENODEV on failure.
524 */
525 int (*init_check)(const struct audio_hw_device *dev);
526
527 /** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
528 int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
529
530 /**
531 * set the audio volume for all audio activities other than voice call.
532 * Range between 0.0 and 1.0. If any value other than 0 is returned,
533 * the software mixer will emulate this capability.
534 */
535 int (*set_master_volume)(struct audio_hw_device *dev, float volume);
536
537 /**
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700538 * Get the current master volume value for the HAL, if the HAL supports
539 * master volume control. AudioFlinger will query this value from the
540 * primary audio HAL when the service starts and use the value for setting
541 * the initial master volume across all HALs. HALs which do not support
John Grossman47bf3d72012-07-17 11:54:04 -0700542 * this method may leave it set to NULL.
Mike J. Chen5ad38a92011-08-15 12:05:00 -0700543 */
544 int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
545
546 /**
Glenn Kasten6df641e2012-01-09 10:41:30 -0800547 * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
Dima Zavinf1504db2011-03-11 11:20:49 -0800548 * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
549 * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
Dima Zavinf1504db2011-03-11 11:20:49 -0800550 */
Glenn Kasten6df641e2012-01-09 10:41:30 -0800551 int (*set_mode)(struct audio_hw_device *dev, audio_mode_t mode);
Dima Zavinf1504db2011-03-11 11:20:49 -0800552
553 /* mic mute */
554 int (*set_mic_mute)(struct audio_hw_device *dev, bool state);
555 int (*get_mic_mute)(const struct audio_hw_device *dev, bool *state);
556
557 /* set/get global audio parameters */
558 int (*set_parameters)(struct audio_hw_device *dev, const char *kv_pairs);
559
560 /*
561 * Returns a pointer to a heap allocated string. The caller is responsible
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800562 * for freeing the memory for it using free().
Dima Zavinf1504db2011-03-11 11:20:49 -0800563 */
564 char * (*get_parameters)(const struct audio_hw_device *dev,
565 const char *keys);
566
567 /* Returns audio input buffer size according to parameters passed or
Glenn Kasten0cacd8d2012-02-10 13:42:44 -0800568 * 0 if one of the parameters is not supported.
569 * See also get_buffer_size which is for a particular stream.
Dima Zavinf1504db2011-03-11 11:20:49 -0800570 */
571 size_t (*get_input_buffer_size)(const struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700572 const struct audio_config *config);
Dima Zavinf1504db2011-03-11 11:20:49 -0800573
Eric Laurentf5e24692014-07-27 16:14:57 -0700574 /** This method creates and opens the audio hardware output stream.
575 * The "address" parameter qualifies the "devices" audio device type if needed.
576 * The format format depends on the device type:
577 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
578 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
579 * - Other devices may use a number or any other string.
580 */
581
Eric Laurent55786bc2012-04-10 16:56:32 -0700582 int (*open_output_stream)(struct audio_hw_device *dev,
583 audio_io_handle_t handle,
584 audio_devices_t devices,
585 audio_output_flags_t flags,
586 struct audio_config *config,
Eric Laurentf5e24692014-07-27 16:14:57 -0700587 struct audio_stream_out **stream_out,
588 const char *address);
Dima Zavinf1504db2011-03-11 11:20:49 -0800589
590 void (*close_output_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700591 struct audio_stream_out* stream_out);
Dima Zavinf1504db2011-03-11 11:20:49 -0800592
593 /** This method creates and opens the audio hardware input stream */
Eric Laurent55786bc2012-04-10 16:56:32 -0700594 int (*open_input_stream)(struct audio_hw_device *dev,
595 audio_io_handle_t handle,
596 audio_devices_t devices,
597 struct audio_config *config,
Glenn Kasten7d973ad2014-07-15 11:10:38 -0700598 struct audio_stream_in **stream_in,
Eric Laurentf5e24692014-07-27 16:14:57 -0700599 audio_input_flags_t flags,
600 const char *address,
601 audio_source_t source);
Dima Zavinf1504db2011-03-11 11:20:49 -0800602
603 void (*close_input_stream)(struct audio_hw_device *dev,
Eric Laurent55786bc2012-04-10 16:56:32 -0700604 struct audio_stream_in *stream_in);
Dima Zavinf1504db2011-03-11 11:20:49 -0800605
606 /** This method dumps the state of the audio hardware */
607 int (*dump)(const struct audio_hw_device *dev, int fd);
John Grossman47bf3d72012-07-17 11:54:04 -0700608
609 /**
610 * set the audio mute status for all audio activities. If any value other
611 * than 0 is returned, the software mixer will emulate this capability.
612 */
613 int (*set_master_mute)(struct audio_hw_device *dev, bool mute);
614
615 /**
616 * Get the current master mute status for the HAL, if the HAL supports
617 * master mute control. AudioFlinger will query this value from the primary
618 * audio HAL when the service starts and use the value for setting the
619 * initial master mute across all HALs. HALs which do not support this
620 * method may leave it set to NULL.
621 */
622 int (*get_master_mute)(struct audio_hw_device *dev, bool *mute);
Eric Laurent73b8a742014-05-22 14:02:38 -0700623
624 /**
625 * Routing control
626 */
627
628 /* Creates an audio patch between several source and sink ports.
629 * The handle is allocated by the HAL and should be unique for this
630 * audio HAL module. */
631 int (*create_audio_patch)(struct audio_hw_device *dev,
632 unsigned int num_sources,
633 const struct audio_port_config *sources,
634 unsigned int num_sinks,
635 const struct audio_port_config *sinks,
636 audio_patch_handle_t *handle);
637
638 /* Release an audio patch */
639 int (*release_audio_patch)(struct audio_hw_device *dev,
640 audio_patch_handle_t handle);
641
642 /* Fills the list of supported attributes for a given audio port.
643 * As input, "port" contains the information (type, role, address etc...)
644 * needed by the HAL to identify the port.
645 * As output, "port" contains possible attributes (sampling rates, formats,
646 * channel masks, gain controllers...) for this port.
647 */
648 int (*get_audio_port)(struct audio_hw_device *dev,
649 struct audio_port *port);
650
651 /* Set audio port configuration */
652 int (*set_audio_port_config)(struct audio_hw_device *dev,
653 const struct audio_port_config *config);
654
Kiran Kandi807edfa2013-10-17 15:49:54 -0700655#ifdef AUDIO_LISTEN_ENABLED
Bharath Ramachandramurthye41db452014-01-14 07:28:09 -0800656 /** This method creates the listen session and returns handle */
Kiran Kandi807edfa2013-10-17 15:49:54 -0700657 int (*open_listen_session)(struct audio_hw_device *dev,
Bharath Ramachandramurthye41db452014-01-14 07:28:09 -0800658 listen_open_params_t *params,
659 struct listen_session** handle);
Kiran Kandi807edfa2013-10-17 15:49:54 -0700660
661 /** This method closes the listen session */
662 int (*close_listen_session)(struct audio_hw_device *dev,
663 struct listen_session* handle);
664
665 /** This method sets the mad observer callback */
666 int (*set_mad_observer)(struct audio_hw_device *dev,
667 listen_callback_t cb_func);
668
Bharath Ramachandramurthye41db452014-01-14 07:28:09 -0800669 /**
670 * This method is used for setting listen hal specfic parameters.
Kiran Kandi807edfa2013-10-17 15:49:54 -0700671 * If multiple paramets are set in one call and setting any one of them
672 * fails it will return failure.
673 */
674 int (*listen_set_parameters)(struct audio_hw_device *dev,
675 const char *kv_pairs);
676#endif
Dima Zavinf1504db2011-03-11 11:20:49 -0800677};
678typedef struct audio_hw_device audio_hw_device_t;
679
680/** convenience API for opening and closing a supported device */
681
682static inline int audio_hw_device_open(const struct hw_module_t* module,
683 struct audio_hw_device** device)
684{
685 return module->methods->open(module, AUDIO_HARDWARE_INTERFACE,
686 (struct hw_device_t**)device);
687}
688
689static inline int audio_hw_device_close(struct audio_hw_device* device)
690{
691 return device->common.close(&device->common);
692}
693
694
695__END_DECLS
696
697#endif // ANDROID_AUDIO_INTERFACE_H