Skip to main content

Graph

Struct Graph 

Source
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>

Source

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>

Source

pub fn new() -> Self

Source

pub fn add_source(&mut self, element: E) -> NodeId

Source

pub fn add_transform(&mut self, element: E) -> NodeId

Source

pub fn add_sink(&mut self, element: E) -> NodeId

Source

pub fn add_tee(&mut self, outputs: u8) -> Tee

Source

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.

Source

pub fn add_muxer(&mut self, element: E, inputs: u8) -> Muxer

Source

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.

Source

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.

Source

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.

Source

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=.

Source

pub fn node_name(&self, node: NodeId) -> Option<&str>

A node’s explicit instance name, if one was set.

Source

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.

Source

pub fn node_log_category(&self, node: NodeId) -> Option<&str>

A node’s log-category override, if one was set.

Source

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=).

Source

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.

Link an output pad to an input pad with the default Block policy.

Link an output pad to an input pad with an explicit backpressure policy.

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.

Source

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).

Source

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).

Source

pub fn node_count(&self) -> usize

Number of nodes added so far. With edges and node_kind this is enough to render the wiring before validation (the DOT dump).

Source

pub fn node_kind(&self, node: NodeId) -> Option<NodeKind>

The NodeKind of a node, or None if the id is past the node count.

Source

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.

Source

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.

Source

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.

Source

pub fn finish(self) -> Result<ValidatedGraph<E>, GraphError>

Validate the graph and compute its topological order + adjacency.

Trait Implementations§

Source§

impl<E> Debug for Graph<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E> Default for Graph<E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Graph<E>
where Vec<Node<E>>: Freeze,

§

impl<E> RefUnwindSafe for Graph<E>
where Vec<Node<E>>: RefUnwindSafe,

§

impl<E> Send for Graph<E>
where Vec<Node<E>>: Send,

§

impl<E> Sync for Graph<E>
where Vec<Node<E>>: Sync,

§

impl<E> Unpin for Graph<E>
where Vec<Node<E>>: Unpin,

§

impl<E> UnsafeUnpin for Graph<E>
where Vec<Node<E>>: UnsafeUnpin,

§

impl<E> UnwindSafe for Graph<E>
where Vec<Node<E>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ElementBound for T
where T: Send,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.