use livekit_protocol::enum_dispatch;
use crate::imp::video_source as vs_imp;
#[derive(Debug, Clone)]
pub struct VideoResolution {
pub width: u32,
pub height: u32,
}
impl Default for VideoResolution {
fn default() -> Self {
VideoResolution { width: 1280, height: 720 }
}
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum RtcVideoSource {
#[cfg(not(target_arch = "wasm32"))]
Native(native::NativeVideoSource),
}
impl RtcVideoSource {
enum_dispatch!(
[Native];
pub fn video_resolution(self: &Self) -> VideoResolution;
);
}
#[cfg(not(target_arch = "wasm32"))]
pub mod native {
use std::fmt::{Debug, Formatter};
use super::*;
use crate::native::packet_trailer::PacketTrailerHandler;
use crate::video_frame::{VideoBuffer, VideoFrame};
#[derive(Clone)]
pub struct NativeVideoSource {
pub(crate) handle: vs_imp::NativeVideoSource,
}
impl Debug for NativeVideoSource {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
f.debug_struct("NativeVideoSource").finish()
}
}
impl Default for NativeVideoSource {
fn default() -> Self {
Self::new(VideoResolution::default(), false)
}
}
impl NativeVideoSource {
pub fn new(resolution: VideoResolution, is_screencast: bool) -> Self {
Self { handle: vs_imp::NativeVideoSource::new(resolution, is_screencast) }
}
pub fn capture_frame<T: AsRef<dyn VideoBuffer>>(&self, frame: &VideoFrame<T>) {
self.handle.capture_frame(frame)
}
pub fn set_packet_trailer_handler(&self, handler: PacketTrailerHandler) {
self.handle.set_packet_trailer_handler(handler)
}
pub fn video_resolution(&self) -> VideoResolution {
self.handle.video_resolution()
}
}
}
#[cfg(target_arch = "wasm32")]
pub mod web {}