pub struct StreamHandle { /* private fields */ }Expand description
Live handle to a memory stream source, sink, or pipeline.
A StreamHandle is a cheap, cloneable reference (an Arc inner) to one
of four kinds of memory endpoint: a pull source, a PCM sink, a MIDI sink, or
a pipeline that connects a source to an optional sink. Reads
(StreamHandle::next_packet), writes (StreamHandle::write_packet), and
whole-stream runs (StreamHandle::run) are dispatched on the handle kind
and fail closed when invoked on an endpoint that does not support them.
Implementations§
Source§impl StreamHandle
impl StreamHandle
Sourcepub fn source(metadata: StreamMetadata, stream: Arc<StreamValue>) -> Self
pub fn source(metadata: StreamMetadata, stream: Arc<StreamValue>) -> Self
Builds a pull-source handle backed by the given stream value.
Sourcepub fn pcm_sink(metadata: StreamMetadata, spec: PcmSpec) -> Self
pub fn pcm_sink(metadata: StreamMetadata, spec: PcmSpec) -> Self
Builds a PCM sink handle that validates writes against spec.
Sourcepub fn midi_sink(metadata: StreamMetadata, tpq: u16) -> Self
pub fn midi_sink(metadata: StreamMetadata, tpq: u16) -> Self
Builds a MIDI sink handle that validates writes against tpq.
Sourcepub fn pipeline(
source: StreamHandle,
sink: Option<StreamHandle>,
) -> Result<Self>
pub fn pipeline( source: StreamHandle, sink: Option<StreamHandle>, ) -> Result<Self>
Builds a pipeline handle from a source-like handle and optional sink.
§Errors
Returns an error when source is not source-like, or when sink is
present but is not a sink handle.
Sourcepub fn metadata(&self) -> &StreamMetadata
pub fn metadata(&self) -> &StreamMetadata
Returns the stream metadata describing this handle.
Sourcepub fn is_pipeline_with_sink(&self) -> bool
pub fn is_pipeline_with_sink(&self) -> bool
Returns true when this handle is a pipeline that drives a sink.
Sourcepub fn next_packet(&self) -> Result<Option<StreamItem>>
pub fn next_packet(&self) -> Result<Option<StreamItem>>
Pulls the next packet from a source or pipeline source.
Returns Ok(None) once the stream is exhausted.
§Errors
Returns an error when called on a sink handle, or when the underlying source fails to produce the next packet.
Sourcepub fn write_packet(&self, packet: StreamPacket) -> Result<()>
pub fn write_packet(&self, packet: StreamPacket) -> Result<()>
Writes one packet into a PCM or MIDI sink.
§Errors
Returns an error when called on a non-sink handle, when the packet media does not match the sink, or when the packet fails sink validation.
Sourcepub fn cancel(&self) -> Result<()>
pub fn cancel(&self) -> Result<()>
Cancels the stream, marking sources and sinks closed and cancelled.
Cancelling a pipeline cancels its source and sink in turn.
§Errors
Returns an error when a sink lock is poisoned or a source cancel fails.
Sourcepub fn stats(&self) -> Result<StreamStats>
pub fn stats(&self) -> Result<StreamStats>
Returns a snapshot of the stream’s runtime statistics.
§Errors
Returns an error when a sink lock is poisoned or a source cannot report its statistics.
Sourcepub fn done(&self) -> Result<bool>
pub fn done(&self) -> Result<bool>
Returns true when the stream has no more work to do.
A pipeline is done only when both its source and its sink are done.
§Errors
Returns an error when a sink lock is poisoned or a source cannot report its completion state.
Sourcepub fn sink_packets(&self) -> Result<Vec<StreamPacket>>
pub fn sink_packets(&self) -> Result<Vec<StreamPacket>>
Returns a copy of the packets accumulated by a sink handle.
§Errors
Returns an error when called on a non-sink handle or when the sink lock is poisoned.
Sourcepub fn graph_lisp_expr(&self) -> Expr
pub fn graph_lisp_expr(&self) -> Expr
Renders this handle as a stream graph expression.
A pipeline renders as a stream/pipe call over its source and optional
sink ids; a bare source or sink renders as its id string.
Trait Implementations§
Source§impl Clone for StreamHandle
impl Clone for StreamHandle
Source§fn clone(&self) -> StreamHandle
fn clone(&self) -> StreamHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Object for StreamHandle
impl Object for StreamHandle
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.