web_codecs/video/
frame.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::time::Duration;

use derive_more::From;

use crate::Timestamp;

#[derive(Debug, From)]
pub struct VideoFrame(web_sys::VideoFrame);

impl VideoFrame {
	pub fn timestamp(&self) -> Timestamp {
		Timestamp::from_micros(self.0.timestamp().unwrap() as _)
	}

	pub fn duration(&self) -> Option<Duration> {
		Some(Duration::from_micros(self.0.duration()? as _))
	}

	pub fn display_width(&self) -> u32 {
		self.0.display_width()
	}

	pub fn display_height(&self) -> u32 {
		self.0.display_height()
	}

	pub fn coded_width(&self) -> u32 {
		self.0.coded_width()
	}

	pub fn coded_height(&self) -> u32 {
		self.0.coded_height()
	}

	pub fn inner(&self) -> &web_sys::VideoFrame {
		&self.0
	}
}

// Make sure we close the frame on drop.
impl Drop for VideoFrame {
	fn drop(&mut self) {
		self.0.close();
	}
}