BlueZ5 and A2DP: Difference between revisions

From Variscite Wiki
(BlueZ5 and A2DP Sink)
 
No edit summary
 
(36 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_DART-MX8M as default
--> {{INIT_RELEASE_PARAM|RELEASE_SUMO_V1.0_DART-MX8M}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:B2QT_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{COMPAT_DEBIAN_LST_MODEL}} <!--
Select bluez-alsa or pulse audio.
bluez-alsa for >= Dunfell or if BLUEZ_ALSA set in Yocto/B2Qt_platform_customization
If Yocto >= 3.1 and not debian:
-->{{#ifexpr: {{#var:YOCTO_VERSION}} >= 3.1|
  {{#ifeq: {{#var:DEBIAN_VERSION}}||
    {{#vardefine:BLUEZ_ALSA|1}}
  }}
|}}<!--
Set audio server to bluez-alsa or pulseaudio:
-->{{#varexists:BLUEZ_ALSA|
{{#vardefine:AUDIO_SERVER|bluez-alsa}}|
{{#vardefine:AUDIO_SERVER|pulseaudio}}
}} <!--
Until now, Debian was always using PA
-->{{#varexists:DEBIAN_NAME|{{#vardefine:AUDIO_SERVER|pulseaudio}}}} <!--
-->{{PageHeader|Bluetooth A2DP}}
{{DocImage|category1=Yocto|category2=Debian}}[[Category:VAR-SOM-MX6]][[Category: DART-6UL]][[Category: VAR-SOM-MX7]][[Category:DART-MX8M]][[Category:DART-MX8M-MINI]][[Category:VAR-SOM-MX8X]][[Category:VAR-SOM-MX8]][[Category:DART-MX8M-PLUS]] __toc__
== AD2DP Introduction ==
A2DP stands for Advanced Audio Distribution Profile. This is the Bluetooth Stereo profile which defines how high quality stereo audio can be streamed from one device to another over a Bluetooth connection - for example, music streamed from a mobile phone to wireless headphones.
A2DP stands for Advanced Audio Distribution Profile. This is the Bluetooth Stereo profile which defines how high quality stereo audio can be streamed from one device to another over a Bluetooth connection - for example, music streamed from a mobile phone to wireless headphones.


Although many products may have Bluetooth enabled for voice calls, in order for music to be streamed from one Bluetooth device to another, both devices will need to have this A2DP profile. If both devices to do not contain this profile, you may still be able to connect using a standard Headset or Handsfree profile, however these profiles will not support stereo music.
Although many products may have Bluetooth enabled for voice calls, in order for music to be streamed from one Bluetooth device to another, both devices will need to have this A2DP profile. If both devices to do not contain this profile, you may still be able to connect using a standard Headset or Handsfree profile, however these profiles will not support stereo music.


BlueZ5 configuration currently support A2DP both in '''server''' and '''client''' mode.
BlueZ5 configuration currently supports A2DP both in '''server''' and '''client''' mode.


{{note|Please note that to correctly work, both hci interface and pulseaudio server must be up&running. Please refer to FAQ section for futher details}}
{{note|Please note that to correctly work, both HCI interface and {{#var:AUDIO_SERVER}} server must be up & running. Please refer to FAQ section for further details}}


== server mode ==
== Server Mode ==


In '''server mode''', you can connect via BT the board to a PC or a mobile phone and play an A2DP audio stream using onboard headphones. connector.
In '''server mode''', you can connect the board via BT to a PC or a mobile phone and play an A2DP audio stream using on-board headphones connector.


1. Start the device in A2DP server mode, running the following command (Into console of device):
=== Playback from external BT source ===


# /opt/var-bluetooth-snd-dev/bluetooth-snd-server.sh
1. Connect headphones or speakers to the on-board headphones connector<br>
2. Put the external device into pairing mode.<br>
3. Scan and connect the external device to Variscite board.<br>


2. Scan and connecting the external device to Variscite board over bluetooth
<pre>
# bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# pairable on
[bluetooth]# scan on


3. Trust external device to Variscite board
Copy mac address


# /opt/var-bluetooth-snd-dev/bluetooth-snd-server.sh -t C8:14:79:27:F1:82
[bluetooth]# scan off
[bluetooth]# pair <mac address>


where "bd address" we can get with command "hcitool scan"
Approve pairing on the device if required


For example:
[bluetooth]# trust <mac address>
[bluetooth]# connect <mac address>
[bluetooth]# quit
</pre>


# /opt/var-bluetooth-snd-dev/bluetooth-snd-server.sh
4. On the client side, connect to the device '''Variscite''' and play sound through it.


.. connect external device via bluetooth
{{#varexists:BLUEZ_ALSA|
 
5. Run bluealsa-aplay on device to play audio through on-board headphones or speakers:
# /opt/var-bluetooth-snd-dev/bluetooth-snd-server.sh -t C8:14:79:27:F1:82
  # bluealsa-aplay <mac address>
[NEW] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
|}}
[NEW] Device C8:14:79:27:F1:82 SM-T315
[bluetooth]# trust C8:14:79:27:F1:82
  [bluetooth]# quit
[DEL] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]


On the client side, connect to the device '''VAR-A2DP''' and play sound through it.
=== Recording from external BT source ===


For audio playback, make sure headphones or speakers are connected to the onboard headphones connector.
{{#varexists:BLUEZ_ALSA|{{#lst:BlueZ5_and_A2DP|BLUEZ_SERVER}}|{{#lst:BlueZ5_and_A2DP|PA_SERVER}}}}


== client mode ==
== Client Mode ==


In '''client mode''', you can connect and play A2DP audio stream using bluetooth headphones.
In '''client mode''', you can connect and play A2DP audio stream using bluetooth headphones.
Line 50: Line 89:
1. Start utility "bluetoothctl":
1. Start utility "bluetoothctl":


  root@imx6ul-var-dart:~# bluetoothctl
  # bluetoothctl


example:
example:


  root@imx6ul-var-dart:~# bluetoothctl
  # bluetoothctl
  [NEW] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
  [NEW] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
  [NEW] Device C8:14:79:27:F1:82 SM-T315
  [NEW] Device C8:14:79:27:F1:82 SM-T315
Line 75: Line 114:
  [bluetooth]#
  [bluetooth]#


3. The first time only, to connect BT headphones, make sure they are in pairing mode. They need to show up.
3. The first time only, to connect BT headphones, make sure they are in pairing mode. They need to show up in the scan.


4. Enable scanning
4. Enable scanning
Line 143: Line 182:
  [MM100]# quit
  [MM100]# quit
  [DEL] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
  [DEL] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
  root@imx6ul-var-dart:~#
  #


=== play test sound using MM100 headphones ===
=== play test sound using MM100 headphones ===


{{#varexists:BLUEZ_ALSA|{{#lst:BlueZ5_and_A2DP|BLUEZ_CLIENT}}|{{#lst:BlueZ5_and_A2DP|PA_CLIENT}}}}
== FAQ ==
1. The sound doesn't play using headphones connector (board in server mode) or BT headphones (board in client mode).
ALSA may be configured incorrectly, use this command:
# amixer set 'Output Mixer HiFi' on
{{#varexists:BLUEZ_ALSA||
Pulseaudio server may not be started, use this command:
# pactl list cards
}}
HCI interface may be down, use this command:
# hciconfig hci0 up
<section begin=PA_SERVER/><includeonly>
1. Follow the steps above to pair and connect with external BT device<br>
2. Check cards availability<br>
# pactl list cards
3. If it's not the current profile, switch to a2dp profile
# pactl set-card-profile <card #id from item 1> a2dp_source
example:
# pactl set-card-profile 3 a2dp_source
4. recording audio originated by external BT source:
# paplay -r --device=bluez_source.C8_14_79_27_F1_82 test.wav
{{Note|'''Note:''' The name format of BT device may differ between Yocto versions. Please check the output of '''pactl list sources short''' for the exact device name.|info}}
</includeonly><section end=PA_SERVER/> <!--
--><section begin=PA_CLIENT/><includeonly>
1. Check cards availability.
1. Check cards availability.


Line 153: Line 231:
example:
example:


  root@imx6ul-var-dart:~# pactl list cards
  # pactl list cards
  Card #0
  Card #0
         Name: alsa_card.platform-sound
         Name: alsa_card.platform-sound
Line 216: Line 294:
We are interested in Card # 6.
We are interested in Card # 6.


2. Switch a2dp profile
2. If it's not the current profile, switch to a2dp profile


  # pactl set-card-profile <card #id from item 1> a2dp_sink
  # pactl set-card-profile <card #id from item 1> a2dp_sink
Line 222: Line 300:
example:
example:


  root@imx6ul-var-dart:~# pactl set-card-profile 6 a2dp_sink
  # pactl set-card-profile 6 a2dp_sink
root@imx6ul-var-dart:~#
 
3. play wav file from pulse subsystem to bluetooth headphones
3. play wav file from pulse subsystem to bluetooth headphones


Line 231: Line 307:
Where:
Where:


XX_XX_XX_XX_XX_XX - bd_add from item 1
XX_XX_XX_XX_XX_XX - MAC address from item 1
/usr/share/sounds/alsa/Front_Center.wav - is the file to be played
/usr/share/sounds/alsa/Front_Center.wav - is the file to be played


example:
example:


  root@imx6ul-var-dart:~# paplay -p --device=bluez_sink.00_06_F7_B3_E9_ED /usr/share/sounds/alsa/Front_Center.wav
  # paplay -p --device=bluez_sink.00_06_F7_B3_E9_ED /usr/share/sounds/alsa/Front_Center.wav
{{Note|'''Note:''' The name format of BT sink device may differ between Yocto versions. Please check the output of '''pactl list sinks short''' to get ethe exact device name.|info}}<!--
--></includeonly><section end=PA_CLIENT/> <!--
 
--><section begin=BLUEZ_SERVER/><includeonly>
1. Follow the steps above to pair and connect with external BT device<br>
2. Check cards availability<br>


== FAQ ==
# bluealsa-aplay -L


1. The sound doesn't play using headphones connector (board in server mode) or BT headphones (board in client mode).
If no cards appear, confirm you're paired with a device


ALSA may be configured incorrectly, use this command:
3. recording audio originated by external BT source using the results from step 2:


  # amixer set 'Output Mixer HiFi' on
  # arecord -f cd -D bluealsa:SRV=org.bluealsa,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp test.wav
</includeonly><section end=BLUEZ_SERVER/> <!--


Pulseaudio server may be not started, use this command:
--><section begin=BLUEZ_CLIENT/><includeonly>
1. Follow the steps above to pair and connect with external BT device<br>
2. Check cards availability<br>


  # pactl list cards
  # bluealsa-aplay -L


HCI interface may be down, use this command:
3. Play audio to bluetooth speaker using device from the previous step


  # hciconfig hci0 up
  # aplay -D bluealsa:SRV=org.bluealsa,DEV=FC:A8:9A:EB:8F:B5,PROFILE=a2dp  /usr/share/sounds/alsa/Front_Center.wav
</includeonly><section end=BLUEZ_CLIENT/>

Latest revision as of 14:12, 30 September 2023

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release RELEASE_SUMO_V1.0_DART-MX8M.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release


Bluetooth A2DP

AD2DP Introduction

A2DP stands for Advanced Audio Distribution Profile. This is the Bluetooth Stereo profile which defines how high quality stereo audio can be streamed from one device to another over a Bluetooth connection - for example, music streamed from a mobile phone to wireless headphones.

Although many products may have Bluetooth enabled for voice calls, in order for music to be streamed from one Bluetooth device to another, both devices will need to have this A2DP profile. If both devices to do not contain this profile, you may still be able to connect using a standard Headset or Handsfree profile, however these profiles will not support stereo music.

BlueZ5 configuration currently supports A2DP both in server and client mode.


Please note that to correctly work, both HCI interface and pulseaudio server must be up & running. Please refer to FAQ section for further details

Server Mode

In server mode, you can connect the board via BT to a PC or a mobile phone and play an A2DP audio stream using on-board headphones connector.

Playback from external BT source

1. Connect headphones or speakers to the on-board headphones connector
2. Put the external device into pairing mode.
3. Scan and connect the external device to Variscite board.

# bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# pairable on
[bluetooth]# scan on

Copy mac address

[bluetooth]# scan off
[bluetooth]# pair <mac address>

Approve pairing on the device if required

[bluetooth]# trust <mac address>
[bluetooth]# connect <mac address>
[bluetooth]# quit

4. On the client side, connect to the device Variscite and play sound through it.


Recording from external BT source

1. Follow the steps above to pair and connect with external BT device
2. Check cards availability

# pactl list cards

3. If it's not the current profile, switch to a2dp profile

# pactl set-card-profile <card #id from item 1> a2dp_source

example:

# pactl set-card-profile 3 a2dp_source

4. recording audio originated by external BT source:

# paplay -r --device=bluez_source.C8_14_79_27_F1_82 test.wav
Note: The name format of BT device may differ between Yocto versions. Please check the output of pactl list sources short for the exact device name.

Client Mode

In client mode, you can connect and play A2DP audio stream using bluetooth headphones.

connect

Into console of device:

1. Start utility "bluetoothctl":

# bluetoothctl

example:

# bluetoothctl
[NEW] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
[NEW] Device C8:14:79:27:F1:82 SM-T315
[bluetooth]#

2. Prepare to сonnection:

[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent

example:

[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]#

3. The first time only, to connect BT headphones, make sure they are in pairing mode. They need to show up in the scan.

4. Enable scanning

[bluetooth]# scan on

example:

[NEW] Device 68:DF:DD:5D:CF:96 malupas
[NEW] Device 00:06:F7:B3:E9:ED MM100
[NEW] Device 00:07:80:41:68:15 KTS540_0000000
[NEW] Device C8:14:79:27:F1:82 SM-T315
[bluetooth]# scan on
Discovery started
[CHG] Controller F8:DC:7A:07:8D:A6 Discovering: yes
[CHG] Device 00:06:F7:B3:E9:ED RSSI: -57
[CHG] Device 00:07:80:41:68:15 RSSI: -65
[CHG] Device 68:DF:DD:5D:CF:96 RSSI: -98
[CHG] Device 00:07:80:41:68:15 RSSI: -73

"[NEW] Device 00:06:F7:B3:E9:ED MM100" are BT headphones.

5. Disable scanning

[bluetooth]# scan off

example:

[bluetooth]# scan off
Discovery stopped
[CHG] Controller F8:DC:7A:07:8D:A6 Discovering: no
[bluetooth]#

6. Pair the device

[bluetooth]# pair 00:06:F7:B3:E9:ED

7. Connect the device

[bluetooth]# connect 00:06:F7:B3:E9:ED

example:

[bluetooth]# connect 00:06:F7:B3:E9:ED
Attempting to connect to 00:06:F7:B3:E9:ED
[CHG] Device 00:06:F7:B3:E9:ED Connected: yes
Connection successful
[MM100]#

8. Trust the device

[MM100]# trust 00:06:F7:B3:E9:ED

example:

[MM100]# trust 00:06:F7:B3:E9:ED
[CHG] Device 00:06:F7:B3:E9:ED Trusted: yes
Changing 00:06:F7:B3:E9:ED trust succeeded
[MM100]#

9. quit from bluetoothctl console

[MM100]# quit

example:

[MM100]# quit
[DEL] Controller F8:DC:7A:07:8D:A6 VAR-A2DP [default]
#

play test sound using MM100 headphones

1. Check cards availability.

# pactl list cards

example:

# pactl list cards
Card #0
       Name: alsa_card.platform-sound
       Driver: module-alsa-card.c
       Owner Module: 6
       Properties:
               alsa.card = "0"
               alsa.card_name = "wm8731-audio"
               alsa.long_card_name = "wm8731-audio"
               device.bus_path = "platform-sound"
               sysfs.path = "/devices/platform/sound/sound/card0"
               device.string = "0"
               device.description = "wm8731-audio"
               module-udev-detect.discovered = "1"
               device.icon_name = "audio-card"
       Profiles:
               input:analog-mono: Analog Mono Input (sinks: 0, sources: 1, priority: 2, available: yes)
               input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
               output:analog-mono: Analog Mono Output (sinks: 1, sources: 0, priority: 200, available: yes)
               output:analog-mono+input:analog-mono: Analog Mono Duplex (sinks: 1, sources: 1, priority: 202, available: yes)
               output:analog-stereo: Analog Stereo Output (sinks: 1, sources: 0, priority: 6000, available: yes)
               output:analog-stereo+input:analog-stereo: Analog Stereo Duplex (sinks: 1, sources: 1, priority: 6060, available: yes)
               off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
       Active Profile: output:analog-stereo+input:analog-stereo
       Ports:
               analog-input-mic: Microphone (priority: 8700, latency offset: 0 usec)
                       Properties:
                               device.icon_name = "audio-input-microphone"
                       Part of profile(s): input:analog-mono, input:analog-stereo, output:analog-mono+input:analog-mono, output:analog-stereo+input:analog-stereo
               analog-input-linein: Line In (priority: 8100, latency offset: 0 usec)
                       Part of profile(s): input:analog-mono, input:analog-stereo, output:analog-mono+input:analog-mono, output:analog-stereo+input:analog-stereo
               analog-output: Analog Output (priority: 9900, latency offset: 0 usec)
                       Part of profile(s): output:analog-mono, output:analog-mono+input:analog-mono, output:analog-stereo, output:analog-stereo+input:analog-stereo

Card #6
       Name: bluez_card.00_06_F7_B3_E9_ED
       Driver: module-bluez5-device.c
       Owner Module: 37
       Properties:
               device.description = "MM100"
               device.string = "00:06:F7:B3:E9:ED"
               device.api = "bluez"
               device.class = "sound"
               device.bus = "bluetooth"
               device.form_factor = "headset"
               bluez.path = "/org/bluez/hci0/dev_00_06_F7_B3_E9_ED"
               bluez.class = "0x240404"
               bluez.alias = "MM100"
               device.icon_name = "audio-headset-bluetooth"
               device.intended_roles = "phone"
       Profiles:
               headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
               a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
               off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
       Active Profile: headset_head_unit
       Ports:
               headset-output: Headset (priority: 0, latency offset: 0 usec)
                       Part of profile(s): headset_head_unit, a2dp_sink
               headset-input: Headset (priority: 0, latency offset: 0 usec)
                       Part of profile(s): headset_head_unit

We are interested in Card # 6.

2. If it's not the current profile, switch to a2dp profile

# pactl set-card-profile <card #id from item 1> a2dp_sink

example:

# pactl set-card-profile 6 a2dp_sink

3. play wav file from pulse subsystem to bluetooth headphones

# paplay -p --device=bluez_sink.XX_XX_XX_XX_XX_XX /usr/share/sounds/alsa/Front_Center.wav

Where:

XX_XX_XX_XX_XX_XX - MAC address from item 1 /usr/share/sounds/alsa/Front_Center.wav - is the file to be played

example:

# paplay -p --device=bluez_sink.00_06_F7_B3_E9_ED /usr/share/sounds/alsa/Front_Center.wav
Note: The name format of BT sink device may differ between Yocto versions. Please check the output of pactl list sinks short to get ethe exact device name.

FAQ

1. The sound doesn't play using headphones connector (board in server mode) or BT headphones (board in client mode).

ALSA may be configured incorrectly, use this command:

# amixer set 'Output Mixer HiFi' on

Pulseaudio server may not be started, use this command:

# pactl list cards

HCI interface may be down, use this command:

# hciconfig hci0 up