现代 Ubuntu 音频架构解析:从 ALSA 到 PipeWire
现代 Ubuntu 音频架构解析:从 ALSA 到 PipeWire
一张图看懂 ALSA、PulseAudio、PipeWire 与 pipewire-pulse 的分层关系,以及它们如何协作。
引言:一个常见的困惑
如果你在 Ubuntu 上排查过音频问题,大概率遇到过这样的场景:
$ pactl info
Server Name: PulseAudio (on PipeWire 1.0.5)
命令叫 pactl,输出里写着 "PulseAudio",但括号里又说是 "PipeWire"。那到底用的是哪个?
这个困惑的根源在于:Ubuntu 的音频栈在过去几年发生了重大变化,但为了兼容旧生态,新旧组件在接口层面被刻意保留了下来。理解这套架构,关键在于分清每个组件所在的层级和职责,而不是把它们当成互相替代的选项。
本文从底层到上层梳理现代 Ubuntu 的音频架构,并给出一张全景图。
一、先认识四个名字
在画图之前,先把四个容易混淆的名字放到正确的位置上。
| 名称 | 所在层级 | 职责 |
|---|---|---|
| ALSA | 内核空间 | 声卡驱动与硬件抽象层,提供 /dev/snd/、hw: 等设备接口 |
| PulseAudio | 用户空间(历史方案) | 传统声音服务器,负责混音、路由、按应用音量 |
| PipeWire | 用户空间(现代方案) | 基于图结构的多媒体服务,统一音频、视频流处理 |
| pipewire-pulse | 用户空间(兼容层) | PipeWire 提供的 PulseAudio 协议兼容服务 |
关键认知:
- ALSA 是基础,不可绕过。无论上层用什么声音服务器,最终都要通过 ALSA 驱动声卡。
- PulseAudio 和 PipeWire 是同一层的竞争者,不是上下级关系。Ubuntu 从 22.10 起默认用 PipeWire 替代了 PulseAudio。
- pipewire-pulse 不是 PulseAudio,它是 PipeWire 的一个兼容模块,让只认识 PulseAudio 协议的应用和工具继续工作。
二、Ubuntu 音频架构的演变
2.1 旧时代:ALSA + PulseAudio
在 Ubuntu 22.04 LTS 及更早版本中,默认架构是:
应用 → libpulse → PulseAudio 守护进程 → ALSA → 声卡
PulseAudio 作为独立守护进程运行,负责软件混音、设备路由、网络音频等功能。ALSA 只负责驱动硬件。
2.2 现代:PipeWire 接管上层
从 Ubuntu 22.10 开始,Canonical 正式用 PipeWire 取代 PulseAudio。但为了避免生态断裂,PipeWire 同时提供了:
- pipewire-pulse:实现 PulseAudio 协议,让旧应用和
pactl/pavucontrol继续工作; - pipewire-jack:实现 JACK 协议,让专业音频软件无缝接入;
- pipewire-alsa:提供 ALSA 配置,把
default设备重定向到 PipeWire。
所以现代 Ubuntu 的音频栈是:
应用 →(PulseAudio/JACK/ALSA 协议)→ 兼容层 → PipeWire 核心 → ALSA → 声卡
三、现代 Ubuntu 音频架构全景图
下面这张图展示了现代 Ubuntu(22.10+,含 24.04 LTS)的完整音频分层结构。

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 880" font-family="Arial, sans-serif">
<defs>
<marker id="arrow" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#555"/>
</marker>
<marker id="arrowBlue" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#1f6feb"/>
</marker>
<marker id="arrowOrange" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#e65100"/>
</marker>
<marker id="arrowGreen" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#2e7d32"/>
</marker>
<marker id="arrowPurple" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L0,6 L9,3 z" fill="#6a1b9a"/>
</marker>
<filter id="shadow" x="-5%" y="-5%" width="110%" height="110%">
<feDropShadow dx="2" dy="2" stdDeviation="3" flood-opacity="0.13"/>
</filter>
</defs>
<rect width="960" height="880" fill="#f8f9fa" rx="12"/>
<text x="480" y="38" text-anchor="middle" font-size="22" font-weight="bold" fill="#222">现代 Ubuntu 音频架构:PipeWire + ALSA(Ubuntu 22.10+)</text>
<!-- 用户空间 -->
<rect x="30" y="60" width="900" height="400" rx="10" fill="#f5f8ff" stroke="#90b4e8" stroke-width="1.5" stroke-dasharray="6,4"/>
<text x="50" y="86" font-size="15" font-weight="bold" fill="#1f4e9e">用户空间(User Space)</text>
<!-- 应用层 -->
<rect x="50" y="100" width="180" height="62" rx="8" fill="#ffffff" stroke="#1f6feb" stroke-width="2" filter="url(#shadow)"/>
<text x="140" y="124" text-anchor="middle" font-size="14" font-weight="bold" fill="#1f6feb">应用 A</text>
<text x="140" y="144" text-anchor="middle" font-size="11" fill="#555">PulseAudio 客户端</text>
<rect x="255" y="100" width="180" height="62" rx="8" fill="#ffffff" stroke="#1f6feb" stroke-width="2" filter="url(#shadow)"/>
<text x="345" y="124" text-anchor="middle" font-size="14" font-weight="bold" fill="#1f6feb">应用 B</text>
<text x="345" y="144" text-anchor="middle" font-size="11" fill="#555">JACK 客户端</text>
<rect x="460" y="100" width="180" height="62" rx="8" fill="#ffffff" stroke="#1f6feb" stroke-width="2" filter="url(#shadow)"/>
<text x="550" y="124" text-anchor="middle" font-size="14" font-weight="bold" fill="#1f6feb">应用 C</text>
<text x="550" y="144" text-anchor="middle" font-size="11" fill="#555">原生 ALSA 应用</text>
<rect x="665" y="100" width="180" height="62" rx="8" fill="#ffffff" stroke="#6a1b9a" stroke-width="2" filter="url(#shadow)"/>
<text x="755" y="124" text-anchor="middle" font-size="14" font-weight="bold" fill="#6a1b9a">专业/低延迟应用</text>
<text x="755" y="144" text-anchor="middle" font-size="11" fill="#555">Ardour / 实时音频</text>
<!-- 兼容层 -->
<rect x="50" y="200" width="180" height="58" rx="8" fill="#fff3e0" stroke="#e65100" stroke-width="2" filter="url(#shadow)"/>
<text x="140" y="224" text-anchor="middle" font-size="13" font-weight="bold" fill="#e65100">pipewire-pulse</text>
<text x="140" y="243" text-anchor="middle" font-size="11" fill="#8a4b00">PulseAudio 协议兼容</text>
<rect x="255" y="200" width="180" height="58" rx="8" fill="#f3e5f5" stroke="#6a1b9a" stroke-width="2" filter="url(#shadow)"/>
<text x="345" y="224" text-anchor="middle" font-size="13" font-weight="bold" fill="#6a1b9a">pipewire-jack</text>
<text x="345" y="243" text-anchor="middle" font-size="11" fill="#4a148c">JACK 协议兼容</text>
<rect x="460" y="200" width="180" height="58" rx="8" fill="#e8f5e9" stroke="#2e7d32" stroke-width="2" filter="url(#shadow)"/>
<text x="550" y="224" text-anchor="middle" font-size="13" font-weight="bold" fill="#2e7d32">ALSA pulse 插件</text>
<text x="550" y="243" text-anchor="middle" font-size="11" fill="#1b5e20">libasound 用户空间插件</text>
<!-- PipeWire 核心 -->
<rect x="50" y="295" width="760" height="115" rx="10" fill="#e8f5e9" stroke="#2e7d32" stroke-width="2.5" filter="url(#shadow)"/>
<text x="430" y="322" text-anchor="middle" font-size="17" font-weight="bold" fill="#1b5e20">PipeWire 核心</text>
<text x="430" y="346" text-anchor="middle" font-size="12" fill="#2e7d32">图结构(graph)· 软件混音 · 设备路由 · 低延迟调度 · 格式转换</text>
<text x="430" y="368" text-anchor="middle" font-size="12" fill="#2e7d32">WirePlumber:会话管理 · 设备策略 · 路由规则</text>
<text x="430" y="390" text-anchor="middle" font-size="12" fill="#2e7d32">同时提供 PulseAudio 兼容接口与 JACK 兼容接口</text>
<!-- 应用 → 兼容层 -->
<path d="M 140 162 L 140 195" stroke="#1f6feb" stroke-width="2" fill="none" marker-end="url(#arrowBlue)"/>
<path d="M 345 162 L 345 195" stroke="#1f6feb" stroke-width="2" fill="none" marker-end="url(#arrowBlue)"/>
<path d="M 550 162 L 550 195" stroke="#1f6feb" stroke-width="2" fill="none" marker-end="url(#arrowBlue)"/>
<path d="M 460 229 L 460 182 L 140 182 L 140 195" stroke="#2e7d32" stroke-width="2" fill="none" marker-end="url(#arrowGreen)"/>
<text x="300" y="177" text-anchor="middle" font-size="11" fill="#2e7d32">PulseAudio 协议</text>
<path d="M 140 258 L 140 290" stroke="#e65100" stroke-width="2" fill="none" marker-end="url(#arrowOrange)"/>
<path d="M 345 258 L 345 290" stroke="#6a1b9a" stroke-width="2" fill="none" marker-end="url(#arrowPurple)"/>
<!-- 内核空间 -->
<rect x="30" y="480" width="900" height="195" rx="10" fill="#faf5ff" stroke="#ab47bc" stroke-width="1.5" stroke-dasharray="6,4"/>
<text x="50" y="506" font-size="15" font-weight="bold" fill="#6a1b9a">内核空间(Kernel Space)</text>
<rect x="60" y="535" width="120" height="45" rx="6" fill="#ffffff" stroke="#4a148c" stroke-width="1.5"/>
<text x="120" y="556" text-anchor="middle" font-size="12" font-weight="bold" fill="#4a148c">/dev/snd/</text>
<text x="120" y="572" text-anchor="middle" font-size="11" fill="#555">设备节点</text>
<rect x="220" y="520" width="440" height="75" rx="10" fill="#f3e5f5" stroke="#4a148c" stroke-width="2.5" filter="url(#shadow)"/>
<text x="440" y="547" text-anchor="middle" font-size="15" font-weight="bold" fill="#4a148c">ALSA(Advanced Linux Sound Architecture)</text>
<text x="440" y="570" text-anchor="middle" font-size="12" fill="#6a1b9a">内核驱动层 · 硬件抽象 · /dev/snd/ · hw: · plughw</text>
<line x1="180" y1="557" x2="215" y2="557" stroke="#4a148c" stroke-width="1.5" stroke-dasharray="4,3"/>
<path d="M 400 410 L 400 515" stroke="#2e7d32" stroke-width="2.5" fill="none" marker-end="url(#arrowGreen)"/>
<text x="410" y="468" font-size="12" fill="#2e7d32">音频流 → ALSA 硬件设备</text>
<!-- 硬件层 -->
<rect x="220" y="730" width="440" height="70" rx="10" fill="#eceff1" stroke="#455a64" stroke-width="2.5" filter="url(#shadow)"/>
<text x="440" y="758" text-anchor="middle" font-size="16" font-weight="bold" fill="#455a64">声卡硬件(Hardware)</text>
<text x="440" y="780" text-anchor="middle" font-size="12" fill="#555">HDMI · USB 音频 · 内置声卡 · 蓝牙芯片</text>
<path d="M 440 595 L 440 725" stroke="#4a148c" stroke-width="2.5" fill="none" marker-end="url(#arrowPurple)"/>
<text x="450" y="665" font-size="12" fill="#4a148c">驱动声卡</text>
<!-- 专业应用直连 ALSA -->
<path d="M 845 130 L 880 130 L 880 490 L 660 490 L 660 515" stroke="#6a1b9a" stroke-width="2" stroke-dasharray="7,4" fill="none" marker-end="url(#arrowPurple)"/>
<text x="892" y="320" font-size="11" fill="#6a1b9a" transform="rotate(90,892,320)" text-anchor="middle">绕过 PipeWire,直连 ALSA hw:(低延迟)</text>
<!-- 图例 -->
<rect x="30" y="825" width="900" height="36" rx="6" fill="#ffffff" stroke="#ccc" stroke-width="1"/>
<line x1="50" y1="843" x2="85" y2="843" stroke="#1f6feb" stroke-width="2" marker-end="url(#arrowBlue)"/>
<text x="92" y="848" font-size="12" fill="#333">应用 → PipeWire 常规路径</text>
<line x1="300" y1="843" x2="335" y2="843" stroke="#e65100" stroke-width="2" marker-end="url(#arrowOrange)"/>
<text x="342" y="848" font-size="12" fill="#333">PulseAudio 协议兼容路径</text>
<line x1="550" y1="843" x2="585" y2="843" stroke="#6a1b9a" stroke-width="2" stroke-dasharray="7,4" marker-end="url(#arrowPurple)"/>
<text x="592" y="848" font-size="12" fill="#333">专业应用 → 直接 ALSA hw:</text>
<line x1="790" y1="843" x2="825" y2="843" stroke="#2e7d32" stroke-width="2" marker-end="url(#arrowGreen)"/>
<text x="832" y="848" font-size="12" fill="#333">PipeWire 内部数据流</text>
</svg>
四、数据是如何流动的
根据上图,日常使用中最常见的有三条路径。
路径一:普通桌面应用(走 PulseAudio 兼容层)
Firefox / 音乐播放器
→ libpulse(PulseAudio 客户端库)
→ pipewire-pulse(UNIX socket)
→ PipeWire 核心(混音、路由)
→ ALSA hw: 设备
→ 声卡
这是绝大多数桌面应用的实际路径。应用以为自己连接的是 PulseAudio,实际上 pipewire-pulse 在中间做协议转换,真正干活的是 PipeWire。
路径二:JACK 专业音频应用
Ardour / 实时音频软件
→ libjack
→ pipewire-jack
→ PipeWire 核心(图结构调度)
→ ALSA hw: 设备
→ 声卡
PipeWire 用 pipewire-jack 实现了 JACK 协议,让专业音频应用和普通桌面应用共享同一个音频图,这是传统 JACK + PulseAudio 双栈时代做不到的。
路径三:绕过 PipeWire 直连 ALSA(低延迟场景)
专业应用
→ ALSA libasound
→ hw:0,0(直接打开硬件)
→ 声卡
这条路径放弃了 PipeWire 的混音和路由功能,换取对硬件的直接控制和更低延迟。但它会与正在运行的 PipeWire 发生硬件冲突,下一节详细讨论。
五、如何确认你的系统用的是什么
一条命令就能确定:
pactl info | grep 'Server Name'
两种可能的输出:
| 输出 | 含义 |
|---|---|
Server Name: PulseAudio (on PipeWire 1.0.5) |
正在使用 PipeWire(现代 Ubuntu 默认) |
Server Name: pulseaudio |
正在使用传统的 PulseAudio 守护进程 |
辅助验证:
systemctl --user status pipewire pipewire-pulse wireplumber pulseaudio
如果 pipewire 和 pipewire-pulse 是 active (running),而 pulseaudio 是 inactive (dead),就印证了 PipeWire 已经接管音频服务。
六、一个经典问题:绕过 PipeWire 直连 ALSA 会冲突吗?
会,默认情况下必然冲突。
这是 Linux 音频中最常见的困惑之一。原因在于 ALSA 的 hw: 设备本身不支持多个客户端同时访问,它代表的是对硬件 PCM 的直接独占。而 PipeWire 启动时,会通过 WirePlumber 使用 D-Bus 的 org.freedesktop.ReserveDevice1 协议宣告对声卡的独占预留。
所以当你运行 aplay -D hw:0,0 或者某个硬编码 hw: 的专业软件时,通常会收到:
Device or resource busy
这不是 bug,而是设计使然:PipeWire 已经持有硬件句柄,你的程序在挑战这个预留。
有没有共存的办法?
有,但都需要改变访问的层级,而不是硬碰硬抢 hw:。
| 方案 | 做法 | 代价 |
|---|---|---|
让程序用 default 而非 hw: |
安装 pipewire-alsa,让 ALSA 的 default 指向 PipeWire |
对硬编码 hw: 的专业软件无效 |
让 PipeWire 改用 dmix |
修改 WirePlumber 配置,让 PipeWire 不独占 hw:,而是走 ALSA 的软件混音插件 dmix |
配置复杂,延迟略增 |
| 临时停止 PipeWire | systemctl --user stop pipewire pipewire-pulse wireplumber |
失去全局混音与路由功能,适合临时排障或专业录音场景 |
需要注意的是,网上流传的 api.alsa.disable-exclusive = true 之类的 PipeWire 配置选项,实际效果高度依赖声卡驱动。很多驱动(尤其是 USB 音频)即使禁用了独占请求,也依然拒绝第二个 hw: 打开操作,冲突依旧。
实践建议
- 日常使用:让所有应用走
default(即 PipeWire),享受混音、按应用音量和设备热切换。 - 专业低延迟:要么完全停止 PipeWire 后再直连
hw:,要么使用pipewire-jack接入 PipeWire 的图结构——后者通常已经能满足专业音频的延迟需求。 - 不要期待“既让 PipeWire 跑着,又让另一个程序独占 hw:”:这在大多数驱动上不可行。
七、排障速查表
| 现象 | 可能原因 | 检查命令 |
|---|---|---|
| 所有应用都没声音 | PipeWire 服务未运行 | systemctl --user status pipewire wireplumber |
| 某个应用没声音,其他正常 | 应用走了错误路径或被静音 | pactl list short sink-inputs |
Device or resource busy |
程序请求 hw:,与 PipeWire 独占冲突 |
fuser -v /dev/snd/* |
| 蓝牙耳机连上但没声音 | WirePlumber 路由未切换或 profile 不对 | wpctl status、pactl list cards |
| Flatpak 应用没声音 | xdg-desktop-portal 音频转发问题 | flatpak override --show 检查权限 |
| 切换设备后无声 | WirePlumber 默认节点策略问题 | wpctl status 查看默认 sink |
常用工具一览:
pactl:PulseAudio 兼容接口,查 sink/source/sink-inputwpctl:PipeWire 原生控制工具,查 graph 与节点状态pw-top:实时查看 PipeWire 各节点的延迟与负载pavucontrol:图形化音量控制,兼容 PulseAudio 与 PipeWire
八、总结
现代 Ubuntu 的音频架构可以概括为三层协作:
- ALSA(内核层):驱动硬件,提供
/dev/snd/和hw:设备,是整个栈不可绕过的基础。 - PipeWire(用户空间核心):基于图结构的多媒体服务,承担混音、路由、调度、格式转换,是真正干活的中枢。
- 兼容层(pipewire-pulse / pipewire-jack / ALSA pulse 插件):让旧应用、旧工具、旧协议继续工作,实现平滑迁移。
传统 PulseAudio 的角色已经被 PipeWire 吸收,但你看到的 pactl、pavucontrol、PulseAudio 协议依然存在——它们现在只是接口,而不是引擎。
理解这套分层关系后,遇到音频问题时就能快速定位:是驱动层(ALSA)、核心层(PipeWire/WirePlumber)、还是兼容层(pipewire-pulse)出了问题,而不是在“到底用的是 PulseAudio 还是 PipeWire”这个问题上打转。
本文基于 Ubuntu 22.10+ / 24.04 LTS 的默认音频栈整理。若你使用的是 22.04 LTS 或更早版本,上层核心应为传统 PulseAudio 守护进程,整体分层逻辑相同,只是把“PipeWire 核心 + pipewire-pulse”替换为“PulseAudio 守护进程”即可。
浙公网安备 33010602011771号