web_codecs/video/
frame.rs

1use std::time::Duration;
2
3use derive_more::From;
4
5use crate::Timestamp;
6
7#[derive(Debug, From)]
8pub struct VideoFrame(web_sys::VideoFrame);
9
10impl VideoFrame {
11	pub fn timestamp(&self) -> Timestamp {
12		Timestamp::from_micros(self.0.timestamp().unwrap() as _)
13	}
14
15	pub fn duration(&self) -> Option<Duration> {
16		Some(Duration::from_micros(self.0.duration()? as _))
17	}
18
19	pub fn display_width(&self) -> u32 {
20		self.0.display_width()
21	}
22
23	pub fn display_height(&self) -> u32 {
24		self.0.display_height()
25	}
26
27	pub fn coded_width(&self) -> u32 {
28		self.0.coded_width()
29	}
30
31	pub fn coded_height(&self) -> u32 {
32		self.0.coded_height()
33	}
34
35	pub fn inner(&self) -> &web_sys::VideoFrame {
36		&self.0
37	}
38}
39
40// Make sure we close the frame on drop.
41impl Drop for VideoFrame {
42	fn drop(&mut self) {
43		self.0.close();
44	}
45}