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

Unified RTSP Media Source - Works with both Stream and AudioStream. More...

#include <RTSPMediaSource.h>

Inheritance diagram for RTSPMediaSource:
IMediaSource

Public Member Functions

 RTSPMediaSource ()=default
 
 RTSPMediaSource (AudioStream &stream)
 Construct from AudioStream with automatic audio info detection.
 
 RTSPMediaSource (Stream &stream, AudioInfo info)
 Construct from generic Stream with manual audio configuration.
 
 RTSPMediaSource (Stream &stream, RTSPFormat &format)
 Construct from generic Stream with format object.
 
virtual ~RTSPMediaSource ()
 Destructor - Clean up resources.
 
RTSPFormatgetFormat () override
 Get the media format configuration.
 
bool isActive ()
 Check if source is actively being read (AudioStream only)
 
bool isStarted ()
 Returns true after start() has been called.
 
virtual int packetSize ()
 Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.
 
int readBytes (void *dest, int byteCount) override
 Read audio data for RTSP streaming.
 
void setAudioInfo (AudioInfo info)
 Set audio configuration manually.
 
void setFormat (RTSPFormat &format)
 
void setFragmentSize (int fragmentSize)
 Defines the fragment size.
 
void setInput (AudioStream &stream)
 Set input from AudioStream (with auto-detection)
 
void setInput (Stream &stream)
 Set input from generic Stream (audio info must be set separately)
 
void setInput (Stream &stream, AudioInfo info)
 Set input from generic Stream with explicit audio info.
 
void setTimeout (uint16_t to)
 
void setTimerPeriod (int period)
 Defines the timer period.
 
void start () override
 Start the audio source.
 
void stop () override
 Stop the audio source.
 

Protected Attributes

RTSPFormatPCM default_format
 
uint32_t m_magic = MAGIC_NUMBER
 
const uint32_t MAGIC_NUMBER
 
AudioStreamp_audiostream = nullptr
 
RTSPFormatp_format = &default_format
 
Streamp_stream = nullptr
 
bool started = false
 
uint32_t time_of_last_read = 0
 
uint16_t timeout = 0
 

Detailed Description

Unified RTSP Media Source - Works with both Stream and AudioStream.

This class can adapt any Arduino Stream or AudioTools AudioStream into an IMediaSource for RTSP streaming. It automatically detects AudioStream capabilities when available and falls back to manual configuration for generic Streams.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ RTSPMediaSource() [1/4]

RTSPMediaSource ( )
default

◆ ~RTSPMediaSource()

virtual ~RTSPMediaSource ( )
inlinevirtual

Destructor - Clean up resources.

◆ RTSPMediaSource() [2/4]

RTSPMediaSource ( AudioStream stream)
inline

Construct from AudioStream with automatic audio info detection.

Parameters
streamAudioStream that provides audio configuration automatically

◆ RTSPMediaSource() [3/4]

RTSPMediaSource ( Stream stream,
AudioInfo  info 
)
inline

Construct from generic Stream with manual audio configuration.

Parameters
streamGeneric Stream to read audio data from
infoAudio configuration (sample rate, channels, bit depth)

◆ RTSPMediaSource() [4/4]

RTSPMediaSource ( Stream stream,
RTSPFormat format 
)
inline

Construct from generic Stream with format object.

Parameters
streamGeneric Stream to read audio data from
formatRTSPFormat configuration object

Member Function Documentation

◆ getFormat()

RTSPFormat & getFormat ( )
inlineoverridevirtual

Get the media format configuration.

Returns the RTSPFormat object that describes the media data characteristics including sample rate, bit depth, number of channels, and RTP packaging parameters. If no format has been explicitly set, creates a default 16-bit PCM format at 16kHz mono.

Returns
Pointer to RTSPFormat describing the media characteristics
Note
Default format: 16-bit PCM, 16000 Hz, 1 channel
See also
setFormat(), RTSPFormatPCM

Implements IMediaSource.

◆ isActive()

bool isActive ( )
inline

Check if source is actively being read (AudioStream only)

Returns
true if recent read activity detected, false otherwise

◆ isStarted()

bool isStarted ( )
inline

Returns true after start() has been called.

◆ packetSize()

virtual int packetSize ( )
inlinevirtualinherited

Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.

Call it once before each readBytes() to size that call, and again right after to tell whether the fragment just read was the last one currently available - a 0 result means the caller should set the RTP marker bit on the fragment it just sent (and may advance the timestamp for the next frame).

Returns
-1 if this source is not packetized (use the plain readBytes() stream instead), 0 if packetized but nothing is queued right now, otherwise the size in bytes of the next fragment

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, and RTSPMediaCallbackSource.

◆ readBytes()

int readBytes ( void *  dest,
int  byteCount 
)
inlineoverridevirtual

Read audio data for RTSP streaming.

Parameters
destBuffer to receive audio data
byteCountNumber of bytes to read
Returns
Actual number of bytes read

Implements IMediaSource.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inline

Set audio configuration manually.

This is required when using generic Stream objects, but optional for AudioStream objects which can provide their own configuration.

Parameters
infoAudio configuration (sample rate, channels, bit depth)

◆ setFormat()

void setFormat ( RTSPFormat format)
inline

◆ setFragmentSize()

void setFragmentSize ( int  fragmentSize)
inline

Defines the fragment size.

◆ setInput() [1/3]

void setInput ( AudioStream stream)
inline

Set input from AudioStream (with auto-detection)

Parameters
streamAudioStream that can provide its own audio configuration

◆ setInput() [2/3]

void setInput ( Stream stream)
inline

Set input from generic Stream (audio info must be set separately)

Parameters
streamGeneric Arduino Stream

◆ setInput() [3/3]

void setInput ( Stream stream,
AudioInfo  info 
)
inline

Set input from generic Stream with explicit audio info.

Parameters
streamGeneric Arduino Stream
infoAudio configuration parameters

◆ setTimeout()

void setTimeout ( uint16_t  to)
inline

◆ setTimerPeriod()

void setTimerPeriod ( int  period)
inline

Defines the timer period.

◆ start()

void start ( )
inlineoverridevirtual

Start the audio source.

For AudioStreams, calls begin() to initialize the stream. For generic Streams, just sets the active flag.

Reimplemented from IMediaSource.

◆ stop()

void stop ( )
inlineoverridevirtual

Stop the audio source.

For AudioStreams, calls end() to cleanup the stream. For generic Streams, just clears the active flag.

Reimplemented from IMediaSource.

Member Data Documentation

◆ default_format

RTSPFormatPCM default_format
protected

◆ m_magic

uint32_t m_magic = MAGIC_NUMBER
protected

◆ MAGIC_NUMBER

const uint32_t MAGIC_NUMBER
protected
Initial value:
=
0xFEEDFACE

◆ p_audiostream

AudioStream* p_audiostream = nullptr
protected

◆ p_format

RTSPFormat* p_format = &default_format
protected

◆ p_stream

Stream* p_stream = nullptr
protected

◆ started

bool started = false
protected

◆ time_of_last_read

uint32_t time_of_last_read = 0
protected

◆ timeout

uint16_t timeout = 0
protected

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