blob: e91fd0044573de26b907647f0734a91f07f61aec [file] [log] [blame]
Sidipotu Ashok404f26d2017-10-10 22:27:51 +05301/*
2 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
5 * Copyright (C) 2011 The Android Open Source Project *
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#ifndef QTI_AUDIO_QAHW_H
20#define QTI_AUDIO_QAHW_H
21
22#include <stdint.h>
23#include <strings.h>
24#include <sys/cdefs.h>
25#include <sys/types.h>
26#include <sys/time.h>
27#include <cutils/bitops.h>
28#include <system/audio.h>
29#include "qahw_defs.h"
Trinath Thammishetty85b19292017-12-18 14:56:50 +053030#include "qahw_effect_api.h"
Sidipotu Ashok404f26d2017-10-10 22:27:51 +053031
32__BEGIN_DECLS
Trinath Thammishetty85b19292017-12-18 14:56:50 +053033
Sidipotu Ashok404f26d2017-10-10 22:27:51 +053034/*
35 * Helper macros for module implementors.
36 *
37 * The derived modules should provide convenience macros for supported
38 * versions so that implementations can explicitly specify module
39 * versions at definition time.
40 */
41
42#define QAHW_MAKE_API_VERSION(maj,min) \
43 ((((maj) & 0xff) << 8) | ((min) & 0xff))
44
45/* First generation of audio devices had version hardcoded to 0. all devices with
46 * versions < 1.0 will be considered of first generation API.
47 */
48#define QAHW_MODULE_API_VERSION_0_0 QAHW_MAKE_API_VERSION(0, 0)
49
50/* Minimal QTI audio HAL version supported by the audio framework */
51#define QAHW_MODULE_API_VERSION_MIN QAHW_MODULE_API_VERSION_0_0
52
53/**
54 * List of known audio HAL modules. This is the base name of the audio HAL
55 * library composed of the "audio." prefix, one of the base names below and
56 * a suffix specific to the device.
57 * e.g: audio.primary.goldfish.so or audio.a2dp.default.so
58 */
59
60#define QAHW_MODULE_ID_PRIMARY "audio.primary"
61#define QAHW_MODULE_ID_A2DP "audio.a2dp"
62#define QAHW_MODULE_ID_USB "audio.usb"
63
64typedef void qahw_module_handle_t;
65typedef void qahw_stream_handle_t;
66
67#ifdef __cplusplus
68extern "C"
69{
70#endif
71/**************************************/
72/* Output stream specific APIs **/
73
74/*
75 * This method creates and opens the audio hardware output stream.
76 * The "address" parameter qualifies the "devices" audio device type if needed.
77 * The format format depends on the device type:
78 * - Bluetooth devices use the MAC address of the device in the form "00:11:22:AA:BB:CC"
79 * - USB devices use the ALSA card and device numbers in the form "card=X;device=Y"
80 * - Other devices may use a number or any other string.
81 */
82
83int qahw_open_output_stream_l(qahw_module_handle_t *hw_module,
84 audio_io_handle_t handle,
85 audio_devices_t devices,
86 audio_output_flags_t flags,
87 struct audio_config *config,
88 qahw_stream_handle_t **out_handle,
89 const char *address);
90
91int qahw_close_output_stream_l(qahw_stream_handle_t *out_handle);
92
93/*
94 * Return the sampling rate in Hz - eg. 44100.
95 */
96uint32_t qahw_out_get_sample_rate_l(const qahw_stream_handle_t *stream);
97
98/*
99 * use set_parameters with key QAHW_PARAMETER_STREAM_SAMPLING_RATE
100 */
101int qahw_out_set_sample_rate_l(qahw_stream_handle_t *stream, uint32_t rate);
102
103/*
104 * Return size of input/output buffer in bytes for this stream - eg. 4800.
105 * It should be a multiple of the frame size. See also get_input_buffer_size.
106 */
107size_t qahw_out_get_buffer_size_l(const qahw_stream_handle_t *stream);
108
109/*
110 * Return the channel mask -
111 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
112 */
113audio_channel_mask_t qahw_out_get_channels_l(const qahw_stream_handle_t *stream);
114
115/*
116 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
117 */
118audio_format_t qahw_out_get_format_l(const qahw_stream_handle_t *stream);
119
120/*
121 * Put the audio hardware input/output into standby mode.
122 * Driver should exit from standby mode at the next I/O operation.
123 * Returns 0 on success and <0 on failure.
124 */
125int qahw_out_standby_l(qahw_stream_handle_t *stream);
126
127/*
128 * set/get audio stream parameters. The function accepts a list of
129 * parameter key value pairs in the form: key1=value1;key2=value2;...
130 *
131 * Some keys are reserved for standard parameters (See AudioParameter class)
132 *
133 * If the implementation does not accept a parameter change while
134 * the output is active but the parameter is acceptable otherwise, it must
135 * return -ENOSYS.
136 *
137 * The audio flinger will put the stream in standby and then change the
138 * parameter value.
139 */
140int qahw_out_set_parameters_l(qahw_stream_handle_t *stream, const char*kv_pairs);
141
142/*
143 * Returns a pointer to a heap allocated string. The caller is responsible
144 * for freeing the memory for it using free().
145 */
146char* qahw_out_get_parameters_l(const qahw_stream_handle_t *stream,
147 const char *keys);
148
149/* API to set playback stream specific config parameters */
150int qahw_out_set_param_data_l(qahw_stream_handle_t *out_handle,
151 qahw_param_id param_id,
152 qahw_param_payload *payload);
153
154/* API to get playback stream specific config parameters */
155int qahw_out_get_param_data_l(qahw_stream_handle_t *out_handle,
156 qahw_param_id param_id,
157 qahw_param_payload *payload);
158
159/*
160 * Return the audio hardware driver estimated latency in milliseconds.
161 */
162uint32_t qahw_out_get_latency_l(const qahw_stream_handle_t *stream);
163
164/*
165 * Use this method in situations where audio mixing is done in the
166 * hardware. This method serves as a direct interface with hardware,
167 * allowing you to directly set the volume as apposed to via the framework.
168 * This method might produce multiple PCM outputs or hardware accelerated
169 * codecs, such as MP3 or AAC.
170 */
171int qahw_out_set_volume_l(qahw_stream_handle_t *stream, float left, float right);
172
173/*
174 * Write audio buffer present in meta_data starting from offset
175 * along with timestamp to driver. Returns number of bytes
176 * written or a negative status_t. If at least one frame was written successfully
177 * prior to the error, it is suggested that the driver return that successful
178 * (short) byte count and then return an error in the subsequent call.
179 * timestamp is only sent driver is session has been opened with timestamp flag
180 * otherwise its ignored.
181 *
182 * If set_callback() has previously been called to enable non-blocking mode
183 * the write() is not allowed to block. It must write only the number of
184 * bytes that currently fit in the driver/hardware buffer and then return
185 * this byte count. If this is less than the requested write size the
186 * callback function must be called when more space is available in the
187 * driver/hardware buffer.
188 */
189ssize_t qahw_out_write_l(qahw_stream_handle_t *stream,
190 qahw_out_buffer_t *out_buf);
191
192/*
193 * return the number of audio frames written by the audio dsp to DAC since
194 * the output has exited standby
195 */
196int qahw_out_get_render_position_l(const qahw_stream_handle_t *stream,
197 uint32_t *dsp_frames);
198
199/*
200 * set the callback function for notifying completion of non-blocking
201 * write and drain.
202 * Calling this function implies that all future rite() and drain()
203 * must be non-blocking and use the callback to signal completion.
204 */
205int qahw_out_set_callback_l(qahw_stream_handle_t *stream,
206 qahw_stream_callback_t callback,
207 void *cookie);
208
209/*
210 * Notifies to the audio driver to stop playback however the queued buffers are
211 * retained by the hardware. Useful for implementing pause/resume. Empty implementation
212 * if not supported however should be implemented for hardware with non-trivial
213 * latency. In the pause state audio hardware could still be using power. User may
214 * consider calling suspend after a timeout.
215 *
216 * Implementation of this function is mandatory for offloaded playback.
217 */
218int qahw_out_pause_l(qahw_stream_handle_t *out_handle);
219
220/*
221 * Notifies to the audio driver to resume playback following a pause.
222 * Returns error if called without matching pause.
223 *
224 * Implementation of this function is mandatory for offloaded playback.
225 */
226int qahw_out_resume_l(qahw_stream_handle_t *out_handle);
227
228/*
229 * Requests notification when data buffered by the driver/hardware has
230 * been played. If set_callback() has previously been called to enable
231 * non-blocking mode, the drain() must not block, instead it should return
232 * quickly and completion of the drain is notified through the callback.
233 * If set_callback() has not been called, the drain() must block until
234 * completion.
235 * If type==AUDIO_DRAIN_ALL, the drain completes when all previously written
236 * data has been played.
237 * If type==AUDIO_DRAIN_EARLY_NOTIFY, the drain completes shortly before all
238 * data for the current track has played to allow time for the framework
239 * to perform a gapless track switch.
240 *
241 * Drain must return immediately on stop() and flush() call
242 *
243 * Implementation of this function is mandatory for offloaded playback.
244 */
245int qahw_out_drain_l(qahw_stream_handle_t *out_handle, qahw_drain_type_t type);
246
247/*
248 * Notifies to the audio driver to flush the queued data. Stream must already
249 * be paused before calling flush().
250 *
251 * Implementation of this function is mandatory for offloaded playback.
252 */
253int qahw_out_flush_l(qahw_stream_handle_t *out_handle);
254
255/*
256 * Return a recent count of the number of audio frames presented to an external observer.
257 * This excludes frames which have been written but are still in the pipeline.
258 * The count is not reset to zero when output enters standby.
259 * Also returns the value of CLOCK_MONOTONIC as of this presentation count.
260 * The returned count is expected to be 'recent',
261 * but does not need to be the most recent possible value.
262 * However, the associated time should correspond to whatever count is returned.
263 * Example: assume that N+M frames have been presented, where M is a 'small' number.
264 * Then it is permissible to return N instead of N+M,
265 * and the timestamp should correspond to N rather than N+M.
266 * The terms 'recent' and 'small' are not defined.
267 * They reflect the quality of the implementation.
268 *
269 * 3.0 and higher only.
270 */
271int qahw_out_get_presentation_position_l(const qahw_stream_handle_t *out_handle,
272 uint64_t *frames, struct timespec *timestamp);
273
274/* Input stream specific APIs */
275
276/* This method creates and opens the audio hardware input stream */
277int qahw_open_input_stream_l(qahw_module_handle_t *hw_module,
278 audio_io_handle_t handle,
279 audio_devices_t devices,
280 struct audio_config *config,
281 qahw_stream_handle_t **stream_in,
282 audio_input_flags_t flags,
283 const char *address,
284 audio_source_t source);
285
286int qahw_close_input_stream_l(qahw_stream_handle_t *in_handle);
287
288/*
289 * Return the sampling rate in Hz - eg. 44100.
290 */
291uint32_t qahw_in_get_sample_rate_l(const qahw_stream_handle_t *in_handle);
292
293/*
294 * currently unused - use set_parameters with key
295 * QAHW_PARAMETER_STREAM_SAMPLING_RATE
296 */
297int qahw_in_set_sample_rate_l(qahw_stream_handle_t *in_handle, uint32_t rate);
298
299/*
300 * Return size of input/output buffer in bytes for this stream - eg. 4800.
301 * It should be a multiple of the frame size. See also get_input_buffer_size.
302 */
303size_t qahw_in_get_buffer_size_l(const qahw_stream_handle_t *in_handle);
304
305/*
306 * Return the channel mask -
307 * e.g. AUDIO_CHANNEL_OUT_STEREO or AUDIO_CHANNEL_IN_STEREO
308 */
309audio_channel_mask_t qahw_in_get_channels_l(const qahw_stream_handle_t *in_handle);
310
311/*
312 * Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT
313 */
314audio_format_t qahw_in_get_format_l(const qahw_stream_handle_t *in_handle);
315
316/*
317 * currently unused - use set_parameters with key
318 * QAHW_PARAMETER_STREAM_FORMAT
319 */
320int qahw_in_set_format_l(qahw_stream_handle_t *in_handle, audio_format_t format);
321
322/*
323 * Put the audio hardware input/output into standby mode.
324 * Driver should exit from standby mode at the next I/O operation.
325 * Returns 0 on success and <0 on failure.
326 */
327int qahw_in_standby_l(qahw_stream_handle_t *in_handle);
328
329/*
330 * set/get audio stream parameters. The function accepts a list of
331 * parameter key value pairs in the form: key1=value1;key2=value2;...
332 *
333 * Some keys are reserved for standard parameters (See AudioParameter class)
334 *
335 * If the implementation does not accept a parameter change while
336 * the output is active but the parameter is acceptable otherwise, it must
337 * return -ENOSYS.
338 *
339 * The audio flinger will put the stream in standby and then change the
340 * parameter value.
341 */
342int qahw_in_set_parameters_l(qahw_stream_handle_t *in_handle, const char *kv_pairs);
343
344/*
345 * Returns a pointer to a heap allocated string. The caller is responsible
346 * for freeing the memory for it using free().
347 */
348char* qahw_in_get_parameters_l(const qahw_stream_handle_t *in_handle,
349 const char *keys);
350/*
351 * Read audio buffer in from audio driver. Returns number of bytes read, or a
352 * negative status_t. meta_data structure is filled buffer pointer, start
353 * offset and valid catpure timestamp (if session is opened with timetamp flag)
354 * and buffer. if at least one frame was read prior to the error,
355 * read should return that byte count and then return an error in the
356 * subsequent call.
357 */
358ssize_t qahw_in_read_l(qahw_stream_handle_t *in_handle,
359 qahw_in_buffer_t *in_buf);
360/*
361 * Return the amount of input frames lost in the audio driver since the
362 * last call of this function.
363 * Audio driver is expected to reset the value to 0 and restart counting
364 * upon returning the current value by this function call.
365 * Such loss typically occurs when the user space process is blocked
366 * longer than the capacity of audio driver buffers.
367 *
368 * Unit: the number of input audio frames
369 */
370uint32_t qahw_in_get_input_frames_lost_l(qahw_stream_handle_t *in_handle);
371
372/*
373 * Return a recent count of the number of audio frames received and
374 * the clock time associated with that frame count.
375 *
376 * frames is the total frame count received. This should be as early in
377 * the capture pipeline as possible. In general,
378 * frames should be non-negative and should not go "backwards".
379 *
380 * time is the clock MONOTONIC time when frames was measured. In general,
381 * time should be a positive quantity and should not go "backwards".
382 *
383 * The status returned is 0 on success, -ENOSYS if the device is not
384 * ready/available, or -EINVAL if the arguments are null or otherwise invalid.
385 */
386int qahw_in_get_capture_position_l(const qahw_stream_handle_t *in_handle,
387 int64_t *frames, int64_t *time);
388
389/* Module specific APIs */
390
391/* convenience API for opening and closing an audio HAL module */
392qahw_module_handle_t *qahw_load_module_l(const char *hw_module_id);
393
394int qahw_unload_module_l(qahw_module_handle_t *hw_module);
395
396/*
397 * check to see if the audio hardware interface has been initialized.
398 * returns 0 on success, -ENODEV on failure.
399 */
400int qahw_init_check_l(const qahw_module_handle_t *hw_module);
401
402/* set the audio volume of a voice call. Range is between 0.0 and 1.0 */
403int qahw_set_voice_volume_l(qahw_module_handle_t *hw_module, float volume);
404
405/*
406 * set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
407 * is for standard audio playback, AUDIO_MODE_RINGTONE when a ringtone is
408 * playing, and AUDIO_MODE_IN_CALL when a call is in progress.
409 */
410int qahw_set_mode_l(qahw_module_handle_t *hw_module, audio_mode_t mode);
411
412/* Mute/unmute mic during voice/voip/HFP call */
413int qahw_set_mic_mute_l(qahw_module_handle_t *hw_module, bool state);
414
415/* Get mute/unmute status of mic during voice call */
416int qahw_get_mic_mute_l(qahw_module_handle_t *hw_module, bool *state);
417
418/* set/get global audio parameters */
419int qahw_set_parameters_l(qahw_module_handle_t *hw_module, const char *kv_pairs);
420
421/*
422 * Returns a pointer to a heap allocated string. The caller is responsible
423 * for freeing the memory for it using free().
424 */
425char* qahw_get_parameters_l(const qahw_module_handle_t *hw_module,
426 const char *keys);
427
428/* Returns audio input buffer size according to parameters passed or
429 * 0 if one of the parameters is not supported.
430 * See also get_buffer_size which is for a particular stream.
431 */
432size_t qahw_get_input_buffer_size_l(const qahw_module_handle_t *hw_module,
433 const struct audio_config *config);
434
435/*returns current QTI HAL version */
436int qahw_get_version_l();
437
438/* Api to implement get parameters based on keyword param_id
439 * and store data in payload.
440 */
441int qahw_get_param_data_l(const qahw_module_handle_t *hw_module,
442 qahw_param_id param_id,
443 qahw_param_payload *payload);
444
445/* Api to implement set parameters based on keyword param_id
446 * and data present in payload.
447 */
448int qahw_set_param_data_l(const qahw_module_handle_t *hw_module,
449 qahw_param_id param_id,
450 qahw_param_payload *payload);
451
452/* Creates an audio patch between several source and sink ports.
453 * The handle is allocated by the HAL and should be unique for this
454 * audio HAL module.
455 */
456int qahw_create_audio_patch_l(qahw_module_handle_t *hw_module,
457 unsigned int num_sources,
458 const struct audio_port_config *sources,
459 unsigned int num_sinks,
460 const struct audio_port_config *sinks,
461 audio_patch_handle_t *handle);
462
463/* Release an audio patch */
464int qahw_release_audio_patch_l(qahw_module_handle_t *hw_module,
465 audio_patch_handle_t handle);
466/* Fills the list of supported attributes for a given audio port.
467 * As input, "port" contains the information (type, role, address etc...)
468 * needed by the HAL to identify the port.
469 * As output, "port" contains possible attributes (sampling rates, formats,
470 * channel masks, gain controllers...) for this port.
471 */
472int qahw_get_audio_port_l(qahw_module_handle_t *hw_module,
473 struct audio_port *port);
474
475/* Set audio port configuration */
476int qahw_set_audio_port_config_l(qahw_module_handle_t *hw_module,
477 const struct audio_port_config *config);
Trinath Thammishetty85b19292017-12-18 14:56:50 +0530478
479/* Audio effects API */
480qahw_effect_lib_handle_t qahw_effect_load_library_l(const char *lib_path);
481
482int32_t qahw_effect_unload_library_l(qahw_effect_lib_handle_t handle);
483
484int32_t qahw_effect_create_l(qahw_effect_lib_handle_t handle,
485 const qahw_effect_uuid_t *uuid,
486 int32_t io_handle,
487 qahw_effect_handle_t *effect_handle);
488
489int32_t qahw_effect_release_l(qahw_effect_lib_handle_t handle,
490 qahw_effect_handle_t effect_handle);
491
492int32_t qahw_effect_get_descriptor_l(qahw_effect_lib_handle_t handle,
493 const qahw_effect_uuid_t *uuid,
494 qahw_effect_descriptor_t *effect_desc);
495
496int32_t qahw_effect_get_version_l();
497
498int32_t qahw_effect_process_l(qahw_effect_handle_t self,
499 qahw_audio_buffer_t *in_buffer,
500 qahw_audio_buffer_t *out_buffer);
501
502int32_t qahw_effect_command_l(qahw_effect_handle_t self,
503 uint32_t cmd_code,
504 uint32_t cmd_size,
505 void *cmd_data,
506 uint32_t *reply_size,
507 void *reply_data);
508
509int32_t qahw_effect_process_reverse_l(qahw_effect_handle_t self,
510 qahw_audio_buffer_t *in_buffer,
511 qahw_audio_buffer_t *out_buffer);
512
Sidipotu Ashok404f26d2017-10-10 22:27:51 +0530513#ifdef __cplusplus
514}
515#endif
516
517__END_DECLS
518
519#endif // QTI_AUDIO_QAHW_H