feat(android): MediaUploader — a phone puts films on a relay, in resumable pieces

MediaOwner signs owner requests and MediaUploader speaks the piece protocol
of media put (window, retries, resync after a lost answer). MediaSealer
.sealStream seals a film to a file; MediaGrant.encode/capabilityUrl make the
link to share. Owner signatures and encoded grants are pinned by new
vectors; scripts/media-live-kotlin.ts runs the uploader against a real TS
relay with a lost answer and a refused piece injected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-19 00:18:31 +02:00
parent f42a9bbe5e
commit f5125b8f66
13 changed files with 897 additions and 5 deletions

View File

@@ -258,6 +258,24 @@ On Android/JVM, `no.zyon.shade.media`: `Grants.fromCapabilityUrl(link)`,
`inputStream()`. `LiveSubscriber(grant).open(frame)` handles live frames, and
`MediaSealer` and `LivePublisher` write both formats byte for byte the way TS does.
Uploading from a phone is `MediaUploader` (blocking; off the main thread):
```kotlin
val owner = MediaOwner(seed) // 32 bytes, kept in the Keystore-backed storage
val up = MediaUploader("https://relay.example", owner)
val grant = contentResolver.openInputStream(uri)!!.use { input ->
up.uploadStream(input, File(cacheDir, "film.smf"), MediaMeta(name = "Kveld.mp4", mime = "video/mp4")) { acked, total -> … }
}
share(grant.capabilityUrl("https://relay.example/watch/"))
```
It speaks the same piece protocol as `media put` (one PUT up to 16 MiB, then pieces
with the relay's window, retries and a resync after a lost answer). To survive the
app being killed, keep the sealed file and the `SealResult` and call `putSealed`
again: the media id is the same, so the relay picks up where it stopped, and a file it
already has gives the same link without sending anything. The relay must list
`owner.id` among its owners.
For playback, `:shade-android-media` hands a reader to Media3/ExoPlayer, so any
container ExoPlayer understands plays and seeks from a sealed file:
@@ -508,7 +526,10 @@ done in v1. A deployment that needs it can pad above this layer.
racing uploads and pins, sweeping, bounded memory.
- `test-vectors/media.json` (`bun run scripts/generate-vectors.ts media.json`): the
Kotlin port reads every vector and reproduces every sealed file and signed frame
byte for byte (`MediaVectorTest`).
byte for byte (`MediaVectorTest`), owner signatures and encoded grants included.
- `bun run scripts/media-live-kotlin.ts`: the Kotlin uploader against a real TS relay,
with a lost answer and a refused piece injected; TS reads the 40 MiB film back
byte for byte (`MediaLiveTest`, skipped without the driver).
- `bench/media.ts`: throughput, seek latency and live fan-out, written as
`bench/media.chart.json`.
- `bench/media-store.ts`: disk store against S3 (+ Postgres) through the real routes,