Context time_base / frame_rate adjustments

- Moves `time_base` from `Decoder` and `set_time_base` from `Encoder` to the base `Context` to unify the API for both types.
- Adds `packet_time_base` and `set_packet_time_base` to `Decoder`.
- Moves `set_frame_rate` from `Encoder` to `Context` and adds a `frame_rate` getter.
This commit is contained in:
Luke Street
2023-10-30 11:30:06 -04:00
parent 1c55c41203
commit 49b41b2840
3 changed files with 34 additions and 20 deletions
+26 -1
View File
@@ -8,7 +8,7 @@ use super::{threading, Compliance, Debug, Flags, Id, Parameters};
use ffi::*;
use libc::c_int;
use media;
use {Codec, Error};
use {Codec, Error, Rational};
pub struct Context {
ptr: *mut AVCodecContext,
@@ -138,6 +138,31 @@ impl Context {
}
}
}
pub fn time_base(&self) -> Rational {
unsafe { Rational::from((*self.as_ptr()).time_base) }
}
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
unsafe {
(*self.as_mut_ptr()).time_base = value.into().into();
}
}
pub fn frame_rate(&self) -> Rational {
unsafe { Rational::from((*self.as_ptr()).framerate) }
}
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
unsafe {
if let Some(value) = value {
(*self.as_mut_ptr()).framerate = value.into().into();
} else {
(*self.as_mut_ptr()).framerate.num = 0;
(*self.as_mut_ptr()).framerate.den = 1;
}
}
}
}
impl Default for Context {
+8 -2
View File
@@ -107,8 +107,14 @@ impl Decoder {
}
}
pub fn time_base(&self) -> Rational {
unsafe { Rational::from((*self.as_ptr()).time_base) }
pub fn packet_time_base(&self) -> Rational {
unsafe { Rational::from((*self.as_ptr()).pkt_timebase) }
}
pub fn set_packet_time_base<R: Into<Rational>>(&mut self, value: R) {
unsafe {
(*self.as_mut_ptr()).pkt_timebase = value.into().into();
}
}
}
-17
View File
@@ -116,23 +116,6 @@ impl Encoder {
}
}
}
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
unsafe {
(*self.as_mut_ptr()).time_base = value.into().into();
}
}
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
unsafe {
if let Some(value) = value {
(*self.as_mut_ptr()).framerate = value.into().into();
} else {
(*self.as_mut_ptr()).framerate.num = 0;
(*self.as_mut_ptr()).framerate.den = 1;
}
}
}
}
impl Deref for Encoder {