pub struct Producer { /* private fields */ }Expand description
A producer for a track, used to create new groups.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn create_group(&mut self, group: Info) -> Result<Producer>
pub fn create_group(&mut self, group: Info) -> Result<Producer>
Create a new group with the given sequence number.
Sourcepub fn append_group(&mut self) -> Result<Producer>
pub fn append_group(&mut self) -> Result<Producer>
Create a new group with the next sequence number.
Sourcepub fn append_datagram<B: IntoBytes>(
&mut self,
timestamp: Timestamp,
payload: B,
) -> Result<u64>
pub fn append_datagram<B: IntoBytes>( &mut self, timestamp: Timestamp, payload: B, ) -> Result<u64>
Append a datagram with the next sequence number, returning the assigned sequence.
A datagram is delivered best-effort over a single QUIC datagram, parallel to the
track’s groups but drawing from the same sequence namespace (so interleaving with
Self::append_group never reuses a number). There is no group fallback: each
session drops (with a debug log) any datagram whose encoded body exceeds the
transport’s datagram size, and sessions that can’t carry datagrams at all (IETF
moq-transport, moq-lite before 05, or stream-only transports like WebSocket) never
deliver them. Keep payloads well under the 1200-byte minimum path MTU. An origin
publisher uses this; a relay preserving upstream numbering uses
Self::write_datagram.
Sourcepub fn write_datagram(&mut self, datagram: Datagram) -> Result<()>
pub fn write_datagram(&mut self, datagram: Datagram) -> Result<()>
Write a datagram with an explicit sequence number.
Preserves the supplied sequence (bumping the shared max_sequence if needed), so a
relay can forward a datagram without renumbering it. Most origin publishers want
Self::append_datagram instead.
Sourcepub fn write_frame<B: IntoBytes>(
&mut self,
timestamp: Timestamp,
frame: B,
) -> Result<()>
pub fn write_frame<B: IntoBytes>( &mut self, timestamp: Timestamp, frame: B, ) -> Result<()>
Create a group with a single frame, at the given presentation timestamp.
The timestamp is converted into the track’s timescale. For data without
a presentation time, pass Timestamp::now explicitly.
Sourcepub fn finish(&mut self) -> Result<()>
pub fn finish(&mut self) -> Result<()>
Mark the track as finished after the last appended group.
Sets the final sequence to one past the current max_sequence. No new groups at or above this sequence can be appended. NOTE: Old groups with lower sequence numbers can still arrive.
Sourcepub fn finish_at(&mut self, final_sequence: u64) -> Result<()>
pub fn finish_at(&mut self, final_sequence: u64) -> Result<()>
Declare the track’s exclusive final sequence, possibly ahead of the live edge.
final_sequence is the first sequence that will never be produced, so a track
whose last group is 89 finishes at 90. Passing a boundary beyond the current
max_sequence records a known ending before the remaining groups arrive (e.g.
learning a track ends at group 89 while only 87 has been received). The boundary
must be strictly greater than the highest produced group, otherwise it would
orphan groups that already exist (Error::ProtocolViolation).
Groups below final_sequence may still be created afterwards; groups at or above
it are rejected. Consumers only see end-of-stream once the live edge reaches the
boundary. Use Self::finish to finish exactly at the live edge.
Sourcepub fn final_sequence(&self) -> Option<u64>
pub fn final_sequence(&self) -> Option<u64>
The exclusive final sequence, once Self::finish or Self::finish_at declared one.
None while the track is still open ended. Both methods reject a second boundary, so
callers that may have already declared one check here first.
Sourcepub fn abort(self, err: Error) -> Result<()>
pub fn abort(self, err: Error) -> Result<()>
Abort the track with the given error.
Consumes the handle, since nothing can be written to an aborted track. Drops the
cached groups so a stale Consumer can’t pin them (and their frame buffers) in
memory forever. Consumers that haven’t drained yet surface the abort error instead
of the leftover cache. Child groups are independent: a consumer that already pulled
a group::Consumer keeps its own handle and can finish reading it.
finish is deliberately not terminal: it declares the final
sequence, and lower-numbered groups may still be written afterwards.
Sourcepub async fn closed(&self) -> Error
pub async fn closed(&self) -> Error
Block until the track is closed or aborted, returning the cause.
Sourcepub fn poll_closed(&self, waiter: &Waiter) -> Poll<Error>
pub fn poll_closed(&self, waiter: &Waiter) -> Poll<Error>
Poll until the track is closed or aborted; ready with the cause.
Sourcepub fn latest(&self) -> Option<u64>
pub fn latest(&self) -> Option<u64>
Return the latest sequence number successfully appended to the track.
Sourcepub fn demand(&self) -> Demand
pub fn demand(&self) -> Demand
Create a Demand: a cloneable, watch-only handle to this track’s
subscriber demand.
Lets a publisher gate work (e.g. on-demand capture) on whether anyone is subscribed, without the ability to publish frames or close the track. The handle is weak, so holding one neither keeps the track alive nor pins its cached groups.
Sourcepub fn consume(&self) -> Consumer
pub fn consume(&self) -> Consumer
Get a consumer handle for this in-process track.
Unlike a wire subscription, the info is already known, so a subscription opened from this handle resolves immediately.
Sourcepub fn subscribe(
&self,
subscription: impl Into<Option<Subscription>>,
) -> Subscriber
pub fn subscribe( &self, subscription: impl Into<Option<Subscription>>, ) -> Subscriber
Subscribing to this in-process track, resolving synchronously.
The info is fixed at creation, so there’s nothing to wait for (no
SUBSCRIBE_OK round trip). Pass None for Subscription::default.
Sourcepub async fn subscription_changed(&mut self) -> Result<Option<Subscription>>
pub async fn subscription_changed(&mut self) -> Result<Option<Subscription>>
Block until the aggregate subscription changes, then return the new value.
Yields the most demanding request across all live subscribers, or None
once the last one drops. Used by relays to forward downstream demand
upstream (e.g. SUBSCRIBE_UPDATE).
Sourcepub fn subscription(&self) -> Option<Subscription>
pub fn subscription(&self) -> Option<Subscription>
A non-blocking snapshot of the current aggregate subscription, or None
when there are no live subscribers. Unlike Self::subscription, this
doesn’t wait for a change or advance the change cursor.
The aggregate’s Subscription::latency_max is clamped to this track’s
Info::latency_max: no subscriber can wait for a late group longer than the
publisher keeps it.
Sourcepub fn poll_subscription_changed(
&mut self,
waiter: &Waiter,
) -> Poll<Result<Option<Subscription>>>
pub fn poll_subscription_changed( &mut self, waiter: &Waiter, ) -> Poll<Result<Option<Subscription>>>
Poll counterpart to subscription_changed: the
aggregate subscription whenever it changes, or None once nobody is subscribed.
Errors once the track is aborted.
Sourcepub fn poll_unused(&self, waiter: &Waiter) -> Poll<()>
pub fn poll_unused(&self, waiter: &Waiter) -> Poll<()>
Poll for the producer becoming unused (every consumer dropped).