在i.MX8MP上如何使能BlueZ A2DP Source
1 软硬件环境
- i.MX8MP EVK
- QCC2076 Wi-Fi/BT Chipset
- Linux Kernel Version: 6.6.x
- Linux BlueZ version: 5.72
2 下载BT固件、配对、连接
gpioset --chip gpiochip5 7=0gpioset --chip gpiochip5 7=1hciattach /dev/ttymxc0 qca 115200 -t120 flowbluetoothctl[bluetooth]# power on[bluetooth]# pairable on[bluetooth]# scan on # 找到耳机 MAC[bluetooth]# pair XX:XX...[bluetooth]# trust XX:XX...[bluetooth]# connect XX:XX......[FreeBuds 3]# devices # 快速列出当前已连设备Device D0:05:E4:17:0E:21 FreeBuds 3
3 检查 PipeWire/WirePlumber 是否在跑
loginctl enable-linger $(whoami) # 若 root 登录控制台可先启用 user-sessionsystemctl --user status pipewire.socket wireplumber.service
两条服务都应是 running,若未启动可手动拉起:
systemctl --user enable --now pipewire.socket wireplumber.service
WirePlumber 是 PipeWire 的会话守护,它负责把蓝牙 Transport fd 挂成可用 Sink。
4 把耳机切到 A2DP 高保真 Profile 并设为默认输出
4.1 列出卡 & Profile
wpctl status # 查看所有声卡与当前默认 Sinkwpctl inspect | grep profile # 找到蓝牙卡可用 profile当前系统的 如下所示,名称为FreeBuds 3:root@imx8mpevk:~# wpctl statusPipeWire 'pipewire-0' [1.0.5, root@imx8mpevk, cookie:1957396837]...├─ Devices:│ 41. HD video [alsa]│ 42. Built-in Audio [alsa]│ 43. Built-in Audio [alsa]│ 44. Built-in Audio [alsa]│ 45. Built-in Audio [alsa]│ 46. Built-in Audio [alsa]│ 99. FreeBuds 3 [bluez5]
2.2 激活 A2DP Sink
wpctl set-profile a2dp-sink # 切到高保真播放wpctl set-default # 设为系统默认输出当前系统的 如下所示,名称为FreeBuds 3:root@imx8mpevk:~# wpctl statusPipeWire 'pipewire-0' [1.0.5, root@imx8mpevk, cookie:1957396837]...├─ Sinks:│ 48. HD video Mono [vol: 0.40]│ 50. Built-in Audio Mono [vol: 0.40]│ 51. Built-in Audio Stereo [vol: 0.40]│ 53. Built-in Audio Stereo [vol: 0.40]│ 66. Built-in Audio Digital Stereo (IEC958) [vol: 0.40]│ * 100. FreeBuds 3 [vol: 0.50]
3 播放本地音乐
播放器 | 典型命令 |
---|---|
mpv | mpv song.flac (PipeWire 会自动把流送进默认 Sink) |
gst-play-1.0 | gst-play-1.0 --audiosink=autoaudiosink track.mp3 (autoaudiosink 路由到默认) |
aplay(WAV 测试) | aplay -D bluealsa:HCI=hci0,DEV=D0:05:E4:17:0E:21,PROFILE=a2dp test.wav (使用 bluez-alsa 时) |
确认过程中可用:
wpctl status # 数据流出现于蓝牙 Sink 的 “CLIENTS” 栏pw-top # 观察实时 PCM 量
4 常见问题速查
现象 | 快速定位 | 解决方案 |
---|---|---|
wpctl status 找不到蓝牙卡 | WirePlumber 未启或蓝牙未 ServicesResolved | 见 #1 拉起服务,或在 bluetoothctl 中再次 connect |
切到 a2dp-sink 秒断开 | 耳机不接受 SBC—需 AAC/LDAC | 安装 libfdk-aac / libldacbt 并确保 WirePlumber bluez5.enable-msbc 、bluez5.enable-aac 打开 |
播放器仍走板载喇叭 | 默认 Sink 未改 | 再次 wpctl set-default <sink-ID> 或在 GUI (Helvum/QPWGraph) 拖拽 |
5 自动化:让耳机每次都走 A2DP
在 /usr/share/wireplumber/bluetooth.lua.d/50-bluez-config.lua 里加入:
bluez_monitor.properties["bluez5.auto-connect"] = {"a2dp-sink"}bluez_monitor.properties["bluez5.profile-priority"] = {["a2dp-sink"] = 10}
WirePlumber 下次重启会自动首选高保真通道,无需手动切换。