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

RTSP Server - Multi-client Audio Streaming Server. More...

#include <RTSPServer.h>

Public Types

using streamer_t = RTSPAudioStreamerBase< Platform >
 

Public Member Functions

 RTSPServer (streamer_t &streamer, int port=8554, int core=1)
 Construct RTSP server.
 
 ~RTSPServer ()
 Destructor - ensures proper cleanup of server resources.
 
bool begin ()
 
int clientCount ()
 Get the number of connected clients.
 
audio_tools::TaskgetTaskHandle ()
 Get the server task handle.
 
 operator bool ()
 Returns true if there is at least one connected client.
 
void setOnSessionPath (bool(*cb)(const char *path, void *ref), void *ref=nullptr)
 Set a callback to receive the RTSP URL path for each new session. The callback is forwarded to every RtspSession and invoked once per session after the first request is parsed.
 
void setSessionTimoutMs (unsigned long ms)
 Set the session timeout in milliseconds.
 

Protected Member Functions

bool runAsync ()
 Start RTSP server asynchronously.
 
void serverThreadLoop ()
 Main server thread loop - listens for RTSP client connections.
 
void sessionThreadLoop ()
 Client session thread loop - handles RTSP protocol for individual clients.
 
void stop ()
 Stop the RTSP server and cleanup resources.
 

Protected Attributes

Platform::TcpClientType client
 
int client_count = 0
 
int core
 
bool(* onSessionPathCb )(const char *, void *) = nullptr
 
void * onSessionPathRef = nullptr
 
int port
 
Platform::TcpServerType * server = nullptr
 
audio_tools::Task serverTask {"RTSPServerThread", 15000, 5, core}
 
audio_tools::Task sessionTask {"RTSPSessionTask", 15000, 8, core}
 
unsigned long sessionTimeoutMs = 20000
 
streamer_tstreamer = nullptr
 

Detailed Description

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

RTSP Server - Multi-client Audio Streaming Server.

The RTSPServer class implements a complete RTSP (Real Time Streaming Protocol) server that manages client connections and coordinates audio streaming sessions. This server:

Author
Phil Schatzmann

RTSP Protocol Support

Note
Supports multiple platforms through AudioTools Task and Timer systems

Constructor & Destructor Documentation

◆ RTSPServer()

template<typename Platform >
RTSPServer ( streamer_t streamer,
int  port = 8554,
int  core = 1 
)
inline

Construct RTSP server.

Creates a new RTSP server instance configured to work with the specified RTSPAudioStreamer. The server will listen for client connections and coordinate streaming sessions.

Parameters
streamerPointer to RTSPAudioStreamer that provides the audio data source. Must remain valid for the server's lifetime.
portTCP port number for RTSP connections (default 8554 - standard RTSP port)
coreCore number to run server tasks on (platform-specific, default 1)
Note
The RTSPAudioStreamer must be properly configured with an audio source
Port 8554 is the IANA-assigned port for RTSP
See also
begin(), runAsync()

Member Function Documentation

◆ begin()

template<typename Platform >
bool begin ( )
inline

Start the RTSP server

◆ clientCount()

template<typename Platform >
int clientCount ( )
inline

Get the number of connected clients.

Returns
Number of clients

◆ getTaskHandle()

template<typename Platform >
audio_tools::Task & getTaskHandle ( )
inline

Get the server task handle.

Returns
Reference to the server task

◆ runAsync()

template<typename Platform >
bool runAsync ( )
inlineprotected

Start RTSP server asynchronously.

Begins listening for RTSP client connections on the configured port. The server runs in a separate FreeRTOS task, allowing the main program to continue executing. Client sessions are handled in additional tasks.

Returns
true on success, false on failure
Note
WiFi must be connected before calling this method
Server runs on the configured core (if platform supports it)
Use this method when WiFi is already established
See also
begin() for WiFi setup + server start

◆ serverThreadLoop()

template<typename Platform >
void serverThreadLoop ( )
inlineprotected

Main server thread loop - listens for RTSP client connections.

This member method implements the main server loop. It accepts incoming TCP connections from RTSP clients and creates session threads to handle each client's RTSP protocol communication.

Note
Currently supports one client at a time (single-threaded sessions)
Runs indefinitely in the task loop
Creates sessionThread tasks for each accepted client

◆ sessionThreadLoop()

template<typename Platform >
void sessionThreadLoop ( )
inlineprotected

Client session thread loop - handles RTSP protocol for individual clients.

This member method runs in a dedicated Task for each connected client. It creates an RTSPSession object and processes RTSP requests (DESCRIBE, SETUP, PLAY, TEARDOWN) until the client disconnects or an error occurs.

Note
Each client gets its own session thread
Thread automatically terminates when client disconnects
Manages RTSPSession lifecycle and socket cleanup

◆ setOnSessionPath()

template<typename Platform >
void setOnSessionPath ( bool(*)(const char *path, void *ref)  cb,
void *  ref = nullptr 
)
inline

Set a callback to receive the RTSP URL path for each new session. The callback is forwarded to every RtspSession and invoked once per session after the first request is parsed.

Return semantics:

  • true: accept session and continue normal RTSP handling
  • false: reject session; the session will be marked closed and no responses will be sent for the pending request

◆ setSessionTimoutMs()

template<typename Platform >
void setSessionTimoutMs ( unsigned long  ms)
inline

Set the session timeout in milliseconds.

Parameters
msTimeout in milliseconds

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