libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
MediaNode Class Referenceabstract

Base class for all pipeline processing nodes. More...

#include <medianode.h>

Inheritance diagram for MediaNode:
Collaboration diagram for MediaNode:

Public Types

enum  State { Idle , Configured , Running , ErrorState }
 Node lifecycle state. More...
 
enum  ThreadingPolicy { UseGraphPool , DedicatedThread , CustomPool }
 Threading policy for this node. More...
 
- Public Types inherited from ObjectBase
using SlotVariantFunc = std::function< void(const VariantList &)>
 Function type for invoking a slot with a list of Variants.
 

Public Member Functions

 MediaNode (ObjectBase *parent=nullptr)
 Constructs a MediaNode.
 
virtual ~MediaNode ()
 Virtual destructor.
 
State state () const
 Returns the current state.
 
const Stringname () const
 Returns the node name.
 
void setName (const String &name)
 Sets the node name.
 
const MediaPort::PtrListinputPorts () const
 Returns the list of input ports.
 
const MediaPort::PtrListoutputPorts () const
 Returns the list of output ports.
 
MediaPort::Ptr inputPort (int index) const
 Returns the input port at the given index.
 
MediaPort::Ptr outputPort (int index) const
 Returns the output port at the given index.
 
MediaPort::Ptr inputPort (const String &name) const
 Returns the input port with the given name.
 
MediaPort::Ptr outputPort (const String &name) const
 Returns the output port with the given name.
 
int inputPortCount () const
 Returns the number of input ports.
 
int outputPortCount () const
 Returns the number of output ports.
 
void setThreadingPolicy (ThreadingPolicy policy)
 Sets the threading policy.
 
void setThreadingPolicy (ThreadPool *pool)
 Sets a custom thread pool and switches policy to CustomPool.
 
ThreadingPolicy threadingPolicy () const
 Returns the current threading policy.
 
ThreadPoolcustomThreadPool () const
 Returns the custom thread pool, or nullptr if not using CustomPool.
 
void setIdealQueueSize (int size)
 Sets the ideal input queue depth.
 
int idealQueueSize () const
 Returns the ideal input queue size.
 
int queuedFrameCount () const
 Returns the current input queue depth.
 
virtual Error configure ()
 Validates ports and allocates resources.
 
virtual Error start ()
 Begins processing.
 
virtual void stop ()
 Stops processing.
 
virtual void process ()=0
 Processes one cycle of data.
 
virtual void starvation ()
 Called when the node's input queue is empty and data is needed.
 
virtual Map< String, Variantproperties () const
 Returns all configurable properties as key-value pairs.
 
virtual Error setProperty (const String &name, const Variant &value)
 Sets a property by name.
 
Variant property (const String &name) const
 Gets a single property value by name.
 
NodeStats stats () const
 Returns a snapshot of the node's performance statistics.
 
void resetStats ()
 Resets all statistics counters to zero.
 
virtual Map< String, VariantextendedStats () const
 Returns additional node-specific statistics.
 
 PROMEKI_SIGNAL (stateChanged, State)
 Emitted when the node's state changes.
 
 PROMEKI_SIGNAL (errorOccurred, Error)
 Emitted when an error occurs.
 
 PROMEKI_SIGNAL (messageEmitted, NodeMessage)
 Emitted when the node produces a message.
 
- 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)
 

Static Public Member Functions

static void registerNodeType (const String &typeName, std::function< MediaNode *()> factory)
 Registers a node type for runtime creation.
 
static MediaNodecreateNode (const String &typeName)
 Creates a node by registered type name.
 
static List< StringregisteredNodeTypes ()
 Returns the list of all registered node type names.
 
- 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
 

Protected Member Functions

void enqueueInput (Frame::Ptr frame)
 Enqueues a frame into this node's input queue.
 
void recordProcessTiming (double duration)
 Records timing for a process() call.
 
void recordStarvation ()
 Records a starvation event.
 
void addInputPort (MediaPort::Ptr port)
 Adds an input port to this node.
 
void addOutputPort (MediaPort::Ptr port)
 Adds an output port to this node.
 
void setState (State state)
 Sets the node state and emits stateChanged.
 
Frame::Ptr dequeueInput ()
 Dequeues a frame from this node's input queue.
 
void deliverOutput (int portIndex, Frame::Ptr frame)
 Delivers a frame to all outgoing links on the given output port.
 
void deliverOutput (Frame::Ptr frame)
 Delivers a frame to all outgoing links on all output ports.
 
void emitMessage (Severity severity, const String &message, uint64_t frameNumber=0)
 Emits a message with the given severity and text.
 
void emitWarning (const String &message)
 Emits a Warning-severity message.
 
void emitError (const String &message)
 Emits an Error-severity message.
 
- 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.
 

Friends

class MediaGraph
 
class MediaLink
 
class MediaPipeline
 

Additional Inherited Members

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

Detailed Description

Base class for all pipeline processing nodes.

MediaNode is the ObjectBase-derived base class for all processing nodes in the media pipeline framework. It manages input and output ports, lifecycle state transitions, threading policy, and provides a uniform property interface for future JSON serialization.

Concrete node subclasses override the virtual lifecycle methods (configure, start, stop, process, starvation) to implement their specific processing logic.

Member Enumeration Documentation

◆ State

Node lifecycle state.

Enumerator
Idle 

Initial state, not configured.

Configured 

Configured and ready to start.

Running 

Actively processing data.

ErrorState 

An error has occurred.

◆ ThreadingPolicy

Threading policy for this node.

Enumerator
UseGraphPool 

Use the graph's default thread pool.

DedicatedThread 

Run on a dedicated thread.

CustomPool 

Use a custom thread pool.

Constructor & Destructor Documentation

◆ MediaNode()

MediaNode::MediaNode ( ObjectBase parent = nullptr)

Constructs a MediaNode.

Parameters
parentOptional parent object.

Member Function Documentation

◆ addInputPort()

void MediaNode::addInputPort ( MediaPort::Ptr  port)
protected

Adds an input port to this node.

Parameters
portThe port to add.

◆ addOutputPort()

void MediaNode::addOutputPort ( MediaPort::Ptr  port)
protected

Adds an output port to this node.

Parameters
portThe port to add.

◆ configure()

virtual Error MediaNode::configure ( )
virtual

Validates ports and allocates resources.

Transitions the node from Idle to Configured on success.

Returns
Error::Ok on success, or an error code.

Reimplemented in FrameDemuxNode, JpegEncoderNode, RtpAudioSinkNode, RtpVideoSinkNode, TestPatternNode, and TimecodeOverlayNode.

◆ createNode()

static MediaNode * MediaNode::createNode ( const String typeName)
static

Creates a node by registered type name.

Parameters
typeNameThe type name to instantiate.
Returns
A new node instance, or nullptr if the type is not registered.

◆ deliverOutput() [1/2]

void MediaNode::deliverOutput ( Frame::Ptr  frame)
protected

Delivers a frame to all outgoing links on all output ports.

Convenience for single-output nodes.

Parameters
frameThe frame to deliver.

◆ deliverOutput() [2/2]

void MediaNode::deliverOutput ( int  portIndex,
Frame::Ptr  frame 
)
protected

Delivers a frame to all outgoing links on the given output port.

Source nodes call this from process() to push frames downstream.

Parameters
portIndexThe output port index.
frameThe frame to deliver.

◆ dequeueInput()

Frame::Ptr MediaNode::dequeueInput ( )
protected

Dequeues a frame from this node's input queue.

Returns a null Ptr if the queue is empty. Subclasses call this from process() to pull input frames.

Returns
The next frame, or a null Ptr if the queue is empty.

◆ emitError()

void MediaNode::emitError ( const String message)
protected

Emits an Error-severity message.

Also transitions the node to ErrorState and emits errorOccurred.

Parameters
messageThe error text.

◆ emitMessage()

void MediaNode::emitMessage ( Severity  severity,
const String message,
uint64_t  frameNumber = 0 
)
protected

Emits a message with the given severity and text.

Auto-populates timestamp and node pointer. Subclasses call this to report events during processing.

Parameters
severityThe message severity.
messageThe message text.
frameNumberThe frame number this relates to (0 if not frame-specific).

◆ emitWarning()

void MediaNode::emitWarning ( const String message)
protected

Emits a Warning-severity message.

Parameters
messageThe warning text.

◆ enqueueInput()

void MediaNode::enqueueInput ( Frame::Ptr  frame)
protected

Enqueues a frame into this node's input queue.

Called by the pipeline to deliver frames from upstream nodes.

Parameters
frameThe frame to enqueue.

◆ extendedStats()

virtual Map< String, Variant > MediaNode::extendedStats ( ) const
virtual

Returns additional node-specific statistics.

Override in concrete nodes to expose custom statistics (e.g., "packetsSent", "bytesSent" for RTP nodes).

Returns
A map of stat names to Variant values.

Reimplemented in JpegEncoderNode, RtpAudioSinkNode, RtpVideoSinkNode, and TestPatternNode.

◆ inputPort() [1/2]

MediaPort::Ptr MediaNode::inputPort ( const String name) const

Returns the input port with the given name.

Parameters
nameThe port name.
Returns
The port, or a null Ptr if not found.

◆ inputPort() [2/2]

MediaPort::Ptr MediaNode::inputPort ( int  index) const

Returns the input port at the given index.

Parameters
indexZero-based port index.
Returns
The port, or a null Ptr if the index is out of range.

◆ outputPort() [1/2]

MediaPort::Ptr MediaNode::outputPort ( const String name) const

Returns the output port with the given name.

Parameters
nameThe port name.
Returns
The port, or a null Ptr if not found.

◆ outputPort() [2/2]

MediaPort::Ptr MediaNode::outputPort ( int  index) const

Returns the output port at the given index.

Parameters
indexZero-based port index.
Returns
The port, or a null Ptr if the index is out of range.

◆ process()

virtual void MediaNode::process ( )
pure virtual

Processes one cycle of data.

Pure virtual — must be implemented by concrete node subclasses.

Implemented in FrameDemuxNode, JpegEncoderNode, RtpAudioSinkNode, RtpVideoSinkNode, TestPatternNode, and TimecodeOverlayNode.

◆ properties()

virtual Map< String, Variant > MediaNode::properties ( ) const
virtual

Returns all configurable properties as key-value pairs.

Concrete nodes override this to expose their configuration.

Returns
A map of property names to Variant values.

◆ property()

Variant MediaNode::property ( const String name) const

Gets a single property value by name.

Parameters
nameThe property name.
Returns
The property value, or an invalid Variant if not found.

◆ recordProcessTiming()

void MediaNode::recordProcessTiming ( double  duration)
protected

Records timing for a process() call.

Called by the pipeline to instrument process() with timing. Updates processCount, lastProcessDuration, avgProcessDuration, and peakProcessDuration.

Parameters
durationThe wall-clock duration of the process() call in seconds.

◆ recordStarvation()

void MediaNode::recordStarvation ( )
protected

Records a starvation event.

Called by the pipeline when starvation() is invoked. Increments starvationCount.

◆ registeredNodeTypes()

static List< String > MediaNode::registeredNodeTypes ( )
static

Returns the list of all registered node type names.

Returns
A list of type name strings.

◆ registerNodeType()

static void MediaNode::registerNodeType ( const String typeName,
std::function< MediaNode *()>  factory 
)
static

Registers a node type for runtime creation.

Parameters
typeNameThe unique type name string.
factoryA factory function that creates a new instance.

◆ setIdealQueueSize()

void MediaNode::setIdealQueueSize ( int  size)
inline

Sets the ideal input queue depth.

The pipeline uses this as a hint for back-pressure.

Parameters
sizeTarget queue depth (default: 2).

◆ setName()

void MediaNode::setName ( const String name)
inline

Sets the node name.

Parameters
nameThe human-readable node name.

◆ setProperty()

virtual Error MediaNode::setProperty ( const String name,
const Variant value 
)
virtual

Sets a property by name.

Parameters
nameThe property name.
valueThe value to set.
Returns
Error::Ok on success, or an error (e.g. unknown property, type mismatch).

◆ setState()

void MediaNode::setState ( State  state)
protected

Sets the node state and emits stateChanged.

Parameters
stateThe new state.

◆ setThreadingPolicy() [1/2]

void MediaNode::setThreadingPolicy ( ThreadingPolicy  policy)
inline

Sets the threading policy.

Parameters
policyThe threading policy to use.

◆ setThreadingPolicy() [2/2]

void MediaNode::setThreadingPolicy ( ThreadPool pool)
inline

Sets a custom thread pool and switches policy to CustomPool.

Parameters
poolThe custom thread pool.

◆ start()

virtual Error MediaNode::start ( )
virtual

Begins processing.

Transitions the node from Configured to Running on success.

Returns
Error::Ok on success, or an error code.

Reimplemented in RtpAudioSinkNode, RtpVideoSinkNode, and TestPatternNode.

◆ starvation()

virtual void MediaNode::starvation ( )
virtual

Called when the node's input queue is empty and data is needed.

Override for nodes that need to handle starvation (e.g. log, insert silence/black, repeat last frame). Default: no-op.

Reimplemented in RtpAudioSinkNode, and RtpVideoSinkNode.

◆ stats()

NodeStats MediaNode::stats ( ) const

Returns a snapshot of the node's performance statistics.

Returns
The current NodeStats.

◆ stop()

virtual void MediaNode::stop ( )
virtual

Stops processing.

Transitions the node from Running to Idle.

Reimplemented in RtpAudioSinkNode, RtpVideoSinkNode, and TestPatternNode.


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