pub struct Server { /* private fields */ }Expand description
High-level RTSP server orchestrator.
Owns the mount registry, session manager, and transport layer.
Delegates TCP connection handling to crate::transport::tcp and
RTP delivery to UdpTransport.
§Simple usage (single stream)
use rtsp::Server;
let mut server = Server::new("0.0.0.0:8554");
server.start().unwrap();
// server.send_frame(&h264_data, 3000).unwrap();§Multi-mount usage
use rtsp::Server;
use rtsp::media::h264::H264Packetizer;
let mut server = Server::new("0.0.0.0:8554");
server.add_mount("/cam1", Box::new(H264Packetizer::with_random_ssrc(96)));
server.start().unwrap();
// server.send_frame_to("/cam1", &data, 3000).unwrap();Implementations§
Source§impl Server
impl Server
Sourcepub fn new(bind_addr: &str) -> Self
pub fn new(bind_addr: &str) -> Self
Create a server with a default H.264 mount at /stream.
bind_addr must be host:port with an explicit non-zero port (e.g. 127.0.0.1:8554).
Port 0 is not allowed; validation happens in start.
Sourcepub fn new_with_mount_path(bind_addr: &str, mount_path: &str) -> Self
pub fn new_with_mount_path(bind_addr: &str, mount_path: &str) -> Self
Create a server with a single H.264 mount at the given path.
Use this when the stream path is configurable (e.g. GStreamer mount-path property).
bind_addr must be host:port with an explicit non-zero port.
Sourcepub fn with_config(bind_addr: &str, config: ServerConfig) -> Self
pub fn with_config(bind_addr: &str, config: ServerConfig) -> Self
Create a server with custom protocol/SDP configuration.
A default H.264 mount at /stream is created automatically.
Sourcepub fn with_packetizer(bind_addr: &str, packetizer: Box<dyn Packetizer>) -> Self
pub fn with_packetizer(bind_addr: &str, packetizer: Box<dyn Packetizer>) -> Self
Create a server with a custom packetizer on the default mount.
Sourcepub fn with_packetizer_and_config(
bind_addr: &str,
packetizer: Box<dyn Packetizer>,
config: ServerConfig,
) -> Self
pub fn with_packetizer_and_config( bind_addr: &str, packetizer: Box<dyn Packetizer>, config: ServerConfig, ) -> Self
Create a server with a custom packetizer and protocol/SDP configuration.
Sourcepub fn add_mount(&self, path: &str, packetizer: Box<dyn Packetizer>)
pub fn add_mount(&self, path: &str, packetizer: Box<dyn Packetizer>)
Register a named mount with its own packetizer.
Must be called before start.
pub fn start(&mut self) -> Result<()>
pub fn stop(&mut self)
pub fn is_running(&self) -> bool
Sourcepub fn send_frame(&self, data: &[u8], timestamp_increment: u32) -> Result<usize>
pub fn send_frame(&self, data: &[u8], timestamp_increment: u32) -> Result<usize>
Send a raw encoded frame to the default mount (/stream).
Packetizes the data into RTP packets and delivers them to all subscribed playing sessions via UDP.
Sourcepub fn send_frame_to(
&self,
mount_path: &str,
data: &[u8],
timestamp_increment: u32,
) -> Result<usize>
pub fn send_frame_to( &self, mount_path: &str, data: &[u8], timestamp_increment: u32, ) -> Result<usize>
Send a raw encoded frame to a specific mount.
Packetizes the data using the mount’s codec and delivers the resulting RTP packets to all subscribed playing sessions.
Sourcepub fn send_rtp_packet(&self, session_id: &str, payload: &[u8]) -> Result<usize>
pub fn send_rtp_packet(&self, session_id: &str, payload: &[u8]) -> Result<usize>
Send a pre-packetized RTP packet to a specific session.
Sourcepub fn broadcast_rtp_packet(&self, payload: &[u8]) -> Result<usize>
pub fn broadcast_rtp_packet(&self, payload: &[u8]) -> Result<usize>
Broadcast a pre-packetized RTP packet to all playing sessions on the default mount.
pub fn get_viewers(&self) -> Vec<Viewer>
pub fn session_manager(&self) -> &SessionManager
Sourcepub fn mounts(&self) -> &MountRegistry
pub fn mounts(&self) -> &MountRegistry
Returns the mount registry (used by adapters that need mount access).
Sourcepub fn config(&self) -> Arc<ServerConfig>
pub fn config(&self) -> Arc<ServerConfig>
Returns the server’s protocol configuration.