arduino-audio-tools
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
RTSPMediaCallbackSource Class Reference

Callback-based RTSP Media Source. More...

#include <RTSPMediaCallbackSource.h>

Inheritance diagram for RTSPMediaCallbackSource:
IMediaSource

Public Types

typedef void(* lifecycle_callback_t) (void *userData)
 
typedef int(* packet_size_callback_t) (void *userData)
 
typedef int(* read_callback_t) (uint8_t *buffer, int maxBytes, void *userData)
 

Public Member Functions

 RTSPMediaCallbackSource ()
 Default constructor.
 
 RTSPMediaCallbackSource (read_callback_t callback, void *userData=nullptr)
 Constructor with read callback.
 
 RTSPMediaCallbackSource (RTSPFormat &format, read_callback_t callback, void *userData=nullptr)
 Constructor with format and read callback.
 
virtual ~RTSPMediaCallbackSource ()
 
RTSPFormatgetFormat () override
 Get the current RTSP format configuration.
 
void * getUserData () const
 Get the user data pointer.
 
bool isActive () const
 Check if the source is active.
 
int packetSize () override
 Report the size of the next queued fragment via the configured packet-size callback (packetized/video sources only)
 
int readBytes (void *dest, int maxBytes) override
 Read media data using the configured callback.
 
void setFormat (RTSPFormat &format)
 Set the RTSP format configuration.
 
void setPacketSizeCallback (packet_size_callback_t callback)
 Set the callback reporting the size of the next already- fragmented, ready-to-send packet. Configuring this switches packetSize() from the default "not packetized" (-1) to forwarding the callback's result, which in turn switches RTSPMediaStreamer to the packetized send path (see IMediaSource::packetSize()) - use this for video sources whose fragmentation/RTP payload framing is done externally (e.g. by an H264RtpEncoder/JPEGRtpEncoder that the read callback pulls from).
 
void setReadCallback (read_callback_t callback, void *userData=nullptr)
 Set the callback function for reading media data.
 
void setStartCallback (lifecycle_callback_t callback)
 Set optional start callback (called when streaming begins)
 
void setStopCallback (lifecycle_callback_t callback)
 Set optional stop callback (called when streaming ends)
 
void start () override
 Start the media source Calls the optional start callback if configured.
 
void stop () override
 Stop the media source Calls the optional stop callback if configured.
 

Protected Attributes

RTSPFormatPCM default_format
 
bool is_active
 
RTSPFormatp_format
 
packet_size_callback_t packet_size_callback
 
read_callback_t read_callback
 
lifecycle_callback_t start_callback
 
lifecycle_callback_t stop_callback
 
void * user_data
 

Detailed Description

Callback-based RTSP Media Source.

RTSPMediaCallbackSource provides a flexible way to stream custom media data over RTSP by using user-provided callback functions. This is ideal for:

The callback approach allows maximum flexibility while maintaining compatibility with the RTSP streaming framework.

Author
Phil Schatzmann

Member Typedef Documentation

◆ lifecycle_callback_t

typedef void(* lifecycle_callback_t) (void *userData)

Callback function type for source lifecycle management

Parameters
userDataOptional user data pointer passed to callback

◆ packet_size_callback_t

typedef int(* packet_size_callback_t) (void *userData)

Callback function type for reporting the size of the next queued, ready-to-send fragment - only needed for packetized (video) sources that hand out already RTP-payload-ready fragments (e.g. H264RtpEncoder, JPEGRtpEncoder) instead of a plain byte stream. See IMediaSource::packetSize() for the exact contract.

Parameters
userDataOptional user data pointer passed to callback
Returns
0 if packetized but nothing queued right now, otherwise the size in bytes of the next fragment

◆ read_callback_t

typedef int(* read_callback_t) (uint8_t *buffer, int maxBytes, void *userData)

Callback function type for reading media data

Parameters
bufferBuffer to write media data to
maxBytesMaximum number of bytes to write
userDataOptional user data pointer passed to callback
Returns
Number of bytes written (0 = no data available, -1 = error)

Constructor & Destructor Documentation

◆ RTSPMediaCallbackSource() [1/3]

Default constructor.

◆ RTSPMediaCallbackSource() [2/3]

RTSPMediaCallbackSource ( read_callback_t  callback,
void *  userData = nullptr 
)
inline

Constructor with read callback.

Parameters
callbackFunction to call for reading media data
userDataOptional pointer passed to callbacks

◆ RTSPMediaCallbackSource() [3/3]

RTSPMediaCallbackSource ( RTSPFormat format,
read_callback_t  callback,
void *  userData = nullptr 
)
inline

Constructor with format and read callback.

Parameters
formatRTSPFormat configuration for the media stream
callbackFunction to call for reading media data
userDataOptional pointer passed to callbacks

◆ ~RTSPMediaCallbackSource()

virtual ~RTSPMediaCallbackSource ( )
inlinevirtual

Member Function Documentation

◆ getFormat()

RTSPFormat & getFormat ( )
inlineoverridevirtual

Get the current RTSP format configuration.

Returns
Reference to the format configuration

Implements IMediaSource.

◆ getUserData()

void * getUserData ( ) const
inline

Get the user data pointer.

Returns
Pointer passed to callbacks

◆ isActive()

bool isActive ( ) const
inline

Check if the source is active.

Returns
true if started and callback is configured

◆ packetSize()

int packetSize ( )
inlineoverridevirtual

Report the size of the next queued fragment via the configured packet-size callback (packetized/video sources only)

Returns
-1 if no packet-size callback is configured (falls back to the generic byte-stream path in RTSPMediaStreamer), 0 if packetized but nothing is queued right now, otherwise the size of the next fragment

Reimplemented from IMediaSource.

◆ readBytes()

int readBytes ( void *  dest,
int  maxBytes 
)
inlineoverridevirtual

Read media data using the configured callback.

Parameters
destBuffer to receive media data
maxBytesMaximum number of bytes to read
Returns
Number of bytes actually read

Implements IMediaSource.

◆ setFormat()

void setFormat ( RTSPFormat format)
inline

Set the RTSP format configuration.

Parameters
formatFormat configuration for the media stream

◆ setPacketSizeCallback()

void setPacketSizeCallback ( packet_size_callback_t  callback)
inline

Set the callback reporting the size of the next already- fragmented, ready-to-send packet. Configuring this switches packetSize() from the default "not packetized" (-1) to forwarding the callback's result, which in turn switches RTSPMediaStreamer to the packetized send path (see IMediaSource::packetSize()) - use this for video sources whose fragmentation/RTP payload framing is done externally (e.g. by an H264RtpEncoder/JPEGRtpEncoder that the read callback pulls from).

Parameters
callbackFunction that reports the next fragment's size

◆ setReadCallback()

void setReadCallback ( read_callback_t  callback,
void *  userData = nullptr 
)
inline

Set the callback function for reading media data.

Parameters
callbackFunction that provides media data
userDataOptional pointer passed to the callback

◆ setStartCallback()

void setStartCallback ( lifecycle_callback_t  callback)
inline

Set optional start callback (called when streaming begins)

Parameters
callbackFunction called during start()

◆ setStopCallback()

void setStopCallback ( lifecycle_callback_t  callback)
inline

Set optional stop callback (called when streaming ends)

Parameters
callbackFunction called during stop()

◆ start()

void start ( )
inlineoverridevirtual

Start the media source Calls the optional start callback if configured.

Reimplemented from IMediaSource.

◆ stop()

void stop ( )
inlineoverridevirtual

Stop the media source Calls the optional stop callback if configured.

Reimplemented from IMediaSource.

Member Data Documentation

◆ default_format

RTSPFormatPCM default_format
protected

◆ is_active

bool is_active
protected

◆ p_format

RTSPFormat* p_format
protected

◆ packet_size_callback

packet_size_callback_t packet_size_callback
protected

◆ read_callback

read_callback_t read_callback
protected

◆ start_callback

lifecycle_callback_t start_callback
protected

◆ stop_callback

lifecycle_callback_t stop_callback
protected

◆ user_data

void* user_data
protected

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