From 49b41b284073d0c4ee967f3012d59ab0d758e424 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 30 Oct 2023 11:02:28 -0400 Subject: [PATCH] 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. --- src/codec/context.rs | 27 ++++++++++++++++++++++++++- src/codec/decoder/decoder.rs | 10 ++++++++-- src/codec/encoder/encoder.rs | 17 ----------------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/codec/context.rs b/src/codec/context.rs index aa91840..50d2e2e 100644 --- a/src/codec/context.rs +++ b/src/codec/context.rs @@ -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>(&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>(&mut self, value: Option) { + 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 { diff --git a/src/codec/decoder/decoder.rs b/src/codec/decoder/decoder.rs index 6990ab7..c7f6923 100644 --- a/src/codec/decoder/decoder.rs +++ b/src/codec/decoder/decoder.rs @@ -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>(&mut self, value: R) { + unsafe { + (*self.as_mut_ptr()).pkt_timebase = value.into().into(); + } } } diff --git a/src/codec/encoder/encoder.rs b/src/codec/encoder/encoder.rs index 3dd507b..ab57202 100644 --- a/src/codec/encoder/encoder.rs +++ b/src/codec/encoder/encoder.rs @@ -116,23 +116,6 @@ impl Encoder { } } } - - pub fn set_time_base>(&mut self, value: R) { - unsafe { - (*self.as_mut_ptr()).time_base = value.into().into(); - } - } - - pub fn set_frame_rate>(&mut self, value: Option) { - 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 {