use std::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub struct RtspServerConfig {
pub bind_address: String,
pub session_timeout: Duration,
pub max_connections: usize,
}
impl Default for RtspServerConfig {
fn default() -> Self {
Self {
bind_address: "0.0.0.0:554".to_string(),
session_timeout: Duration::from_secs(60),
max_connections: 100,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RtspSessionState {
Init,
Ready,
Playing,
Paused,
}
pub struct RtspSession {
pub id: String,
pub state: RtspSessionState,
pub mount_path: String,
pub channel_id: u8,
pub expires_at: Instant,
pub timeout: Duration,
}
impl RtspSession {
#[must_use]
pub fn new(id: String, mount_path: String, channel_id: u8, timeout: Duration) -> Self {
Self {
expires_at: Instant::now() + timeout,
id,
state: RtspSessionState::Init,
mount_path,
channel_id,
timeout,
}
}
pub fn refresh(&mut self) {
self.expires_at = Instant::now() + self.timeout;
}
#[must_use]
pub fn is_expired(&self) -> bool {
Instant::now() > self.expires_at
}
}