-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPalApi.h
593 lines (546 loc) · 20.2 KB
/
PalApi.h
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*
* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file pal_api.h
* \brief Function prototypes for the PAL(Platform Audio
* Layer).
*
* This contains the prototypes for the PAL(Platform Audio
* layer) and any macros, constants, or global variables
* needed.
*/
#ifndef PAL_API_H
#define PAL_API_H
#include "PalDefs.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Get PAL version in the form of Major and Minor number
* seperated by period.
*
* @return the version string in the form of Major and Minor
* e.g '1.0'
*/
char* pal_get_version( );
/**
* Initialize PAL. Increases ref count.
*
* @return 0 on success, error code on failure.
*/
int32_t pal_init( );
/**
* De-Initialize PAL. Decreases the ref count.
*/
void pal_deinit();
/**
* \brief Open the stream with specified configuration.
*
* \param[in] attributes - Valid stream attributes obtained
* from pal_stream_open
* \param[in] no_of_devices - no of audio devices that the
* stream should be initially started with.
* \param[in] pal_device - an array of pal_devices. The size of
* the array is based on the no_of_devices specified by
* the client.
* If pal_media_config in pal_device is specified as NULL,
* PAL uses the default device configuration or appropriate
* configuration based on the usecases running.
* Clients can query the device configuration by using
* pal_get_device().
* \param[in] no_of_modifiers - no of modifiers.
* \param[in] modifiers - an array of modifiers. Modifiers are
* used to add additional key-value pairs. e.g to
* identify the topology of usecase from default set.
* \param[in] cb - callback function associated with stream.
* Any event will notified through this callback
* function.
* \param[in] cookie - client data associated with the stream.
* This cookie will be returned back in the callback
* function.
* \param[out] stream_handle - Updated with valid stream handle
* if the operation is successful.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_open(struct pal_stream_attributes *attributes,
uint32_t no_of_devices, struct pal_device *devices,
uint32_t no_of_modifiers, struct modifier_kv *modifiers,
pal_stream_callback cb, uint64_t cookie,
pal_stream_handle_t **stream_handle);
/**
* \brief Close the stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_close(pal_stream_handle_t *stream_handle);
/**
* \brief Register for specific event on a given stream. Events
* will be notified via the callback function registered
* in pal_stream_open cmd.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] event_id - Valid event id that the client would like notificaiton.
* \param[in] event_data - Event configuration data.
*
* \return 0 on success, error code otherwise
*/
//int32_t pal_stream_register_for_event(pal_stream_handle_t *stream_handle,
// uint32_t event_id, pal_event_cfg_t *event_cfg);
/**
* \brief Start the stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_start(pal_stream_handle_t *stream_handle);
/**
* \brief Stop the stream. Stream must be in started/paused
* state before stoping.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_stop(pal_stream_handle_t *stream_handle);
/**
* \brief Pause the stream. Stream must be in started state
* before resuming.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_pause(pal_stream_handle_t *stream_handle);
/**
* \brief Resume the stream. Stream must be in paused state
* before resuming.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_resume(pal_stream_handle_t *stream_handle);
/**
* \brief Flush accumlated data from the stream. Stream must be
* in paused state before flushing.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_flush(pal_stream_handle_t *stream_handle);
/**
* Drain audio data buffered by the driver/hardware has been
* played depending on the drain type specified. If stream is
* opened with AUDIO_STREAM_FLAG_NON_BLOCKING and callback
* function is set in pal_open_stream(), drain complete
* notificaiton will be sent via the callback function
* otherwise will block until drain is completed.
*
* Drain will return immediately on stop() and flush() call.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] type - drain type, DRAIN or DRAIN_PARTIAL.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_drain(pal_stream_handle_t *stream_handle, pal_drain_type_t type);
/**
* \brief Suspend graph and stop processing data from the stream.
* Stream must be in started state before suspending.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_suspend(pal_stream_handle_t *stream_handle);
/**
* Get audio buffer size based on the direction of the stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open.
* \param[out] in_buffer - filled if stream was opened with
* PAL_AUDIO_INPUT direction.
* \param[out] out_buffer - filled if stream was opened with
* PAL_AUDIO_OUTPUT direction.
* \param[out] in buffer and out_buffer - filled if stream was
* opened with PAL_AUDIO_OUTPUT|PAL_AUDIO_INPUT direction.
*
* \return - 0 on success, error code otherwise.
*/
int32_t pal_stream_get_buffer_size(pal_stream_handle_t *stream_handle,
size_t *in_buffer, size_t *out_buffer);
/**
* Gets all the tags and associated module iid and module_id
* mapping associated with a Pal session handle
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open.
* \param[in/out] size - size of the memory passed by the client. If it is not
enough to copy the tag_module_info a error is returned with
the size set to the expected size of the memory to be passed.
* \param[out] payload - It is in the form of struct pal_tag_module_info
*
* \return - 0 on success, error code otherwise.
*/
int32_t pal_stream_get_tags_with_module_info(pal_stream_handle_t *stream_handle,
size_t *size ,uint8_t *payload);
/**
* Set audio buffer size based on the direction of the stream.
* This overwrites the default buffer size configured for
* certain stream types.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open.
* \param[in] in_buff_cfg - input buffers configuratoin when stream is
* opened with PAL_AUDIO_INPUT or PAL_AUDIO_INPUT_OUTPUT direction.
* \param[in] output_buff_count - output buffers configuratoin when stream is
* opened with PAL_AUDIO_OUTPUT or PAL_AUDIO_INPUT_OUTPUT direction.
*
* \return - 0 on success, error code otherwise.
*/
int32_t pal_stream_set_buffer_size (pal_stream_handle_t *stream_handle,
pal_buffer_config_t *in_buff_cfg,
pal_buffer_config_t *out_buff_cfg);
/**
* Read audio buffer captured from in the audio stream.
* an error code.
* Capture timestamps will be populated if session was
* opened with timetamp flag.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] buf - pointer to pal_buffer containing audio
* samples and metadata.
*
* \return - number of bytes read or error code on failure
*/
ssize_t pal_stream_read(pal_stream_handle_t *stream_handle, struct pal_buffer *buf);
/**
* Write audio buffer of a stream for rendering.If at least one
* frame was written successfully prior to the error, PAL will
* return number of bytes returned.
*
* Timestamp is honored if the stream was opened with timestamp
* flag otherwise it is ignored.
*
* If the stream was opened with non-blocking mode, the write()
* will operate in non-blocking mode. PAL will write only the
* number of bytes that currently fit in the driver/hardware
* buffer. If the callback function is set during
* pal_stream_open, the callback function will be called when
* more space is available in the driver/hardware buffer.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] buf - pointer to pal_buffer containing audio
* samples and metadata.
*
* \return number of bytes written or error code.
*/
ssize_t pal_stream_write(pal_stream_handle_t *stream_handle, struct pal_buffer *buf);
/**
* \brief get current device on stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] no_of_devices - no of audio devices that the
* stream should be initially started with.
* \param[in] pal_device - an array of pal_device. The size of
* the array is based on the no_of_devices the stream is
* associated.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_get_device(pal_stream_handle_t *stream_handle,
uint32_t no_of_devices, struct pal_device *devices);
/**
* \brief set new device on stream. This api will disable the
* existing device and set the new device. If the new
* device is a combo device and includes previously set
* device, it will retain the old device to avoid
* setting the same device again unless device
* configuration chagnes.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] no_of_devices - no of audio devices that the
* stream should be initially started with.
* \param[in] pal_device - an array of pal_device. The size of
* the array is based on the no_of_devices specified by
* the client.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_set_device(pal_stream_handle_t *stream_handle,
uint32_t no_of_devices, struct pal_device *devices);
/**
* \brief Get audio parameters specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] param_id - param id whose parameters are
* retrieved.
* \param[out] param_payload - param data applicable to the
* param_id
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_get_param(pal_stream_handle_t *stream_handle,
uint32_t param_id, pal_param_payload **param_payload);
/**
* \brief Set audio parameters specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] param_id - param id whose parameters are to be
* set.
* \param[out] param_payload - param data applicable to the
* param_id
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_set_param(pal_stream_handle_t *stream_handle,
uint32_t param_id, pal_param_payload *param_payload);
/**
* \brief Get audio volume specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] volume - volume data to be set on a stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_get_volume(pal_stream_handle_t *stream_handle,
struct pal_volume_data *volume);
/**
* \brief Set audio volume specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[out] volume - volume data to be retrieved from the
* stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_set_volume(pal_stream_handle_t *stream_handle,
struct pal_volume_data *volume);
/**
* \brief Get current audio audio mute state to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] mute - mute state to be retrieved from the
* stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_get_mute(pal_stream_handle_t *stream_handle, bool *state);
/**
* \brief Set mute specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[out] mute - mute state to be set to the stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_set_mute(pal_stream_handle_t *stream, bool state);
/**
* \brief Get microphone mute state.
*
*\param[out] mute - global mic mute flag to be retrieved.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_get_mic_mute(bool *state);
/**
* \brief Set global mic mute state.
*
* \param[out] mute - global mic mute state
*
* \return 0 on success, error code otherwise
*/
int32_t pal_set_mic_mute(bool state);
/**
* \brief Get time stamp.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[out] stime - time stamp data to be retrieved from the
* stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_get_timestamp(pal_stream_handle_t *stream_handle, struct pal_session_time *stime);
/**
* \brief Add remove effects for Voip TX path.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] effect - effect to be enabled or disable
* \param[in] enable - enable/disable
*
* \return 0 on success, error code otherwise
*/
int32_t pal_add_remove_effect(pal_stream_handle_t *stream_handle, pal_audio_effect_t effect, bool enable);
/**
* \brief Set pal parameters
*
* \param[in] param_id - param id whose parameters are to be
* set.
* \param[in] param_payload - param data applicable to the
* param_id
* \param[in] payload_size - size of payload
*
* \return 0 on success, error code otherwise
*/
int32_t pal_set_param(uint32_t param_id, void *param_payload, size_t payload_size);
/**
* \brief Get pal parameters
*
*
* \param[in] param_id - param id whose parameters are
* retrieved.
* \param[out] param_payload - param data applicable to the
* param_id
* \param[out] payload_size - size of payload
*
* \return 0 on success, error code otherwise
*/
int32_t pal_get_param(uint32_t param_id, void **param_payload,
size_t *payload_size, void *query);
/**
* \brief Set audio volume specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[in] min_size_frames - minimum frame size required.
* \param[out] info - map buffer descriptor returned by
* stream.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_create_mmap_buffer(pal_stream_handle_t *stream_handle,
int32_t min_size_frames,
struct pal_mmap_buffer *info);
/**
* \brief Set audio volume specific to a stream.
*
* \param[in] stream_handle - Valid stream handle obtained
* from pal_stream_open
* \param[out] position - Mmap buffer read/write position returned.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_stream_get_mmap_position(pal_stream_handle_t *stream_handle,
struct pal_mmap_position *position);
/**
* \brief Register global callback to pal.
* This can be used to inform client about any information
* needed even before stream is created.
*
* \param[in] cb - Valid callback.
* \param[in] cookie - client data. This cookie will be
* returned back in the callback function.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_register_global_callback(pal_global_callback cb, uint64_t cookie);
/**
* \brief Set and get pal parameters for generic effect framework
*
* \param[in] param_id - param id whose parameters are to be
* set.
* \param[in/out] param_payload - param data applicable to the
* param_id
* \param[in] payload_size - size of payload
*
* \param[in] pal_stream_type - type of stream to apply the GEF param
*
* \param[in] pal_device_id - device id to apply the effect
*
* \param[i] pal_stream_type - stream type to apply the effect
*
* \param[in] dir - param read or write
*
* \return 0 on success, error code otherwise
*/
int32_t pal_gef_rw_param(uint32_t param_id, void *param_payload,
size_t payload_size, pal_device_id_t pal_device_id,
pal_stream_type_t pal_stream_type, unsigned int dir);
/**
* \brief Set and get pal parameters for generic effect framework with ACDB
*
* \param[in] param_id - param id whose parameters are to be
* set.
* \param[in/out] param_payload - param data applicable to the
* param_id
* \param[in] payload_size - size of payload
*
* \param[in] pal_stream_type - type of stream to apply the GEF param
*
* \param[in] pal_device_id - device id to apply the effect
*
* \param[i] pal_stream_type - stream type to apply the effect
*
* \param[in] sample_rate - sample_rate value for CKV. 0 for default CKV
*
* \param[in] instance_id - instance id
*
* \param[in] dir - param read or write
*
* \param[in] is_play - stream direction. true for playback. false for recording.
*
* \return 0 on success, error code otherwise
*/
int32_t pal_gef_rw_param_acdb(uint32_t param_id, void *param_payload,
size_t payload_size, pal_device_id_t pal_device_id,
pal_stream_type_t pal_stream_type, uint32_t sample_rate,
uint32_t instance_id, uint32_t dir, bool is_play);
extern void __gcov_flush();
/**
* Enable Gcov for PAL.
*/
//void enable_gcov();
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*PAL_API_H*/