|
1 | 1 | //! Video decoding library. |
2 | 2 |
|
| 3 | +mod time; |
| 4 | + |
3 | 5 | pub mod decode; |
4 | 6 | pub mod demux; |
5 | 7 |
|
6 | | -pub use decode::{Chunk, Frame, PixelFormat}; |
7 | | -pub use demux::{Config, Sample, VideoData, VideoLoadError}; |
8 | 8 | pub use re_mp4::{TrackId, TrackKind}; |
9 | 9 |
|
10 | | -/// A value in time units. |
11 | | -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | | -pub struct Time(i64); |
13 | | - |
14 | | -impl Time { |
15 | | - pub const ZERO: Self = Self(0); |
16 | | - pub const MAX: Self = Self(i64::MAX); |
17 | | - |
18 | | - /// Create a new value in _time units_. |
19 | | - /// |
20 | | - /// ⚠️ Don't use this for regular timestamps in seconds/milliseconds/etc., |
21 | | - /// use the proper constructors for those instead! |
22 | | - /// This only exists for cases where you already have a value expressed in time units, |
23 | | - /// such as those received from the `WebCodecs` APIs. |
24 | | - #[inline] |
25 | | - pub fn new(v: i64) -> Self { |
26 | | - Self(v) |
27 | | - } |
28 | | - |
29 | | - #[inline] |
30 | | - pub fn from_secs(v: f64, timescale: Timescale) -> Self { |
31 | | - Self((v * timescale.0 as f64).round() as i64) |
32 | | - } |
33 | | - |
34 | | - #[inline] |
35 | | - pub fn from_millis(v: f64, timescale: Timescale) -> Self { |
36 | | - Self::from_secs(v / 1e3, timescale) |
37 | | - } |
38 | | - |
39 | | - #[inline] |
40 | | - pub fn from_micros(v: f64, timescale: Timescale) -> Self { |
41 | | - Self::from_secs(v / 1e6, timescale) |
42 | | - } |
43 | | - |
44 | | - #[inline] |
45 | | - pub fn from_nanos(v: i64, timescale: Timescale) -> Self { |
46 | | - Self::from_secs(v as f64 / 1e9, timescale) |
47 | | - } |
48 | | - |
49 | | - /// Convert to a duration |
50 | | - #[inline] |
51 | | - pub fn duration(self, timescale: Timescale) -> std::time::Duration { |
52 | | - std::time::Duration::from_nanos(self.into_nanos(timescale) as _) |
53 | | - } |
54 | | - |
55 | | - #[inline] |
56 | | - pub fn into_secs(self, timescale: Timescale) -> f64 { |
57 | | - self.0 as f64 / timescale.0 as f64 |
58 | | - } |
| 10 | +pub use self::{ |
| 11 | + decode::{Chunk, Frame, PixelFormat}, |
| 12 | + demux::{Config, Sample, VideoData, VideoLoadError}, |
| 13 | + time::{Time, Timescale}, |
| 14 | +}; |
59 | 15 |
|
60 | | - #[inline] |
61 | | - pub fn into_millis(self, timescale: Timescale) -> f64 { |
62 | | - self.into_secs(timescale) * 1e3 |
| 16 | +/// Which features was this crate compiled with? |
| 17 | +pub fn features() -> Vec<&'static str> { |
| 18 | + // TODO(emilk): is there a helper crate for this? |
| 19 | + let mut features = vec![]; |
| 20 | + if cfg!(feature = "av1") { |
| 21 | + features.push("av1"); |
63 | 22 | } |
64 | | - |
65 | | - #[inline] |
66 | | - pub fn into_micros(self, timescale: Timescale) -> f64 { |
67 | | - self.into_secs(timescale) * 1e6 |
68 | | - } |
69 | | - |
70 | | - #[inline] |
71 | | - pub fn into_nanos(self, timescale: Timescale) -> i64 { |
72 | | - (self.into_secs(timescale) * 1e9).round() as i64 |
73 | | - } |
74 | | -} |
75 | | - |
76 | | -impl std::ops::Add for Time { |
77 | | - type Output = Self; |
78 | | - |
79 | | - #[inline] |
80 | | - fn add(self, rhs: Self) -> Self::Output { |
81 | | - Self(self.0.saturating_add(rhs.0)) |
82 | | - } |
83 | | -} |
84 | | - |
85 | | -impl std::ops::Sub for Time { |
86 | | - type Output = Self; |
87 | | - |
88 | | - #[inline] |
89 | | - fn sub(self, rhs: Self) -> Self::Output { |
90 | | - Self(self.0.saturating_sub(rhs.0)) |
91 | | - } |
92 | | -} |
93 | | - |
94 | | -/// The number of time units per second. |
95 | | -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
96 | | -pub struct Timescale(u64); |
97 | | - |
98 | | -impl Timescale { |
99 | | - pub(crate) fn new(v: u64) -> Self { |
100 | | - Self(v) |
| 23 | + if cfg!(feature = "nasm") { |
| 24 | + features.push("nasm"); |
101 | 25 | } |
| 26 | + features |
102 | 27 | } |
0 commit comments