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