> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Perform Bluetooth A2DP source functions

> You can perform Bluetooth A2DP source functions using the ``bluetoothctl`` menu, ``menu transport`` submenu, and ``paplay`` commands. Bluetooth A2DP source functions include connecting or disconnecting to a remote device and listing available transport options. They allow you to retrieve information about codec capabilities, set the absolute volume, and play an audio file. You can also get a list of available sinks and play audio on a specific sink using the Bluetooth A2DP source functions.

## Prerequisites

Before you begin, set up your device and go to the required menu as described in <a href="verify-a2-dp-functions#set-up-the-device-for-a2dp-functions" target="_self">Set up the device for A2DP functions</a>.

## Connect a remote device

To connect a remote device in the A2DP source role, run the following command from the `bluetoothctl` menu:

```text theme={null}
connect <bt_address>
```

**Parameters**

`<bt_address>` is the Bluetooth address of the remote device.

**Example**

To connect to a paired remote device with `<bt_address>` `17:1A:35:8D:A2:A4`, run the following command:

```text theme={null}
connect 17:1A:35:8D:A2:A4
```

**Sample output**

```text theme={null}
[bluetooth]# connect 17:1A:35:8D:A2:A4
Attempting to connect to 17:1A:35:8D:A2:A4
[CHG] Device 17:1A:35:8D:A2:A4 Connected: yes
[CHG] Device 17:1A:35:8D:A2:A4 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 17:1A:35:8D:A2:A4 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 17:1A:35:8D:A2:A4 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 17:1A:35:8D:A2:A4 ServicesResolved: yes
[CHG] Device 17:1A:35:8D:A2:A4 Bonded: yes
[CHG] Device 17:1A:35:8D:A2:A4 Paired: yes
[NEW] Endpoint /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1
[NEW] Endpoint /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep2
[NEW] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0
Connection successful
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 State: active
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 Volume: 0x0040 (64)
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 State: idle
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 Volume: 0x0044 (68)
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 Volume: 0x0040 (64)
[MySoundbar]#
```

## List available transport

To list the available transport, run the following command from the `menu transport` submenu:

```text theme={null}
list
```

**Sample output**

```text theme={null}
[MySoundbar]# list
Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0
```

## Get information about codec capabilities

To get the information about the codec capabilities of a transport, run the following command from the `menu transport` submenu:

```text theme={null}
show <transport>
```

**Parameters**

`<transport>` is the transport path.

**Example**

To get the information about the codec capabilities of `<transport>` `/org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0`, run the following command:

```text theme={null}
show /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0
```

**Sample output**

```text theme={null}
[MySoundbar]# show /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0
Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0
      UUID: 0000110a-0000-1000-8000-00805f9b34fb
      Codec: 0x00 (0)
      Configuration: 0x21 (33)
      Configuration: 0x15 (21)
      Configuration: 0x02 (2)
      Configuration: 0x35 (53)
      Device: /org/bluez/hci0/dev_17_1A_35_8D_A2_A4
      State: idle
      Volume: 0x0040 (64)
```

## Set absolute volume

<Note>
  Ensure that the DUT and the remote device support the `setabsvolume` feature.
</Note>

To set the absolute volume of a transport, run the following command from the `menu transport` submenu:

```text theme={null}
volume <transport> [value]
```

**Parameters**

* `<transport>` is the transport path.

* `[value]` is the volume level.

**Example**

To set the absolute volume of `<transport>` `/org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0` as `50`, run the following command:

```text theme={null}
volume /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 50
```

**Sample output**

```text theme={null}
[MySoundbar]# volume /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 50
Changing Volume succeeded
[CHG] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 Volume: 0x0032 (50)
[MySoundbar]# volume /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 10
Changing Volume succeeded
```

## Play an audio file

<Note>
  The DUT doesn't support an audio player. Use `paplay` commands to play music.

  Only PCM audio sample is supported.
</Note>

To play songs from the DUT, do the following:

1. Run SSH.

2. Play a WAV file by running the following command:

   ```text theme={null}
   paplay <audio_filepath> -v
   ```

   **Parameters**

   `<audio_filepath>` is the filepath of the WAV file.

   **Example**

   To play a WAV file at `/tmp/playback.wav`, run the following command:

   ```text theme={null}
   paplay /tmp/playback.wav -v
   ```

   **Sample output**

   ```text theme={null}
   sh-5.1# paplay /tmp/playback.wav -v
   Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
   Connection established.
   Stream successfully created.
   Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528
   Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'.
   Connected to device bluez_output.17:1A:35:8D:A2:A4 (index: 68, suspended: no).
   Stream started.
   ```

## Get a list of sinks

To get the list of sinks when multiple devices are connected, run the following command in SSH:

```text theme={null}
pactl list sinks short
```

<Note>
  The pactl tool isn't available by default. Enable and build the tool on your device.
</Note>

**Sample output**

```text theme={null}
sh-5.1# pactl list sinks short
51      alsa_output.platform-sound.HiFi__Speaker__sink  PipeWire        s16le 2ch 48000Hz       SUSPENDED
68      bluez_output.17:1A:35:8D:A2:A4  PipeWire        float32le 2ch 48000Hz   SUSPENDED
```

## Play audio on a specific sink

To play audio on a specific sink when multiple devices are connected, run the following command in SSH:

```text theme={null}
paplay <audio_filepath> --device=<device_name> -v
```

**Parameters**

* `<audio_filepath>` is the filepath of the WAV file.

* `<device_name>` is the sink name.

**Example**

To play `pcmtest.wav` on the `bluez_output.17:1A:35:8D:A2:A4` sink, run the following command:

```text theme={null}
paplay pcmtest.wav --device=bluez_output.17:1A:35:8D:A2:A4 -v
```

**Sample output**

```text theme={null}
sh-5.1# paplay pcmtest.wav --device=bluez_output.17:1A:35:8D:A2:A4 -v
Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
Connection established.
Stream successfully created.
Buffer metrics: maxlength=4194304, tlength=352800, prebuf=349276, minreq=3528
Using sample spec 's16le 2ch 44100Hz', channel map 'front-left,front-right'.
Connected to device bluez_output.17:1A:35:8D:A2:A4 (index: 68, suspended: no).
Stream started.
Time: 2.925 sec; Latency: 2062081 usec.
```

## Disconnect a remote device

To disconnect a remote device, run the following command from the `bluetoothctl` menu:

```text theme={null}
disconnect <bt_address>
```

**Parameters**

`<bt_address>` is the Bluetooth address of the remote device.

**Example**

To disconnect a paired remote device with `<bt_address>` `17:1A:35:8D:A2:A4`, run the following command:

```text theme={null}
disconnect 17:1A:35:8D:A2:A4
```

**Sample output**

```text theme={null}
[MySoundbar]# disconnect 17:1A:35:8D:A2:A4
Attempting to disconnect from 17:1A:35:8D:A2:A4
[DEL] Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd2
[DEL] Endpoint /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1
[DEL] Endpoint /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep2
[CHG] Device 17:1A:35:8D:A2:A4 ServicesResolved: no
Successful disconnected
[CHG] Device 17:1A:35:8D:A2:A4 Connected: no
```
