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

@@ -102,7 +102,7 @@ fn main() -> Result<()> {
println!(" (Select a screen to share in the portal dialog)");
let portal_args = Args {
output: bench_args.output.clone(),
output: Some(bench_args.output.clone()),
output_name: None,
fps: 60,
codec: "h264".to_string(),
@@ -113,6 +113,7 @@ fn main() -> Result<()> {
verbose: false,
backend: Some("portal".to_string()),
port: 0,
no_persist: false,
};
let cap = CapPortal::new(&portal_args)?;