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
26 changes: 26 additions & 0 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8382,6 +8382,7 @@ class FfiConverterMoqTrackProducer {
abstract class MoqTrackRequestInterface {
void abort({required int errorCode});
MoqTrackProducer accept({required MoqTrackInfo? info});
MoqTrackDemand demand();
MoqTrackDynamic dynamic_();
String name();
}
Expand Down Expand Up @@ -8431,6 +8432,17 @@ class MoqTrackRequest implements MoqTrackRequestInterface {
);
}

MoqTrackDemand demand() {
return rustCallWithLifter(
(status) => uniffi_moq_ffi_fn_method_moqtrackrequest_demand(
uniffiClonePointer(),
status,
),
FfiConverterMoqTrackDemand.lift,
moqExceptionErrorHandler,
);
}

MoqTrackDynamic dynamic_() {
return rustCallWithLifter(
(status) => uniffi_moq_ffi_fn_method_moqtrackrequest_dynamic(
Expand Down Expand Up @@ -11969,6 +11981,14 @@ external Pointer<Void> uniffi_moq_ffi_fn_method_moqtrackrequest_accept(
Pointer<RustCallStatus> uniffiStatus,
);

@Native<Pointer<Void> Function(Pointer<Void>, Pointer<RustCallStatus>)>(
assetId: _uniffiAssetId,
)
external Pointer<Void> uniffi_moq_ffi_fn_method_moqtrackrequest_demand(
Pointer<Void> ptr,
Pointer<RustCallStatus> uniffiStatus,
);

@Native<Pointer<Void> Function(Pointer<Void>, Pointer<RustCallStatus>)>(
assetId: _uniffiAssetId,
)
Expand Down Expand Up @@ -12923,6 +12943,9 @@ external int uniffi_moq_ffi_checksum_method_moqtrackrequest_abort();
@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_method_moqtrackrequest_accept();

@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_method_moqtrackrequest_demand();

@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_method_moqtrackrequest_dynamic();

Expand Down Expand Up @@ -13448,6 +13471,9 @@ void _checkApiChecksums() {
if (uniffi_moq_ffi_checksum_method_moqtrackrequest_accept() != 31841) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqtrackrequest_demand() != 3618) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqtrackrequest_dynamic() != 24801) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
Expand Down
4 changes: 4 additions & 0 deletions doc/lib/cpp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ Never block the executor. A continuation or resumed coroutine that calls
which deadlocks. `moq::inline_executor` runs a continuation right where the
future completed, which is the executor thread.

## Track demand

Obtain a dynamic track request’s `demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Shutdown

`moq::shutdown()` stops the `moq-ffi` runtime thread, then the executor.
Expand Down
1 change: 1 addition & 0 deletions doc/lib/dart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ one to one; the API reference has the names.
- **Live encoder timing.** After writing a frame you encoded yourself, call `flush(timestampUs: ...)` with the same timestamp so the catalog advertises your jitter. Skip it for file and network imports. On a seek or pause, call `discontinuity()`, then keep timestamps moving forward and resume video on a keyframe.
- **Closing.** `await moq.close()` or `session.shutdown()` gives finished tracks up to one second to deliver and fails if they did not. `session.cancel(code: 0)` closes at once. Finish or abort live tracks first. Cancelling a stream subscription releases its native cursor.
- **Stats.** `session.stats()` reports `rttUs`, `estimatedSendRateBps`, `estimatedRecvRateBps`, and the byte and packet counters (`bytesSent`, `bytesReceived`, `bytesLost`, `packetsSent`, `packetsReceived`, `packetsLost`). A field is `null` when the transport does not report it, which is not the same as zero.
- **Track demand.** Obtain a dynamic track request’s `demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Reference

Expand Down
1 change: 1 addition & 0 deletions doc/lib/go/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ one to one; the API reference has the names.
- **Decoded frames hold decoder buffers.** `Close` each `VideoDecodedFrame` promptly, or the decoder stalls. `Resize` is best effort, so read each frame's `Width()` and `Height()`.
- **Closing.** `client.Close()` gives finished tracks up to one second to deliver and returns an error if they did not. `session.Shutdown(ctx)` does the same, and `session.Cancel(code)` closes at once. Finish or abort live tracks first.
- **Stats.** `Session().Stats()` reports `RTT`, `EstimatedSendRateBps`, `EstimatedRecvRateBps`, and the byte and packet counters (`BytesSent`, `BytesReceived`, `BytesLost`, `PacketsSent`, `PacketsReceived`, `PacketsLost`). A field is nil when the transport does not report it, which is not the same as zero.
- **Track demand.** Obtain a dynamic track request’s `Demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Reference

Expand Down
1 change: 1 addition & 0 deletions doc/lib/kt/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ one to one; the API reference has the names.
- **Decoded frames hold decoder buffers.** `close()` each frame from `decodeVideo` promptly (or `use { }` it), or the decoder stalls. `resize` is best effort, so read each frame's `width()` and `height()`.
- **Closing.** Suspending `moq.shutdown()` gives finished tracks up to one second to deliver and throws if they did not. `Moq.close()`, and so `use { }`, cancels at once. Finish or abort live tracks first.
- **Stats.** `session.stats()` reports `rttUs`, `estimatedSendRateBps`, `estimatedRecvRateBps`, and the byte and packet counters (`bytesSent`, `bytesReceived`, `bytesLost`, `packetsSent`, `packetsReceived`, `packetsLost`). A field is `null` when the transport does not report it, which is not the same as zero.
- **Track demand.** Obtain a dynamic track request’s `demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Reference

Expand Down
1 change: 1 addition & 0 deletions doc/lib/py/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ one to one; the API reference has the names.
- **Decoded frames hold decoder buffers.** Drop each frame from `decode_video` promptly, or the decoder stalls. `resize` is best effort, so read each frame's `width()` and `height()`.
- **Closing.** `await session.shutdown()` gives finished tracks up to one second to deliver and raises if they did not. `cancel(code)` closes at once. Finish or abort live tracks first.
- **Stats.** `session.stats()` reports `rtt`, `estimated_send_rate_bps`, `estimated_recv_rate_bps`, and the byte and packet counters (`bytes_sent`, `bytes_received`, `bytes_lost`, `packets_sent`, `packets_received`, `packets_lost`). A field is `None` when the transport does not report it, which is not the same as zero.
- **Track demand.** Obtain a dynamic track request’s `demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Reference

Expand Down
1 change: 1 addition & 0 deletions doc/lib/swift/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ one to one; the API reference has the names.
- **Decoded frames hold decoder buffers.** Release each frame from `decodeVideo` promptly, or the decoder stalls. `resize` is best effort, so read each frame's `width()` and `height()`.
- **Closing.** `try await session.shutdown()` gives finished tracks up to one second to deliver and throws if they did not. `session.cancel(code:)` closes at once. Finish or abort live tracks first.
- **Stats.** `session.stats()` reports `rttUs`, `estimatedSendRateBps`, `estimatedRecvRateBps`, and the byte and packet counters (`bytesSent`, `bytesReceived`, `bytesLost`, `packetsSent`, `packetsReceived`, `packetsLost`). A field is `nil` when the transport does not report it, which is not the same as zero.
- **Track demand.** Obtain a dynamic track request’s `demand()` before accepting it to watch subscribers through the handoff to its producer. The watch does not keep the track alive and ends when the track closes or the request is rejected.

## Reference

Expand Down
9 changes: 9 additions & 0 deletions go/wrapper/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func (r *TrackRequest) Name() (string, error) {
return r.inner.Name()
}

// Demand watches this track's subscribers, including after accepting it.
func (r *TrackRequest) Demand() (*TrackDemand, error) {
inner, err := r.inner.Demand()
if err != nil {
return nil, err
}
return &TrackDemand{inner: inner}, nil
}

// Dynamic creates a fetch handler before accepting this requested track.
func (r *TrackRequest) Dynamic() (*TrackDynamic, error) {
inner, err := r.inner.Dynamic()
Expand Down
4 changes: 4 additions & 0 deletions py/moq-rs/moq/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def accept(self, info: TrackInfo | None = None) -> TrackProducer:
"""
return TrackProducer(self._inner.accept(_track_info(info)))

def demand(self) -> TrackDemand:
"""Watch this track's subscribers, including after accepting it."""
return TrackDemand(self._inner.demand())

def dynamic(self) -> TrackDynamic:
"""Create a fetch handler before accepting this requested track."""
return TrackDynamic(self._inner.dynamic())
Expand Down
8 changes: 8 additions & 0 deletions py/moq-rs/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ async def test_dynamic_track_request():

request = await asyncio.wait_for(dynamic.requested_track(), timeout=5.0)
assert request.name == "events"
demand = request.demand()
assert demand.is_used()

# Accept the request as a raw track (which unblocks the subscribe), then write.
track = request.accept()
Expand All @@ -517,7 +519,13 @@ async def test_dynamic_track_request():
assert frame is not None
assert frame.payload == payload

track_consumer.cancel()
await asyncio.wait_for(demand.unused(), timeout=5.0)
track.finish()
broadcast.close()
del track
with pytest.raises(moq.Error.Closed): # type: ignore[attr-defined]
await asyncio.wait_for(demand.used(), timeout=5.0)


async def test_dynamic_track_request_can_publish_media():
Expand Down
1 change: 0 additions & 1 deletion quest/m1/ffi-shape/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ runs `just test interop --all`.
- [Codecs](/quest/m1/ffi-shape/codec.md) - audio and video producers, codec-only encoders, and decoders move under their own namespaces, named as in Rust; binding releases wait for it
- [Named error fields](/quest/m1/ffi-shape/error-fields.md) - `MoqError` variants name their fields, so no binding exposes a positional `v1`
- [Bindings](/quest/m0/broadcast-epoch/bindings.md) - the wrappers expose epochs and rename `session.epoch()`, on the reshaped wrappers
- [Track request demand](/quest/m1/ffi-shape/track-request-demand.md) - `MoqTrackRequest::demand()` in moq-ffi and every wrapper, built on group request demand and coordinated with Bindings
- [Layers guide](/quest/m1/ffi-shape/layers-guide.md) - a `doc/lib` page maps each Rust layer to every binding's module, once Codecs adds `audio` and `video`
34 changes: 0 additions & 34 deletions quest/m1/ffi-shape/track-request-demand.md

This file was deleted.

4 changes: 0 additions & 4 deletions quest/m1/group-demand-accept.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ docs in Rust, Go, Python, and Swift. Hand-written moq-c is frozen, so it gets
no change.

Public API: behavior only (the error a demand wait returns). Wire: none.

## Related

- [Track request demand](/quest/m1/ffi-shape/track-request-demand.md) - its demand should end the same way
6 changes: 6 additions & 0 deletions rs/moq-ffi/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ impl MoqTrackRequest {
Ok(request.name().to_string())
}

/// Watch this track's subscribers, including after the request is accepted.
pub fn demand(&self) -> Result<Arc<MoqTrackDemand>, MoqError> {
let guard = self.inner.lock().unwrap();
Ok(MoqTrackDemand::new(guard.as_ref().ok_or(MoqError::Closed)?.demand()))
}

/// Create a handler for uncached group fetches before accepting this track.
///
/// Obtain and retain this handle before `accept()` when the track itself was
Expand Down
39 changes: 39 additions & 0 deletions rs/moq-ffi/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,45 @@ async fn json_consumer_takes_an_unread_track() {
));
}

#[tokio::test]
async fn track_request_demand_survives_accept() {
let broadcast = MoqBroadcastProducer::new().unwrap();
let dynamic = broadcast.dynamic().unwrap();
let consumer = broadcast.consume().unwrap();
let subscribe = tokio::spawn(async move { consumer.subscribe_track("events".into(), None).await });
let request = dynamic.requested_track().await.unwrap();
let demand = request.demand().unwrap();
assert_eq!(demand.name(), "events");
assert!(demand.is_used());
let track = request.accept(None).unwrap();
assert!(matches!(request.demand(), Err(MoqError::Closed)));
let consumer = subscribe.await.unwrap().unwrap();
demand.used().await.unwrap();
consumer.cancel();
demand.unused().await.unwrap();
let consumer = track.consume(None).unwrap();
demand.used().await.unwrap();
consumer.cancel();
demand.unused().await.unwrap();
drop(track);
broadcast.close().unwrap();
assert!(matches!(demand.used().await, Err(MoqError::Closed)));
}

#[tokio::test]
async fn track_request_demand_ends_on_rejection() {
let broadcast = MoqBroadcastProducer::new().unwrap();
let dynamic = broadcast.dynamic().unwrap();
let consumer = broadcast.consume().unwrap();
let subscribe = tokio::spawn(async move { consumer.subscribe_track("events".into(), None).await });
let request = dynamic.requested_track().await.unwrap();
let demand = request.demand().unwrap();
request.abort(404).unwrap();
assert!(subscribe.await.unwrap().is_err());
assert!(demand.used().await.is_err());
assert!(matches!(request.demand(), Err(MoqError::Closed)));
}

#[tokio::test]
async fn dynamic_track_request() {
let broadcast = MoqBroadcastProducer::new().unwrap();
Expand Down
5 changes: 5 additions & 0 deletions swift/Sources/Moq/Dynamic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public final class TrackRequest: Sendable {
TrackProducer(try ffi.accept(info: info))
}

/// Watch this track's subscribers, including after accepting it.
public func demand() throws -> TrackDemand {
TrackDemand(try ffi.demand())
}

/// Create a fetch handler before accepting this requested track.
public func dynamic() throws -> TrackDynamic {
TrackDynamic(try ffi.dynamic())
Expand Down
Loading