Device view phase 2: Android H.264 video through the hub (scrcpy), plan

Offen
#460 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
28/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
android, flutter, go
Bereich
backend, mobile

Rechercherichtung

This issue is a multi-part implementation plan and names no source files. Start by reading the hub, shared device-view component, and CLI entry points, then verify WebCodecs support in Studio's macOS WebView as the plan requires. Work is done when the Android video path, input mapping, cleanup, and agent-frame fallback meet the listed acceptance criteria and tests pass.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Goal

A smooth, full-screen Android view in the device view (Studio, VS Code panel, probe device view) that also shows system UI and native screens, which the agent's Flutter-layer frames cannot. Android only. iOS stays on agent frames. No code in this issue; it is the plan for the work.

Why

Agent frames are Flutter-layer screenshots: no status bar, no keyboard, no native dialogs, and a rate bounded by capture cost on the device (the agent re-renders each frame). A hardware-encoded H.264 stream is cheaper on the device and shows everything. An earlier local spike exercised the pieces below.

What the spike found (facts to build on)

  • scrcpy is Apache-2.0. Its server is one small jar (about 734 KB for the version tried) pushed to the device and started with app_process; video and control travel over local sockets reached with adb forward.
  • The control channel takes touch events as fixed-size binary messages (32 bytes for a touch) in the video coordinate space, not the device's logical pixels. Using the wrong space was the one real mistake in the spike.
  • Decoding in the viewer needs WebCodecs VideoDecoder. The decode-rate spike for JPEG (#448) showed createImageBitmap is fast; WebCodecs availability in Studio's macOS WebView (WKWebView) still has to be verified before committing (see Risks).

Plan

  1. Find or fetch scrcpy, pinned. Order: a configured path, then scrcpy-server found next to an installed scrcpy, then a download of one pinned release asset into the user cache. The pinned version and its SHA-256 are constants in the CLI; the download is checked against the digest and refused on mismatch (same approach as the CI integrations). Never download silently: probe device view --video (opt in) says what it fetches and from where. Offline and CI: use a configured path or fall back.
  2. Hub: a video source beside the agent source. The hub keeps its single-client, token and origin rules. A new source starts the server on the device, forwards a loopback port with a random socket id (scid), reads the video socket and relays packets as binary WebSocket frames with a new frame type; the hello's caps gains video: "h264". The adb forward and the on-device process are cleaned up when the view closes, on takeover, and when the hub exits (including --exit-on-stdin-close).
  3. Viewer: WebCodecs decode in the shared component. Feature-detect VideoDecoder with isConfigSupported; configure from the stream's codec data; decode on a worker where possible; draw to the same canvas so hover, selection and the letterbox mapping keep working. Drop frames rather than queue when the decoder falls behind; keyframe request on resume.
  4. Input through the control socket. Taps, swipes and text go to scrcpy's control socket from the hub, mapped from the canvas into video coordinates. Selection and hover (widget tree) still come from the agent, which reports logical pixels: the mapping between agent logical pixels and video pixels is one function with tests, because the two spaces differ by the device pixel ratio and any scaling option.
  5. Fallback to agent frames. If scrcpy is missing, cannot start (older Android, a blocked app_process, a physical device with USB debugging limits), or the viewer has no VideoDecoder, the hub reports caps.video absent and the existing agent frames are used, with a one-line reason in the header (the capability note Studio already shows). The first release changes nothing for people who do not opt in.
  6. Licence and notices. Apache-2.0 allows redistribution, but the first release does not bundle the jar: it is fetched and cached by the user's machine, so the repository and the release binaries carry no scrcpy code. The docs state the source, the licence and that the user's machine downloads it. If bundling is wanted later, the NOTICE text and licence copy ship with the binary and the BSL licensing page lists scrcpy as a third-party component.
  7. Safety. Loopback only; the existing token; random scid per session; no new listening port reachable from the network; the pushed jar goes to a fixed temp path and is removed on close; the command lines are built from constants and validated numbers (no user text reaches a device shell).

Acceptance

  • On an Android emulator: 30 fps video at 720p or better in Studio, the VS Code panel and probe device view, with taps, swipes and typing working in the right place after rotation.
  • CPU on the host stays below what the JPEG path costs at the same size (measure and record on a named device).
  • No scrcpy process, forward or temp file is left after close, takeover, crash or Ctrl-C.
  • Fallback proven: with the server missing, with an old Android API, and without VideoDecoder.
  • Tests: protocol framing, coordinate mapping, cleanup, fallback; one browser test with a recorded H.264 clip; one device run on a named emulator.

Risks and open questions

  • WKWebView and WebCodecs. If Studio's WebView lacks VideoDecoder (or only supports it behind a flag), the viewer needs a software H.264 decoder (a WASM build) or Studio stays on agent frames while VS Code (Chromium) gets video. Verify first.
  • Physical phones: vendor builds may block app_process-launched servers; treat as fallback, not an error.
  • Rotation and resolution changes mid-stream restart the codec; the viewer must reconfigure without a blank flash.
  • Version drift: scrcpy changes its protocol between releases; the pinned version is the only supported one, and the CLI refuses a mismatching server.
  • Running scrcpy next to a user's own scrcpy session: one client per device for control; document it.

Order of work (small PRs)

  1. Detection, pinned download with digest check, and cleanup helpers, with tests (no streaming yet).
  2. Hub video source and framing, with a fake server in tests.
  3. Viewer decode in the shared component, behind feature detection, with the browser test.
  4. Input mapping and control socket.
  5. Fallback, header note, docs, device run on a named emulator.
Vorherrschende Sprache
Go
Sterne
6
Forks
3
Ø Merge
6 Std. 28 Min.
Gemergte PRs (30 T.)
362

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus AlphaWaveSystems/flutter-probe

Alle Issues in AlphaWaveSystems/flutter-probe

Ähnliche Issues

Weitere Issues zu Go

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.