|
arduino-audio-tools
|
RTSPMediaStreamerUsingTask - Task-driven RTP Media Streaming Engine. More...
#include <RTSPMediaStreamerUsingTask.h>
Public Member Functions | |
| RTSPMediaStreamerUsingTask (bool throttled=true) | |
| RTSPMediaStreamerUsingTask (IMediaSource &source, bool throttled=true) | |
| virtual | ~RTSPMediaStreamerUsingTask () |
| bool | checkTimerPeriodChange () |
| Check if timer period has changed and update if necessary. | |
| uint32_t | currentRtpTimestamp () const |
| Get current RTP timestamp value that will be used in the next packet. | |
| uint16_t | currentSeq () const |
| Get current RTP sequence number that will be used in the next packet. | |
| uint32_t | currentSsrc () const |
| Get current SSRC used in RTP header. | |
| IMediaSource * | getMediaSource () |
| Get the configured audio source. | |
| u_short | getRtcpServerPort () |
| Get the RTCP server port number. | |
| u_short | getRtpServerPort () |
| Get the RTP server port number. | |
| uint32_t | getTimerPeriodMs () const |
| Get the timer period in milliseconds. | |
| uint32_t | getTimerPeriodUs () const |
| Get the timer period in microseconds. | |
| bool | initMediaSource () |
| Initialize audio source configuration. | |
| void | initTcpInterleavedTransport (typename Platform::TcpClientType *tcpSock, int rtpChannel, int rtcpChannel) |
| Initialize TCP interleaved transport for RTP over RTSP. | |
| bool | initUdpTransport (IPAddress aClientIP, uint16_t aClientPort) |
| Initialize UDP transport for RTP streaming. | |
| bool | isTaskRunning () const |
| void | releaseUdpTransport (void) |
| Release UDP transport resources. | |
| int | sendPacketizedFrame (int firstPacketSize) |
| Send every already-fragmented RTP payload belonging to the next queued video frame (packetized sources, e.g. JPEGRtpEncoder). | |
| int | sendRtpPacketDirect () |
| Send a single RTP packet with audio data. | |
| void | setFixedDelayMs (uint32_t delayUs) |
| virtual void | setMediaSource (IMediaSource *source) |
| Configure the audio source for streaming. | |
| void | setTaskParameters (uint32_t stackSize, uint8_t priority, int core=-1) |
| void | setThrottled (bool isThrottled) |
| void | setThrottleInterval (uint32_t interval) |
| void | start () override |
| Start audio source (base implementation) | |
| void | stop () override |
| Stop audio source (base implementation) | |
Static Public Member Functions | |
| static void | timerCallback (void *audioStreamerObj) |
| Static timer callback function for periodic RTP streaming. | |
Protected Member Functions | |
| void | applyThrottling (unsigned long iterationStartUs) |
| void | buildRtpHeader (bool markerBit=false) |
| uint32_t | computeTimestampIncrement (int bytesSent) |
| Compute RTP timestamp increment based on samples sent. | |
| void | sendOut (uint16_t totalLen) |
| void | streamingTaskLoop () |
| void | tryLearnClientFromUdp (bool warnIfNone) |
RTSPMediaStreamerUsingTask - Task-driven RTP Media Streaming Engine.
The RTSPMediaStreamerUsingTask class extends RTSPMediaStreamerBase with AudioTools Task-driven streaming functionality. Instead of using hardware timers, this class creates a dedicated task that continuously calls the timer callback at the appropriate intervals. This approach provides:
The throttling feature is particularly important when working with media sources that can provide data faster than the defined sampling rate, such as file readers, buffer sources, or fast generators. Without throttling, these sources would flood the network with packets faster than real-time playback.
|
inline |
|
inline |
|
inlinevirtual |
|
inlineprotected |
|
inlineprotectedinherited |
|
inlineinherited |
Check if timer period has changed and update if necessary.
Checks the audio source format for timer period changes and updates the cached value if different. This enables dynamic timer period adjustments during playback when the audio format changes.
|
inlineprotectedinherited |
Compute RTP timestamp increment based on samples sent.
Calculates the appropriate RTP timestamp increment based on the number of audio samples sent in the last packet. This ensures proper timing and synchronization in the RTP stream.
| bytesSent | Number of bytes sent in the last RTP packet |
|
inlineinherited |
Get current RTP timestamp value that will be used in the next packet.
|
inlineinherited |
Get current RTP sequence number that will be used in the next packet.
|
inlineinherited |
Get current SSRC used in RTP header.
|
inlineinherited |
Get the configured audio source.
|
inlineinherited |
Get the RTCP server port number.
|
inlineinherited |
Get the RTP server port number.
|
inlineinherited |
Get the timer period in milliseconds.
|
inlineinherited |
Get the timer period in microseconds.
|
inlineinherited |
Initialize audio source configuration.
Extracts and caches configuration parameters from the audio source including fragment size (bytes per packet) and timer period (microseconds between packets). This method must be called before streaming can begin.
|
inlineinherited |
Initialize TCP interleaved transport for RTP over RTSP.
Configures the streamer to send RTP packets using RTSP TCP interleaving. RTP and RTCP packets are framed with '$', channel byte, and 2-byte length per RFC 2326 section 10.12 and sent over the RTSP control socket.
| tcpSock | Pointer to the RTSP TCP client socket |
| rtpChannel | Interleaved channel number for RTP packets (e.g., 0) |
| rtcpChannel | Interleaved channel number for RTCP packets (e.g., 1) |
|
inlineinherited |
Initialize UDP transport for RTP streaming.
Sets up UDP sockets for RTP and RTCP communication with a specific client. Automatically allocates consecutive port pairs starting from 6970. Supports multiple clients through reference counting - subsequent calls with different clients will reuse existing sockets.
| aClientIP | IP address of the RTP client that will receive the stream |
| aClientPort | Port number on the client for receiving RTP packets |
|
inline |
|
inlineinherited |
Release UDP transport resources.
Decrements the reference count for UDP socket usage and closes sockets when no more clients are using them. This implements proper resource management for multiple concurrent streaming sessions.
|
inlineprotectedinherited |
|
inlineinherited |
Send every already-fragmented RTP payload belonging to the next queued video frame (packetized sources, e.g. JPEGRtpEncoder).
Each fragment already carries its own payload-format header (e.g. RFC 2435); this method only wraps it in the generic 12-byte RTP header. The marker bit is set on a fragment when packetSize() reports nothing left queued right after sending it - i.e. the source is expected to keep at most one frame's worth of fragments queued at a time (see JPEGRtpEncoder::m_maxQueuedFrames), so "nothing left" means "that was the last fragment of this frame". All fragments of the frame share a single timestamp (advanced once by the caller after this method returns, matching one call = one frame).
| firstPacketSize | Result of the packetSize() call the caller already made to detect that this source is packetized; reused here instead of querying it again for the first fragment. |
|
inlineinherited |
Send a single RTP packet with audio data.
Constructs and sends one RTP packet containing audio data from the configured source. This method handles the complete RTP packet creation process including:
| -1 | RTP buffer not allocated or audio source not configured |
|
inline |
|
inlinevirtualinherited |
Configure the audio source for streaming.
Sets or changes the audio source that provides data for the RTP stream. This method automatically initializes the audio source configuration including fragment size and timer period based on the source's format specifications.
| source | Pointer to an IMediaSource implementation. Must not be nullptr. |
|
inline |
|
inline |
|
inline |
|
inlineoverridevirtual |
Start audio source (base implementation)
Begins the audio source and initializes the RTP buffer if not already done. This base implementation does not start any timer - derived classes should override this method to add timer functionality.
Reimplemented from RTSPMediaStreamerBase< Platform >.
|
inlineoverridevirtual |
Stop audio source (base implementation)
Stops the audio source. This base implementation does not manage any timer - derived classes should override this method to add timer management.
Reimplemented from RTSPMediaStreamerBase< Platform >.
|
inlineprotected |
|
inlinestaticinherited |
Static timer callback function for periodic RTP streaming.
This static method is called periodically by timers to send RTP packets. It handles timing measurements and calls sendRtpPacketDirect() to transmit audio data. Performance monitoring ensures the streaming keeps up with real-time requirements.
This method can be used by any derived class that implements timer-driven streaming functionality.
| audioStreamerObj | Void pointer to the RTSPMediaStreamerBase instance (passed as callback parameter) |
|
inlineprotectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |