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

Ouverte
#460 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
28/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
Active
Stack technique
android, flutter, go
Domaine
backend, mobile

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
Go
Étoiles
6
Forks
3
Merge moyen
6 h 28 min
PR mergées (30 j)
362

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de AlphaWaveSystems/flutter-probe

Toutes les issues de AlphaWaveSystems/flutter-probe

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.