fix(state): add WebRTC support to wlr-screencopy backend

Fixes #1 -- --port mode with wlr-screencopy backend caused panic at
negotiate_format() because self.args.output is None and .expect() was
called unconditionally.

Changes:
- Introduce StreamingEncoder enum wrapping EncState (MP4) and
  SwEncState (WebRTC) with unified frames_rgb/encode_frame/flush API
- Add WebRTC fields to State<S> (webrtc, webrtc_tx, webrtc_rx,
  webrtc_frames_sent) matching Portal backend pattern
- State::new() returns Result<Self> for clean WebRtcState init failure
- negotiate_format() branches on webrtc_tx: WebRTC path uses
  SwEncState::new_webrtc(), MP4 path unchanged (hardware VAAPI)
- Add poll_webrtc() method to drive signaling + channel drain
- Event loop calls poll_webrtc() each iteration
- Fix pre-existing test/bench Args construction (Option<String> output,
  missing no_persist field)
This commit is contained in:
dailz
2026-06-04 22:10:46 +08:00
parent b0ed6548a6
commit 46367ef6b5
6 changed files with 136 additions and 26 deletions

View File

@@ -178,7 +178,7 @@ mod tests {
// 测试辅助函数:构造指定后端参数的 Args 实例
fn make_args(backend: Option<&str>) -> Args {
Args {
output: "test.mp4".to_string(),
output: Some("test.mp4".to_string()),
output_name: None,
fps: 30,
codec: "h264".to_string(),
@@ -189,6 +189,7 @@ mod tests {
verbose: false,
backend: backend.map(String::from),
port: 0,
no_persist: false,
}
}