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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use crate::video::pixel::Pixel;
use crate::video::FrameInfo;
use crate::video::{ChromaSamplePosition, ChromaSampling};
#[cfg(feature = "y4m-decode")]
mod y4m;
#[cfg(feature = "y4m-decode")]
pub use self::y4m::*;
pub trait Decoder: Send + Sync {
fn read_video_frame<T: Pixel>(&mut self) -> Result<FrameInfo<T>, ()>;
fn read_specific_frame<T: Pixel>(&mut self, frame_number: usize) -> Result<FrameInfo<T>, ()>;
fn get_bit_depth(&self) -> usize;
fn get_video_details(&self) -> VideoDetails;
}
#[derive(Debug, Clone, Copy)]
pub struct VideoDetails {
pub width: usize,
pub height: usize,
pub bit_depth: usize,
pub chroma_sampling: ChromaSampling,
pub chroma_sample_position: ChromaSamplePosition,
pub time_base: Rational,
pub luma_padding: usize,
}
impl Default for VideoDetails {
fn default() -> Self {
VideoDetails {
width: 640,
height: 480,
bit_depth: 8,
chroma_sampling: ChromaSampling::Cs420,
chroma_sample_position: ChromaSamplePosition::Unknown,
time_base: Rational { num: 30, den: 1 },
luma_padding: 0,
}
}
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct Rational {
pub num: u64,
pub den: u64,
}
impl Rational {
pub const fn new(num: u64, den: u64) -> Self {
Rational { num, den }
}
pub const fn from_reciprocal(reciprocal: Self) -> Self {
Rational {
num: reciprocal.den,
den: reciprocal.num,
}
}
pub fn as_f64(self) -> f64 {
self.num as f64 / self.den as f64
}
}