-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbt-sound-Bluez5_PulseAudio5.txt
273 lines (200 loc) · 10.6 KB
/
bt-sound-Bluez5_PulseAudio5.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#################################################################
#################################################################
# Bluetooth and Audio # Bluez-5 + PulseAudio-5
#################################################################
#################################################################
#################################################################
# KERNEL PREREQUISITES
#################################################################
First things first.
You will need a kernel with Bluetooth, Sound and BT-audio support
See the kernel guide for the optional part about it.
# Connect your USB BT dongle - your dmesg should be similar to:
Bluetooth: Core ver 2.20
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO socket layer initialized
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bluetooth: BNEP filters: protocol multicast
Bluetooth: BNEP socket layer initialized
usb 3-1.3: new full-speed USB device number 3 using orion-ehci
usbcore: registered new interface driver btusb
#################################################################
# INSTALL PACKAGES
#################################################################
# Install BlueZ-5 and PulseAudio-5 with Bluetooth support:
apt-get --no-install-recommends install pulseaudio pulseaudio-module-bluetooth bluez
# If your dongle is a based on a BCM203x chipset, install the firmware
apt-get bluez-firmware
# Install MPlayer, along with some codecs, to later test audio output
apt-get install mplayer
#################################################################
# BLUETOOTH/DBUS/PULSE PERMISSIONS
#################################################################
## Authorize users (each user that will be using PA must belong to group pulse-access)
# Examples:
adduser root pulse-access
adduser squeezeboxserver pulse-access
adduser ... pulse-access
# Authorize PulseAudio - which will run as user pulse - to use BlueZ D-BUS interface:
############################################################################
cat <<EOF >/etc/dbus-1/system.d/pulseaudio-bluetooth.conf
<busconfig>
<policy user="pulse">
<allow send_destination="org.bluez"/>
</policy>
</busconfig>
EOF
############################################################################
#################################################################
# CONFIGURE PULSEAUDIO
#################################################################
# Not strictly required, but you may need:
# In /etc/pulse/daemon.conf change "resample-method" to either:
# trivial: lowest cpu, low quality
# src-sinc-fastest: more cpu, good resampling
# speex-fixed-N: N from 1 to 7, lower to higher CPU/quality
resample-method = trivial
# Load Bluetooth discover module in SYSTEM MODE:
############################################################################
cat <<EOF >> /etc/pulse/system.pa
#
### Bluetooth Support
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
EOF
############################################################################
# Create a systemd service for running pulseaudio in System Mode as user "pulse".
############################################################################
cat <<EOF >/etc/systemd/system/pulseaudio.service
[Unit]
Description=Pulse Audio
[Service]
Type=simple
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1
[Install]
WantedBy=multi-user.target
EOF
############################################################################
systemctl daemon-reload
systemctl enable pulseaudio.service
#################################################################
# CONNECT!
#################################################################
# Restart Bluetooth and check its status (those errors are fine)
systemctl restart bluetooth
systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
Active: active (running) since Thu 2015-08-13 23:58:53 CEST; 28s ago
Docs: man:bluetoothd(8)
Main PID: 5604 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─5604 /usr/lib/bluetooth/bluetoothd
Aug 13 23:58:53 nasivadaras bluetoothd[5604]: Bluetooth daemon 5.23
Aug 13 23:58:53 nasivadaras bluetoothd[5604]: Starting SDP server
Aug 13 23:58:53 nasivadaras bluetoothd[5604]: Bluetooth management interface 1.9 initialized
Aug 13 23:58:53 nasivadaras bluetoothd[5604]: Sap driver initialization failed.
Aug 13 23:58:53 nasivadaras bluetoothd[5604]: sap-server: Operation not permitted (1)
Aug 13 23:58:53 nasivadaras systemd[1]: Started Bluetooth service.
# Now use bluetoothctl to: power on the device, pair, trust and connect with bt speakers
# It will be fine if connect will fail - it's pulseaudio that will do the actual connect.
[NEW] Controller 00:19:5B:52:94:A3 nasivadaras [default]
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 00:19:5B:52:94:A3 Powered: yes
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:19:5B:52:94:A3 Discovering: yes
[NEW] Device 00:1D:DF:BE:10:4C 00-1D-DF-BE-10-4C
[CHG] Device 00:1D:DF:BE:10:4C LegacyPairing: no
[CHG] Device 00:1D:DF:BE:10:4C Name: PHILIPS AS111
[CHG] Device 00:1D:DF:BE:10:4C Alias: PHILIPS AS111
[CHG] Device 00:1D:DF:BE:10:4C LegacyPairing: yes
[bluetooth]# pair 00:1D:DF:BE:10:4C
Attempting to pair with 00:1D:DF:BE:10:4C
[CHG] Device 00:1D:DF:BE:10:4C Connected: yes
[CHG] Device 00:1D:DF:BE:10:4C UUIDs:
00001101-0000-1000-8000-00805f9b34fb
0000110b-0000-1000-8000-00805f9b34fb
0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:DF:BE:10:4C Paired: yes
Pairing successful
[CHG] Device 00:1D:DF:BE:10:4C Connected: no
[bluetooth]# trust 00:1D:DF:BE:10:4C
[CHG] Device 00:1D:DF:BE:10:4C Trusted: yes
Changing 00:1D:DF:BE:10:4C trust succeeded
[bluetooth]# connect 00:1D:DF:BE:10:4C
Attempting to connect to 00:1D:DF:BE:10:4C
Failed to connect: org.bluez.Error.Failed
[bluetooth]# scan off
[CHG] Device 00:1D:DF:BE:10:4C RSSI is nil
Discovery stopped
[CHG] Controller 00:19:5B:52:94:A3 Discovering: no
[bluetooth]# exit
Agent unregistered
[DEL] Controller 00:19:5B:52:94:A3 nasivadaras [default]
# Start PulseAudio - it should pick up the bluetooth devices that it can handle
systemctl start pulseaudio.service
pactl list short |grep bluez
11 module-bluez5-discover
12 module-bluez4-discover
13 module-bluez5-device path=/org/bluez/hci0/dev_00_1D_DF_BE_10_4C
1 bluez_sink.00_1D_DF_BE_10_4C module-bluez5-device.c s16le 2ch 44100Hz SUSPENDED
1 bluez_sink.00_1D_DF_BE_10_4C.monitor module-bluez5-device.c s16le 2ch 44100Hz SUSPENDED
0 bluez_card.00_1D_DF_BE_10_4C module-bluez5-device.c
# Also see logs:
# dmesg:
input: 00:1D:DF:BE:10:4C as /devices/virtual/input/input1
# systemctl -l status pulseaudio.service
● pulseaudio.service - Pulse Audio
Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled)
Active: active (running) since Fri 2015-08-14 01:05:19 CEST; 2min 21s ago
Main PID: 1708 (pulseaudio)
CGroup: /system.slice/pulseaudio.service
└─1708 /usr/bin/pulseaudio --system --disallow-exit --disable-shm
Aug 14 01:05:19 nasivadaras systemd[1]: Started Pulse Audio.
Aug 14 01:05:19 nasivadaras pulseaudio[1708]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
Aug 14 01:05:19 nasivadaras pulseaudio[1708]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
Aug 14 01:05:19 nasivadaras pulseaudio[1708]: W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
Aug 14 01:05:19 nasivadaras pulseaudio[1708]: W: [pulseaudio] main.c: Please read http://pulseaudio.org/wiki/WhatIsWrongWithSystemMode for an explanation why system mode is usually a bad idea.
Aug 14 01:05:19 nasivadaras pulseaudio[1708]: E: [pulseaudio] bluez4-util.c: org.bluez.Manager.GetProperties() failed: org.freedesktop.DBus.Error.UnknownMethod: Method "GetProperties" with signature "" on interface "org.bluez.Manager" doesn't exist
# systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled)
Active: active (running) since Fri 2015-08-14 00:25:52 CEST; 40min ago
Docs: man:bluetoothd(8)
Main PID: 971 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─971 /usr/lib/bluetooth/bluetoothd
Aug 14 00:43:45 nasivadaras bluetoothd[971]: Endpoint unregistered: sender=:1.6 path=/MediaEndpoint/A2DPSource
Aug 14 00:43:45 nasivadaras bluetoothd[971]: Endpoint unregistered: sender=:1.6 path=/MediaEndpoint/A2DPSink
Aug 14 00:43:45 nasivadaras bluetoothd[971]: Endpoint registered: sender=:1.7 path=/MediaEndpoint/A2DPSource
Aug 14 00:43:45 nasivadaras bluetoothd[971]: Endpoint registered: sender=:1.7 path=/MediaEndpoint/A2DPSink
Aug 14 00:44:32 nasivadaras bluetoothd[971]: /org/bluez/hci0/dev_00_1D_DF_BE_10_4C/fd2: fd(21) ready
Aug 14 01:05:08 nasivadaras bluetoothd[971]: Endpoint unregistered: sender=:1.7 path=/MediaEndpoint/A2DPSource
Aug 14 01:05:08 nasivadaras bluetoothd[971]: Endpoint unregistered: sender=:1.7 path=/MediaEndpoint/A2DPSink
Aug 14 01:05:19 nasivadaras bluetoothd[971]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource
Aug 14 01:05:19 nasivadaras bluetoothd[971]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink
Aug 14 01:05:54 nasivadaras bluetoothd[971]: /org/bluez/hci0/dev_00_1D_DF_BE_10_4C/fd3: fd(21) ready
#################################################################
# Try it!
#################################################################
# Test audio MP3
mplayer -ao pulse file.mp3
#######################################################################################################################
## Credits:
## https://wiki.archlinux.org/index.php/Bluetooth_headset#Headset_via_Bluez5.2FPulseAudio
## https://github.com/ev3dev/ev3dev/issues/198
## http://www.instructables.com/id/Enhance-your-Raspberry-Pi-media-center-with-Blueto/?ALLSTEPS
## (legacy) http://rootprompt.apatsch.net/2013/04/23/raspberry-pi-network-audio-player-pulseaudio-dlna-and-bluetooth-a2dp-part-3-bluetooth/
#######################################################################################################################