特にbluetoothでのオーディオ再生に関しては、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ソースからjson-cをインストールします(PA6に必要)
cd ~
git clone https://github.com/json-c/json-c.git
cd json-c
./configure
make
sudo make install
ホームディレクトリに移動し、gitソースから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
ホームディレクトリに移動し、gitソースから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
次の2行を編集して追加します。
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
概要
ここで何が行われていますか?
- BluetoothとPulseAudioのinit.dサービスを作成して有効にする
- PulseAudio6の依存関係のインストール
- PulseAudio6をコンパイルし、pulseユーザーを必要なグループに追加します(ほとんどは既に完了しています)
- 適切なモジュールをロードするためにdaemon.confとsystem.paを設定します
- udevルールを作成し、デバイスが接続されるたびにbluez-udevを実行します。bluez-udevは、デバイスがBluetoothデバイスであるかどうかを確認します。そうである場合、現在再生中のオーディオを、pulseaudioによって作成されたBluetoothデバイスシンクに接続しようとします。Bluetooth接続が解除されると、ストリームがデフォルトのシンクまたはシンク0に戻ります。これで、自動接続されたBluetoothデバイスが揃ったので、bluez-udevルールにより、再生中の音楽が自動的に接続されます。接続されたBluetoothデバイス。もちろん、これが困難な場合