# Perform Bluetooth A2DP source functions

Source: [https://docs.qualcomm.com/doc/80-70017-13/topic/bluez-perform-bluetooth-a2dp-source-functions.html](https://docs.qualcomm.com/doc/80-70017-13/topic/bluez-perform-bluetooth-a2dp-source-functions.html)

You can perform Bluetooth A2DP source functions using the
            `bluetoothctl` menu, `menu transport` submenu, and
            `paplay` commands.

Before you begin, set up your device and go to the required menu as described in
                    [Set up device for A2DP functions](https://docs.qualcomm.com/doc/80-70017-13/topic/bluez-a2dp.html#bluez-a2dp__section_fwp_mx5_mcc_navyanka_08-25-24-1121-38-413).

## Connect a remote device

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

    connect <bt_address>Copy to clipboard

**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:

    connect 17:1A:35:8D:A2:A4Copy to clipboard

**Sample output**

[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]#Copy to clipboard

## List available transport

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

    listCopy to clipboard

**Sample output**

[MySoundbar]# list
    Transport /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0Copy to clipboard

## 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:

    show <transport>Copy to clipboard

**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:

    show /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0Copy to clipboard

**Sample output**

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

## Set absolute volume

Note: 
                
Ensure that the DUT and the remote device support the
                        `setabsvolume` feature.

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

    volume <transport> [value]Copy to clipboard

**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:

    volume /org/bluez/hci0/dev_17_1A_35_8D_A2_A4/sep1/fd0 50Copy to clipboard

**Sample output**

[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 succeededCopy to clipboard

## Play an audio file

Note:
- The DUT does not support an audio player. Use `paplay`
                        commands to play music.
- Only PCM audio sample is supported.

To play songs from the DUT, do the following:

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

        paplay <audio_filepath> -vCopy to clipboard

    **Parameters**

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

    **Example**

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

        paplay /tmp/pcmtest.wav -vCopy to clipboard

    **Sample                            output**

sh-5.1# paplay /tmp/pcmtest.wav -v
        Opening a playback stream with sample specification 's16le 2ch 44100Hz' and channel map 'front-left,front-right'.
        Connection established.
        Strean 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_sink.20_19_D8_36_90_40.a2dp_sink (index: 4, suspended: no).
        Stream started.
        Time: 4.427 sec; Latency: 2042656 usec.Copy to clipboard

## Get a list of sinks

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

    pactl list sinks shortCopy to clipboard

**Sample output**

sh-5.1# pactl list sinks short
    0 low-latency0    module-pal-card.c    s16le 2ch 48000Hz    SUSPENDED
    1 deep-buffer0    module-pal-card.c    s16le 2ch 48000Hz    SUSPENDED
    2 offload0        module-pal-card.c    s16le 2ch 48000Hz    SUSPENDED
    3 voip-rx0        module-pal-card.c    s16le 2ch 48000Hz    SUSPENDED
    4 bluez_sink.20_19_D8_36_90_40.a2dp_sink    module-bluez5-device.c    s16le 2ch 44100Hz    SUSPENDEDCopy to clipboard

## Play audio on a specific sink

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

    paplay <audio_filepath> --device=<device_name> -vCopy to clipboard

**Parameters**

- `<audio_filepath>` is the filepath of the WAV file.
- `<device_name>` is the sink name.

**Example**

To play pcmtest.wav on the
                    `bluez_sink.20_19_D8_36_90_40.a2dp_sink` sink, run the following
                command:

    paplay pcmtest.wav --device=bluez_sink.20_19_D8_36_90_40.a2dp_sink -vCopy to clipboard

**Sample output**

sh-5.1# paplay pcmtest.wav --device=bluez_sink.20_19_D8_36_90_40.a2dp_sink -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_sink.20_19_D8_36_90_40.a2dp_sink (index: 4, suspended: no).
    Stream started.
    Time: 2.925 sec; Latency: 2062081 usec.Copy to clipboard

## Disconnect a remote device

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

    disconnect <bt_address>Copy to clipboard

**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:

    disconnect 17:1A:35:8D:A2:A4Copy to clipboard

**Sample output**

[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: noCopy to clipboard

**Parent Topic:** [Advanced Audio Distribution Profile](https://docs.qualcomm.com/doc/80-70017-13/topic/bluez-a2dp.html)

Last Published: Dec 26, 2024

[Previous Topic
Advanced Audio Distribution Profile](https://docs.qualcomm.com/bundle/publicresource/80-70017-13/topics/bluez-a2dp.md) [Next Topic
Perform Bluetooth A2DP sink functions](https://docs.qualcomm.com/bundle/publicresource/80-70017-13/topics/bluez-perform-bluetooth-a2dp-sink-functions.md)