AudioDriverKit示例驱动在M1 iPad上暂停后无法恢复播放
AudioDriverKit示例驱动暂停后无法恢复播放问题
操作步骤
- 编译苹果官方的AudioDriverKit示例驱动并安装到M1 iPad
- 在系统设置中允许该驱动
- 打开浏览器访问YouTube
- 播放视频
- 暂停播放并等待10秒
- 再次启动播放,此时播放未如预期恢复
控制台日志
0x976e 2025-07-29 15:35:23.854280 +0200 com.example.apple-samplecode.SimpleAudioKS6W2DLCW9.Driver.dext <private>: Stop IO: device 2 default 15:35:23.854280+0200 kernel 0 0x98cf 2025-07-29 15:35:23.854757 +0200 CoreAudio 8967 HALS_IOUAEngine.cpp:182 Throwing Exception: error != 0 Failed to disassociate event link -1 error 15:35:23.854757+0200 audiomxd 710 0x98cf 2025-07-29 15:35:23.854854 +0200 CoreAudio 8967 HALS_IOUAEngine.cpp:189 Failed to unregister io thread! error 15:35:23.854854+0200 audiomxd 710 0x98cf 2025-07-29 15:35:23.854938 +0200 CoreAudio HALS_IOEngine2.cpp:2289 HALS_IOEngine2::StopIO: stopping IO on device <private> default 15:35:23.854938+0200 audiomxd 710 0x98a0 2025-07-29 15:35:23.856657 +0200 CoreAudio HALS_IOUADevice.cpp:1513 HALS_IOUADevice::HandlePropertiesChanged: Object: 283: <private> default 15:35:23.856657+0200 audiomxd 710 0x98a0 2025-07-29 15:35:23.857907 +0200 CoreAudio HALS_IOUADevice.cpp:1518 '<private>', '<private>', 0 default 15:35:23.857907+0200 audiomxd 710 0x98cf 2025-07-29 15:35:23.858266 +0200 CoreAudio HALS_IOContext_Legacy_Impl.cpp:2040 IO Stopped Context 296 after 1134592 frames. default 15:35:23.858266+0200 audiomxd 710 0x98cf 2025-07-29 15:35:23.858508 +0200 CoreAudio HALS_IOContext_Legacy_Impl.cpp:2064 HALS_IOContext_Legacy_Impl::IOWorkLoopDeinit: 296 SimpleAudioDevice-UID (VAD [vdef] AggDev 15): stopping with error 0 default 15:35:23.858508+0200 audiomxd 710 0x99ad 2025-07-29 15:35:23.858736 +0200 CoreAudio HALB_PowerAssertion.cpp:157 HALB_PowerAssertion::Release: releasing power assertion ID 33576 of type 'PreventUserIdleSystemSleep' with name: 'com.apple.audio.VAD [vdef] AggDev 15.context.preventuseridlesleep' taken at <private> for 26.476128 seconds default 15:35:23.858736+0200 audiomxd 710 0x66f4 2025-07-29 15:35:23.859920 +0200 CoreAudio 8967 HALS_IOEngine2.cpp:2685 HALS_IOEngine2::_StopIO(289) called on Context 296 current state: Prewarm: 0 Play: 1 State: Running default 15:35:23.859920+0200 audiomxd 710 0x98a0 2025-07-29 15:35:39.433552 +0200 CoreAudio HALS_IOContext_Legacy_Impl.cpp:365 HALS_IOContext_Legacy_Impl::Server_Internal_StartIOProcID: 296 SimpleAudioDevice-UID (VAD [vdef] AggDev 15): default 15:35:39.433552+0200 audiomxd 710 0x98a0 2025-07-29 15:35:39.433638 +0200 CoreAudio HALS_IOContext_Legacy_Impl.cpp:371 starting ProcID 0x21 state: Prewarm: 0 Play: 0 State: Stopped IOProc 0x21: no default 15:35:39.433638+0200 audiomxd 710 0x98d0 2025-07-29 15:35:39.433753 +0200 com.example.apple-samplecode.SimpleAudioKS6W2DLCW9.Driver.dext <private>: Start I/O: device 2 default 15:35:39.433753+0200 kernel 0 0x9a8f 2025-07-29 15:35:39.434142 +0200 CoreAudio HALS_IOContext_Legacy_Impl.cpp:1707 HALS_IOContext_Legacy_Impl::IOWorkLoopInit: 296 SimpleAudioDevice-UID (VAD [vdef] AggDev 15): starting default 15:35:39.434142+0200 audiomxd 710 0x9a8f 2025-07-29 15:35:39.434182 +0200 CoreAudio HALS_IOEngine2.cpp:2275 HALS_IOEngine2::StartIO: starting IO on device <private> default 15:35:39.434182+0200 audiomxd 710 0x99d2 2025-07-29 15:35:39.434205 +0200 CoreAudio HALB_PowerAssertion.cpp:119 HALB_PowerAssertion::Take: taking power assertion ID 33576 of type 'PreventUserIdleSystemSleep' with name: 'com.apple.audio.VAD [vdef] AggDev 15.context.preventuseridlesleep' default
故障原因分析
从日志可见,暂停播放触发的StopIO流程出现两个核心错误:
Failed to disassociate event link -1:驱动与系统音频HAL的事件关联未正确解绑Failed to unregister io thread!:IO线程资源未成功注销
这两个错误会导致音频上下文处于异常中间态,即便后续恢复播放时日志显示触发了Start IO并重新获取电源断言,残留的无效资源仍会阻止音频流正常启动,最终导致播放无法恢复。
社区反馈与修复方向
已有开发者在社区反馈类似问题,集中在iPadOS环境下的AudioDriverKit示例驱动,核心原因是官方示例的IO线程、事件链接生命周期逻辑未完全适配iPadOS的音频HAL闲置回收机制。
可尝试以下修复:
- 检查驱动
StopIO方法的资源释放逻辑,确保事件链接、IO线程的注销流程完整执行,必要时添加错误重试 - 调整驱动电源管理逻辑,避免闲置超时后过早释放关键音频资源
- 恢复播放前手动重置音频上下文状态,确保资源处于干净初始态
内容的提问来源于stack exchange,提问作者tuple_cat
相关产品推荐
相关产品推荐

