Engineering Notes
Things that cost significant debugging time while building Extraspace, recorded so they cost you less.
1. vulkanh264enc silently ignores its bitrate setting
Section titled “1. vulkanh264enc silently ignores its bitrate setting”vulkanh264enc advertises CBR and accepts a bitrate property, yet produces byte-identical output at 5, 15, and 40 Mbit/s — unusable for adaptive streaming. Extraspace deliberately skips it and prefers gst-plugin-va (vah264enc / vah264lpenc), where CBR/VBR is actually honoured.
2. Fedora strips NVENC out of GStreamer’s nvcodec plugin
Section titled “2. Fedora strips NVENC out of GStreamer’s nvcodec plugin”Only CUDA utility elements register; nvh264enc does not exist, and plugins-freeworld does not add it. Fortunately, x264enc at veryfast achieves ~168 fps at 2000×1200 on a mid-range CPU (2.8× headroom over 60 fps), making CPU fallback fast in practice.
3. Bitrate unit mismatch across encoders (1000× trap)
Section titled “3. Bitrate unit mismatch across encoders (1000× trap)”vah264enc,vah264lpenc, andx264encacceptbitratein kbit/s;openh264encacceptsbitratein bit/s.
A 1000× bug waiting to happen; the conversion is intentionally centralized in a single function in xs-video.
4. USB 2.0 is not the bottleneck
Section titled “4. USB 2.0 is not the bottleneck”Raw 2000×1200@60 would require ~550 MB/s, far beyond USB 2.0 High Speed’s ~30 MB/s. Encoded H.264 at 15 Mbit/s is under 2 MB/s — roughly 15× headroom even on USB 2.0.
5. adb forward accepts connections to nothing
Section titled “5. adb forward accepts connections to nothing”adb accepts the local TCP connection regardless of whether anything is listening on the device, then closes it once the remote open fails. As a result, connect() succeeds on the first attempt even when the companion app is not running, and failure surfaces milliseconds later as an EOF mid-handshake. Retrying on ConnectionRefused never helps; the only reliable readiness signal is reading actual handshake bytes.
6. Half-closing one direction kills the whole adb channel
Section titled “6. Half-closing one direction kills the whole adb channel”Tokio’s OwnedWriteHalf calls shutdown(Write) on drop, and adb’s forwarder tears down the entire device-side Unix socket whenever either direction closes. Splitting a read-only stream and dropping the unused write half causes the peer’s next write to fail with EPIPE. One-way streams in xs-transport are never split.
7. Draining MediaCodec only on input loses the last frame
Section titled “7. Draining MediaCodec only on input loses the last frame”Because mutter only emits frames on damage, an idle desktop sends nothing for seconds at a time. If output is drained inside the input loop, the final frame stays decoded in the output queue until something else moves on screen — and queue-depth telemetry stays stuck at 6–8, pinning adaptive bitrate to the floor. A dedicated output drain thread fixed both issues.
8. “60 fps” is a ceiling, not a constant rate
Section titled “8. “60 fps” is a ceiling, not a constant rate”Mutter only emits frames when screen content changes, so an idle desktop averages around 11 fps and well under 1 Mbit/s. Because encoder GOPs are measured in frames, a tablet attaching to an idle desktop could otherwise wait many seconds for a periodic keyframe. Extraspace forces an IDR immediately on attach and whenever the tablet sends an RFI request, keeping steady-state streaming free of periodic keyframe spikes.