gstreamer: Add numer()/denom() functions to gst::Fraction to get the values by value instead of reference

This commit is contained in:
Sebastian Dröge 2021-11-05 22:40:05 +02:00
parent a3015ab507
commit 220c500799
7 changed files with 38 additions and 30 deletions

View file

@ -109,8 +109,8 @@ fn create_pipeline(uri: String, out_path: std::path::PathBuf) -> Result<gst::Pip
// Calculate a target width/height that keeps the display aspect ratio while having
// a height of 240 pixels
let display_aspect_ratio = (info.width() as f64 * *info.par().numer() as f64)
/ (info.height() as f64 * *info.par().denom() as f64);
let display_aspect_ratio = (info.width() as f64 * info.par().numer() as f64)
/ (info.height() as f64 * info.par().denom() as f64);
let target_height = 240;
let target_width = target_height as f64 * display_aspect_ratio;

View file

@ -157,10 +157,10 @@ pub fn calculate_display_ratio(
dar_d.as_mut_ptr(),
video_width,
video_height,
*video_par.numer() as u32,
*video_par.denom() as u32,
*display_par.numer() as u32,
*display_par.denom() as u32,
video_par.numer() as u32,
video_par.denom() as u32,
display_par.numer() as u32,
display_par.denom() as u32,
));
if res {
Some(gst::Fraction::new(

View file

@ -400,13 +400,13 @@ impl<'a> VideoInfoBuilder<'a> {
}
if let Some(par) = self.par {
info.par_n = *par.numer();
info.par_d = *par.denom();
info.par_n = par.numer();
info.par_d = par.denom();
}
if let Some(fps) = self.fps {
info.fps_n = *fps.numer();
info.fps_d = *fps.denom();
info.fps_n = fps.numer();
info.fps_d = fps.denom();
}
if let Some(offset) = self.offset {

View file

@ -46,8 +46,8 @@ impl VideoTimeCode {
let mut v = mem::MaybeUninit::zeroed();
ffi::gst_video_time_code_init(
v.as_mut_ptr(),
*fps.numer() as u32,
*fps.denom() as u32,
fps.numer() as u32,
fps.denom() as u32,
latest_daily_jam.to_glib_none().0,
flags.into_glib(),
hours,
@ -71,13 +71,13 @@ impl VideoTimeCode {
field_count: u32,
) -> Result<Self, glib::error::BoolError> {
assert_initialized_main_thread!();
assert!(*fps.denom() > 0);
assert!(fps.denom() > 0);
unsafe {
let mut v = mem::MaybeUninit::zeroed();
let res = ffi::gst_video_time_code_init_from_date_time_full(
v.as_mut_ptr(),
*fps.numer() as u32,
*fps.denom() as u32,
fps.numer() as u32,
fps.denom() as u32,
dt.to_glib_none().0,
flags.into_glib(),
field_count,
@ -97,8 +97,8 @@ impl VideoTimeCode {
}
pub fn set_fps(&mut self, fps: gst::Fraction) {
self.0.config.fps_n = *fps.numer() as u32;
self.0.config.fps_d = *fps.denom() as u32;
self.0.config.fps_n = fps.numer() as u32;
self.0.config.fps_d = fps.denom() as u32;
}
pub fn set_flags(&mut self, flags: VideoTimeCodeFlags) {

View file

@ -61,12 +61,12 @@ impl GstParamSpecExt for glib::ParamSpec {
name.to_glib_none().0,
nick.to_glib_none().0,
blurb.to_glib_none().0,
*min.numer(),
*min.denom(),
*max.numer(),
*max.denom(),
*default.numer(),
*default.denom(),
min.numer(),
min.denom(),
max.numer(),
max.denom(),
default.numer(),
default.denom(),
flags.into_glib(),
))
}

View file

@ -638,8 +638,8 @@ impl StructureRef {
from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
&mut self.0,
name.to_glib_none().0,
*target.numer(),
*target.denom(),
target.numer(),
target.denom(),
))
}
}

View file

@ -28,6 +28,14 @@ impl Fraction {
assert_initialized_main_thread!();
Rational32::approximate_float(x).map(|r| r.into())
}
pub fn numer(&self) -> i32 {
*self.0.numer()
}
pub fn denom(&self) -> i32 {
*self.0.denom()
}
}
impl fmt::Display for Fraction {
@ -263,7 +271,7 @@ impl glib::value::ToValue for Fraction {
fn to_value(&self) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
unsafe {
ffi::gst_value_set_fraction(value.to_glib_none_mut().0, *self.numer(), *self.denom());
ffi::gst_value_set_fraction(value.to_glib_none_mut().0, self.numer(), self.denom());
}
value
}
@ -526,10 +534,10 @@ impl glib::value::ToValue for FractionRange {
unsafe {
ffi::gst_value_set_fraction_range_full(
value.to_glib_none_mut().0,
*self.min().numer(),
*self.min().denom(),
*self.max().numer(),
*self.max().denom(),
self.min().numer(),
self.min().denom(),
self.max().numer(),
self.max().denom(),
);
}
value