use crate::{DecodedSurface, FrameDimensions, PixelFormat};
#[derive(Debug)]
pub struct WebVideoFrame {
frame: web_codecs::VideoFrame,
dimensions: FrameDimensions,
}
impl WebVideoFrame {
pub(crate) fn new(frame: web_codecs::VideoFrame) -> Self {
let dimensions = frame.dimensions();
Self {
frame,
dimensions: FrameDimensions {
width: dimensions.width,
height: dimensions.height,
},
}
}
pub fn from_video_frame(frame: web_sys::VideoFrame) -> Self {
Self::new(web_codecs::VideoFrame::from(frame))
}
pub fn video_frame(&self) -> &web_sys::VideoFrame {
&self.frame
}
pub fn clone_video_frame(&self) -> web_sys::VideoFrame {
web_sys::VideoFrame::from(self.frame.clone())
}
}
impl DecodedSurface for WebVideoFrame {
fn dimensions(&self) -> FrameDimensions {
self.dimensions
}
fn pixel_format(&self) -> PixelFormat {
match self.frame.format() {
Some(web_sys::VideoPixelFormat::Nv12) => PixelFormat::Nv12VideoRange,
Some(web_sys::VideoPixelFormat::Bgra | web_sys::VideoPixelFormat::Bgrx) => {
PixelFormat::Bgra8
}
Some(format) => PixelFormat::Native(format as u32),
None => PixelFormat::Native(0),
}
}
}