블루투스를 통한 오디오 재생과 관련하여 pulseaudio5에 현재 문제가 있음을 발견했습니다. 따라서 나는 그들이 올 때 그것들을 디버깅하는 대신 단순히 원하는 것에 PulseAudio6를 사용하도록 제안합니다.
나는 아래의 모든 것을 자동화 할 레포를 만들었으므로 모든 다리 작업을 할 필요는 없지만 여전히 스스로 할 수 있다면 아래에서 계속하십시오.
레포 : https://github.com/BaReinhard/a2dp_bluetooth
설치 과정 :
git clone https://github.com/bareinhard/a2dp_bluetooth
cd a2dp_bluetooth/a2dp_source
./configure
설치 프로세스가 완료 될 때까지 기다렸다가 재부팅하십시오. 완료되면 장치를 초기에 페어링하고, 신뢰하고, 연결해야합니다. 처음 시간이 지나면 장치를 켜면됩니다.
페어링, 신뢰 및 연결 :
sudo bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# scan on
[bluetooth]# pair XX:XX:XX:XX:XX
[bluetooth]# trust XX:XX:XX:XX:XX
[bluetooth]# connect XX:XX:XX:XX:XX
[bluetooth]# exit
-------------------- 전체 연습 : --------------------
PulseAudio 6 컴파일
다음 파일을 추가하십시오
/etc/init.d/pulseaudio
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: pulseaudio esound
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: udev network-manager
# Should-Stop: udev network-manager
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the PulseAudio sound server
# Description: System mode startup script for
# the PulseAudio sound server.
### END INIT INFO
DAEMON=/usr/local/bin/pulseaudio
PIDDIR=/var/run/pulse
PIDFILE=$PIDDIR/pid
DAEMONUSER=pulse
PATH=/sbin:/bin:/usr/sbin:/usr/bin
test -x $DAEMON || exit 0
. /lib/lsb/init-functions
pulseaudio_start () {
log_daemon_msg "Starting system PulseAudio Daemon"
if [ ! -d $PIDDIR ]; then
mkdir -p $PIDDIR
chown $DAEMONUSER:$DAEMONUSER $PIDDIR
fi
start-stop-daemon -x $DAEMON -p $PIDFILE --start -- --system --disallow-exit --disallow-module-loading=0 --daemonize --log-target=syslog --high-priority
status=$?
if [ -e /var/run/pulse/.esd_auth ]; then
chown pulse:pulse-access /var/run/pulse/.esd_auth
chmod 640 /var/run/pulse/.esd_auth
fi
if [ -e /var/run/pulse/.pulse-cookie ]; then
chown pulse:pulse-access /var/run/pulse/.pulse-cookie
chmod 640 /var/run/pulse/.pulse-cookie
fi
log_end_msg ${status}
}
pulseaudio_stop () {
log_daemon_msg "Stopping system PulseAudio Daemon"
start-stop-daemon -p $PIDFILE --stop --retry 5 || echo -n "...which is not running"
log_end_msg $?
}
case "$1" in
start|stop)
pulseaudio_${1}
;;
restart|reload|force-reload)
if [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1; then
pulseaudio_stop
pulseaudio_start
fi
;;
force-stop)
pulseaudio_stop
killall pulseaudio || true
sleep 2
killall -9 pulseaudio || true
;;
status)
status_of_proc -p $PIDFILE "$DAEMON" "system-wide PulseAudio" && exit 0 || exit $?
;;
*)
echo "Usage: /etc/init.d/pulseaudio {start|stop|force-stop|restart|reload|force-reload|status}"
exit 1
;;
esac
exit 0
/etc/init.d/bluetooth
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: bluetooth
# Required-Start: $local_fs $syslog dbus
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts bluetooth daemons
### END INIT INFO
. /lib/lsb/init-functions
DESC=bluetoothd
DAEMON=/usr/libexec/bluetooth/bluetoothd
#SSD_OPTIONS="--oknodo --quiet --exec $DAEMON --plugin=a2dp"
SSD_OPTIONS="--oknodo --quiet --exec $DAEMON" #Change to this if you want media control using DBus at the expense of volume control
HCI=hci0
case "${1}" in
start)
log_daemon_msg "Starting Bluetooth daemon bluetoothd..."
start-stop-daemon --start --background $SSD_OPTIONS
log_progress_msg "${DAEMON}"
hciconfig $HCI up > /dev/null 2>&1
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping Bluetooth daemon bluetoothd..."
start-stop-daemon --stop $SSD_OPTIONS
log_progress_msg "${DAEMON}"
log_end_msg 0
;;
restart)
${0} stop
sleep 1
${0} start
;;
status)
status_of_proc "$DAEMON" "$DESC" && exit 0 || exit $?
;;
*)
echo "Usage: ${0} {start|stop|restart|status}"
exit 1
;;
esac
exit 0
새로운 init.d 서비스 활성화 및 실행 가능
sudo chmod +x /etc/init.d/bluetooth
sudo chmod +x /etc/init.d/pulseaudio
sudo update-rc.d bluetooth defaults
sudo update-rc.d pulseaudio defaults
필요한 모든 모듈이 있는지 확인하십시오
sudo apt-get install bluez pulseaudio-module-bluetooth python-dbus libtool intltool libsndfile-dev libcap-dev libjson0-dev libasound2-dev libavahi-client-dev libbluetooth-dev libglib2.0-dev libsamplerate0-dev libsbc-dev libspeexdsp-dev libssl-dev libtdb-dev libbluetooth-dev intltool autoconf autogen automake build-essential libasound2-dev libflac-dev libogg-dev libtool libvorbis-dev pkg-config python -y
홈 디렉토리로 변경하고 git source에서 json-c 설치 (PA6에 필요)
cd ~
git clone https://github.com/json-c/json-c.git
cd json-c
./configure
make
sudo make install
홈 디렉토리로 변경하고 git source에서 libsndfile 설치
git clone git://github.com/erikd/libsndfile.git
cd libsndfile
./autogen.sh
./configure --enable-werror
make
sudo make install
Bluetooth가 검색 중인지 확인하십시오 ( sudo hciconfig hci0 piscan
더 이상 사용되지 않음)
cat << EOT | sudo tee -a /etc/bluetooth/main.conf
[Policy]
AutoEnable=true
EOT
홈 디렉토리로 이동하여 자식 소스에서 PulseAudio 6 설치
git clone --branch v6.0 https://github.com/pulseaudio/pulseaudio
cd pulseaudio
sudo ./bootstrap.sh
sudo make
sudo make install
sudo ldconfig
펄스가 필요한 모든 그룹에 있는지 확인하십시오
sudo addgroup --system pulse
sudo adduser --system --ingroup pulse --home /var/run/pulse pulse
sudo addgroup --system pulse-access
sudo adduser pulse audio
sudo adduser root pulse-access
sudo adduser pulse lp
다음과 같이 업데이트 /etc/pulse/system.pa
하고 /etc/pulse/daemon.conf
살펴보십시오.
/etc/pulse/system.pa
#!/usr/bin/pulseaudio -nF
#
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
# This startup script is used only if PulseAudio is started in system
# mode.
### Automatically load driver modules depending on the hardware available
.ifexists module-udev-detect.so
#load-module module-udev-detect
load-module module-udev-detect tsched=0
.else
### Use the static hardware detection module (for systems that lack udev/hal support)
load-module module-detect
.endif
### Load several protocols
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix
.endif
load-module module-native-protocol-unix
### Automatically restore the volume of streams and devices
load-module module-stream-restore
load-module module-device-restore
### Automatically restore the default sink/source when changed by the user
### during runtime
### NOTE: This should be loaded as early as possible so that subsequent modules
### that look up the default sink/source get the right value
load-module module-default-device-restore
### Automatically move streams to the default sink if the sink they are
### connected to dies, similar for sources
load-module module-rescue-streams
### Make sure we always have a sink around, even if it is a null sink.
load-module module-always-sink
### Automatically suspend sinks/sources that become idle for too long
load-module module-suspend-on-idle
### Enable positioned event sounds
load-module module-position-event-sounds
### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
load-module module-bluetooth-policy
load-module module-switch-on-connect
/etc/pulse/daemon.conf
# This file is part of PulseAudio.
#
# PulseAudio is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# PulseAudio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with PulseAudio; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
## Configuration file for the PulseAudio daemon. See pulse-daemon.conf(5) for
## more information. Default values are commented out. Use either ; or # for
## commenting.
; daemonize = no
; fail = yes
; allow-module-loading = yes
; allow-exit = yes
; use-pid-file = yes
; system-instance = no
; local-server-type = user
; enable-shm = yes
; shm-size-bytes = 0 # setting this 0 will use the system-default, usually 64 MiB
; lock-memory = no
; cpu-limit = no
; high-priority = yes
; nice-level = -15
; realtime-scheduling = yes
; realtime-priority = 5
exit-idle-time = -1
; scache-idle-time = 20
; dl-search-path = (depends on architecture)
; load-default-script-file = yes
; default-script-file = /etc/pulse/default.pa
; log-target = auto
; log-level = notice
; log-meta = no
; log-time = no
; log-backtrace = 0
# resample-method defaults to speex-float-1 on most architectures,
# speex-fixed-1 on ARM
; resample-method = speex-float-1
resample-method = ffmpeg
enable-remixing = no
enable-lfe-remixing = no
; flat-volumes = yes
; rlimit-fsize = -1
; rlimit-data = -1
; rlimit-stack = -1
; rlimit-core = -1
; rlimit-as = -1
; rlimit-rss = -1
; rlimit-nproc = -1
; rlimit-nofile = 256
; rlimit-memlock = -1
; rlimit-locks = -1
; rlimit-sigpending = -1
; rlimit-msgqueue = -1
; rlimit-nice = 31
; rlimit-rtprio = 9
; rlimit-rttime = 1000000
default-sample-format = s16le
default-sample-rate = 44100
;alternate-sample-rate = 48000
default-sample-channels = 2
; default-channel-map = front-left,front-right
default-fragments = 10
default-fragment-size-msec = 10
; enable-deferred-volume = yes
; deferred-volume-safety-margin-usec = 8000
; deferred-volume-extra-delay-usec = 0
udev 규칙 설정
/etc/udev/rules.d/99-com.rules
다음 두 줄을 편집 하고 추가하십시오.
SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="input[0-9]*", RUN+="/usr/local/bin/bluez-udev"
창조하다 /usr/local/bin/bluez-udev
/ usr / local / bin / bluez-udev
#!/bin/bash
name=$(sed 's/\"//g' <<< $NAME)
#exit if not a BT address
if [[ ! $name =~ ^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$ ]]; then exit 0; fi
bt_name=`grep Name /var/lib/bluetooth/*/$name/info | awk -F'=' '{print $2}'`
audio_sink=bluez_source.$(sed 's/:/_/g' <<< $name)
action=$(expr "$ACTION" : "\([a-zA-Z]\+\).*")
logger "Action: $action"
if [ "$action" = "add" ]; then
logger "[$(basename $0)] Bluetooth device is being added [$name] - $bt_name"
logger "[$(basename $0)] Patching $audio_source into ALSA sink #$audio_sink"
#hciconfig hci0 noscan
bluetoothctl << EOT
discoverable off
EOT
# Grab Card Number
PACARD=`pactl list cards | grep "Card #" | sed "s/Card #//"`
# Grab Sink Input if it exists
audio_source=`pactl pactl list sink-inputs | grep "Sink Input" | sed "s/Sink Input #//"`
if [ $audio_source = "" ];then
sleep 5
audio_source=`pactl pactl list sink-inputs | grep "Sink Input" | sed "s/Sink Input #//"`
fi
pactl set-sink-volume $audio_sink 65537
if [ $audio_source != "" ]; then
pactl set-source-volume $audio_source 90%
fi
pactl set-card-profile $PACARD a2dp_sink
pactl set-default-sink $audio_sink
# loop back this source to the default sink
handle=$(pactl load-module module-loopback source=$audio_source sink=$audio_sink)
logger "[$(basename $0)] PulseAudio module-loopback returned handle [$handle]"
logger "$bt_name"
fi
if [ "$action" = "remove" ]; then
# Grab Sink Input if it exists
audio_source=`pactl pactl list sink-inputs | grep "Sink Input" | sed "s/Sink Input #//"`
if [ $audio_source = "" ];then
sleep 5
audio_source=`pactl pactl list sink-inputs | grep "Sink Input" | sed "s/Sink Input #//"`
fi
pactl set-sink-volume 0 65537
if [ $audio_source = "" ]; then
# pactl set-default-sink 0
pactl set-source-volume $audio_source 90%
else
pactl move-sink-input $audio_source 0
fi
logger "[$(basename $0)] Bluetooth device is being removed [$name] - $bt_name"
#hciconfig hci0 pscan
bluetoothctl << EOT
discoverable on
EOT
# remove any loopback modules assigned to this source
# only required for USB sound cards, which PulseAudio will not automatically remove
for handle in $(pactl list short modules | grep module-loopback | grep source=$audio_source | cut -f 1); do
logger "[$(basename $0)] Unloading module-loopback with handle [$handle]"
pactl unload-module $handle
done
sleep 5
amixer cset numid=3 80%
amixer cset numid=3 80%
fi
bluez-udev가 실행 가능한지 확인하십시오
sudo chmod +x /usr/local/bin/bluez-udev
요약
여기서 뭐하는거야?
- 블루투스 및 펄스 오디오 용 init.d 서비스 생성 및 활성화
- PulseAudio6에 대한 종속성 설치
- PulseAudio6 컴파일 및 펄스 사용자를 필요한 그룹에 추가 (대부분 이미 완료되었을 것임)
- 적절한 모듈을로드하도록 daemon.conf 및 system.pa 설정
- 장치가 연결될 때마다 bluez-udev를 실행하려면 udev 규칙을 만듭니다. bluez-udev는 장치가 Bluetooth 장치인지 확인합니다. 현재 재생중인 오디오를 pulseaudio에 의해 생성 된 Bluetooth 장치 싱크에 연결하려고 시도합니다. 블루투스 연결이 끊어지면 스트림이 기본 싱크 또는 싱크 0으로 다시 이동합니다. 이제 블루투스 장치가 자동으로 연결되면 bluez-udev 규칙이 재생중인 음악을 새로 연결합니다. 연결된 블루투스 장치. 물론, 이것이 어려운 것처럼 보인다면