mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-28 20:41:31 +00:00
gstreamer: Add numer()/denom() functions to gst::Fraction to get the values by value instead of reference
This commit is contained in:
parent
a3015ab507
commit
220c500799
7 changed files with 38 additions and 30 deletions
|
@ -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
|
// Calculate a target width/height that keeps the display aspect ratio while having
|
||||||
// a height of 240 pixels
|
// a height of 240 pixels
|
||||||
let display_aspect_ratio = (info.width() as f64 * *info.par().numer() as f64)
|
let display_aspect_ratio = (info.width() as f64 * info.par().numer() as f64)
|
||||||
/ (info.height() as f64 * *info.par().denom() as f64);
|
/ (info.height() as f64 * info.par().denom() as f64);
|
||||||
let target_height = 240;
|
let target_height = 240;
|
||||||
let target_width = target_height as f64 * display_aspect_ratio;
|
let target_width = target_height as f64 * display_aspect_ratio;
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,10 @@ pub fn calculate_display_ratio(
|
||||||
dar_d.as_mut_ptr(),
|
dar_d.as_mut_ptr(),
|
||||||
video_width,
|
video_width,
|
||||||
video_height,
|
video_height,
|
||||||
*video_par.numer() as u32,
|
video_par.numer() as u32,
|
||||||
*video_par.denom() as u32,
|
video_par.denom() as u32,
|
||||||
*display_par.numer() as u32,
|
display_par.numer() as u32,
|
||||||
*display_par.denom() as u32,
|
display_par.denom() as u32,
|
||||||
));
|
));
|
||||||
if res {
|
if res {
|
||||||
Some(gst::Fraction::new(
|
Some(gst::Fraction::new(
|
||||||
|
|
|
@ -400,13 +400,13 @@ impl<'a> VideoInfoBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(par) = self.par {
|
if let Some(par) = self.par {
|
||||||
info.par_n = *par.numer();
|
info.par_n = par.numer();
|
||||||
info.par_d = *par.denom();
|
info.par_d = par.denom();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(fps) = self.fps {
|
if let Some(fps) = self.fps {
|
||||||
info.fps_n = *fps.numer();
|
info.fps_n = fps.numer();
|
||||||
info.fps_d = *fps.denom();
|
info.fps_d = fps.denom();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(offset) = self.offset {
|
if let Some(offset) = self.offset {
|
||||||
|
|
|
@ -46,8 +46,8 @@ impl VideoTimeCode {
|
||||||
let mut v = mem::MaybeUninit::zeroed();
|
let mut v = mem::MaybeUninit::zeroed();
|
||||||
ffi::gst_video_time_code_init(
|
ffi::gst_video_time_code_init(
|
||||||
v.as_mut_ptr(),
|
v.as_mut_ptr(),
|
||||||
*fps.numer() as u32,
|
fps.numer() as u32,
|
||||||
*fps.denom() as u32,
|
fps.denom() as u32,
|
||||||
latest_daily_jam.to_glib_none().0,
|
latest_daily_jam.to_glib_none().0,
|
||||||
flags.into_glib(),
|
flags.into_glib(),
|
||||||
hours,
|
hours,
|
||||||
|
@ -71,13 +71,13 @@ impl VideoTimeCode {
|
||||||
field_count: u32,
|
field_count: u32,
|
||||||
) -> Result<Self, glib::error::BoolError> {
|
) -> Result<Self, glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
assert!(*fps.denom() > 0);
|
assert!(fps.denom() > 0);
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut v = mem::MaybeUninit::zeroed();
|
let mut v = mem::MaybeUninit::zeroed();
|
||||||
let res = ffi::gst_video_time_code_init_from_date_time_full(
|
let res = ffi::gst_video_time_code_init_from_date_time_full(
|
||||||
v.as_mut_ptr(),
|
v.as_mut_ptr(),
|
||||||
*fps.numer() as u32,
|
fps.numer() as u32,
|
||||||
*fps.denom() as u32,
|
fps.denom() as u32,
|
||||||
dt.to_glib_none().0,
|
dt.to_glib_none().0,
|
||||||
flags.into_glib(),
|
flags.into_glib(),
|
||||||
field_count,
|
field_count,
|
||||||
|
@ -97,8 +97,8 @@ impl VideoTimeCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_fps(&mut self, fps: gst::Fraction) {
|
pub fn set_fps(&mut self, fps: gst::Fraction) {
|
||||||
self.0.config.fps_n = *fps.numer() as u32;
|
self.0.config.fps_n = fps.numer() as u32;
|
||||||
self.0.config.fps_d = *fps.denom() as u32;
|
self.0.config.fps_d = fps.denom() as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_flags(&mut self, flags: VideoTimeCodeFlags) {
|
pub fn set_flags(&mut self, flags: VideoTimeCodeFlags) {
|
||||||
|
|
|
@ -61,12 +61,12 @@ impl GstParamSpecExt for glib::ParamSpec {
|
||||||
name.to_glib_none().0,
|
name.to_glib_none().0,
|
||||||
nick.to_glib_none().0,
|
nick.to_glib_none().0,
|
||||||
blurb.to_glib_none().0,
|
blurb.to_glib_none().0,
|
||||||
*min.numer(),
|
min.numer(),
|
||||||
*min.denom(),
|
min.denom(),
|
||||||
*max.numer(),
|
max.numer(),
|
||||||
*max.denom(),
|
max.denom(),
|
||||||
*default.numer(),
|
default.numer(),
|
||||||
*default.denom(),
|
default.denom(),
|
||||||
flags.into_glib(),
|
flags.into_glib(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
|
@ -638,8 +638,8 @@ impl StructureRef {
|
||||||
from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
|
from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
|
||||||
&mut self.0,
|
&mut self.0,
|
||||||
name.to_glib_none().0,
|
name.to_glib_none().0,
|
||||||
*target.numer(),
|
target.numer(),
|
||||||
*target.denom(),
|
target.denom(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,14 @@ impl Fraction {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
Rational32::approximate_float(x).map(|r| r.into())
|
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 {
|
impl fmt::Display for Fraction {
|
||||||
|
@ -263,7 +271,7 @@ impl glib::value::ToValue for Fraction {
|
||||||
fn to_value(&self) -> glib::Value {
|
fn to_value(&self) -> glib::Value {
|
||||||
let mut value = glib::Value::for_value_type::<Self>();
|
let mut value = glib::Value::for_value_type::<Self>();
|
||||||
unsafe {
|
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
|
value
|
||||||
}
|
}
|
||||||
|
@ -526,10 +534,10 @@ impl glib::value::ToValue for FractionRange {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_value_set_fraction_range_full(
|
ffi::gst_value_set_fraction_range_full(
|
||||||
value.to_glib_none_mut().0,
|
value.to_glib_none_mut().0,
|
||||||
*self.min().numer(),
|
self.min().numer(),
|
||||||
*self.min().denom(),
|
self.min().denom(),
|
||||||
*self.max().numer(),
|
self.max().numer(),
|
||||||
*self.max().denom(),
|
self.max().denom(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
value
|
value
|
||||||
|
|
Loading…
Reference in a new issue