Skip to content

How It Works

Most “tablet as second screen” tools on Linux mirror an existing display, require X11, or rely on DisplayLink drivers / EVDI kernel modules to create a new Wayland output.

Mutter can already do this natively:

  • org.gnome.Mutter.ScreenCast provides RecordVirtual, which creates a real virtual monitor with no backing physical hardware.
  • org.gnome.Mutter.RemoteDesktop injects multi-touch events whose coordinates are relative to that PipeWire stream, so input lands on the right monitor with no geometry maths at all.

The exact sequence is not obvious from mutter’s interface XML and must happen in this order:

  1. Call RemoteDesktop.CreateSession() and read its SessionId.
  2. Call ScreenCast.CreateSession({"remote-desktop-session-id": id}). Linking the two sessions is what makes injected input land on the virtual monitor.
  3. Call ScreenCast.Session.RecordVirtual({ modes, is-platform, cursor-mode }):
    • is-platform: true makes it a real monitor in Settings → Displays rather than a shared surface.
    • modes pins it to an exact resolution on GNOME 50+ so PipeWire cannot renegotiate it (GNOME 46–49 pins it via PipeWire caps negotiation).
  4. Subscribe to PipeWireStreamAdded before starting, or the signal is missed.
  5. Call RemoteDesktop.Session.Start() — not ScreenCast.Session.Start(), which mutter rejects for a linked session with “Must be started from remote desktop session”. Teardown is symmetric.

Once the PipeWire node ID arrives, the host runs a zero-reorder GStreamer pipeline.

When VA-API hardware acceleration is available (AMD / Intel gst-plugin-va):

pipewiresrc → videorate → vapostproc (VAMemory NV12) → vah264enc → h264parse → appsink → USB / TCP

When VA-API is absent, it falls back cleanly to CPU encoding:

pipewiresrc → videorate → videoconvert → videoscale → x264enc / openh264enc → h264parse → appsink → USB / TCP

Zero-Reorder SPS VUI Rewrite & RFI Recovery

Section titled “Zero-Reorder SPS VUI Rewrite & RFI Recovery”
  • In-flight SPS VUI rewriting: Keyframes have their H.264 SPS VUI rewritten (max_num_reorder_frames = 0, max_dec_frame_buffering = 1) so Android’s MediaCodec outputs decoded frames immediately without reorder buffering — even on OMX decoders lacking KEY_LOW_LATENCY.
  • Rolling Intra Refresh + RFI (Reference Frame Invalidation): Keeps steady-state streaming free of periodic full-screen IDR spikes while recovering from dropped or overwritten frames within a single round trip (~1 ms over USB).
  • Adaptive Bitrate Control: Periodic Stats reports from the tablet (decode_queue_depth, decoded/dropped frame counters, render timestamps) drive bitrate probing upward on healthy links and back off immediately if the decoder queue grows.

Bulk video is never allowed to head-of-line block latency-critical touch input or power events. Extraspace opens four dedicated sockets (forwarded over adb on USB, or directly over LAN TCP):

Stream Port Direction Purpose
Control / Touch 27183 Bidirectional Handshake, video config, pings, RFI, adaptive bitrate stats, and high-rate touch events
Video 27184 Host → Tablet H.264 desktop video stream
Camera 27185 Tablet → Host H.264 camera stream decoded into /dev/video10
Power 27186 Bidirectional Dedicated lock/unlock/suspend/wake sync (systemd-logind + org.gnome.ScreenSaver)

Because mutter assigns a fresh serial to every RecordVirtual monitor, GNOME cannot remember its position across reconnects on its own. xs-mutter watches org.gnome.Mutter.DisplayConfig, records the virtual monitor’s edge attachment, offset, rotation, and scale relative to its neighbouring physical display, and restores it automatically on reconnect.