Subclassing GstSystemClock in Rust
Rodrigo Santos
rsantos at sequence.film
Fri Oct 21 15:30:03 UTC 2022
Hey folks, I'm trying to create a CustomClock implementation in Rust that is a subclass of GstSystemClock. I found some examples of how one can create GstElements in Rust but none explaining how to subclass a GstSystemClock.
Is it possible to create a custom clock implementation purely in Rust?
The code below is the boilerplate I implemented so far. This code doesn't compiler, one of the error messages says:
type ParentType = gst_sys::GstSystemClock;
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromGlibPtrNone<*mut _>` is not implemented for `GstSystemClock`
I'm fairly new to create new GLib types and Gstreamer plugins in Rust, what am I missing?
PS: a while ago I've done a similar implementation in C (https://github.com/TeleMidia/LibPlay/blob/master/lib/lp-clock.c) and now I'm trying to do it purely in Rust.
use gstreamer as gst;
use gst::glib;
use gst::prelude::*;
use gst::subclass::prelude::*;
use gstreamer_sys as gst_sys;
pub struct CustomClock {
current_time_in_ns: gst::ClockTime,
internal_clock: gst::Clock,
}
impl CustomClock {
pub fn new() -> Self {
let sys_clock = gst::SystemClock::obtain();
let now = sys_clock.internal_time();
Self {
current_time_in_ns: now,
internal_clock: sys_clock
}
}
pub fn advance_time(self: &mut Self, time_in_ns: gst::ClockTime) {
self.current_time_in_ns += time_in_ns;
}
}
#[glib::object_subclass]
impl ObjectSubclass for CustomClock {
const NAME: &'static str = "CustomClock";
type Type = CustomClock;
type ParentType = gst_sys::GstSystemClock;
}
// Implementation of glib::Object virtual methods
impl ObjectImpl for CustomClock {}
impl GstObjectImpl for CustomClock {}
impl ClockImpl for CustomClock {
fn internal_time(&self, clock: &Self::Type) -> gst::ClockTime {
self.current_time_in_ns
}
}
Rodrigo Santos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20221021/180b150f/attachment.htm>
More information about the gstreamer-devel
mailing list