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:
tilpner
2023-08-29 16:09:37 +02:00
parent df08039eeb
commit 3d6efeba5e
4 changed files with 10 additions and 10 deletions
+4 -4
View File
@@ -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();
}
}
+2 -2
View File
@@ -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 {
+2 -2
View File
@@ -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> {
+2 -2
View File
@@ -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();
}
}