mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-28 08:20:49 +08:00
54 lines
1.2 KiB
Rust
54 lines
1.2 KiB
Rust
use rand::RngExt;
|
|
use rtsp_types as rtsp;
|
|
use std::collections::HashMap;
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub enum RtspServiceStatus {
|
|
Stopped,
|
|
Starting,
|
|
Running,
|
|
Error(String),
|
|
}
|
|
|
|
impl fmt::Display for RtspServiceStatus {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::Stopped => write!(f, "stopped"),
|
|
Self::Starting => write!(f, "starting"),
|
|
Self::Running => write!(f, "running"),
|
|
Self::Error(err) => write!(f, "error: {}", err),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct RtspRequest {
|
|
pub method: rtsp::Method,
|
|
pub uri: String,
|
|
pub version: rtsp::Version,
|
|
pub headers: HashMap<String, String>,
|
|
}
|
|
|
|
pub(crate) struct RtspConnectionState {
|
|
pub session_id: String,
|
|
pub setup_done: bool,
|
|
pub interleaved_channel: u8,
|
|
}
|
|
|
|
impl RtspConnectionState {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
session_id: generate_session_id(),
|
|
setup_done: false,
|
|
interleaved_channel: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) fn generate_session_id() -> String {
|
|
let mut rng = rand::rng();
|
|
let value: u64 = rng.random();
|
|
format!("{:016x}", value)
|
|
}
|