# Platform Adaptation Layer (PAL)

Source: [https://docs.qualcomm.com/doc/80-70014-16/topic/platform_adaptation_layer_pal.html](https://docs.qualcomm.com/doc/80-70014-16/topic/platform_adaptation_layer_pal.html)

The Platform Adaptation Layer (PAL) provides higher-level audio-specific APIs to
        access the underlying audio hardware and drivers to enable feature-rich audio use
        cases.

PulseAudio uses the same PAL APIs for different audio use cases. The source code for the
            PAL module is located at:

build-qcom-wayland/workspace/sources/pal/opensource/arpal-lx

All APIs that are exposed by the PAL module are declared in:

build-qcom-wayland/workspace/sources/pal/opensource/arpal-lx/inc/PalApi.h

Some of the frequently used PAL APIs are described below.

## pal\_init

Initializes the PAL, parses the related configuration files, and stores them in local
                structure to be used during a use case.

    int32_t pal_init( )
    Copy to clipboard

**Parameters**

None

**Return value**
- 0 on success
- Error code on failure

## pal\_deinit

De-initializes PAL and frees up the resources allocated during initialization.

    void pal_deinit()
    Copy to clipboard

**Parameters**

None

**Return value**
- 0 on success
- Error code on failure

## pal\_stream\_open

Opens a stream with the specified configuration such as source/sink devices, media
                configuration, etc. Returns the stream handle on successful execution.

    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)Copy to clipboard

**Parameters**

| attributes | Valid stream attributes obtained from pal\_stream\_open |
| --- | --- |
| no\_of\_devices | Number of audio devices with which to initially start the<br>                                stream |
| devices | Array of pal\_devices. The size of the array is based on the<br>                                no\_of\_devices specified by the client. |
| no\_of\_modifiers | Number of modifiers |
| modifiers | Array of modifiers. Modifiers are used to add additional<br>                                key-value pairs. |
| cb | Callback function associated with the stream. Any event will be<br>                                notified through this callback function. |
| cookie | Client data associated with the stream. This cookie will be<br>                                returned in the callback function. |
| stream\_handle | Updated with valid stream handle if the operation is<br>                                successful |

**Return value**
- 0 on success
- Error code on failure

## pal\_stream\_start

Starts a stream.

    int32_t pal_stream_start(
         pal_stream_handle_t *stream_handle)Copy to clipboard

**Parameters**

| stream\_handle | Valid stream handle obtained from pal\_stream\_open |
| --- | --- |

**Return value**
- 0 on success
- Error code on failure

## pal\_stream\_read

Reads the audio buffer captured from the audio source device.

    ssize_t pal_stream_read(
         pal_stream_handle_t *stream_handle, 
         struct pal_buffer *buf)Copy to clipboard

**Parameters**

| stream\_handle | Valid stream handle obtained from pal\_stream\_open |
| --- | --- |
| buf | Pointer to pal\_buffer containing audio samples and<br>                                metadata |

**Return value**
- Number of bytes read
- Error code on failure

## pal\_stream\_write

Writes the audio buffer for stream rendering over sink device.

    ssize_t pal_stream_write(
         pal_stream_handle_t *stream_handle, 
         struct pal_buffer *buf)Copy to clipboard

**Parameters**

| stream\_handle | Valid stream handle obtained from pal\_stream\_open |
| --- | --- |
| buf | Pointer to pal\_buffer containing audio samples and<br>                                metadata |

**Return value**
- Number of bytes read
- Error code on failure

## pal\_stream\_stop

Stops a stream.

    int32_t pal_stream_stop(
         pal_stream_handle_t *stream_handle)Copy to clipboard

**Parameters**

| stream\_handle | Valid stream handle obtained from pal\_stream\_open |
| --- | --- |

**Return value**
- 0 on success
- Error code on failure

## pal\_stream\_close

Closes a stream.

    int32_t pal_stream_close(
         pal_stream_handle_t *stream_handle)Copy to clipboard

**Parameters**

| stream\_handle | Valid stream handle obtained from pal\_stream\_open |
| --- | --- |

**Return value**
- `0` on success
- Error code on failure

**Parent Topic:** [APIs and Sample Apps](https://docs.qualcomm.com/doc/80-70014-16/topic/apis_and_sample_apps.html)

Last Published: Jul 15, 2024

[Previous Topic
PulseAudio](https://docs.qualcomm.com/bundle/publicresource/80-70014-16/topics/pulseaudio.md) [Next Topic
TinyALSA](https://docs.qualcomm.com/bundle/publicresource/80-70014-16/topics/tinyalsa_apis.md)