3e09dbc09a
Moonshine f184d5e (BSD-2, CLEAN_ROOM S-21) reads no body from START_B, PERIODIC_PING or the IDR request, ignores LOSS_STATS and FRAME_STATS, does not know START_A (skipped inside the encrypted frame, fatal outside it), and stops a stream after 60 s without a ping. No GPL-provenance value taken. - Probe defaults: START_A and START_B empty, PERIODIC_PING empty every 500 ms, an empty IDR request on frame loss; every body stays overridable by hex or `none`. - Tests: the candidates' plaintext headers, their sealed frame layout and Moonshine's client-to-host IV, and the INVALIDATE_REF_FRAMES field offsets Moonshine reads. - PROTOCOL.md 3.3 and the U10 row narrowed with the [M] facts. - LIVE-INTEROP.md: P3 decided (dev-only `sunshine-api` in arena-host behind a never-shipped feature, credentials from Custos), P4 done, table V rewritten without guessed bodies, first launch 90 s to outlast a 60 s ping deadline, the black-box list pointed at PLAY-REMOTELY's handover, §8 and §15 (§17 is the installer spec).
601 lines
36 KiB
Markdown
601 lines
36 KiB
Markdown
# GameStream protocol, as DomiStream speaks it (client side)
|
||
|
||
The protocol between a GameStream host (Sunshine, later Lumen) and a client (Arena Domi TV). Written from the Wolf
|
||
protocol docs in our own words, completed with facts read in Moonshine (BSD-2). Every fact has a tag; every gap is
|
||
marked **UNKNOWN Un** with what would settle it. Status: 2026-11-25, implemented as stream-v0.1.0 per these docs and the approved sources; interop with a real host
|
||
is unverified (the lab capture was not run, [LAB_CAPTURE.md](LAB_CAPTURE.md)). U9 narrowed and U14 settled from the
|
||
approved sources (sections 3.1, 5.3); where an UNKNOWN remains, the code follows the Wolf-documented behaviour.
|
||
|
||
**Tags** (details in the source log, [CLEAN_ROOM.md](CLEAN_ROOM.md)):
|
||
|
||
| Tag | Source |
|
||
| :-- | :-- |
|
||
| [W1]-[W7] | Wolf docs: index, pairing, RTSP, control, RTP video, RTP Opus, input (S-1 to S-7) |
|
||
| [M] | Moonshine `f184d5e` (S-9). A host implementation: we mirror its behaviour for the client. |
|
||
| [M*] | Moonshine, but the value has GPL provenance (Moonshine cites Sunshine or moonlight-common-c). Confirm by measurement before use. |
|
||
| [T] | tokio-enet `364628e` (S-10), approved 2026-11-25 |
|
||
| [E] | stock ENet v1.3.18 `2662c0d` (S-17), MIT, approved 2026-11-25 |
|
||
| [F] | fec-rs README and source `402f41f` (S-13, S-18), BSD-2, approved 2026-11-25 |
|
||
| [RFC n] | the RFC |
|
||
|
||
**Not in DomiStream:** sockets, TLS, the clock, video decoding and **Opus decoding**. DomiStream hands the platform
|
||
layer (ArenaTV: webOS NDL, Android MediaCodec, Windows D3D11VA) a complete Annex-B access unit per video frame and one
|
||
Opus packet (or a "lost" marker) per audio packet, plus the Opus multistream configuration. Decoding, packet-loss
|
||
concealment and output are the platform's job.
|
||
|
||
---
|
||
|
||
## 0. Overview
|
||
|
||
Six protocols [W1]:
|
||
|
||
| Protocol | Default port | Transport | Protection | Purpose |
|
||
| :-- | :-- | :-- | :-- | :-- |
|
||
| HTTP | TCP 47989 | plain | none | server info, pairing |
|
||
| HTTPS | TCP 47984 | TLS, client certificate | TLS | app list, launch/resume/cancel, the last pairing step |
|
||
| RTSP | TCP 48010 | plain | none | negotiate the three streams |
|
||
| Control | UDP 47999 | ENet | AES-128-GCM per message | input, feedback, host events |
|
||
| Video | UDP 47998 | RTP | none by default; optional AES-128-GCM [M] | H.264 / HEVC / AV1 |
|
||
| Audio | UDP 48000 | RTP | AES-128-CBC | Opus |
|
||
|
||
All ports except HTTP/HTTPS can be changed by the host and reach the client through RTSP [W1].
|
||
|
||
Session order (client view): `serverinfo` (HTTP) → pair once (HTTP + one HTTPS step) → `applist` (HTTPS) →
|
||
`launch` (HTTPS, hands over the stream keys) → RTSP OPTIONS, DESCRIBE, SETUP ×3, ANNOUNCE, PLAY → UDP PING to the
|
||
video and audio ports + ENet connect to the control port → `START_B` on control → video and audio flow [W1][W3][M].
|
||
|
||
---
|
||
|
||
## 1. HTTP and HTTPS
|
||
|
||
Source: [Wolf: HTTP/S pairing](https://games-on-whales.github.io/wolf/stable/protocols/http-pairing.html) [W2], Moonshine `src/webserver/` and `src/clients.rs` [M].
|
||
|
||
### 1.1 Common shape
|
||
|
||
- Every call is a `GET` with a query string. Every response body is XML with one root:
|
||
`<root status_code="200">…</root>`; a non-200 `status_code` is an error, possibly with a `status_message`
|
||
attribute (UNKNOWN U27: attribute names on errors). [M]
|
||
- Every call carries `uniqueid=<client id>` [M]. Our client id: 16 random hex characters, stored with the pairing
|
||
(UNKNOWN U1: whether the host requires a particular form).
|
||
- Binary values travel as hex in both directions [M]. Our parser accepts upper and lower case.
|
||
- HTTPS: the host presents its certificate (the same one it sends as `plaincert` while pairing [M]); the client
|
||
presents its own certificate. Only a client certificate that completed pairing may call HTTPS APIs [W2].
|
||
The client **pins** the host certificate: the TLS certificate must equal the paired `plaincert` byte for byte.
|
||
TLS itself (version, ciphers) belongs to the platform layer (UNKNOWN U24: TLS versions Sunshine offers).
|
||
|
||
### 1.2 serverinfo
|
||
|
||
`GET /serverinfo?uniqueid=…` over HTTP (unpaired) or HTTPS (paired). `PairStatus` is 1 only over HTTPS with a
|
||
paired certificate [M]. Elements under `root` [M]:
|
||
|
||
| Element | Meaning |
|
||
| :-- | :-- |
|
||
| `hostname` | host name to show |
|
||
| `appversion` | protocol version string, e.g. `7.1.431.-1`; a negative fourth part marks the Sunshine-era protocol [M] |
|
||
| `GfeVersion` | compatibility version string |
|
||
| `uniqueid` | host id (stable across restarts) |
|
||
| `HttpsPort`, `ExternalPort` | HTTPS and HTTP ports |
|
||
| `mac` | MAC address for Wake-on-LAN (may be empty) |
|
||
| `LocalIP` | host's address as it sees it |
|
||
| `MaxLumaPixelsHEVC` | HEVC capability (0 = none) |
|
||
| `ServerCodecModeSupport` | codec bitmask (UNKNOWN U25: bit meanings) |
|
||
| `SupportedDisplayMode` | display modes (may be empty) |
|
||
| `PairStatus` | 1 = this client is paired |
|
||
| `currentgame` | running app id, 0 = none |
|
||
| `state` | busy/free string, host-specific suffix (e.g. `…_SERVER_BUSY`, `…_SERVER_FREE`) |
|
||
|
||
### 1.3 applist
|
||
|
||
`GET /applist?uniqueid=…` over HTTPS. One `<App>` per app with `<AppTitle>`, `<ID>` (decimal) and
|
||
`<IsHdrSupported>` (0/1) [M]. Box art: `GET /appasset?appid=<ID>…` returns an image [M] (not used: Arena Domi TV
|
||
shows Arena's own covers).
|
||
|
||
### 1.4 launch, resume, cancel
|
||
|
||
`GET /launch?…` over HTTPS. Parameters [M]:
|
||
|
||
| Parameter | Value |
|
||
| :-- | :-- |
|
||
| `appid` | app `ID` from applist |
|
||
| `mode` | `<width>x<height>x<fps>`, e.g. `1920x1080x60` |
|
||
| `rikey` | 16-byte AES key, hex. Used for control, audio and video encryption [W6][M] |
|
||
| `rikeyid` | integer key id, decimal. Feeds the audio IV (section 6.3) [M] |
|
||
| `hdrMode` | 0/1 |
|
||
| `surroundAudioInfo` | `(channel_mask << 16) | channel_count`; stereo default 196610 = `0x30002` [M] |
|
||
| others | UNKNOWN U4 (e.g. local audio playback, SOPS, gamepad mask, any version field) |
|
||
|
||
Response [M]: `<gamesession>1</gamesession>` and `<sessionUrl0>rtsp://<host>:<port></sessionUrl0>`
|
||
(UNKNOWN U4: what to assume when `sessionUrl0` is missing; we use port 48010 of the same host).
|
||
|
||
`GET /resume?rikey=…&rikeyid=…` reattaches to the running app with fresh keys [M]. `GET /cancel` quits the running
|
||
app [M]. `GET /unpair` forgets this client [M].
|
||
|
||
**Key rule (ours):** a fresh random `rikey` and `rikeyid` for every launch and resume. Counters behind the GCM
|
||
nonces restart with each session (section 7), so a reused key would reuse nonces.
|
||
|
||
### 1.5 Pairing
|
||
|
||
The host shows nothing to the user in Arena Domi: arena-host submits the PIN to Sunshine locally. On the wire the PIN
|
||
handshake is unchanged.
|
||
|
||
Inputs: `PIN` (4 ASCII digits [M]), the client's RSA certificate and key, randomness. Notation: `‖` concatenation,
|
||
`E_K` / `D_K` AES-128-ECB with key `K` and no padding (inputs are whole blocks) [M], `sig(cert)` the raw
|
||
`signatureValue` bytes of an X.509 certificate [M], `Sign`/`Verify` RSASSA-PKCS1-v1_5 with SHA-256 [M][RFC 8017].
|
||
|
||
| Step | Client sends | Host answers | Client then |
|
||
| :-- | :-- | :-- | :-- |
|
||
| 1 (HTTP) | `/pair?uniqueid&devicename&updateState=1&phrase=getservercert&salt=hex(salt)&clientcert=hex(client cert PEM)`; `salt` 16 random bytes | blocks until the PIN is entered on the host [M], then `paired=1`, `plaincert=hex(host cert PEM)` | derives `K = SHA-256(salt ‖ PIN)[0..16]` [W2][M]; stores the host cert |
|
||
| 2 (HTTP) | `clientchallenge=hex(E_K(C))`; `C` 16 random bytes | `challengeresponse=hex(E_K(H_s ‖ S_c))`, 48 bytes: `H_s = SHA-256(C ‖ sig(host cert) ‖ secret_s)`, `S_c` the 16-byte host challenge [W2][M] | decrypts, keeps `H_s` and `S_c`; cannot check `H_s` yet |
|
||
| 3 (HTTP) | `serverchallengeresp=hex(E_K(H_c))`, `H_c = SHA-256(S_c ‖ sig(client cert) ‖ secret_c)`, `secret_c` 16 random bytes | `pairingsecret=hex(secret_s ‖ Sign_host(secret_s))` [W2][M] | checks `Verify_host(secret_s, signature)` **and** `SHA-256(C ‖ sig(host cert) ‖ secret_s) == H_s`. Failure = wrong PIN or man in the middle: stop. |
|
||
| 4 (HTTP) | `clientpairingsecret=hex(secret_c ‖ Sign_client(secret_c))` | host checks `H_c` and the signature, answers `paired=1` (or `paired=0`) [W2][M] | |
|
||
| 5 (HTTPS) | `phrase=pairchallenge`, with the client certificate | `paired=1` [W2] | pairing done; store host cert + host `uniqueid` |
|
||
|
||
All step responses are `<root status_code="200"><paired>1</paired>…</root>` with the named element inside [M].
|
||
`paired` is `0` when the host refuses.
|
||
|
||
- UNKNOWN U1: whether Sunshine requires `devicename` / `updateState`, and the order of steps 4 and 5 (Wolf's diagram:
|
||
secret then HTTPS `pairchallenge`; Moonshine's comment lists `pairchallenge` first). We follow Wolf. Settle: lab
|
||
capture of a pairing against Sunshine.
|
||
- UNKNOWN U2: what Sunshine checks in the client certificate (key size, validity, subject). Our certificate: RSA-2048,
|
||
SHA-256, self-signed, long validity, `CN` from the device name. Settle: lab pairing.
|
||
- UNKNOWN U28: what a client should do after a failed step (call `/unpair`? just stop?). Settle: lab capture.
|
||
|
||
---
|
||
|
||
## 2. RTSP
|
||
|
||
Source: [Wolf: RTSP](https://games-on-whales.github.io/wolf/stable/protocols/rtsp.html) [W3], Moonshine `src/rtsp.rs` [M], [RFC 2326].
|
||
|
||
### 2.1 Messages
|
||
|
||
Plain text over TCP [W3]. A request is a start line `<METHOD> <target> RTSP/1.0`, header lines `Name: value`, an
|
||
empty line, then an optional payload; lines end in CRLF [W3]. A response starts `RTSP/1.0 <status> <reason>` [W3].
|
||
`CSeq` is always present and counts requests [W3]. Wolf's example carries `X-GS-ClientVersion: 14` [W3]
|
||
(UNKNOWN U5: which value Sunshine expects).
|
||
|
||
- UNKNOWN U5: framing. Wolf calls the payload "anything after the headers". Our framer uses `Content-Length` when
|
||
present and otherwise ends the message when the host closes the connection. Settle: lab capture (does Sunshine
|
||
close the TCP connection after each reply, and does it send `Content-Length`?).
|
||
- Target: `rtsp://<host>:<port>` from `sessionUrl0` [W3][M].
|
||
|
||
### 2.2 Sequence [W3]
|
||
|
||
| # | Request | Answer that matters |
|
||
| :-- | :-- | :-- |
|
||
| 1 | `OPTIONS` | 200 |
|
||
| 2 | `DESCRIBE` | SDP payload with the host's capabilities (2.3) |
|
||
| 3 | `SETUP` audio | `Transport: server_port=<audio port>` |
|
||
| 4 | `SETUP` video | `Transport: server_port=<video port>` |
|
||
| 5 | `SETUP` control | `Transport: server_port=<control port>` |
|
||
| 6 | `ANNOUNCE` | SDP payload from the client with the stream settings (2.4); 200 |
|
||
| 7 | `PLAY` | 200 |
|
||
|
||
SETUP details [M]: the target's query is `streamid=<audio|video|control>/…` (Moonshine's example:
|
||
`streamid=control/13/0`); a `Transport` header must be present (its value is not interpreted by Moonshine); the reply
|
||
has `Session: <id>;timeout = 90` and `Transport: server_port=<port>`.
|
||
|
||
- UNKNOWN U5: the exact SETUP targets and `Transport` value Sunshine expects, whether later requests must echo
|
||
`Session`, and the PLAY target.
|
||
- UNKNOWN U7: whether Sunshine's SETUP replies carry extra headers the client must use (for example a payload for the
|
||
UDP ping or a value for the ENet connect). Settle: lab capture.
|
||
|
||
### 2.3 DESCRIBE reply (host → client)
|
||
|
||
SDP-like lines, one attribute per line [M][RFC 4566]:
|
||
|
||
| Line | Meaning |
|
||
| :-- | :-- |
|
||
| `a=x-ss-general.featureFlags:<n>` | bit 0x01 pen/touch events, 0x02 controller touch events [M] |
|
||
| `a=x-ss-general.encryptionSupported:<n>` | bit 0x01 control V2, 0x02 video, 0x04 audio [M] |
|
||
| `a=x-nv-video[0].refPicInvalidation:1` | host can invalidate reference frames instead of sending an IDR [M] |
|
||
| `a=rtpmap:98 AV1/90000` | host can send AV1 [M] |
|
||
| `a=fmtp:96 packetization-mode=1` | H.264 packetization [M] |
|
||
| `sprop-parameter-sets=…` | present, value not used [M] |
|
||
| `a=fmtp:97 surround-params=<digits>` | one line per Opus configuration [W3][M] |
|
||
|
||
`surround-params` is a run of single decimal digits: channel count, stream count, coupled-stream count, then one
|
||
mapping digit per channel. Wolf's example `21101` = 2 channels, 1 stream, 1 coupled stream, mapping `0 1` [W3].
|
||
These are the Opus multistream parameters of [RFC 7845] §5.1.1 and go straight to the platform's Opus decoder.
|
||
UNKNOWN U26: the host advertises 5.1/7.1 normal-quality mappings with a channel rotated [M*]; settle by capture.
|
||
|
||
### 2.4 ANNOUNCE payload (client → host)
|
||
|
||
SDP attribute lines `a=<name>:<value>`. Names the host reads [M]; values and the full required set are UNKNOWN U6:
|
||
|
||
| Attribute | What |
|
||
| :-- | :-- |
|
||
| `x-nv-video[0].clientViewportWd`, `…clientViewportHt` | resolution |
|
||
| `x-nv-video[0].maxFPS` | frame rate |
|
||
| `x-nv-video[0].packetSize` | video packet size (default 1024 [W5]) |
|
||
| `x-nv-video[0].maxNumReferenceFrames` | 0 = host's choice when the decoder supports invalidation [M*] |
|
||
| `x-nv-video[0].refPicInvalidation` | client supports invalidation |
|
||
| `x-nv-video[0].dynamicRangeMode`, `…encoderCscMode` | HDR, colour space |
|
||
| `x-nv-vqos[0].bitStreamFormat` | codec |
|
||
| `x-nv-vqos[0].fec.minRequiredFecPackets` | minimum parity packets per block |
|
||
| `x-nv-vqos[0].qosTrafficType`, `x-nv-aqos.qosTrafficType` | DSCP class |
|
||
| `x-ml-video.configuredBitrateKbps` | bitrate |
|
||
| `x-nv-aqos.packetDuration` | audio packet duration in ms |
|
||
| `x-nv-audio.surround.enable`, `…numChannels`, `…channelMask`, `…AudioQuality` | audio layout |
|
||
| `x-ss-video[0].chromaSamplingType` | 4:2:0 / 4:4:4 |
|
||
| `x-ss-general.encryptionEnabled` | encryption flags the client turns on (bits as in 2.3) [M] |
|
||
|
||
Settle U6: lab capture of an ANNOUNCE accepted by Sunshine, then vary one attribute at a time.
|
||
|
||
---
|
||
|
||
## 3. Control channel (ENet + AES-GCM)
|
||
|
||
Source: [Wolf: control](https://games-on-whales.github.io/wolf/stable/protocols/control-specs.html) [W4], Moonshine `src/session/stream/control/mod.rs` [M], tokio-enet [T].
|
||
|
||
### 3.1 ENet
|
||
|
||
The control stream runs over a custom fork of ENet supporting IPv4 and IPv6 [W4]. The wire is stock ENet 1.3 [E][T]
|
||
(all multi-byte fields big-endian):
|
||
|
||
- **Datagram** = protocol header + up to 32 commands [E]. Header: `peer_id u16` whose bits 15 and 14 are flags (`1<<15`
|
||
sent time present, `1<<14` compressed) and bits 12-13 the session id; then `sent_time u16` (low 16 bits of the
|
||
sender's millisecond clock) if flagged [E]. Peer id `0xFFF` = "no peer yet" (the connect datagram) [E].
|
||
- **Checksum** [E]: optional, a setting of the host on *both* ends; when on, 4 bytes follow the header (crc32 over the
|
||
datagram with the field first set to the peer's connect id). **Nothing on the wire says whether it is on**, so both
|
||
ends must agree.
|
||
- **Command header** (4 bytes): `command u8` (low 4 bits type, `0x80` acknowledge wanted, `0x40` unsequenced),
|
||
`channel_id u8` (`0xFF` for connection-level commands), `reliable_sequence u16` [E].
|
||
- **Commands and total sizes** [E]: 1 acknowledge (8: received reliable sequence, received sent time),
|
||
2 connect (48), 3 verify connect (44), 4 disconnect (8: data u32), 5 ping (4), 6 send reliable (6 + data),
|
||
7 send unreliable (8 + data), 8 send fragment (24 + data: start sequence, data length, fragment count, fragment
|
||
number, total length, fragment offset), 9 send unsequenced (8 + data: unsequenced group), 10 bandwidth limit (12),
|
||
11 throttle configure (16), 12 send unreliable fragment (24 + data).
|
||
- **Connect** fields [E]: outgoing peer id u16, incoming and outgoing session id u8 (a stock client sends `0xFF` for
|
||
both, "pick one"), MTU, window size, channel count, incoming and outgoing bandwidth, throttle interval, acceleration,
|
||
deceleration, connect id (random), data u32. Verify connect has the same fields without `data`; the connect id must
|
||
match [E].
|
||
- **Limits** [E]: MTU 576-4096, window 4096-65536, channels 1-255, peer id ≤ 0xFFF, at most 1024 × 1024 fragments.
|
||
- **Stock defaults** [E]: MTU 1392; window 65536 when bandwidth is unlimited; ping every 500 ms when idle;
|
||
retransmission timeout = RTT + 4 × RTT variance (initial RTT 500 ms), doubling per retry; a peer is dropped when
|
||
the oldest unacknowledged command is 30 s old, or once it has been sent 6 times (`2^(attempts-1) ≥ 32`, the
|
||
timeout limit) and is at least 5 s old.
|
||
|
||
How the host uses it [M]: one peer per session; host created with a channel limit of 0x30; every host message is sent
|
||
**reliable on channel 0**. Moonshine does this with stock-wire ENet and real Moonlight clients (see
|
||
[research/open-point-2.md](research/open-point-2.md)).
|
||
|
||
What follows without a capture (our reasoning on [E][T][M]):
|
||
- tokio-enet has no checksum and Moonlight clients work with it, so **Moonlight clients run without the checksum**.
|
||
The checksum must match on both ends, and Sunshine works with the same clients, so **Sunshine runs without it too**.
|
||
Same reasoning for compression: a client that compressed would fail against tokio-enet without a compressor.
|
||
- So everything a Moonlight client *sends* parses as stock 1.3. What stays open is only what the fork might add on the
|
||
host's *sending* side, which the fork-aware client accepts and a stock parser might not.
|
||
|
||
UNKNOWN U9 (narrowed): anything Sunshine's ENet sends that stock 1.3 does not; the channel count, MTU and `connect
|
||
data` a client offers; whether the client sets non-default ping or timeout values. Settle: the lab capture's control
|
||
port datagrams, decoded with our parser (LAB_CAPTURE.md). Until then our client offers stock defaults.
|
||
|
||
### 3.2 Encrypted frame
|
||
|
||
Every control message is wrapped [W4] (little-endian):
|
||
|
||
| Offset | Size | Field |
|
||
| :-- | :-- | :-- |
|
||
| 0 | 2 | type, always `0x0001` |
|
||
| 2 | 2 | length of the rest (`4 + 16 + ciphertext`) |
|
||
| 4 | 4 | sequence number, increasing |
|
||
| 8 | 16 | GCM tag |
|
||
| 24 | n | ciphertext |
|
||
|
||
- Cipher: AES-128-GCM with the launch `rikey` [W4][W6].
|
||
- Nonce (12 bytes) [M]: bytes 0-3 the sequence number (LE), bytes 4-9 zero, byte 10 the direction (`'C'` client to
|
||
host, `'H'` host to client), byte 11 `'C'`. No associated data [M].
|
||
- Minimum frame: 24 bytes + at least the 4-byte message header [M].
|
||
- UNKNOWN U11: the first sequence number and whether the host rejects gaps or repeats. Settle: lab capture.
|
||
We start at 0, never reuse a number, and drop host frames whose number is not greater than the last accepted one
|
||
(replay protection, ours).
|
||
- UNKNOWN U10: whether anything is ever sent outside the wrapper once control encryption (V2) is negotiated. Our
|
||
client refuses to stream with a host that does not offer control V2.
|
||
|
||
### 3.3 Messages (decrypted payload)
|
||
|
||
`type u16 LE`, `length u16 LE` (bytes that follow, must equal the rest of the payload [M]), then the body [W4].
|
||
|
||
| Type | Name | Direction | Body |
|
||
| :-- | :-- | :-- | :-- |
|
||
| 0x0305 | START_A | client → host | UNKNOWN U10. Moonshine has no such type; inside the encrypted frame it skips an unknown type [M] |
|
||
| 0x0307 | START_B | client → host | Moonshine reads no body [M]. The host starts video and audio when it arrives [M]; Moonshine's video receiver (and so its PING handling) only runs from then on [M] |
|
||
| 0x0200 | PERIODIC_PING | client → host | Moonshine reads no body [M]. Each one pushes the host's stop deadline out; Moonshine stops a stream after 60 s without one (its default) [M] |
|
||
| 0x0201 | LOSS_STATS | client → host | Moonshine ignores it [M]; body UNKNOWN U10 |
|
||
| 0x0204 | FRAME_STATS | client → host | Moonshine ignores it [M]; body UNKNOWN U10 |
|
||
| 0x0206 | INPUT_DATA | client → host | section 4 |
|
||
| 0x0302 | IDR_FRAME (request) | client → host | Moonshine reads no body [M] |
|
||
| 0x0301 | INVALIDATE_REF_FRAMES | client → host | `first u32`, `reserved u32`, `last u32`, `reserved 12 bytes`, LE [M] |
|
||
| 0x0100 | TERMINATION | host → client | UNKNOWN U10 |
|
||
| 0x0109 | TERMINATION (extended) | host → client | `error_code u32 BE`; `0x80030023` = graceful [M] |
|
||
| 0x010b | RUMBLE_DATA | host → client | `unused 4`, `controller u16`, `low u16`, `high u16` [W4] |
|
||
| 0x5500 | RUMBLE_TRIGGERS | host → client | `controller u16`, `left u16`, `right u16` [W4] |
|
||
| 0x5501 | MOTION_EVENT | host → client | `controller u16`, `rate u16`, `type u8` (1 accelerometer, 2 gyroscope) [W4] |
|
||
| 0x5502 | RGB_LED | host → client | `controller u16`, `r u8`, `g u8`, `b u8` [W4] |
|
||
| 0x5503 | trigger effect | host → client | UNKNOWN [M] |
|
||
| 0x010e | HDR_MODE | host → client | `enabled u8` + 30 bytes HDR metadata (15 × u16 LE) [M*] |
|
||
|
||
UNKNOWN U23: Wolf states "all data is little-endian" for the frame; we assume LE for the host event bodies too.
|
||
|
||
How Moonshine treats what a client sends on control [M]: a message whose type it does not know, or whose length field
|
||
does not match, **ends the session** when it arrives outside the encrypted frame; inside the encrypted frame the same
|
||
message is skipped, and so is a frame that fails decryption. Whether Sunshine reads bodies (and which) is what U10
|
||
still settles live: the probe sends empty bodies first ([LIVE-INTEROP.md](LIVE-INTEROP.md), table V).
|
||
|
||
---
|
||
|
||
## 4. Input and gamepad packets
|
||
|
||
Source: [Wolf: input](https://games-on-whales.github.io/wolf/stable/protocols/input-data.html) [W7].
|
||
|
||
An INPUT_DATA message (inside the encrypted frame) [W7]:
|
||
|
||
| Offset | Size | Field |
|
||
| :-- | :-- | :-- |
|
||
| 0 | 2 | `0x0206` LE |
|
||
| 2 | 2 | length LE = 4 + size |
|
||
| 4 | 4 | **size, big-endian** = 4 + data length |
|
||
| 8 | 4 | input type, LE |
|
||
| 12 | n | data |
|
||
|
||
Input types [W7]: MOUSE_MOVE_REL `0x07`, MOUSE_MOVE_ABS `0x05`, MOUSE_BUTTON_DOWN `0x08`, MOUSE_BUTTON_UP `0x09`,
|
||
KEY_DOWN `0x03`, KEY_UP `0x04`, MOUSE_SCROLL `0x0A`, MOUSE_HSCROLL `0x55000001`, TOUCH `0x55000002`,
|
||
PEN `0x55000003`, CONTROLLER_MULTI `0x0C`, CONTROLLER_ARRIVAL `0x55000004`, CONTROLLER_TOUCH `0x55000005`,
|
||
CONTROLLER_MOTION `0x55000006`, CONTROLLER_BATTERY `0x55000007`, HAPTICS `0x0D`, UTF8_TEXT `0x17`.
|
||
|
||
Data layouts [W7]:
|
||
|
||
| Type | Data |
|
||
| :-- | :-- |
|
||
| MOUSE_MOVE_REL | `dx i16 BE`, `dy i16 BE` |
|
||
| MOUSE_MOVE_ABS | `x i16 BE`, `y i16 BE`, `unused 2`, `width u16 BE`, `height u16 BE` (client viewport) |
|
||
| MOUSE_BUTTON_DOWN/UP | `button u8`: 1 left, 2 middle, 3 right, 4 side, 5 extra |
|
||
| KEY_DOWN/UP | `flags u8`, `key code u16 LE`, `modifiers u8`, `zero 2` |
|
||
| MOUSE_SCROLL | `amount1 i16 BE`, `amount2 i16 BE`, `zero 2`; hosts use amount1 |
|
||
| MOUSE_HSCROLL | `amount i16 BE` |
|
||
| CONTROLLER_ARRIVAL | `controller u8`, `type u8` (0 unknown, 1 Xbox, 2 PlayStation, 3 Nintendo), `capabilities u8`, `supported buttons u32` |
|
||
| CONTROLLER_MULTI | below |
|
||
|
||
Key codes are Windows virtual-key style (`0x41` A … `0x5A` Z, `0x70` F1 …, `0xA0`/`0xA1` shifts, …) [W7].
|
||
UNKNOWN U20: the example key packet carries `A4 80` (LE `0x80A4`) for LEFTALT `0xA4`, so the high byte has a flag
|
||
meaning; also the bit meanings of `flags` and `modifiers` (the example has `modifiers = 0x04` with Alt).
|
||
|
||
Controller capability bits [W7]: analog triggers 0x01, rumble 0x02, trigger rumble 0x04, touchpad 0x08,
|
||
accelerometer 0x10, gyro 0x20, battery 0x40, RGB LED 0x80.
|
||
|
||
**CONTROLLER_MULTI** data (26 bytes, LE) [W7]:
|
||
|
||
| Offset | Size | Field |
|
||
| :-- | :-- | :-- |
|
||
| 0 | 2 | `0x001A` |
|
||
| 2 | 2 | controller number |
|
||
| 4 | 2 | active mask (bit per connected controller; mask 0 with number 1 = controller 1 unplugged) |
|
||
| 6 | 2 | `0x0014` |
|
||
| 8 | 2 | button flags (low 16 bits) |
|
||
| 10 | 1 | left trigger |
|
||
| 11 | 1 | right trigger |
|
||
| 12 | 2 | left stick X, i16 |
|
||
| 14 | 2 | left stick Y, i16 |
|
||
| 16 | 2 | right stick X, i16 |
|
||
| 18 | 2 | right stick Y, i16 |
|
||
| 20 | 2 | `0x009C` |
|
||
| 22 | 2 | button flags (high 16 bits; 0 in the legacy format) |
|
||
| 24 | 2 | `0x0055` |
|
||
|
||
Buttons = `low | (high << 16)` [W7]: DPAD_UP 0x0001, DPAD_DOWN 0x0002, DPAD_LEFT 0x0004, DPAD_RIGHT 0x0008,
|
||
START 0x0010, BACK 0x0020, LEFT_STICK 0x0040, RIGHT_STICK 0x0080, LEFT_BUTTON 0x0100, RIGHT_BUTTON 0x0200,
|
||
HOME 0x0400, A 0x1000, B 0x2000, X 0x4000, Y 0x8000, PADDLE1-4 0x010000-0x080000, TOUCHPAD 0x100000,
|
||
MISC 0x200000.
|
||
|
||
UNKNOWN U21: layouts of TOUCH, PEN, CONTROLLER_TOUCH, CONTROLLER_MOTION, CONTROLLER_BATTERY, HAPTICS and
|
||
UTF8_TEXT (Wolf lists them without a layout). Not needed for Day 1 (gamepad + Magic Remote pointer + keys).
|
||
UNKNOWN U22: meaning of the constants `0x1A`, `0x14`, `0x9C`, `0x55`, and whether the arrival packet has more
|
||
bytes. Settle: lab capture with a gamepad.
|
||
|
||
### Test vectors QA can build from [W7]
|
||
|
||
Full INPUT_DATA messages (plaintext, before the encrypted frame), hex:
|
||
|
||
| Event | Bytes |
|
||
| :-- | :-- |
|
||
| relative move dx = -1, dy = 0 | `06 02 0C 00 00 00 00 08 07 00 00 00 FF FF 00 00` |
|
||
| absolute move x 1464, y 528, viewport 1919 × 1079 | `06 02 12 00 00 00 00 0E 05 00 00 00 05 B8 02 10 00 00 07 7F 04 37` |
|
||
| left button down | `06 02 09 00 00 00 00 05 08 00 00 00 01` |
|
||
| key down, code `0x80A4`, modifiers 0x04 | `06 02 0E 00 00 00 00 0A 03 00 00 00 00 A4 80 04 00 00` |
|
||
| scroll -120 | `06 02 0E 00 00 00 00 0A 0A 00 00 00 FF 88 FF 88 00 00` |
|
||
| horizontal scroll 30 | `06 02 0A 00 00 00 00 06 01 00 00 55 00 1E` |
|
||
| controller 0, active mask 1, right stick Y -104 | `06 02 22 00 00 00 00 1E 0C 00 00 00 1A 00 00 00 01 00 14 00 00 00 00 00 00 00 00 00 00 00 98 FF 9C 00 00 00 55 00` |
|
||
|
||
---
|
||
|
||
## 5. RTP video
|
||
|
||
Source: [Wolf: RTP video](https://games-on-whales.github.io/wolf/stable/protocols/rtp-video.html) [W5], Moonshine `src/session/stream/video/packetizer.rs` [M], [RFC 3550].
|
||
|
||
### 5.1 Ping
|
||
|
||
The SETUP port is not where video arrives from: the client sends a PING from its own UDP socket to that port, and
|
||
the host sends the stream back to the source address of the PING (NAT) [W5]. Moonshine accepts the 4 bytes `PING`
|
||
[M]. UNKNOWN U8: Sunshine's ping payload and how often to repeat it. Settle: lab capture.
|
||
|
||
### 5.2 Packet
|
||
|
||
Each packet is `packetSize + 16` bytes, `packetSize` from ANNOUNCE (default 1024) [W5]:
|
||
|
||
| Offset | Size | Field |
|
||
| :-- | :-- | :-- |
|
||
| 0 | 1 | RTP byte 0, `0x90` [M] (version 2, extension bit set) |
|
||
| 1 | 1 | payload type, 0 [M] |
|
||
| 2 | 2 | sequence number, BE [W5][RFC 3550] |
|
||
| 4 | 4 | timestamp, BE (UNKNOWN U29: clock rate, probably 90 kHz) |
|
||
| 8 | 4 | SSRC, 0 [M] |
|
||
| 12 | 4 | reserved [W5] |
|
||
| 16 | 4 | stream packet index, LE (= RTP sequence << 8 [M]) |
|
||
| 20 | 4 | frame index, LE [W5][M] |
|
||
| 24 | 1 | flags: 0x01 picture data, 0x02 end of frame, 0x04 start of frame [W5] |
|
||
| 25 | 1 | reserved [W5] |
|
||
| 26 | 1 | multi-FEC flags, `0x10` [M] (UNKNOWN U15: meaning) |
|
||
| 27 | 1 | multi-FEC blocks: bits 4-5 this block's index, bits 6-7 the last block's index [M] |
|
||
| 28 | 4 | FEC info, LE: bits 4-11 FEC percentage, bits 12-21 shard index in block, bits 22-31 data shards in block [M] |
|
||
| 32 | n | payload: `packetSize - 16` bytes of frame data |
|
||
|
||
A frame's data = an 8-byte frame header + the Annex-B bitstream (start codes `00 00 01` / `00 00 00 01`) [W5].
|
||
Wolf shows the 8 bytes as the constant `01 37 63 68 61 72 73 73` [W5]; Moonshine fills them as
|
||
`header type u8 = 0x01`, `processing latency u16 LE`, `frame type u8` (1 predicted, 2 key, 5 first frame after a
|
||
reference invalidation), `last shard payload length u32 LE` [M]. UNKNOWN U13: which one Sunshine sends. Our parser
|
||
returns the 8 bytes raw plus the structured reading. The last data shard is zero-padded to full size [M]; the
|
||
last-payload length (or the Annex-B content) tells where the frame really ends.
|
||
|
||
### 5.3 FEC
|
||
|
||
Reed-Solomon erasure code over GF(2^8), polynomial `0x11D` [F] [W5]:
|
||
|
||
- A frame splits into **blocks** (up to 4 [M]); each block has `k` data shards and
|
||
`m = ceil(k × percentage / 100)` parity shards, `k + m ≤ 255` [M]. Wolf's example: 4 KB at packetSize 1024 and
|
||
50 % → 4 data + 2 parity packets [W5].
|
||
- **Where the receiver gets the parameters:** from every packet of the block: `k` = FEC info bits 22-31, shard index =
|
||
bits 12-21 (0..k-1 data, k..k+m-1 parity), percentage = bits 4-11, block index and last block index from the
|
||
multi-FEC byte. `m` follows from `k` and the percentage. The requested percentage and the minimum parity count are
|
||
set by the client (`x-nv-vqos[0].fec.minRequiredFecPackets`, ANNOUNCE) [M].
|
||
- Shards are the **whole packets** (all `packetSize + 16` bytes, headers included) [M]. Parity packets have flags 0
|
||
[W5] and their RTP and NV header fields are written **after** the parity is computed [M], so parity bytes 0-31 are
|
||
not parity. Consequence for the receiver: a recovered data shard's bytes 0-31 are garbage; use only its payload
|
||
(offset 32 on) and take its place from the shard index.
|
||
- **Matrix (U14, settled from [F], to be confirmed by the capture):** systematic: the data shards pass through, and
|
||
parity shard `j` (0..m) is `Σ_i P[j][i] · data_i` with the Cauchy matrix `P[j][i] = 1 / ((m + i) XOR j)` over
|
||
GF(2^8), polynomial `0x11D`, generator 2 [F]. Nothing in the Wolf docs contradicts this: they only say Reed-Solomon
|
||
with parity blocks [W5]. Examples (our own arithmetic): `k = 4, m = 2`:
|
||
`P = [[8e f4 47 a7], [f4 8e a7 47]]`; `k = 3, m = 1`: `P = [[01 8e f4]]`.
|
||
The capture settles it without any loss: parity packets are always sent, so our encoder must reproduce the
|
||
captured parity bytes (offset 32 on) of every block.
|
||
- The audio code is **not** this matrix (section 6.4).
|
||
|
||
### 5.4 Feedback
|
||
|
||
On an unrecoverable frame the client asks for an IDR frame or, when the host advertised `refPicInvalidation`, sends
|
||
INVALIDATE_REF_FRAMES with the lost range (section 3.3) [W5][M].
|
||
|
||
---
|
||
|
||
## 6. RTP audio (Opus)
|
||
|
||
Source: [Wolf: RTP Opus](https://games-on-whales.github.io/wolf/stable/protocols/rtp-opus.html) [W6], Moonshine `src/session/stream/audio/encoder.rs` [M], [RFC 6716].
|
||
|
||
### 6.1 Ping
|
||
|
||
As for video: the client pings the SETUP audio port and audio comes back to the ping's source address [W6].
|
||
|
||
### 6.2 Packets
|
||
|
||
RTP header, 12 bytes [W6]: byte 0 `0x80` [M], payload type **97** for audio and **127** for FEC parity [M],
|
||
sequence BE, timestamp BE, SSRC 0 [M]. The timestamp counts **milliseconds** and advances by the packet duration
|
||
(`x-nv-aqos.packetDuration`) per packet [M].
|
||
|
||
Data packet: RTP header + one Opus packet [RFC 6716], encrypted (6.3).
|
||
|
||
Parity packet [W6]: RTP header (sequence continues after the 4 data packets [M]) + a 12-byte FEC header + parity:
|
||
|
||
| Offset | Size | Field |
|
||
| :-- | :-- | :-- |
|
||
| 12 | 1 | shard index (0 or 1) [W6][M] |
|
||
| 13 | 1 | payload type of the protected packets, 97 [M] |
|
||
| 14 | 2 | base sequence number, BE [W6][M] |
|
||
| 16 | 4 | base timestamp, BE [W6][M] |
|
||
| 20 | 4 | SSRC [W6] |
|
||
| 24 | n | parity bytes |
|
||
|
||
### 6.3 Encryption
|
||
|
||
AES-128-CBC with `rikey` [W6]. IV (16 bytes) [M]: `u32 BE (rikeyid + sequence number)` then 12 zero bytes; PKCS#7
|
||
padding [M]. UNKNOWN U17: Wolf says audio is always encrypted; Moonshine only when the audio flag is negotiated.
|
||
Settle: lab capture.
|
||
|
||
### 6.4 FEC
|
||
|
||
Every 4 data packets are followed by 2 parity packets [W6]. A block is the 4 data packets whose sequence numbers
|
||
start at a multiple of 4 [M]; the base sequence and timestamp in the FEC header are the first data packet's [M].
|
||
Shards are the encrypted payloads (all 4 the same length, constant-bitrate Opus) [M]. A lost data packet is rebuilt
|
||
from any 4 of the 6 packets; its RTP header comes from the base values (sequence = base + index, timestamp = base +
|
||
index × duration) [M]. DomiStream waits for the jitter budget (`loss_timeout`) before rebuilding a missing packet,
|
||
so a packet that arrives late is played as sent rather than as a rebuilt copy.
|
||
|
||
UNKNOWN U16 (blocks audio FEC): the parity matrix. It is a fixed 2 × 4 matrix over GF(2^8), **not** the default
|
||
construction of the RS library Moonshine uses [M]. The only value we have seen carries GPL provenance and is not
|
||
used (see CLEAN_ROOM.md). Settle by measurement: capture a few audio blocks from a lab host and solve for the 8
|
||
coefficients (each parity byte is a linear combination of the 4 data bytes at the same offset: 4 unknowns per
|
||
parity row, so a handful of byte positions gives a unique solution). Until then, audio loss falls back to the
|
||
platform's packet-loss concealment.
|
||
|
||
### 6.5 Decoding
|
||
|
||
**Not DomiStream.** DomiStream outputs each Opus packet (or a "lost" marker) in sequence order plus the multistream
|
||
configuration from `surround-params` (section 2.3). ArenaTV decodes (NDL or libopus on webOS, MediaCodec on
|
||
Android) and does concealment.
|
||
|
||
---
|
||
|
||
## 7. Stream encryption
|
||
|
||
| Stream | When | Cipher | Key | Nonce / IV |
|
||
| :-- | :-- | :-- | :-- | :-- |
|
||
| Pairing | always | AES-128-ECB + RSA PKCS#1 v1.5 SHA-256 | SHA-256(salt ‖ PIN)[0..16] | none (ECB) |
|
||
| HTTPS | after pairing | TLS (platform), pinned host cert, client cert | | |
|
||
| Control | control V2 flag (0x01) | AES-128-GCM, 16-byte tag, no AAD | `rikey` | seq LE ‖ 6 zero ‖ dir (`C`/`H`) ‖ `C` [M] |
|
||
| Audio | audio flag (0x04) [M] (always, per [W6]) | AES-128-CBC, PKCS#7 | `rikey` | BE(rikeyid + seq) ‖ 12 zero [M] |
|
||
| Video | video flag (0x02) [M] | AES-128-GCM, 16-byte tag, no AAD | `rikey` | 8-byte LE counter ‖ 3 zero ‖ `V` [M] |
|
||
|
||
Negotiation: the host lists what it supports in DESCRIBE (`x-ss-general.encryptionSupported`), the client turns on
|
||
what it wants in ANNOUNCE (`x-ss-general.encryptionEnabled`) [M].
|
||
|
||
Encrypted video packet [M]: `IV 12 bytes ‖ frame number u32 LE ‖ tag 16 bytes ‖ ciphertext`, where the ciphertext is
|
||
the whole plaintext packet of section 5.2; FEC is applied before encryption, so the client decrypts first.
|
||
UNKNOWN U19: whether Sunshine uses this exact layout (Moonlight Android 12.1 added end-to-end encryption with
|
||
Sunshine, S-16). Settle: lab capture with video encryption on.
|
||
|
||
Our policy (Day 1: "stream encryption on"): request every flag the host supports; refuse to stream without control
|
||
V2; show in the stats overlay whether video is encrypted. A new `rikey`/`rikeyid` per launch and resume, because the
|
||
three nonce spaces (control `C`/`H`, video `V`) share one key and their counters restart per session. On top of this,
|
||
traffic goes through the Via Domi tunnel whenever Via is installed (roadmap J6).
|
||
|
||
---
|
||
|
||
## 8. UNKNOWNs
|
||
|
||
**B** = blocks a Day 1 stream against Sunshine. Almost everything is settled by **one lab capture** (a GameStream
|
||
client and Sunshine on a lab machine, not Mark's PC, his Sunshine or his TV); the column says what to look at.
|
||
|
||
| # | What | B | Settle by |
|
||
| :-- | :-- | :-- | :-- |
|
||
| U1 | Pairing query params beyond `uniqueid/phrase/salt/clientcert`; order of steps 4 and 5 | B | capture a pairing |
|
||
| U2 | Client certificate requirements | B | lab pairing with our certificate |
|
||
| U4 | Full launch parameter set; default when `sessionUrl0` is missing | B | capture a launch |
|
||
| U5 | RTSP framing, `X-GS-ClientVersion`, SETUP targets and `Transport`, `Session` echo, PLAY target | B | capture the RTSP exchange |
|
||
| U6 | ANNOUNCE attributes and values Sunshine requires | B | capture, then vary one at a time |
|
||
| U7 | Extra headers in SETUP replies | B | capture |
|
||
| U8 | UDP ping payload and repeat interval | B | capture |
|
||
| U9 | Narrowed (3.1): only what Sunshine's ENet may add when *sending*; the client's channel count, MTU, connect data | B | capture, decode with our parser |
|
||
| U10 | Narrowed (3.3): Moonshine reads no body from START_B, PERIODIC_PING or the IDR request and ignores START_A, LOSS_STATS and FRAME_STATS; what Sunshine reads, the ping interval it needs, TERMINATION's body | B | live sitting: empty bodies first, then the hex variants |
|
||
| U11 | First control sequence number; host's replay rules | | capture |
|
||
| U13 | Video frame header: Wolf's constant or Moonshine's fields | | capture |
|
||
| U14 | Video RS matrix: **settled** (5.3, Cauchy from fec-rs) | | capture confirms: our parity = captured parity |
|
||
| U15 | Multi-FEC flags `0x10` | | capture |
|
||
| U16 | Audio RS parity matrix | (audio plays without it) | capture, solve over GF(2^8) |
|
||
| U17 | Audio encryption always or only when negotiated | B | capture |
|
||
| U19 | Video encryption layout against Sunshine | | capture with video encryption on |
|
||
| U20 | Key code high byte, `flags`, `modifiers` bits | | capture with a keyboard |
|
||
| U21 | TOUCH, PEN, controller touch/motion/battery, HAPTICS, UTF8_TEXT layouts | | capture (Day 5 scope) |
|
||
| U22 | CONTROLLER_MULTI constants, arrival packet length | | capture with a gamepad |
|
||
| U23 | Endianness of host event bodies | | capture rumble |
|
||
| U24 | TLS versions and ciphers | | capture (platform concern) |
|
||
| U25 | `ServerCodecModeSupport` bits | | serverinfo from hosts with known codecs |
|
||
| U26 | Surround mapping rotation | | capture 5.1 |
|
||
| U27 | Error attributes on non-200 XML | | capture a refused call |
|
||
| U28 | Client behaviour after a failed pairing step | | capture a wrong PIN |
|
||
| U29 | Video RTP clock rate | | capture |
|
||
|
||
## 9. Notes on the Wolf docs
|
||
|
||
- The video FEC example sums the overhead as "32 * 6 + 2048 = 2248 bytes"; the arithmetic gives 2240.
|
||
- The button table lists both HOME and SPECIAL_FLAG as `0x0400`.
|
||
- The key table prints NUMPAD PLUS as `x6B` (meaning `0x6B`).
|