diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2020-04-23 21:06:13 +0300 |
---|---|---|
committer | Mathieu Duponchelle <mathieu@centricular.com> | 2020-04-23 21:58:54 +0300 |
commit | 510c1cf2df4aef4caad786b325451bd5c26bdd0a (patch) | |
tree | ad96b7f84a17a6bd0a9959351a5d64a6232e9c68 /video | |
parent | 5c82e6fe6c517adaff1f8081b6651607cae3cf37 (diff) |
tttocea608: use mul_div_round
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/314>
Diffstat (limited to 'video')
-rw-r--r-- | video/closedcaption/Cargo.toml | 1 | ||||
-rw-r--r-- | video/closedcaption/src/lib.rs | 2 | ||||
-rw-r--r-- | video/closedcaption/src/tttocea608.rs | 80 |
3 files changed, 33 insertions, 50 deletions
diff --git a/video/closedcaption/Cargo.toml b/video/closedcaption/Cargo.toml index 2e8ec93b6..50d902a44 100644 --- a/video/closedcaption/Cargo.toml +++ b/video/closedcaption/Cargo.toml @@ -9,7 +9,6 @@ repository = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs" [dependencies] glib = { git = "https://github.com/gtk-rs/glib" } -gstreamer-sys = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys" } combine = "4.0" either = "1" uuid = { version = "0.8", features = ["v4"] } diff --git a/video/closedcaption/src/lib.rs b/video/closedcaption/src/lib.rs index 0485777d6..fa77b0c16 100644 --- a/video/closedcaption/src/lib.rs +++ b/video/closedcaption/src/lib.rs @@ -30,8 +30,6 @@ extern crate gst; #[macro_use] extern crate lazy_static; -extern crate gstreamer_sys as gst_sys; - #[cfg(test)] #[macro_use] extern crate pretty_assertions; diff --git a/video/closedcaption/src/tttocea608.rs b/video/closedcaption/src/tttocea608.rs index ddcb4db1b..efb0073b6 100644 --- a/video/closedcaption/src/tttocea608.rs +++ b/video/closedcaption/src/tttocea608.rs @@ -26,26 +26,24 @@ use gst::subclass::prelude::*; use super::cea608tott_ffi as ffi; use std::sync::Mutex; -fn scale_round(val: u64, num: u64, denom: u64) -> u64 { - unsafe { gst_sys::gst_util_uint64_scale_round(val, num, denom) } -} - -fn decrement_pts(min_frame_no: u64, frame_no: &mut u64, fps_n: u64, fps_d: u64) -> (u64, u64) { - let old_pts = scale_round( - (*frame_no * gst::SECOND).nseconds().unwrap() as u64, - fps_d, - fps_n, - ); +fn decrement_pts( + min_frame_no: u64, + frame_no: &mut u64, + fps_n: u64, + fps_d: u64, +) -> (gst::ClockTime, gst::ClockTime) { + let old_pts = (*frame_no * gst::SECOND) + .mul_div_round(fps_d, fps_n) + .unwrap(); if *frame_no > min_frame_no { *frame_no -= 1; } - let new_pts = scale_round( - (*frame_no * gst::SECOND).nseconds().unwrap() as u64, - fps_d, - fps_n, - ); + let new_pts = (*frame_no * gst::SECOND) + .mul_div_round(fps_d, fps_n) + .unwrap(); + let duration = old_pts - new_pts; (new_pts, duration) @@ -203,18 +201,12 @@ impl TtToCea608 { *state.framerate.numer() as u64, *state.framerate.denom() as u64, ); - let start: gst::ClockTime = scale_round( - (last_frame_no * gst::SECOND).nseconds().unwrap() as u64, - fps_d, - fps_n, - ) - .into(); - let end: gst::ClockTime = scale_round( - (new_frame_no * gst::SECOND).nseconds().unwrap() as u64, - fps_d, - fps_n, - ) - .into(); + let start = (last_frame_no * gst::SECOND) + .mul_div_round(fps_d, fps_n) + .unwrap(); + let end = (new_frame_no * gst::SECOND) + .mul_div_round(fps_d, fps_n) + .unwrap(); let event = gst::Event::new_gap(start, end - start).build(); @@ -252,10 +244,10 @@ impl TtToCea608 { let (pts, duration) = decrement_pts(min_frame_no, &mut erase_display_frame_no, fps_n, fps_d); - erase_display_memory(bufferlist.get_mut().unwrap(), pts.into(), duration.into()); + erase_display_memory(bufferlist.get_mut().unwrap(), pts, duration); let (pts, duration) = decrement_pts(min_frame_no, &mut erase_display_frame_no, fps_n, fps_d); - erase_display_memory(bufferlist.get_mut().unwrap(), pts.into(), duration.into()); + erase_display_memory(bufferlist.get_mut().unwrap(), pts, duration); drop(state); @@ -404,8 +396,7 @@ impl TtToCea608 { /* Calculate the frame for which we want the first of our * (doubled) end_of_caption control codes to be output */ - let mut frame_no = - scale_round(pts.nseconds().unwrap(), fps_n, fps_d) / gst::SECOND.nseconds().unwrap(); + let mut frame_no = (pts.mul_div_round(fps_n, fps_d).unwrap() / gst::SECOND).unwrap(); let mut erase_display_frame_no = { if state.erase_display_frame_no < Some(frame_no) { @@ -428,18 +419,16 @@ impl TtToCea608 { state.last_frame_no = frame_no; state.erase_display_frame_no = Some( - scale_round((pts + duration).nseconds().unwrap(), fps_n, fps_d) - / gst::SECOND.nseconds().unwrap() - + 2, + ((pts + duration).mul_div_round(fps_n, fps_d).unwrap() / gst::SECOND).unwrap() + 2, ); for mut buffer in buffers.drain(..).rev() { /* Insert display erasure at the correct moment */ if erase_display_frame_no == Some(frame_no) { let (pts, duration) = decrement_pts(min_frame_no, &mut frame_no, fps_n, fps_d); - erase_display_memory(bufferlist.get_mut().unwrap(), pts.into(), duration.into()); + erase_display_memory(bufferlist.get_mut().unwrap(), pts, duration); let (pts, duration) = decrement_pts(min_frame_no, &mut frame_no, fps_n, fps_d); - erase_display_memory(bufferlist.get_mut().unwrap(), pts.into(), duration.into()); + erase_display_memory(bufferlist.get_mut().unwrap(), pts, duration); erase_display_frame_no = None; } @@ -447,8 +436,8 @@ impl TtToCea608 { let (pts, duration) = decrement_pts(min_frame_no, &mut frame_no, fps_n, fps_d); let buf_mut = buffer.get_mut().unwrap(); - buf_mut.set_pts(pts.into()); - buf_mut.set_duration(duration.into()); + buf_mut.set_pts(pts); + buf_mut.set_duration(duration); bufferlist.get_mut().unwrap().insert(0, buffer); } @@ -485,12 +474,9 @@ impl TtToCea608 { *state.framerate.denom() as u64, ); - let our_latency: gst::ClockTime = scale_round( - (LATENCY_BUFFERS * gst::SECOND).nseconds().unwrap(), - fps_d, - fps_n, - ) - .into(); + let our_latency: gst::ClockTime = (LATENCY_BUFFERS * gst::SECOND) + .mul_div_round(fps_d, fps_n) + .unwrap(); min += our_latency; max += our_latency; @@ -548,9 +534,9 @@ impl TtToCea608 { ); let (timestamp, duration) = e.get(); - let mut frame_no = - scale_round((timestamp + duration).nseconds().unwrap(), fps_n, fps_d) - / gst::SECOND.nseconds().unwrap(); + let mut frame_no = ((timestamp + duration).mul_div_round(fps_n, fps_d).unwrap() + / gst::SECOND) + .unwrap(); if frame_no < LATENCY_BUFFERS { return true; |