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

RTP session for sending and receiving packets (RFC 3550). More...

#include <rtpsession.h>

Inheritance diagram for RtpSession:
Collaboration diagram for RtpSession:

Public Member Functions

 RtpSession (ObjectBase *parent=nullptr)
 Constructs an RtpSession.
 
 ~RtpSession () override
 Destructor. Stops the session if running.
 
Error start (const SocketAddress &localAddr)
 Starts the session, binding to a local address.
 
void stop ()
 Stops the session and closes the socket.
 
bool isRunning () const
 Returns true if the session is started.
 
Error sendPacket (const Buffer &payload, uint32_t timestamp, uint8_t payloadType, const SocketAddress &dest, bool marker=false)
 Sends a single RTP packet with raw payload data.
 
Error sendPackets (RtpPacket::List &packets, uint32_t timestamp, const SocketAddress &dest, bool markerOnLast=true)
 Sends pre-packed RTP packets from a payload handler.
 
uint32_t ssrc () const
 Returns the locally generated SSRC.
 
void setSsrc (uint32_t ssrc)
 Overrides the auto-generated SSRC.
 
uint16_t sequenceNumber () const
 Returns the current sequence number.
 
void setPayloadType (uint8_t pt)
 Sets the default payload type.
 
uint8_t payloadType () const
 Returns the default payload type.
 
void setClockRate (uint32_t hz)
 Sets the RTP timestamp clock rate in Hz.
 
uint32_t clockRate () const
 Returns the RTP timestamp clock rate.
 
UdpSocketsocket () const
 Returns the internal UDP socket.
 
 PROMEKI_SIGNAL (packetReceived, Buffer, uint32_t, uint8_t, bool)
 Emitted when a packet is received.
 
 PROMEKI_SIGNAL (ssrcCollision, uint32_t)
 Emitted when an SSRC collision is detected.
 
- 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

RTP session for sending and receiving packets (RFC 3550).

RtpSession manages the RTP protocol state for a single synchronization source (SSRC). It handles RTP header construction, sequence number management, and timestamp tracking.

The session operates on pre-built RtpPacket lists from RtpPayload handlers. It fills in the RTP header fields (version, payload type, sequence number, timestamp, SSRC, marker bit) and transmits via a UdpSocket.

Example
session.setPayloadType(96);
session.setClockRate(90000);
// Send pre-packed RTP packets
RtpPayloadJpeg payload(1920, 1080);
auto packets = payload.pack(jpegData, jpegSize);
session.sendPackets(packets, timestamp, dest, true);
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
RTP payload handler for RFC 2435 JPEG (Motion JPEG).
Definition rtppayload.h:264
RTP session for sending and receiving packets (RFC 3550).
Definition rtpsession.h:47
static SocketAddress any(uint16_t port)
Returns INADDR_ANY with the given port.
Definition socketaddress.h:71

Constructor & Destructor Documentation

◆ RtpSession()

RtpSession::RtpSession ( ObjectBase parent = nullptr)

Constructs an RtpSession.

Parameters
parentThe parent object, or nullptr.

Member Function Documentation

◆ PROMEKI_SIGNAL() [1/2]

RtpSession::PROMEKI_SIGNAL ( packetReceived  ,
Buffer  ,
uint32_t  ,
uint8_t  ,
bool   
)

Emitted when a packet is received.

Parameters: payload data (Buffer), RTP timestamp (uint32_t), payload type (uint8_t), marker bit (bool).

Signal:

◆ PROMEKI_SIGNAL() [2/2]

RtpSession::PROMEKI_SIGNAL ( ssrcCollision  ,
uint32_t   
)

Emitted when an SSRC collision is detected.

Signal:

◆ sendPacket()

Error RtpSession::sendPacket ( const Buffer payload,
uint32_t  timestamp,
uint8_t  payloadType,
const SocketAddress dest,
bool  marker = false 
)

Sends a single RTP packet with raw payload data.

Constructs a complete RTP packet with header and sends it.

Parameters
payloadThe payload data.
timestampThe RTP timestamp for this packet.
payloadTypeThe RTP payload type.
destThe destination address.
markerIf true, the marker bit is set.
Returns
Error::Ok on success, or an error on failure.

◆ sendPackets()

Error RtpSession::sendPackets ( RtpPacket::List packets,
uint32_t  timestamp,
const SocketAddress dest,
bool  markerOnLast = true 
)

Sends pre-packed RTP packets from a payload handler.

Fills in the RTP header fields on each packet and transmits. The marker bit is set on the last packet in the list (end of frame/access unit).

Parameters
packetsThe pre-packed packet list. Modified in-place: RTP header fields are overwritten before transmission.
timestampThe RTP timestamp for this frame.
destThe destination address.
markerOnLastIf true, set marker bit on the last packet.
Returns
Error::Ok on success, or an error on first failure.

◆ socket()

UdpSocket * RtpSession::socket ( ) const
inline

Returns the internal UDP socket.

Use this to configure socket options (DSCP, multicast, etc.) after calling start().

Returns
Pointer to the socket, or nullptr if not started.

◆ start()

Error RtpSession::start ( const SocketAddress localAddr)

Starts the session, binding to a local address.

Creates and opens the internal UDP socket, then binds it to the specified local address. Use port 0 to let the OS assign a port.

Parameters
localAddrThe local address and port to bind to.
Returns
Error::Ok on success, or an error on failure.

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