From 825e0d448419870859b28bfbf7365a987d05875f Mon Sep 17 00:00:00 2001 From: tilpner Date: Tue, 29 Aug 2023 14:00:18 +0200 Subject: [PATCH] feat(codec/packet, util/frame): expose `time_base` fields --- src/codec/packet/packet.rs | 10 ++++++++++ src/util/frame/mod.rs | 14 +++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/codec/packet/packet.rs b/src/codec/packet/packet.rs index 7b36c90..b3a9e3e 100644 --- a/src/codec/packet/packet.rs +++ b/src/codec/packet/packet.rs @@ -106,6 +106,16 @@ impl Packet { self.0.stream_index = index as c_int; } + #[inline] + pub fn time_base(&self) -> Option { + Rational::from(self.0.time_base).non_zero() + } + + #[inline] + pub fn set_time_base(&mut self, time_base: Option>) { + self.0.time_base = time_base.map(Into::into).unwrap_or(Rational::ZERO).into(); + } + #[inline] pub fn pts(&self) -> Option { match self.0.pts { diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index 49bf1d9..1d07739 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -10,7 +10,7 @@ pub use self::audio::Audio; pub mod flag; pub use self::flag::Flags; -use crate::{ffi::*, Dictionary, DictionaryRef, Error}; +use crate::{ffi::*, Dictionary, DictionaryRef, Error, Rational}; #[derive(PartialEq, Eq, Copy, Clone, Debug)] pub struct Packet { @@ -102,6 +102,18 @@ impl Frame { } } + #[inline] + pub fn time_base(&self) -> Option { + unsafe { Rational::from((*self.as_ptr()).time_base).non_zero() } + } + + #[inline] + pub fn set_time_base(&mut self, time_base: Option>) { + unsafe { + (*self.as_mut_ptr()).time_base = time_base.map(Into::into).unwrap_or(Rational::ZERO).into(); + } + } + #[inline] pub fn pts(&self) -> Option { unsafe {