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

Abierto
#460 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
28/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, flutter, go
Área
backend, mobile

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Go
Estrellas
6
Forks
3
Merge medio
6 h 28 min
PR fusionados (30 d)
362

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AlphaWaveSystems/flutter-probe

Todos los issues de AlphaWaveSystems/flutter-probe

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.