Skip to main content

VideoTimestamp

Struct VideoTimestamp 

Source
pub struct VideoTimestamp {
    pub value: i64,
    pub timescale: i32,
}
Expand description

Rational media timestamp.

Fields§

§value: i64

Timestamp numerator.

§timescale: i32

Ticks per second.

Implementations§

Source§

impl VideoTimestamp

Source

pub const RTP_VIDEO_TIMESCALE: i32 = 90_000

RTP video clock frequency used by OpenIPC streams.

Source

pub const fn new(value: i64, timescale: i32) -> Option<Self>

Construct a timestamp, rejecting a non-positive timescale.

Source

pub const fn from_rtp(value: u32) -> Self

Construct a timestamp from a 90 kHz RTP video timestamp.

Examples found in repository?
examples/decode_access_unit.rs (line 37)
2fn main() -> Result<(), Box<dyn std::error::Error>> {
3    use std::{
4        env, fs, thread,
5        time::{Duration, Instant},
6    };
7
8    use openipc_video::{
9        DecoderOptions, EncodedAccessUnit, PlatformDecoder, VideoCodec, VideoDecoder,
10        VideoTimestamp,
11    };
12
13    let mut args = env::args().skip(1);
14    let codec =
15        match args.next().as_deref() {
16            Some("h264") => VideoCodec::H264,
17            Some("h265") | Some("hevc") => VideoCodec::H265,
18            _ => return Err(
19                "usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]"
20                    .into(),
21            ),
22        };
23    let path = args
24        .next()
25        .ok_or("usage: decode_access_unit <h264|h265> <annex-b-access-unit> [--allow-software]")?;
26    let allow_software = args.any(|argument| argument == "--allow-software");
27    let data = fs::read(path)?;
28    let capabilities = PlatformDecoder::probe_capabilities();
29    println!("capabilities={capabilities:?}");
30    let mut decoder = PlatformDecoder::new(DecoderOptions {
31        require_hardware: !allow_software,
32        ..DecoderOptions::default()
33    })?;
34    let outcome = decoder.submit(EncodedAccessUnit::new(
35        codec,
36        data,
37        VideoTimestamp::from_rtp(0),
38        true,
39    ))?;
40    println!("submit={outcome:?}");
41
42    let deadline = Instant::now() + Duration::from_secs(1);
43    while Instant::now() < deadline {
44        if let Some(frame) = decoder.latest_frame() {
45            let dimensions = frame.dimensions();
46            println!(
47                "decoded={}x{} pixel_format={:?}",
48                dimensions.width,
49                dimensions.height,
50                openipc_video::DecodedSurface::pixel_format(&frame.surface),
51            );
52            #[cfg(target_os = "macos")]
53            println!("iosurface={}", frame.surface.is_io_surface_backed());
54            #[cfg(target_os = "linux")]
55            println!(
56                "drm_fourcc={:#010x} pitches={:?}",
57                frame.surface.drm_fourcc(),
58                frame.surface.plane_pitches()
59            );
60            #[cfg(target_os = "windows")]
61            println!(
62                "d3d11_subresource={} texture={:?}",
63                frame.surface.subresource_index(),
64                frame.surface.texture()
65            );
66            return Ok(());
67        }
68        thread::sleep(Duration::from_millis(2));
69    }
70    Err(format!("no decoded frame; stats={:?}", decoder.stats()).into())
71}

Trait Implementations§

Source§

impl Clone for VideoTimestamp

Source§

fn clone(&self) -> VideoTimestamp

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for VideoTimestamp

Source§

impl Debug for VideoTimestamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VideoTimestamp

Source§

fn default() -> VideoTimestamp

Returns the “default value” for a type. Read more
Source§

impl Eq for VideoTimestamp

Source§

impl Hash for VideoTimestamp

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for VideoTimestamp

Source§

fn eq(&self, other: &VideoTimestamp) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VideoTimestamp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.