arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RtspSession< Platform > Class Template Reference

RTSP Session Handler - Individual Client Protocol Management. More...

#include <RTSPSession.h>

Public Member Functions

 RtspSession (typename Platform::TcpClientType &aClient, RTSPAudioStreamerBase< Platform > &aStreamer)
 Construct RTSP session for a connected client.
 
 ~RtspSession ()
 Destructor - cleanup session resources.
 
bool handleRequests (uint32_t readTimeoutMs)
 Process incoming RTSP requests from the client.
 
bool isSessionOpen ()
 
bool isStreaming ()
 

Protected Member Functions

char const * dateHeader ()
 
void detectClientHeaderPreference (char *req)
 
void determineCommandType ()
 
Platform::TcpClientType *& getClient ()
 
uint16_t getRtpClientPort ()
 
int getStreamID ()
 
void handleRtspDescribe ()
 
void handleRtspOption ()
 
void handleRtspPause ()
 
void handleRtspPlay ()
 
RTSP_CMD_TYPES handleRtspRequest (char const *aRequest, unsigned aRequestSize)
 
void handleRtspSetup ()
 
void handleRtspTeardown ()
 
void init ()
 
void initTransport (u_short aRtpPort, u_short aRtcpPort)
 
void parseClientPorts (char *req)
 
bool parseCommandName (char *req, unsigned reqSize, unsigned &outIdx)
 
void parseContentLength (char *req, unsigned reqSize, unsigned startIdx)
 
bool parseCSeq (char *req, unsigned reqSize, unsigned startIdx)
 
bool parseRtspRequest (char const *aRequest, unsigned aRequestSize)
 
void parseTransportHeader (char *req)
 
void parseUrlHostPortAndSuffix (char *req, unsigned reqSize, unsigned &i)
 
int readSocket (typename Platform::TcpClientType *sock, char *buf, size_t buflen, int timeoutmsec)
 Inline helper to read from socket.
 
ssize_t sendSocket (typename Platform::TcpClientType *sock, const void *buf, size_t len)
 Inline helper to send data over socket.
 

Protected Attributes

audio_tools::Vector< char > m_Buf1
 
audio_tools::Vector< char > m_Buf2
 
Platform::TcpClientType m_Client
 
uint16_t m_ClientRTCPPort
 
uint16_t m_ClientRTPPort
 
audio_tools::Vector< char > m_CmdName
 
unsigned m_ContentLength
 
audio_tools::Vector< char > m_CSeq
 
int m_InterleavedRtcp = -1
 
int m_InterleavedRtp = -1
 
bool m_is_init = false
 
audio_tools::Vector< char > m_Response
 
uint16_t m_RtcpClientPort
 
uint16_t m_RtpClientPort
 
Platform::TcpClientType * m_RtspClient
 
RTSP_CMD_TYPES m_RtspCmdType
 
int m_RtspSessionID
 
audio_tools::Vector< char > m_SDPBuf
 
volatile bool m_sessionOpen = true
 
RTSPAudioStreamerBase< Platform > * m_Streamer
 
int m_StreamID = -1
 
bool m_streaming = false
 
bool m_TransportIsTcp = false
 
audio_tools::Vector< char > m_URLBuf
 
audio_tools::Vector< char > m_URLHostPort
 
audio_tools::Vector< char > m_URLPreSuffix
 
audio_tools::Vector< char > m_URLSuffix
 
audio_tools::Vector< char > mCurRequest
 
audio_tools::Vector< char > mRecvBuf
 
const char * STD_URL_PRE_SUFFIX = "trackID"
 

Detailed Description

template<typename Platform>
class audio_tools::RtspSession< Platform >

RTSP Session Handler - Individual Client Protocol Management.

The RtspSession class manages RTSP protocol communication with a single client. It handles the complete RTSP session lifecycle from initial connection through streaming termination. Key responsibilities include:

The memory for buffers is allocated in PSRAM if available and active.

RTSP Protocol Support

  1. OPTIONS - Client queries supported methods
  2. DESCRIBE - Server returns SDP with audio format details
  3. SETUP - Client requests RTP transport, server allocates ports
  4. PLAY - Client starts playback, server begins RTP streaming
  5. TEARDOWN - Client ends session, server cleans up resources
Note
This class is typically instantiated by RTSPServer, not directly by users
Requires a configured RTSPAudioStreamer for media delivery
Author
Thomas Pfitzinger
Version
0.2.0

Constructor & Destructor Documentation

◆ RtspSession()

template<typename Platform >
RtspSession ( typename Platform::TcpClientType &  aClient,
RTSPAudioStreamerBase< Platform > &  aStreamer 
)
inline

Construct RTSP session for a connected client.

Creates a new RTSP session instance to handle protocol communication with a specific client. Initializes session state and prepares for RTSP message processing. Buffer initialization is handled by the init() method.

Parameters
aClientWiFiClient object representing the connected RTSP client
aStreamerPointer to RTSPAudioStreamer that will provide audio data for this session
Note
Session automatically generates unique session ID and initializes internal state
Vector buffers are initialized lazily by the init() method when needed
See also
handleRequests(), init()

◆ ~RtspSession()

template<typename Platform >
~RtspSession ( )
inline

Destructor - cleanup session resources.

Closes the RTSP client socket and ensures streaming is properly stopped. Vector buffers are automatically managed.

Note
Ensures UDP transport cleanup for proper resource management

Member Function Documentation

◆ dateHeader()

template<typename Platform >
char const * dateHeader ( )
inlineprotected

Create the DateHeader string for RTSP responses

Returns
pointer to Date Header string

◆ getStreamID()

template<typename Platform >
int getStreamID ( )
inlineprotected

Gives the current stream ID

Returns
ID of current stream or -1 if invalid

◆ handleRequests()

template<typename Platform >
bool handleRequests ( uint32_t  readTimeoutMs)
inline

Process incoming RTSP requests from the client.

Reads RTSP messages from the client socket and dispatches them to appropriate handler methods. This is the main processing loop for RTSP protocol communication. Supports all standard RTSP commands (OPTIONS, DESCRIBE, SETUP, PLAY, TEARDOWN).

Parameters
readTimeoutMsMaximum time in milliseconds to wait for incoming data
Returns
true if request was processed successfully, false on timeout or session end
Note
Returns false when client disconnects or times out
Filters messages to ensure they are valid RTSP commands
Should be called repeatedly in a loop until it returns false

◆ handleRtspDescribe()

template<typename Platform >
void handleRtspDescribe ( )
inlineprotected

Sends Response to DESCRIBE command

◆ handleRtspOption()

template<typename Platform >
void handleRtspOption ( )
inlineprotected

Sends Response to OPTIONS command

◆ handleRtspPause()

template<typename Platform >
void handleRtspPause ( )
inlineprotected

Sends Response to PAUSE command and stops RTP stream without closing session

◆ handleRtspPlay()

template<typename Platform >
void handleRtspPlay ( )
inlineprotected

Sends Response to PLAY command and starts the RTP stream

◆ handleRtspRequest()

template<typename Platform >
RTSP_CMD_TYPES handleRtspRequest ( char const *  aRequest,
unsigned  aRequestSize 
)
inlineprotected

Parses the an RTSP request and calls the response function depending on the type of command

Parameters
aRequestc string containing the request
aRequestSizelength of the request
Returns
the command type of the RTSP request

◆ handleRtspSetup()

template<typename Platform >
void handleRtspSetup ( )
inlineprotected

Sends Response to SETUP command and prepares RTP stream

◆ handleRtspTeardown()

template<typename Platform >
void handleRtspTeardown ( )
inlineprotected

Sends Response to TEARDOWN command, stops the RTP stream

◆ init()

template<typename Platform >
void init ( )
inlineprotected

Initializes memory and buffers

Lazily initializes Vector buffers if they haven't been allocated yet, and resets all RTSP parsing state variables to their default values. This method can be called multiple times safely.

◆ initTransport()

template<typename Platform >
void initTransport ( u_short  aRtpPort,
u_short  aRtcpPort 
)
inlineprotected

Prepares sockets for RTP stream

Parameters
aRtpPortlocal port number for RTP connection
aRtcpPortlocal port number for RTCP connection

◆ parseRtspRequest()

template<typename Platform >
bool parseRtspRequest ( char const *  aRequest,
unsigned  aRequestSize 
)
inlineprotected

Parses an RTSP request, storing the extracted information in the RTSPSession object

Parameters
aRequestc string containing the request
aRequestSizelength of the request
Returns
true if parsing was successful

◆ readSocket()

template<typename Platform >
int readSocket ( typename Platform::TcpClientType *  sock,
char *  buf,
size_t  buflen,
int  timeoutmsec 
)
inlineprotected

Inline helper to read from socket.

Parameters
sockTCP socket to read from
bufBuffer to read into
buflenBuffer length
timeoutmsecTimeout in milliseconds
Returns
Number of bytes read, 0=closed, -1=timeout

◆ sendSocket()

template<typename Platform >
ssize_t sendSocket ( typename Platform::TcpClientType *  sock,
const void *  buf,
size_t  len 
)
inlineprotected

Inline helper to send data over socket.

Parameters
sockTCP socket to send to
bufData buffer to send
lenLength of data
Returns
Number of bytes sent

Member Data Documentation

◆ m_RtcpClientPort

template<typename Platform >
uint16_t m_RtcpClientPort
protected
Initial value:
=
0

◆ m_RtpClientPort

template<typename Platform >
uint16_t m_RtpClientPort
protected
Initial value:
=
0

◆ m_RtspClient

template<typename Platform >
Platform::TcpClientType* m_RtspClient
protected
Initial value:
=
nullptr

◆ m_Streamer

template<typename Platform >
RTSPAudioStreamerBase<Platform>* m_Streamer
protected
Initial value:
=
nullptr

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