Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions c/moq/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ Publish a replacement under a new name, and expect a finished track's demand ter
To answer with a broadcast you already hold, `moq_broadcast_request_serve(request, consumer)` serves it under the prefix route without announcing an exact route; the consumer stays yours to free.
`moq_broadcast_prepared_free` refuses an answer you will not publish.

### `moq_track_info` gains `compress` (#5928)
### `moq_track_info` gains `compression` (#5928)

The new trailing field changes its ABI. A zero-initialized struct leaves it false, as before.
The new trailing field changes its ABI. A zero-initialized struct leaves it `MOQ_COMPRESSION_NONE`, as before.

### Anchors can name a time (#6074)

Expand Down
2 changes: 1 addition & 1 deletion dart/moq/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ A fixed audio playout delay `d` is `delay: Delay(min: d, max: ...)` with `estima
### Compression moves to the track

`package:moq/flate.dart` is removed: publish opaque bytes on a `TrackProducer`.
`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `MoqTrackInfo(compress: true)` instead.
`SnapshotConfig` and `WindowConfig` lose `compression`, and `StreamConfig` is removed. Publish the track with `MoqTrackInfo(compression: MoqCompression.deflate)` instead.
`StreamProducer` drops its `config`, and `StreamConsumer` and `WindowConsumer` take only the track. `SnapshotConsumer` takes the broadcast and track name; see the entry above.

### Paths with an empty segment are refused ([#6648](https://github.com/moq-dev/moq/pull/6648))
Expand Down
4 changes: 2 additions & 2 deletions dart/moq/lib/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// snapshot and stream producers also advertise it in the broadcast's catalog,
/// which has no window mode), and a consumer takes over a `TrackConsumer` that
/// has not read a group yet. Values cross as JSON strings. Compression is the
/// track's: publish JSON with `MoqTrackInfo(compress: true)`, and a consumer
/// track's: publish JSON with `MoqTrackInfo(compression: MoqCompression.deflate)`, and a consumer
/// reads it with no option of its own. Every write (a snapshot update, a stream
/// append, a window push or pop) takes a timestamp on the broadcast clock, the
/// epoch every track in the broadcast shares, so the track needs a timescale;
Expand All @@ -18,7 +18,7 @@
/// broadcast: broadcast,
/// track: broadcast.publishTrack(
/// name: 'status',
/// info: MoqTrackInfo(timescale: 1000, compress: true),
/// info: MoqTrackInfo(timescale: 1000, compression: MoqCompression.deflate),
/// ),
/// config: moq_json.SnapshotConfig(),
/// );
Expand Down
10 changes: 8 additions & 2 deletions dart/moq/test/moq_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,10 @@ void main() {
broadcast: broadcast,
track: broadcast.publishTrack(
name: 'status',
info: MoqTrackInfo(timescale: 1000000, compress: true),
info: MoqTrackInfo(
timescale: 1000000,
compression: MoqCompression.deflate,
),
),
config: moq_json.SnapshotConfig(),
);
Expand Down Expand Up @@ -752,7 +755,10 @@ void main() {
final producer = moq_json.WindowProducer(
track: broadcast.publishTrack(
name: 'log',
info: MoqTrackInfo(timescale: 1000000, compress: true),
info: MoqTrackInfo(
timescale: 1000000,
compression: MoqCompression.deflate,
),
),
config: moq_json.WindowConfig(),
);
Expand Down
101 changes: 91 additions & 10 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3257,14 +3257,14 @@ class MoqTrackInfo {
final bool maxAgeUnlimited;
final int? refresh;
final int? timescale;
final bool compress;
final MoqCompression? compression;
MoqTrackInfo({
this.priority = 0,
this.maxAge = null,
this.maxAgeUnlimited = false,
this.refresh = null,
this.timescale = null,
this.compress = false,
this.compression = null,
});
}

Expand Down Expand Up @@ -3300,19 +3300,19 @@ class FfiConverterMoqTrackInfo {
);
final timescale = timescale_lifted.value;
new_offset += timescale_lifted.bytesRead;
final compress_lifted = FfiConverterBool.read(
final compression_lifted = FfiConverterOptionalMoqCompression.read(
Uint8List.view(buf.buffer, new_offset),
);
final compress = compress_lifted.value;
new_offset += compress_lifted.bytesRead;
final compression = compression_lifted.value;
new_offset += compression_lifted.bytesRead;
return LiftRetVal(
MoqTrackInfo(
priority: priority,
maxAge: maxAge,
maxAgeUnlimited: maxAgeUnlimited,
refresh: refresh,
timescale: timescale,
compress: compress,
compression: compression,
),
new_offset - buf.offsetInBytes,
);
Expand All @@ -3325,7 +3325,7 @@ class FfiConverterMoqTrackInfo {
FfiConverterBool.allocationSize(value.maxAgeUnlimited) +
FfiConverterOptionalUInt32.allocationSize(value.refresh) +
FfiConverterOptionalUInt64.allocationSize(value.timescale) +
FfiConverterBool.allocationSize(value.compress) +
FfiConverterOptionalMoqCompression.allocationSize(value.compression) +
0;
final buf = Uint8List(total_length);
write(value, buf);
Expand Down Expand Up @@ -3354,8 +3354,8 @@ class FfiConverterMoqTrackInfo {
value.timescale,
Uint8List.view(buf.buffer, new_offset),
);
new_offset += FfiConverterBool.write(
value.compress,
new_offset += FfiConverterOptionalMoqCompression.write(
value.compression,
Uint8List.view(buf.buffer, new_offset),
);
return new_offset - buf.offsetInBytes;
Expand All @@ -3367,7 +3367,7 @@ class FfiConverterMoqTrackInfo {
FfiConverterBool.allocationSize(value.maxAgeUnlimited) +
FfiConverterOptionalUInt32.allocationSize(value.refresh) +
FfiConverterOptionalUInt64.allocationSize(value.timescale) +
FfiConverterBool.allocationSize(value.compress) +
FfiConverterOptionalMoqCompression.allocationSize(value.compression) +
0;
}
}
Expand Down Expand Up @@ -8576,6 +8576,40 @@ class AbsentMoqAnnounceEvent extends MoqAnnounceEvent {
}
}

enum MoqCompression { deflate }

class FfiConverterMoqCompression {
static LiftRetVal<MoqCompression> read(Uint8List buf) {
final index = buf.buffer.asByteData(buf.offsetInBytes).getInt32(0);
switch (index) {
case 1:
return LiftRetVal(MoqCompression.deflate, 4);
default:
throw UniffiInternalError(
UniffiInternalError.unexpectedEnumCase,
"Unable to determine enum variant",
);
}
}

static MoqCompression lift(RustBuffer buffer) {
return FfiConverterMoqCompression.read(buffer.asUint8List()).value;
}

static RustBuffer lower(MoqCompression input) {
return toRustBuffer(createUint8ListFromInt(input.index + 1));
}

static int allocationSize(MoqCompression _value) {
return 4;
}

static int write(MoqCompression value, Uint8List buf) {
buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, value.index + 1);
return 4;
}
}

enum MoqTransport { quic, webSocket, tcp, unix, webTransport }

class FfiConverterMoqTransport {
Expand Down Expand Up @@ -17639,6 +17673,53 @@ class FfiConverterOptionalMoqCatalog {
}
}

class FfiConverterOptionalMoqCompression {
static MoqCompression? lift(RustBuffer buf) {
return FfiConverterOptionalMoqCompression.read(buf.asUint8List()).value;
}

static LiftRetVal<MoqCompression?> read(Uint8List buf) {
if (ByteData.view(buf.buffer, buf.offsetInBytes).getInt8(0) == 0) {
return LiftRetVal(null, 1);
}
final result = FfiConverterMoqCompression.read(
Uint8List.view(buf.buffer, buf.offsetInBytes + 1),
);
return LiftRetVal<MoqCompression?>(result.value, result.bytesRead + 1);
}

static int allocationSize([MoqCompression? value]) {
if (value == null) {
return 1;
}
return FfiConverterMoqCompression.allocationSize(value) + 1;
}

static RustBuffer lower(MoqCompression? value) {
if (value == null) {
return toRustBuffer(Uint8List.fromList([0]));
}
final buf = Uint8List(
FfiConverterOptionalMoqCompression.allocationSize(value),
);
FfiConverterOptionalMoqCompression.write(value, buf);
return toRustBuffer(buf);
}

static int write(MoqCompression? value, Uint8List buf) {
if (value == null) {
buf[0] = 0;
return 1;
}
buf[0] = 1;
return FfiConverterMoqCompression.write(
value,
Uint8List.view(buf.buffer, buf.offsetInBytes + 1),
) +
1;
}
}

class FfiConverterOptionalMoqCongestionControl {
static MoqCongestionControl? lift(RustBuffer buf) {
return FfiConverterOptionalMoqCongestionControl.read(
Expand Down
2 changes: 1 addition & 1 deletion demo/carla/sim/moq_carla_sim/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class StatusPublisher:
"""

def __init__(self, broadcast: moq.BroadcastProducer) -> None:
track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compress=True))
track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compression=moq.Compression.DEFLATE))
self._catalog = moq.media.CatalogProducer(broadcast)
self._producer = moq.json.SnapshotProducer(broadcast, track)
# Weak: watching demand neither keeps the track open nor locks it.
Expand Down
1 change: 1 addition & 0 deletions demo/carla/sim/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def update(self, value: object, timestamp: object) -> None:
moq.Subscription = lambda **kwargs: SimpleNamespace(**kwargs)
moq.Delay = lambda **kwargs: SimpleNamespace(**kwargs)
moq.Order = SimpleNamespace(ASCENDING="ascending")
moq.Compression = SimpleNamespace(DEFLATE="deflate")
# Tests that run a truck's endpoint script it in place of this.
moq.socket = ModuleType("moq.socket")
moq.Timestamp = lambda value, scale: SimpleNamespace(value=value, scale=scale)
Expand Down
2 changes: 1 addition & 1 deletion demo/carla/web/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function populatePreview(add: (path: Moq.Path.Valid) => Truck) {
const truck = add(Moq.Path.from(`carla/truck${index + 1}/front.hang`));
const origin = new Moq.Broadcast.Producer();
const producer = new Json.Snapshot.Producer<TruckStatus>({
track: origin.createTrack("status", { compress: true }),
track: origin.createTrack("status", { compression: "deflate" }),
});
(truck.broadcast.out.active as Moq.Signals.Signal<Moq.Broadcast.Consumer | undefined>).set(origin.consume());
producer.update({
Expand Down
4 changes: 2 additions & 2 deletions demo/carla/web/src/truck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("Truck status", () => {

function statusBroadcast() {
const broadcast = new Moq.Broadcast.Producer();
const track = broadcast.createTrack("status", { compress: true });
const track = broadcast.createTrack("status", { compression: "deflate" });
const producer = new Json.Snapshot.Producer<TruckStatus>({ track });
return { broadcast, producer };
}
Expand Down Expand Up @@ -525,7 +525,7 @@ describe("Truck sessions", () => {
// The truck's status echoing the latch is what lets the session go.
const broadcast = new Moq.Broadcast.Producer();
const producer = new Json.Snapshot.Producer<TruckStatus>({
track: broadcast.createTrack("status", { compress: true }),
track: broadcast.createTrack("status", { compression: "deflate" }),
});
try {
(truck.broadcast.out.active as Moq.Signals.Signal<Moq.Broadcast.Consumer | undefined>).set(
Expand Down
4 changes: 2 additions & 2 deletions doc/bin/relay/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ relay.with_web(web).run().await?;
example to leave DNS before draining, call `with_signals(false)` and fire
`shutdown_trigger()` yourself. The drain reaches only MoQ sessions, so stop any extra listener
(RTMP, SRT, ...) on your own deadline.
- To serve MoQ from your own `moq_tokio::server::Config`, set its `activity`
from `relay.shutdown().activity()` and pass `relay.shutdown().clone()` to
- To serve MoQ from your own `moq_tokio::server::Config`, set its `admission`
from `relay.shutdown().admission()` and pass `relay.shutdown().clone()` to
`Connection::with_shutdown`, so the drain waits for its handshakes too.
- To serve a session from any other moq-net transport, such as the in-memory
one in tests, enable the `test-support` feature, read its SETUP with `moq_net::Server::accept_request` and pass
Expand Down
6 changes: 3 additions & 3 deletions doc/concept/compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Applications still write and read plain frames. A reader whose session cannot
carry compression gets an inflated copy from the relay.

```rust
let info = moq_net::track::Info::default().with_compress(true);
let info = moq_net::track::Info::default().with_compression(moq_net::track::Compression::Deflate);
```

```ts
const track = broadcast.createTrack("state.json", { compress: true });
const track = broadcast.createTrack("state.json", { compression: "deflate" });
```

## When to set it
Expand All @@ -42,7 +42,7 @@ moq-lite 07 is still opt-in, so compressed bytes cross a hop only where both
ends list `moq-lite-07-wip`. Sessions on the default versions, and relay links
among them, carry the inflated frames. Only Rust offers the moq-transport
extension, so a JavaScript or third-party moq-transport peer reads the
inflated copy. A received track's `compress` flag says which form arrived. A
inflated copy. A received track's `compression` says which form arrived. A
datagram track is never compressed.

## Cost on the relay
Expand Down
2 changes: 1 addition & 1 deletion doc/concept/stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ should prefer the canonical name and fall back to the legacy one.
"requests": 3, "sessions_started": 12, "sessions_ended": 10,
"sessions": 12, "sessions_closed": 10,
"sent_bytes": 1048576, "received_bytes": 524288,
"sessions_refused": { "refused": 0, "unavailable": 0, "request": 0, "forbidden": 0, "lan": 0, "expired": 0 },
"sessions_refused": { "refused": 0, "unavailable": 0, "request": 0, "forbidden": 0, "membership": 0, "expired": 0 },
"sessions_failed": { "idle_timeout": 1, "transport": 0, "application": 0, "expired": 0 },
"announces_peak": 40, "subscriptions_peak": 900,
"wire_tx": 2048, "wire_rx": 1024
Expand Down
2 changes: 1 addition & 1 deletion doc/lib/c/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ inside. The header is the reference: each function carries a doc comment.
- **Threading.** Call any function from any thread. Callbacks run on moq-c's runtime thread; the callback and its `user_data` must be safe to use there. Synchronize access to data shared with other threads, and dispatch UI work to your UI thread. Raw publish calls block until the codec takes the frame, which paces a publisher.
- **Zeroed config is the default.** A zeroed `moq_client_config` means the default for every field, so new fields don't break callers. A field whose default isn't zero has a `has_*` flag: `backoff_timeout_us = 0` means "retry forever" only with `has_backoff_timeout = true`.
- **Subscription defaults.** A zeroed `moq_subscription`, a NULL pointer, and `moq_subscription_defaults()` all mean moq-net's defaults, whose zero `delay` starts at the newest group and skips a superseded one at once. Set `delay.max_unlimited` for no subscriber limit, and `delay.min_unstated` to leave the target latency unstated.
- **Compressed tracks.** `moq_track_info.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.
- **Compressed tracks.** `moq_track_info.compression` set to `MOQ_COMPRESSION_DEFLATE` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.
- **fMP4 import.** `MOQ_CONTAINER_FORMAT_FMP4` splits each fragment into one frame per sample.
- **Audio needs cuts.** Video groups at its keyframes, but audio forms a group only where you call `moq_publish_media_cut`: after every frame, or less often to batch frames into fewer groups. Pass that cadence as `moq_audio_init.hint.join_us`.
- **Catalog hints.** Give the catalog what the encoder knows instead of having it estimated: `moq_video_init.hint` (coded size, bitrate, frame rate, join) and `moq_audio_init.hint` (bitrate, join). A supplied bitrate is never re-estimated. `join_us` is the time between join points, the longest span between two group starts: the GOP, or your cut cadence. Leave a field's `has_*` flag false to have it measured. A bitrate or `join_us` flag set with a 0 value returns `MOQ_ERROR_INVALID_CONFIG`.
Expand Down
2 changes: 1 addition & 1 deletion doc/lib/cpp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ screen.reset(); // stopped watching: its share returns to camera

## Compressed tracks

`moq::TrackInfo::compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.
`moq::TrackInfo::compression` set to DEFLATE on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.

## Subscription defaults

Expand Down
4 changes: 2 additions & 2 deletions doc/lib/dart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ Import `package:moq/media.dart` with a prefix for catalogs, encoded-media import
container consumers. `TrackProducer.audio` / `.video` take a broadcast, an init record,
and a `Named` or `Requested` target. `CatalogProducer(broadcast: ...)` owns catalog properties
and sections; it holds the broadcast weakly and fails after the broadcast closes.
Publish JSON tracks with `MoqTrackInfo(compress: true)`; a `package:moq/json.dart` consumer reads one with no option of its own.
Publish JSON tracks with `MoqTrackInfo(compression: MoqCompression.deflate)`; a `package:moq/json.dart` consumer reads one with no option of its own.
A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now.
`SnapshotProducer.update`, `StreamProducer.append`, and `WindowProducer.push` and `pop` require a timestamp on the broadcast clock (`CatalogProducer.now()`), the epoch every track in the broadcast shares, so their track needs a timescale.
`package:moq/json.dart` consumers return `Value` (`value`, `timestamp`) from `next()`; a snapshot consumer
yields each state in order, and `latest()` skips to the newest.
Media times are exact `Timestamp` records, `value` units at `scale` units per second, so a 90 kHz tick survives a
read and republish. `Duration.toTimestamp()` converts exactly; `Timestamp.toDuration()` rounds down to a whole microsecond.
Raw tracks with a `null` timescale are untimed on both publish and receive.
`MoqTrackInfo.compress` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.
`MoqTrackInfo.compression` set to `MoqCompression.deflate` on a raw track sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames.
Whole-frame media writes require caller time; container imports keep their own timeline handling.
Timed raw/data tracks require caller-supplied timestamps. Use `CatalogProducer.now()` to stamp a locally
created event on the broadcast clock; reading it fixes that clock for later media producers.
Expand Down
2 changes: 1 addition & 1 deletion doc/lib/go/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ catalog writes fail with `ErrClosed` after the broadcast closes. Media timestamp
`TimestampFromDuration` converts exactly; `TimestampToDuration` rounds down to a whole nanosecond.
A raw frame without a timestamp stays untimed, which only an untimed track accepts; JSON writes always take one. The library never substitutes zero or now.
Raw tracks with a `nil` timescale are untimed on both publish and receive.
`TrackInfo.Compress` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks.
`TrackInfo.Compression` set to `CompressionDeflate` sends each group DEFLATE-compressed to opt-in `moq-lite-07-wip` peers; other peers, and every reader here, get the original frames. Set it on JSON tracks.
The JSON producers' `Update`, `Append`, `Push`, and `Pop` take a final `moq.Timestamp` on the broadcast clock, the epoch every track in the broadcast shares, so their track needs a timescale.
JSON consumers return a `*Timed` holding the value and that timestamp; `SnapshotConsumer.Latest`
skips to the newest state where `Next` yields each one. A read timestamp is at the track's timescale.
Expand Down
Loading
Loading