Bug: --port 模式下 wlr-screencopy 后端 negotiate_format panic #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
位置
src/state.rs:616严重性
🔴 高
问题描述
main.rs:64仅要求--output或--port二选一,但state.rs的negotiate_format中没有任何 WebRTC 分支判断。当用户以--port(WebRTC 模式)在 wlroots 合成器上运行且未指定--output时,self.args.output为None,.expect()会直接 panic。对比
state_portal.rs:150-174,Portal 后端在创建编码器前会检查self.webrtc_tx,WebRTC 模式下走new_webrtc分支而完全避开 MP4 路径。建议修复
在
main.rs中增加校验:wlr-screencopy 后端暂不支持 WebRTC,应提前报错并给出清晰提示。或在state.rs的negotiate_format中增加self.args.port > 0的判断。修复方案
已通过 commit
46367ef修复。问题根因
wlr-screencopy 后端的 negotiate_format() 无条件调用 .expect("output required for MP4 mode"),没有 WebRTC 分支判断。当 --port 模式下 output 为 None 时直接 panic。
修复内容
采用方案 B(完整 WebRTC 支持),而非提前拒绝:
引入 StreamingEncoder 枚举 — 包装 EncState(MP4 硬编)和 SwEncState(WebRTC 软编),统一 frames_rgb/encode_frame/flush 接口,EncConstructionStage::Streaming 持有枚举而非裸 EncState
State
增加 WebRTC 字段 — webrtc/webrtc_tx/webrtc_rx/webrtc_frames_sent,与 Portal 后端模式一致State::new() 返回 Result — WebRtcState::new() 可干净地失败而非 panic
negotiate_format() 增加分支 — webrtc_tx 存在时走 SwEncState::new_webrtc(),否则走原有 create_encoder()(VAAPI 硬编,无性能退化)
新增 poll_webrtc() 方法 — 驱动 signaling + channel drain,在事件循环每轮迭代调用
修复预存的测试编译错误 — Args 构造 output 类型不匹配 + 缺少 no_persist 字段
验证