blob: fa7c31d571cfa1a0054b602c9784f81728027fa6 [file] [log] [blame]
/*
* 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*/