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