use bytes::Bytes;
use serde::Serialize;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum VideoCodec {
Vp8,
H264,
}
impl VideoCodec {
pub fn as_str(self) -> &'static str {
match self {
VideoCodec::Vp8 => "vp8",
VideoCodec::H264 => "h264",
}
}
pub fn from_mime(mime: &str) -> Option<VideoCodec> {
let m = mime.to_ascii_lowercase();
let name = m.strip_prefix("video/").unwrap_or(&m);
match name {
"vp8" => Some(VideoCodec::Vp8),
"h264" => Some(VideoCodec::H264),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum VideoSource {
Camera,
ScreenShare,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum VideoPause {
Congestion,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct VideoLayerInfo {
pub width: u32,
pub height: u32,
pub bitrate: u32,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct VideoTrack {
pub id: u64,
pub identity: String,
pub member_id: Option<String>,
pub source: VideoSource,
pub track_sid: String,
pub codec: Option<VideoCodec>,
pub width: u32,
pub height: u32,
pub muted: bool,
pub paused: Option<VideoPause>,
pub layers: Vec<VideoLayerInfo>,
pub unsupported: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub struct VideoTrackView {
pub id: u64,
pub track_sid: String,
pub codec: Option<VideoCodec>,
pub width: u32,
pub height: u32,
pub muted: bool,
pub paused: Option<VideoPause>,
pub unsupported: bool,
}
impl VideoTrack {
pub fn view(&self) -> VideoTrackView {
VideoTrackView {
id: self.id,
track_sid: self.track_sid.clone(),
codec: self.codec,
width: self.width,
height: self.height,
muted: self.muted,
paused: self.paused,
unsupported: self.unsupported,
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct VideoFrame {
pub track: u64,
pub codec: VideoCodec,
pub data: Bytes,
pub keyframe: bool,
pub rtp_ts: u32,
pub arrival_us: u64,
pub width: Option<u32>,
pub height: Option<u32>,
}
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum VideoRecvItem {
Added {
track: u64,
codec: VideoCodec,
},
Removed {
track: u64,
},
Frame(VideoFrame),
Broken {
track: u64,
},
KeyframeNeeded {
track: u64,
},
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct VideoSinkSpec {
pub width: u32,
pub height: u32,
pub visible: bool,
pub large: bool,
}
impl VideoSinkSpec {
pub fn new(width: u32, height: u32, large: bool) -> VideoSinkSpec {
VideoSinkSpec {
width,
height,
visible: true,
large,
}
}
pub fn visible(mut self, visible: bool) -> VideoSinkSpec {
self.visible = visible;
self
}
}