pub struct Graph<E> { /* private fields */ }Expand description
Builder for a multimedia DAG. Add nodes, link their pads, then finish()
to validate and produce a ValidatedGraph.
Implementations§
Source§impl<E> Graph<E>
impl<E> Graph<E>
Sourcepub fn to_dot(
&self,
title: &str,
label: impl Fn(NodeId) -> Option<String>,
ann: &DotAnnotations<'_>,
) -> String
pub fn to_dot( &self, title: &str, label: impl Fn(NodeId) -> Option<String>, ann: &DotAnnotations<'_>, ) -> String
Render the (not-yet-validated) graph as Graphviz DOT, for a dump before
finish() runs (a parsed launch line, a half-built graph). Same shape as
ValidatedGraph::to_dot; only DotAnnotations caps/memory are
usually absent pre-negotiation. Node ids 0..node_count always exist, so
the kind lookup never misses.
Source§impl<E> Graph<E>
impl<E> Graph<E>
pub fn new() -> Self
pub fn add_source(&mut self, element: E) -> NodeId
pub fn add_transform(&mut self, element: E) -> NodeId
pub fn add_sink(&mut self, element: E) -> NodeId
pub fn add_tee(&mut self, outputs: u8) -> Tee
Sourcepub fn add_tee_with_policy(&mut self, outputs: u8, policy: FanOutPolicy) -> Tee
pub fn add_tee_with_policy(&mut self, outputs: u8, policy: FanOutPolicy) -> Tee
Add a tee with an explicit FanOutPolicy. add_tee is the
FailLoud shorthand; this opts a fan-out into AllowBranchDrop so a
branch that cannot follow a mid-stream CapsChanged drops out instead of
failing the run.
pub fn add_muxer(&mut self, element: E, inputs: u8) -> Muxer
Sourcepub fn add_fanin_sink(&mut self, element: E, inputs: u8) -> FaninSink
pub fn add_fanin_sink(&mut self, element: E, inputs: u8) -> FaninSink
Add a terminal fan-in element: inputs input pads, no output. element
is a MultiInputElement that consumes all its
inputs and produces no downstream stream (a WebRTC publisher, a
multi-stream batching sink). The runner drives it the run_fanin_session
way: per-input Eos flush, end once every input has ended, and per-input
reverse-signal routing back to the arm feeding each pad.
Sourcepub fn add_fanout_src(&mut self, element: E, outputs: u8) -> FanoutSrc
pub fn add_fanout_src(&mut self, element: E, outputs: u8) -> FanoutSrc
Add a terminal fan-out source: no inputs, outputs output pads.
element is a MultiOutputSource that
generates every output itself (a WebRTC session receiving its tracks
over one PeerConnection). The runner drives it the run_fanout_session
way: the element pushes to each port and owes every port an Eos.
Sourcepub fn add_demux(&mut self, element: E, outputs: u8) -> Demux
pub fn add_demux(&mut self, element: E, outputs: u8) -> Demux
Add a content-routing demultiplexer: 1 input, outputs outputs. The node
is Tee(outputs)-shaped (so it validates and negotiates exactly like a
tee, all outputs initially carrying the input caps) but carries a
routing element; the runner drives it via
GraphNodeRef::Demux and each
branch retypes from a per-output CapsChanged at runtime (M210). Unlike
add_tee, a demux carries an element payload.
Sourcepub fn set_node_name(&mut self, node: NodeId, name: String)
pub fn set_node_name(&mut self, node: NodeId, name: String)
Give a node an explicit instance name, the runner’s <category>N naming
otherwise. The launch parser sets it from a name=.
Sourcepub fn node_name(&self, node: NodeId) -> Option<&str>
pub fn node_name(&self, node: NodeId) -> Option<&str>
A node’s explicit instance name, if one was set.
Sourcepub fn set_node_log_category(&mut self, node: NodeId, category: String)
pub fn set_node_log_category(&mut self, node: NodeId, category: String)
Override this node’s log category, the element type otherwise. The launch
parser sets it from a log-category=; the runner hands it to the element
before naming, so G2G_DEBUG filtering keys off it for this instance.
Sourcepub fn node_log_category(&self, node: NodeId) -> Option<&str>
pub fn node_log_category(&self, node: NodeId) -> Option<&str>
A node’s log-category override, if one was set.
Sourcepub fn node_by_name(&self, name: &str) -> Option<NodeId>
pub fn node_by_name(&self, name: &str) -> Option<NodeId>
The node carrying this instance name, for attaching to a graph someone
else built (a parse_launch line’s name=).
Sourcepub fn set_node_control(&mut self, node: NodeId, program: ControlProgram)
pub fn set_node_control(&mut self, node: NodeId, program: ControlProgram)
Animate this node’s properties over stream time (M882): the runner samples
program at each frame’s PTS and sets the bound properties on the element
before it processes that frame. Replaces any program already attached.
Validated when the run starts, against the element’s own declared properties, so an unknown or non-animatable property name fails the run before any frame flows.
Sourcepub fn link(
&mut self,
from: impl Into<PadId>,
to: impl Into<PadId>,
) -> Result<(), GraphError>
pub fn link( &mut self, from: impl Into<PadId>, to: impl Into<PadId>, ) -> Result<(), GraphError>
Link an output pad to an input pad with the default Block policy.
Sourcepub fn link_with(
&mut self,
from: impl Into<PadId>,
to: impl Into<PadId>,
policy: LinkPolicy,
) -> Result<(), GraphError>
pub fn link_with( &mut self, from: impl Into<PadId>, to: impl Into<PadId>, policy: LinkPolicy, ) -> Result<(), GraphError>
Link an output pad to an input pad with an explicit backpressure policy.
Sourcepub fn link_full(
&mut self,
from: impl Into<PadId>,
to: impl Into<PadId>,
policy: LinkPolicy,
capacity: Option<usize>,
) -> Result<(), GraphError>
pub fn link_full( &mut self, from: impl Into<PadId>, to: impl Into<PadId>, policy: LinkPolicy, capacity: Option<usize>, ) -> Result<(), GraphError>
Link with an explicit policy and a per-edge channel depth (None = use
the runner’s graph-wide link_capacity). The launch parser passes the
depth from a queue max-size-buffers=N.
Sourcepub fn edges(&self) -> &[Edge]
pub fn edges(&self) -> &[Edge]
The edges in declaration order, including each one’s backpressure
LinkPolicy. Lets callers inspect the wiring before finish
(e.g. the launch parser’s queue-to-policy mapping).
Sourcepub fn insert_on_edge(&mut self, edge_idx: usize, element: E) -> NodeId
pub fn insert_on_edge(&mut self, edge_idx: usize, element: E) -> NodeId
Splice a new transform node carrying element onto edge edge_idx,
returning its id. The edge P -> C becomes P -> K -> C (K the new
node), preserving the original LinkPolicy on both halves. Existing node
and edge ids are unchanged (the new node is appended, the new K -> C edge
is appended, and the original edge is rewired to P -> K), so a caller
iterating a snapshot of the original edge ids can splice several without
re-indexing. The new node is a single-pad Transform,
so the spliced element must be a 1-in/1-out transform (e.g. a memory-domain
converter). Used by the domain-converter auto-plug (M354).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Sourcepub fn node_kind(&self, node: NodeId) -> Option<NodeKind>
pub fn node_kind(&self, node: NodeId) -> Option<NodeKind>
The NodeKind of a node, or None if the id is past the node count.
Sourcepub fn element(&self, node: NodeId) -> Option<&E>
pub fn element(&self, node: NodeId) -> Option<&E>
Borrow a node’s element payload (None for tee nodes or an unknown id),
for labeling a pre-validation dump from the element itself.
Sourcepub fn merge(&mut self, inner: Graph<E>) -> NodeIdOffset
pub fn merge(&mut self, inner: Graph<E>) -> NodeIdOffset
Append every node and edge of inner into this graph, returning the
NodeIdOffset that maps inner’s ids into this graph’s id space.
Composition is a pure index shift: nodes are a flat Vec and edges carry
only pad indices, so re-basing inner’s ids by the current node count is
all it takes. The union is not re-validated here; the host’s finish()
validates the whole. This is the one primitive under bin flattening
(add_bin) and the decodebin / uridecodebin / autoplug
splices.
Sourcepub fn add_bin(&mut self, bin: Bin<E>) -> BinInstance
pub fn add_bin(&mut self, bin: Bin<E>) -> BinInstance
Flatten bin into this graph, returning a BinInstance whose ghost pads
are this graph’s pad ids: link them like any other pad
(graph.link(src, inst.input(0)), graph.link(inst.output(0), dst)).
Construction-time only, no new node kind, so the solver and runner see the
flattened union with no awareness the bin ever existed.
Sourcepub fn finish(self) -> Result<ValidatedGraph<E>, GraphError>
pub fn finish(self) -> Result<ValidatedGraph<E>, GraphError>
Validate the graph and compute its topological order + adjacency.