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
2 changes: 1 addition & 1 deletion bench/browser/page/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function publish(config: Media): Promise<void> {
codec: config.codec,
frameRate: config.fps,
maxPixels: config.width * config.height,
keyframeInterval: Milli(config.keyframe_ms),
join: Milli(config.keyframe_ms),
maxBitrate: config.bitrate,
},
});
Expand Down
6 changes: 0 additions & 6 deletions dart/moq/lib/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ typedef PixelBuffer = PixelBufferMoqVideoSurface;
/// One encoded access unit from an [Encoder].
typedef Packet = MoqVideoPacket;

/// How pictures are split into independently decodable groups.
typedef Gop = MoqVideoGop;

/// A keyframe every `interval` pictures.
typedef Keyframe = KeyframeMoqVideoGop;

/// H.264 or H.265.
typedef Codec = MoqVideoCodec;

Expand Down
149 changes: 11 additions & 138 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4729,12 +4729,12 @@ class FfiConverterMoqVideoEncoderInput {
class MoqVideoEncoderOutput {
final MoqVideoCodec codec;
final int? bitrate;
final MoqVideoGop? gop;
final Duration? join;
final MoqVideoEncoderKind kind;
MoqVideoEncoderOutput({
required this.codec,
this.bitrate = null,
this.gop = null,
this.join = null,
required this.kind,
});
}
Expand All @@ -4756,11 +4756,11 @@ class FfiConverterMoqVideoEncoderOutput {
);
final bitrate = bitrate_lifted.value;
new_offset += bitrate_lifted.bytesRead;
final gop_lifted = FfiConverterOptionalMoqVideoGop.read(
final join_lifted = FfiConverterOptionalDuration.read(
Uint8List.view(buf.buffer, new_offset),
);
final gop = gop_lifted.value;
new_offset += gop_lifted.bytesRead;
final join = join_lifted.value;
new_offset += join_lifted.bytesRead;
final kind_lifted = FfiConverterMoqVideoEncoderKind.read(
Uint8List.view(buf.buffer, new_offset),
);
Expand All @@ -4770,7 +4770,7 @@ class FfiConverterMoqVideoEncoderOutput {
MoqVideoEncoderOutput(
codec: codec,
bitrate: bitrate,
gop: gop,
join: join,
kind: kind,
),
new_offset - buf.offsetInBytes,
Expand All @@ -4781,7 +4781,7 @@ class FfiConverterMoqVideoEncoderOutput {
final total_length =
FfiConverterMoqVideoCodec.allocationSize(value.codec) +
FfiConverterOptionalUInt64.allocationSize(value.bitrate) +
FfiConverterOptionalMoqVideoGop.allocationSize(value.gop) +
FfiConverterOptionalDuration.allocationSize(value.join) +
FfiConverterMoqVideoEncoderKind.allocationSize(value.kind) +
0;
final buf = Uint8List(total_length);
Expand All @@ -4799,8 +4799,8 @@ class FfiConverterMoqVideoEncoderOutput {
value.bitrate,
Uint8List.view(buf.buffer, new_offset),
);
new_offset += FfiConverterOptionalMoqVideoGop.write(
value.gop,
new_offset += FfiConverterOptionalDuration.write(
value.join,
Uint8List.view(buf.buffer, new_offset),
);
new_offset += FfiConverterMoqVideoEncoderKind.write(
Expand All @@ -4813,7 +4813,7 @@ class FfiConverterMoqVideoEncoderOutput {
static int allocationSize(MoqVideoEncoderOutput value) {
return FfiConverterMoqVideoCodec.allocationSize(value.codec) +
FfiConverterOptionalUInt64.allocationSize(value.bitrate) +
FfiConverterOptionalMoqVideoGop.allocationSize(value.gop) +
FfiConverterOptionalDuration.allocationSize(value.join) +
FfiConverterMoqVideoEncoderKind.allocationSize(value.kind) +
0;
}
Expand Down Expand Up @@ -8888,86 +8888,6 @@ class NamedMoqVideoEncoderKind extends MoqVideoEncoderKind {
}
}

abstract class MoqVideoGop {
RustBuffer lower();
int allocationSize();
int write(Uint8List buf);
}

class FfiConverterMoqVideoGop {
static MoqVideoGop lift(RustBuffer buffer) {
return FfiConverterMoqVideoGop.read(buffer.asUint8List()).value;
}

static LiftRetVal<MoqVideoGop> read(Uint8List buf) {
final index = buf.buffer.asByteData(buf.offsetInBytes).getInt32(0);
final subview = Uint8List.view(buf.buffer, buf.offsetInBytes + 4);
switch (index) {
case 1:
final lifted = KeyframeMoqVideoGop.read(subview);
return LiftRetVal<MoqVideoGop>(
lifted.value,
lifted.bytesRead - subview.offsetInBytes + 4,
);
default:
throw UniffiInternalError(
UniffiInternalError.unexpectedEnumCase,
"Unable to determine enum variant",
);
}
}

static RustBuffer lower(MoqVideoGop value) {
return value.lower();
}

static int allocationSize(MoqVideoGop value) {
return value.allocationSize();
}

static int write(MoqVideoGop value, Uint8List buf) {
return value.write(buf) - buf.offsetInBytes;
}
}

class KeyframeMoqVideoGop extends MoqVideoGop {
final int interval;
KeyframeMoqVideoGop(int this.interval);
KeyframeMoqVideoGop._(int this.interval);
static LiftRetVal<KeyframeMoqVideoGop> read(Uint8List buf) {
int new_offset = buf.offsetInBytes;
final interval_lifted = FfiConverterUInt32.read(
Uint8List.view(buf.buffer, new_offset),
);
final interval = interval_lifted.value;
new_offset += interval_lifted.bytesRead;
return LiftRetVal(KeyframeMoqVideoGop._(interval), new_offset);
}

@override
RustBuffer lower() {
final buf = Uint8List(allocationSize());
write(buf);
return toRustBuffer(buf);
}

@override
int allocationSize() {
return FfiConverterUInt32.allocationSize(interval) + 4;
}

@override
int write(Uint8List buf) {
buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 1);
int new_offset = buf.offsetInBytes + 4;
new_offset += FfiConverterUInt32.write(
interval,
Uint8List.view(buf.buffer, new_offset),
);
return new_offset;
}
}

enum MoqVideoPixelFormat { i420, rgba }

class FfiConverterMoqVideoPixelFormat {
Expand Down Expand Up @@ -18889,53 +18809,6 @@ class FfiConverterOptionalMoqTrackInfo {
}
}

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

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

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

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

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

class FfiConverterOptionalMoqVideoHint {
static MoqVideoHint? lift(RustBuffer buf) {
return FfiConverterOptionalMoqVideoHint.read(buf.asUint8List()).value;
Expand Down Expand Up @@ -24982,7 +24855,7 @@ void _checkApiChecksums() {
if (uniffi_moq_ffi_checksum_method_moqvideoencoder_set_bitrate() != 34315) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqvideoproducer_cut() != 18974) {
if (uniffi_moq_ffi_checksum_method_moqvideoproducer_cut() != 56974) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqvideoproducer_demand() != 283) {
Expand Down
2 changes: 1 addition & 1 deletion demo/web/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function encoderConfig(effect: Signals.Effect, target: VideoTarget): Video.Confi
codec: effect.get(codec),
maxPixels: target.width && target.height ? target.width * target.height : undefined,
maxBitrate: br != null ? br * 1000 : undefined,
keyframeInterval: kf != null ? Milli(kf) : undefined,
join: kf != null ? Milli(kf) : undefined,
frameRate: target.frameRate,
};
}
Expand Down
2 changes: 1 addition & 1 deletion doc/bin/hls.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ support the publisher's codecs.

What that means for you:

- **The publisher declares the interval.** Only a broadcast whose catalog carries `media.join.interval` gets playlists. Rust publishers built on `moq-mux` (the CLI, the RTMP, SRT, and WebRTC gateways, and the native bindings) declare it: an encoder that knows its GOP passes it as a hint, and an ingest without one measures each track over its first second or group, whichever is longer, then declares the longest. `@moq/publish` declares its keyframe interval.
- **The publisher declares the interval.** Only a broadcast whose catalog carries `media.join.interval` gets playlists. Rust publishers built on `moq-mux` (the CLI, the RTMP, SRT, and WebRTC gateways, and the native bindings) declare it: an encoder that knows its GOP passes it as a hint, and an ingest without one measures each track over its first second or group, whichever is longer, then declares the longest. `@moq/publish` declares its encoders' `join`.
- **Every rendition shares the grid.** A group spans from its first frame's timestamp to the next group's and belongs to the first grid line it contains, or, containing none, the line it starts after. Segment N therefore starts at the group containing N times the segment length, every rendition numbers its segments alike, and each cuts its boundaries at its own keyframes. A grid line no group starts a segment at, because a GOP ran past it or the content paused, is listed as an `EXT-X-GAP` so the numbering never skips: on a 2 s grid, a GOP from 0 to 7 s is segment 0, segments 1 and 2 are gaps, and the next GOP starts segment 3. Timestamps that go back start a discontinuity on that rendition alone; `EXT-X-PROGRAM-DATE-TIME`, written after every discontinuity when the catalog has a clock, lets players resync.
- **Include media starts on selection.** The HTTP multivariant playlist reads each root `include` entry's catalog and lists its audio and video beside the broadcast's own. An include shares the broadcast's timeline: its renditions are segmented on the broadcast's join interval and clock, whatever its own catalog declares, so publish it on the same timestamps. One not yet routed is listed once its broadcast is announced. Reading its catalog starts no encoding: only a request to one of its rendition URLs subscribes to that rendition's media. Demand lasts through active responses and, after the last one finishes, for three target durations or the playlist window plus one target duration, whichever is longer (20 s by default); a later request starts it again. The broadcast's own renditions stay subscribed. A segment is servable for as long as the relay's [cache](/bin/relay/config#cache) retains it. Keep `--window` (the playlist length, default 16 s) within that retention and within the media's max age (30 s by default), after which a superseded segment's groups are stale.
- **Live joins cost the window.** The exporter subscribes 30 s behind the live edge and lists at most 256 segments. One joining partway through a segment lists nothing before the first segment it sees start.
Expand Down
2 changes: 1 addition & 1 deletion doc/concept/hang.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ A few things the catalog can express beyond decoder config:
- **Spatial media.** A video rendition may carry `projection` (flat `rectilinear`, or `equirectangular` with the degrees of longitude it spans, 180 for VR180) and `stereo` (`mono`, `left-right`, or `top-bottom` frame packing), and an audio rendition may carry `layout: "ambisonic"` for AmbiX channels. Readers treat a value they don't recognize as absent. Nothing in `@moq/watch` renders them yet.
- **Disabled renditions.** An audio or video rendition with `enabled: false` has no new frames coming, and a player must not select it. A subscriber may still get audio retained from before the disable, as when it subscribed a moment earlier. Disabling a rendition in `@moq/publish`, as hiding video does, keeps it in the catalog this way rather than removing it, so it is a one-field update; a disabled video rendition encodes one black keyframe first, so a player that predates the field shows black instead of a frozen picture. The field is written only when false. The older video `stalled` field is no longer written, and readers ignore it. A muted `@moq/publish` microphone is not disabled: it stays enabled and sends nothing, ending each utterance with a discontinuity marker, so listeners stay subscribed and play the gap as intentional silence.
- **Preference.** A video rendition may carry a signed `preference`, default `0`. A player keeps only the highest preference it can decode, then picks by size and bitrate within it, as do the single-rendition egresses (RTMP play, WHEP, FLV, the transcoder's source). A publisher that adds its own H.264 copy of an H.265 source marks the copy `-1`, so only a viewer that can't decode H.265 pulls it. Picking a rendition by name still overrides it. The field is written only when nonzero.
- **Join interval.** The root `media.join.interval` promises that every audio and video track starts a group at least that often: the longest GOP any of them publishes. It is fixed for the broadcast, and the [HLS gateway](/bin/hls) numbers every rendition's segments on the grid it fixes, segments the smallest whole multiple of it at least a second long, from each group's first timestamp, so renditions share segment numbers. A publisher that knows its GOP declares it; Rust publishers (`moq-mux` and everything built on it) without one measure each track over its first second or group, whichever is longer, and `@moq/publish` declares its keyframe interval. A broadcast without it gets no HLS playlists.
- **Join interval.** The root `media.join.interval` promises that every audio and video track starts a group at least that often: the longest GOP any of them publishes. It is fixed for the broadcast, and the [HLS gateway](/bin/hls) numbers every rendition's segments on the grid it fixes, segments the smallest whole multiple of it at least a second long, from each group's first timestamp, so renditions share segment numbers. A publisher that knows its GOP declares it; Rust publishers (`moq-mux` and everything built on it) without one measure each track over its first second or group, whichever is longer, and `@moq/publish` declares its encoders' `join`. A broadcast without it gets no HLS playlists.
- **Clock.** The optional `media.clock` maps PTS zero to wall time so every media track shares one fixed epoch after timescale conversion. Publish independent sources as sibling broadcasts under one prefix, such as `robot/front.hang` and `robot/rear.hang`; each broadcast's audio and video entries are renditions of that source. In one Rust publisher, pass the same `moq_mux::Clock` to each `catalog::Config::with_clock`; JS publishers on one page already share the page clock. Consumers discover the siblings by prefix and align their timestamps through the advertised wall mapping; `@moq/watch` plays one broadcast at a time.
- **Version.** The root `version` is the oldest moq-hang draft that reads the catalog correctly, written only when a field needs one newer than 03: a `track` that differs from its ID, or a video `warmup`. Readers ignore fields they don't know, but refuse a `version` above their own with a typed "unsupported catalog version" error, so a player can say to upgrade instead of misreading the catalog. An additive field never raises it.
- **Extensions.** The root is a loose object. Applications add their own sections (`scte35`, for example) next to the ones hang defines, optionally naming a track that carries the data. Every library exposes a way to write your section without clobbering the built-in ones, and readers ignore what they don't know.
Expand Down
4 changes: 2 additions & 2 deletions doc/lib/c/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ inside. The header is the reference: each function carries a doc comment.
- **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.
- **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.group_duration_us`.
- **Catalog hints.** Give the catalog what the encoder knows instead of having it estimated: `moq_video_init.hint` (coded size, bitrate, frame rate, group duration) and `moq_audio_init.hint` (bitrate, group duration). A supplied bitrate is never re-estimated. `group_duration_us` is 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 `group_duration_us` flag set with a 0 value returns `MOQ_ERROR_INVALID_CONFIG`.
- **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`.
- **Discovery.** Announcement captures are always a list of wildcard matches, empty when the filter has no wildcards.
- **Ending cleanly.** When the input ends, finish every track, then call `moq_publish_catalog_finish()` to finish the catalog, which ends the content. The broadcast stays announced and keeps serving the finished tracks, so a subscriber still catching up can drain them, until `moq_publish_close()` or `moq_route_free()` takes it offline. How long to keep it up is yours to decide. A track still open at the close ends with `UNROUTABLE` (an internal error over moq-transport, which has no such code), and its handle is released. Readers follow a publisher's runs by announcement, not by that error: see [identity and recovery](/concept/identity).
- **Timeline breaks.** On a seek or pause, call `moq_publish_media_discontinuity`, then keep timestamps moving forward and resume video on a keyframe.
Expand Down
Loading
Loading