libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
MediaGraph Class Reference

Directed acyclic graph of MediaNodes connected by MediaLinks. More...

#include <mediagraph.h>

Inheritance diagram for MediaGraph:
Collaboration diagram for MediaGraph:

Public Member Functions

 MediaGraph (ObjectBase *parent=nullptr)
 Constructs an empty graph.
 
virtual ~MediaGraph ()
 Destructor. Deletes all owned nodes.
 
Error addNode (MediaNode *node)
 Adds a node to the graph. Takes ownership.
 
Error removeNode (MediaNode *node)
 Removes a node from the graph.
 
const List< MediaNode * > & nodes () const
 Returns all nodes in the graph.
 
MediaNodenode (const String &name) const
 Finds a node by name.
 
MediaLink::Ptr connect (MediaPort::Ptr output, MediaPort::Ptr input)
 Connects an output port to an input port.
 
MediaLink::Ptr connect (MediaNode *source, int outputIndex, MediaNode *sink, int inputIndex)
 Connects nodes by port index.
 
MediaLink::Ptr connect (MediaNode *source, const String &outputName, MediaNode *sink, const String &inputName)
 Connects nodes by port name.
 
Error disconnect (MediaLink::Ptr link)
 Disconnects a link.
 
Error disconnect (MediaPort::Ptr output, MediaPort::Ptr input)
 Disconnects the link between two specific ports.
 
const MediaLink::PtrListlinks () const
 Returns all links in the graph.
 
Error validate () const
 Validates the graph topology.
 
List< MediaNode * > topologicalSort () const
 Returns nodes in topological order (dependencies first).
 
List< MediaNode * > sourceNodes () const
 Returns nodes with no input connections (source nodes).
 
List< MediaNode * > sinkNodes () const
 Returns nodes with no output connections (sink nodes).
 
void clear ()
 Removes all nodes and links.
 
- Public Member Functions inherited from ObjectBase
 ObjectBase (ObjectBase *p=nullptr)
 Default ObjectBase constructor.
 
virtual ~ObjectBase ()
 Destructor. Emits aboutToDestroy, detaches from parent, and destroys children.
 
ObjectBaseparent () const
 Returns the parent object, if one. nullptr if none.
 
void setParent (ObjectBase *p)
 Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one.
 
const ObjectBaseListchildList () const
 Returns a list of children of this object.
 
template<typename... Args>
int registerSlot (Slot< Args... > *slot)
 Registers a slot with this object and assigns it an ID.
 
EventLoopeventLoop () const
 Returns the EventLoop this object is affiliated with.
 
void moveToThread (EventLoop *loop)
 Changes the EventLoop affinity of this object.
 
int startTimer (unsigned int intervalMs, bool singleShot=false)
 Starts a timer on this object's EventLoop.
 
void stopTimer (int timerId)
 Stops a timer previously started with startTimer().
 
template<typename... Args>
PROMEKI_NAMESPACE_BEGIN void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 

Additional Inherited Members

- Public Types inherited from ObjectBase
using SlotVariantFunc = std::function< void(const VariantList &)>
 Function type for invoking a slot with a list of Variants.
 
- Static Public Member Functions inherited from ObjectBase
static const MetaInfometaInfo ()
 Returns the MetaInfo for the ObjectBase class.
 
template<typename... Args>
static void connect (Signal< Args... > *signal, Slot< Args... > *slot)
 connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object
 
- Public Attributes inherited from ObjectBase
Signal< ObjectBase * > aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName)
 
- Static Public Attributes inherited from ObjectBase
static constexpr const charaboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")"
 
static SignalMeta aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName)
 
- Protected Member Functions inherited from ObjectBase
ObjectBasesignalSender ()
 Returns the ObjectBase that emitted the signal currently being handled.
 
virtual void event (Event *e)
 Called by EventLoop to deliver events to this object.
 
virtual void timerEvent (TimerEvent *e)
 Called when a timer fires for this object.
 

Detailed Description

Directed acyclic graph of MediaNodes connected by MediaLinks.

MediaGraph manages the topology of a media processing pipeline. Nodes are added to the graph, then connected via their ports. The graph validates the topology (no cycles, compatible formats, all required ports connected) and provides topological ordering for processing.

An output port may be connected to multiple input ports (fan-out). The same frame is delivered to all connected links.

Constructor & Destructor Documentation

◆ MediaGraph()

MediaGraph::MediaGraph ( ObjectBase parent = nullptr)

Constructs an empty graph.

Parameters
parentOptional parent object.

Member Function Documentation

◆ addNode()

Error MediaGraph::addNode ( MediaNode node)

Adds a node to the graph. Takes ownership.

Parameters
nodeThe node to add.
Returns
Error::Ok on success.

◆ clear()

void MediaGraph::clear ( )

Removes all nodes and links.

Deletes all owned nodes.

◆ connect() [1/3]

MediaLink::Ptr MediaGraph::connect ( MediaNode source,
const String outputName,
MediaNode sink,
const String inputName 
)

Connects nodes by port name.

Parameters
sourceThe source node.
outputNameOutput port name on the source node.
sinkThe sink node.
inputNameInput port name on the sink node.
Returns
The created link, or a null Ptr on error.

◆ connect() [2/3]

MediaLink::Ptr MediaGraph::connect ( MediaNode source,
int  outputIndex,
MediaNode sink,
int  inputIndex 
)

Connects nodes by port index.

Parameters
sourceThe source node.
outputIndexOutput port index on the source node.
sinkThe sink node.
inputIndexInput port index on the sink node.
Returns
The created link, or a null Ptr on error.

◆ connect() [3/3]

MediaLink::Ptr MediaGraph::connect ( MediaPort::Ptr  output,
MediaPort::Ptr  input 
)

Connects an output port to an input port.

Parameters
outputThe source output port.
inputThe sink input port.
Returns
The created link, or a null Ptr on error.

◆ disconnect() [1/2]

Error MediaGraph::disconnect ( MediaLink::Ptr  link)

Disconnects a link.

Parameters
linkThe link to disconnect.
Returns
Error::Ok on success.

◆ disconnect() [2/2]

Error MediaGraph::disconnect ( MediaPort::Ptr  output,
MediaPort::Ptr  input 
)

Disconnects the link between two specific ports.

Parameters
outputThe output port.
inputThe input port.
Returns
Error::Ok on success, Error::NotExist if not found.

◆ node()

MediaNode * MediaGraph::node ( const String name) const

Finds a node by name.

Parameters
nameThe node name.
Returns
The node, or nullptr if not found.

◆ removeNode()

Error MediaGraph::removeNode ( MediaNode node)

Removes a node from the graph.

Disconnects all links involving this node first. The caller regains ownership and must delete the node.

Parameters
nodeThe node to remove.
Returns
Error::Ok on success, Error::NotExist if not found.

◆ sinkNodes()

List< MediaNode * > MediaGraph::sinkNodes ( ) const

Returns nodes with no output connections (sink nodes).

Returns
A list of sink nodes.

◆ sourceNodes()

List< MediaNode * > MediaGraph::sourceNodes ( ) const

Returns nodes with no input connections (source nodes).

Returns
A list of source nodes.

◆ topologicalSort()

List< MediaNode * > MediaGraph::topologicalSort ( ) const

Returns nodes in topological order (dependencies first).

Source nodes appear first, sink nodes last.

Returns
An ordered list of node pointers, or empty if the graph has cycles.

◆ validate()

Error MediaGraph::validate ( ) const

Validates the graph topology.

Checks for cycles (DAG requirement), format compatibility on all links, and that the graph is non-empty.

Returns
Error::Ok if valid, or an error describing the problem.

The documentation for this class was generated from the following file: