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
1 change: 1 addition & 0 deletions cpp/moq/bench/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void throughput(Case c, double budget, std::vector<Result> &results)
std::vector<std::shared_ptr<moq::TrackProducer>> tracks;
std::vector<std::shared_ptr<moq::TrackConsumer>> consumers;
moq::TrackInfo info;
info.max_age = std::chrono::nanoseconds::zero();
info.timescale = 1000000;
for (int p = 0; p < c.publishers; ++p) {
auto track = ok(broadcast->publish_track(std::to_string(p), info));
Expand Down
2 changes: 2 additions & 0 deletions cpp/moq/test/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void timestamp_roundtrip()
{
auto broadcast = ok(moq::BroadcastProducer::init(), "timestamp broadcast");
moq::TrackInfo timed;
timed.max_age = std::chrono::nanoseconds::zero();
timed.timescale = 90000;
auto track = ok(broadcast->publish_track("timed", timed), "publish timed track");
auto consumer = ok(track->consume(std::nullopt), "consume timed track");
Expand Down Expand Up @@ -367,6 +368,7 @@ int main()
CHECK(route->instance_id() && !route->instance_id()->is_minted());
auto broadcast = route->broadcast();
moq::TrackInfo info;
info.max_age = std::chrono::nanoseconds::zero();
info.timescale = 1000000;
auto track = ok(broadcast->publish_track("data", info), "publish_track");
ok(route->announce(), "announce");
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(compression: MoqCompression.deflate)`, and a consumer
/// track's: publish JSON with `TrackInfo(compression: Compression.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, compression: MoqCompression.deflate),
/// info: TrackInfo(timescale: 1000, compression: Compression.deflate()),
/// ),
/// config: moq_json.SnapshotConfig(),
/// );
Expand Down
35 changes: 29 additions & 6 deletions dart/moq/lib/src/aliases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import 'package:moq_ffi/moq_ffi.dart';
// Re-export the UniFFI types without their `Moq` prefix, so consumers spell
// them the way the Rust API does. These are type aliases, not wrappers: the
// values are the exact same objects, so every generated method applies
// unchanged and the prefixed names stay valid. `Delay`, `Subscription`, and
// `Timestamp` are extension types instead, which are the same objects too but
// add constructors: an omitted delay bound is the zero moq-net defaults to,
// where the generated record leaves it null, and a timestamp is built either
// scaled or [Timestamp.unscaled], as in Rust.
// unchanged and the prefixed names stay valid. `Delay`, `Subscription`,
// `TrackInfo`, and `Timestamp` are extension types instead, which are the same
// objects too but add constructors: an omitted delay bound or max age is the
// zero moq-net defaults to, where the generated record leaves it null (no
// limit), and a timestamp is built either scaled or [Timestamp.unscaled], as in
// Rust.
//
// Four types are deliberately not aliased, because the unprefixed name is
// already taken where this package is used:
Expand Down Expand Up @@ -216,8 +217,30 @@ typedef Position = MoqPosition;
/// Options for fetching one past group by sequence.
typedef FetchGroupOptions = MoqFetchGroupOptions;

/// How a track's frames are compressed on the wire: `Compression.deflate()`, or null in
/// [TrackInfo] for none. Compare a received one by `name()`.
typedef Compression = MoqCompression;

/// Delivery settings for a raw track: priority, ordering, latency budget, and timescale.
typedef TrackInfo = MoqTrackInfo;
extension type TrackInfo._(MoqTrackInfo _info) implements MoqTrackInfo {
/// `maxAge` is how long a superseded group stays fresh, defaulting to zero, moq-net's
/// default, which serves only the live edge. An explicit null sets no publisher limit.
TrackInfo({
int priority = 0,
Duration? maxAge = Duration.zero,
int? refresh,
int? timescale,
MoqCompression? compression,
}) : this._(
MoqTrackInfo(
priority: priority,
maxAge: maxAge,
refresh: refresh,
timescale: timescale,
compression: compression,
),
);
}

/// Divides one connection's send estimate among the tracks sharing it.
typedef Allocator = MoqAllocator;
Expand Down
29 changes: 6 additions & 23 deletions dart/moq/lib/src/surface.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import 'package:moq_ffi/moq_ffi.dart';

/// The platform image backing a `DecodedFrame`, when `DecoderOutput` asked for one.
///
/// Switch on it with a default case, since new platforms add kinds.
abstract class Surface {
const Surface._();
}
/// The platform image backing a `DecodedFrame`, when `DecoderOutput` asked for one: a
/// [PixelBuffer] on macOS and iOS, or an [UnknownSurface] for a kind this version cannot name yet.
typedef Surface = MoqVideoSurface;

/// A borrowed `CVPixelBufferRef` address (macOS and iOS), valid while its `DecodedFrame` lives.
final class PixelBuffer extends Surface {
/// The address of the `CVPixelBufferRef`.
final int pointer;
typedef PixelBuffer = PixelBufferMoqVideoSurface;

const PixelBuffer._(this.pointer) : super._();
}

/// A surface kind this version of the package does not know yet.
final class UnknownSurface extends Surface {
const UnknownSurface._() : super._();
}

/// Maps a generated surface to [Surface], so a variant this package predates is an [UnknownSurface].
Surface? surfaceFrom(MoqVideoSurface? surface) => switch (surface) {
null => null,
PixelBufferMoqVideoSurface(:final pointer) => PixelBuffer._(pointer),
_ => const UnknownSurface._(),
};
/// A surface kind this version of the package cannot name yet.
typedef UnknownSurface = UnknownMoqVideoSurface;
4 changes: 2 additions & 2 deletions dart/moq/lib/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef Frame = MoqVideoFrame;
/// One encoded access unit from an [Encoder].
typedef Packet = MoqVideoPacket;

/// H.264 or H.265.
/// Selects the video encoder codec. Build one with `Codec.h264()` or `Codec.h265()`.
typedef Codec = MoqVideoCodec;

/// A CPU pixel layout (I420 or RGBA).
Expand Down Expand Up @@ -162,7 +162,7 @@ final class DecodedFrame {
_inner.pixels(format: format);

/// The decoder's platform surface, or null when the frame is in CPU memory.
Surface? surface() => surfaceFrom(_inner.surface());
Surface? surface() => _inner.surface();

/// Release the frame's surface back to the decoder.
void dispose() => _inner.dispose();
Expand Down
52 changes: 13 additions & 39 deletions dart/moq/test/moq_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:moq/audio.dart' as moq_audio;
import 'package:moq/media.dart' as moq_media;
import 'package:moq/json.dart' as moq_json;
import 'package:moq/moq.dart';
import 'package:moq/src/surface.dart' show surfaceFrom;
import 'package:moq/video.dart' as moq_video;
import 'package:test/test.dart';

Expand Down Expand Up @@ -158,19 +157,20 @@ void main() {
broadcast.close();
});

test('an omitted max age is zero and the unlimited flag sets none', () {
test('an omitted max age is zero and a null one sets none', () {
final broadcast = BroadcastProducer();
final omitted = broadcast
.publishTrack(name: 'omitted', info: null)
.consume(subscription: null)
.info();
expect(omitted.maxAge, Duration.zero);
for (final (i, info) in [null, TrackInfo()].indexed) {
final omitted = broadcast
.publishTrack(name: 'omitted$i', info: info)
.consume(subscription: null)
.info();
expect(omitted.maxAge, Duration.zero);
}
final unlimited = broadcast
.publishTrack(name: 'unlimited', info: TrackInfo(maxAgeUnlimited: true))
.publishTrack(name: 'unlimited', info: TrackInfo(maxAge: null))
.consume(subscription: null)
.info();
expect(unlimited.maxAge, isNull);
expect(unlimited.maxAgeUnlimited, isTrue);
broadcast.close();
});

Expand Down Expand Up @@ -204,7 +204,7 @@ void main() {
final broadcast = BroadcastProducer();
final track = broadcast.publishTrack(
name: 'backlog',
info: TrackInfo(maxAgeUnlimited: true, timescale: 1000000),
info: TrackInfo(maxAge: null, timescale: 1000000),
);
for (var ms = 0; ms < 3; ms++) {
final group = track.appendGroup();
Expand Down Expand Up @@ -912,10 +912,7 @@ void main() {
broadcast: broadcast,
track: broadcast.publishTrack(
name: 'status',
info: MoqTrackInfo(
timescale: 1000000,
compression: MoqCompression.deflate,
),
info: TrackInfo(timescale: 1000000, compression: Compression.deflate()),
),
config: moq_json.SnapshotConfig(),
);
Expand Down Expand Up @@ -951,10 +948,7 @@ void main() {
final producer = moq_json.WindowProducer(
track: broadcast.publishTrack(
name: 'log',
info: MoqTrackInfo(
timescale: 1000000,
compression: MoqCompression.deflate,
),
info: TrackInfo(timescale: 1000000, compression: Compression.deflate()),
),
config: moq_json.WindowConfig(),
);
Expand Down Expand Up @@ -1015,7 +1009,7 @@ void main() {
framerate: moq_video.FrameRate(numerator: 30000, denominator: 1001),
),
output: moq_video.EncoderOutput(
codec: moq_video.Codec.h264,
codec: moq_video.Codec.h264(),

kind: moq_video.SoftwareEncoder(),
),
Expand Down Expand Up @@ -1079,14 +1073,6 @@ void main() {
broadcast.close();
});

// A surface kind the package predates maps to the fallback arm instead of failing.
test('video surface maps an unknown kind', () {
expect(surfaceFrom(null), isNull);
final pixels = surfaceFrom(PixelBufferMoqVideoSurface(7));
expect((pixels as moq_video.PixelBuffer).pointer, 7);
expect(surfaceFrom(_FutureSurface()), isA<moq_video.UnknownSurface>());
});

// A fixed playout delay is reported back as is, and an estimated one moves as frames are read.
test('audio consumer reports its playout delay', () async {
final broadcast = BroadcastProducer();
Expand Down Expand Up @@ -1184,15 +1170,3 @@ void main() {
broadcast.close();
});
}

/// Stands in for a generated surface variant this package predates.
final class _FutureSurface extends MoqVideoSurface {
@override
RustBuffer lower() => throw UnimplementedError();

@override
int allocationSize() => throw UnimplementedError();

@override
int write(Uint8List buf) => throw UnimplementedError();
}
Loading