Skip to content

feat(screencapture): H.264/H.265 VideoToolbox streaming under /mobilerun#1

Open
Timo972 wants to merge 4 commits into
masterfrom
timo/dro-2183-wda-h264-h265-screen-capture
Open

feat(screencapture): H.264/H.265 VideoToolbox streaming under /mobilerun#1
Timo972 wants to merge 4 commits into
masterfrom
timo/dro-2183-wda-h264-h265-screen-capture

Conversation

@Timo972

@Timo972 Timo972 commented Jun 8, 2026

Copy link
Copy Markdown

Add a live, hardware-encoded screen-capture stream exposed under a new /mobilerun namespace, separate from default WDA routes. A shared capture loop grabs and decodes each XCUIScreen screenshot once and fans it out to one or more independent encoder sessions, each with its own codec, resolution and TCP port, enabling concurrent multi-codec capture.

Pipeline: XCUIScreen screenshot -> CVPixelBuffer (aspect-preserving letterbox) -> VTCompressionSession -> raw Annex-B elementary stream (SPS/PPS prepended before each IDR) broadcast over a dedicated TCP port with TCP_NODELAY for low latency.

Endpoints (id-scoped for multi-session fan-out):
POST /mobilerun/screencapture/start -> { id, port, ... }
GET /mobilerun/screencapture list sessions
GET /mobilerun/screencapture/:id session status
POST /mobilerun/screencapture/:id/keyframe force an IDR on demand
POST /mobilerun/screencapture/:id/stop stop one session
POST /mobilerun/screencapture/stop stop all

New files: FBPixelBufferConverter, FBVideoEncoder, FBVideoStreamSession, FBVideoStreamManager, FBScreenCaptureCommands (+ unit tests for the converter and encoder). Adds FBConfiguration.screenCaptureServerPort (default 9200, SCREEN_CAPTURE_SERVER_PORT env) and wires session teardown into FBWebServer.

Timo972 and others added 4 commits June 8, 2026 14:58
Add a live, hardware-encoded screen-capture stream exposed under a new
/mobilerun namespace, separate from default WDA routes. A shared capture
loop grabs and decodes each XCUIScreen screenshot once and fans it out to
one or more independent encoder sessions, each with its own codec,
resolution and TCP port, enabling concurrent multi-codec capture.

Pipeline: XCUIScreen screenshot -> CVPixelBuffer (aspect-preserving
letterbox) -> VTCompressionSession -> raw Annex-B elementary stream
(SPS/PPS prepended before each IDR) broadcast over a dedicated TCP port
with TCP_NODELAY for low latency.

Endpoints (id-scoped for multi-session fan-out):
  POST /mobilerun/screencapture/start         -> { id, port, ... }
  GET  /mobilerun/screencapture                list sessions
  GET  /mobilerun/screencapture/:id            session status
  POST /mobilerun/screencapture/:id/keyframe   force an IDR on demand
  POST /mobilerun/screencapture/:id/stop       stop one session
  POST /mobilerun/screencapture/stop           stop all

New files: FBPixelBufferConverter, FBVideoEncoder, FBVideoStreamSession,
FBVideoStreamManager, FBScreenCaptureCommands (+ unit tests for the
converter and encoder). Adds FBConfiguration.screenCaptureServerPort
(default 9200, SCREEN_CAPTURE_SERVER_PORT env) and wires session teardown
into FBWebServer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Invalidate stale capture-loop callbacks via a generation token. A stop/start
  cycle no longer lets a dispatch_after block queued by a previous run revive
  itself and spawn a second concurrent capture loop. Each run carries a
  generation; callbacks whose generation no longer matches refuse to proceed
  or reschedule.
- Reject out-of-range 'port' arguments (must be 0..65535) instead of silently
  wrapping the uint16_t cast (e.g. 65536 -> 0 -> unintended auto-assign).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A 'codec' argument sent as JSON null or a non-string value reached
-length/-lowercaseString on NSNull/NSNumber, raising an unhandled
exception instead of the intended invalid-argument response. Guard that
codec is an NSString before using string methods; an absent codec still
defaults to h264.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Auto port assignment (port 0 / omitted) previously picked only the next
port unused by this process's sessions and failed if the socket could not
bind. When the default SCREEN_CAPTURE_SERVER_PORT (9200) is already held by
another process (multi-WDA or a stale runner), start now scans forward over
a range of ports until one binds, matching the documented auto-assign
behavior. An explicitly requested port still fails fast on conflict.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant