|
arduino-audio-tools
|
RTSPAudioStreamerUsingTask - Task-driven RTP Audio Streaming Engine. More...
#include <RTSPAudioStreamerUsingTask.h>
Public Member Functions | |
| RTSPAudioStreamerUsingTask (bool throttled=true) | |
| RTSPAudioStreamerUsingTask (IAudioSource &source, bool throttled=true) | |
| 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. | |
| IAudioSource * | getAudioSource () |
| 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 | initAudioSource () |
| 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 | sendRtpPacketDirect () |
| Send a single RTP packet with audio data. | |
| virtual void | setAudioSource (IAudioSource *source) |
| Configure the audio source for streaming. | |
| void | setFixedDelayMs (uint32_t delayUs) |
| 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 () |
| uint32_t | computeTimestampIncrement (int bytesSent) |
| Compute RTP timestamp increment based on samples sent. | |
| void | sendOut (uint16_t totalLen) |
| void | streamingTaskLoop () |
| void | tryLearnClientFromUdp (bool warnIfNone) |
Protected Attributes | |
| const int | HEADER_SIZE = 12 |
| IAudioSource * | m_audioSource = nullptr |
| IPAddress | m_ClientIP |
| uint16_t | m_ClientPort |
| uint16_t | m_fixed_delay_ms = 1 |
| int | m_fragmentSize = 0 |
| unsigned long | m_last_throttle_us = 0 |
| int | m_lastSamplesSent = 0 |
| int | m_payloadType = 96 |
| uint32_t | m_prevMsec |
| uint16_t | m_RtcpServerPort |
| Platform::UdpSocketType * | m_RtcpSocket |
| uint16_t | m_RtpServerPort |
| Platform::UdpSocketType * | m_RtpSocket |
| Platform::TcpClientType * | m_RtspTcpSocket |
| uint32_t | m_send_counter = 0 |
| int | m_SendIdx |
| u_short | m_SequenceNumber |
| uint32_t | m_Ssrc = 0x13F97E67 |
| audio_tools::Task | m_streamingTask |
| int | m_taskCore = -1 |
| uint8_t | m_taskPriority = 5 |
| volatile bool | m_taskRunning |
| uint32_t | m_taskStackSize = 8192 |
| int | m_TcpRtcpChannel |
| int | m_TcpRtpChannel |
| uint32_t | m_throttle_interval = 50 |
| bool | m_throttled = true |
| int | m_timer_period_us = 20000 |
| volatile bool | m_timer_restart_needed |
| uint32_t | m_Timestamp |
| int | m_udpRefCount |
| bool | m_useTcpInterleaved |
| audio_tools::Vector< uint8_t > | mMp3Carry |
| int | mMp3CarryLen = 0 |
| audio_tools::Vector< uint8_t > | mRtpBuf |
| const int | STREAMING_BUFFER_SIZE = 1024 * 3 |
RTSPAudioStreamerUsingTask - Task-driven RTP Audio Streaming Engine.
The RTSPAudioStreamerUsingTask class extends RTSPAudioStreamerBase 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 audio 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.
|
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 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 |
|
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.
|
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 |
|
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 IAudioSource implementation. Must not be nullptr. |
|
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 RTSPAudioStreamerBase< 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 RTSPAudioStreamerBase< Platform >.
|
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 RTSPAudioStreamerBase instance (passed as callback parameter) |
|
protectedinherited |