mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
fix(codec, format)!: detect unset time_bases, allow unsetting time_base
Instead of silently passing possibly unset `time_base`s back into ffmpeg, force users to explicitly handle (even if just by early panic) their absence. BREAKING CHANGE: `time_base` and `set_time_base` functions now return/accept Option<Rational> (±Into). `unwrap`/`expect` is a valid way to surface this unwanted state early in user code. For symmetry, `set_time_base` also allows unsetting by passing a `None`, so all existing calls (with non-zero timebases) need to wrap the argument in `Some`.
This commit is contained in:
@@ -125,13 +125,13 @@ impl Context {
|
||||
Parameters::from(self)
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
pub fn time_base(&self) -> Option<Rational> {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base).non_zero() }
|
||||
}
|
||||
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
(*self.as_mut_ptr()).time_base = value.map(Into::into).unwrap_or(Rational::ZERO).into();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ impl<'a> Chapter<'a> {
|
||||
unsafe { (*self.as_ptr()).id }
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
pub fn time_base(&self) -> Option<Rational> {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base).non_zero() }
|
||||
}
|
||||
|
||||
pub fn start(&self) -> i64 {
|
||||
|
||||
@@ -53,8 +53,8 @@ impl<'a> Stream<'a> {
|
||||
unsafe { (*self.as_ptr()).index as usize }
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
pub fn time_base(&self) -> Option<Rational> {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base).non_zero() }
|
||||
}
|
||||
|
||||
pub fn start_time(&self) -> Option<i64> {
|
||||
|
||||
@@ -26,9 +26,9 @@ impl<'a> StreamMut<'a> {
|
||||
}
|
||||
|
||||
impl<'a> StreamMut<'a> {
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
(*self.as_mut_ptr()).time_base = value.map(Into::into).unwrap_or(Rational::ZERO).into();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user