[RUST] how to thread fetch element instance

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[RUST] how to thread fetch element instance

kakakong
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
    match event.view() {
        let state = self.state.lock().unwrap();
        EventView::StreamStart(_) => {
            state.inspect_timer
                .schedule_repeating(chrono::Duration::seconds(1), move ||
unsafe {
                    // how to get self and element instance
                })
                .ignore();
        }
        _ => (),
    }
}

i need get element state and element instance's real-time data.
i attempt to use raw pointer, but it not work;




--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [RUST] how to thread fetch element instance

Sebastian Dröge-3
On Thu, 2021-04-08 at 21:54 -0500, kakakong wrote:
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
    match event.view() {
        let state = self.state.lock().unwrap();
        EventView::StreamStart(_) => {
            state.inspect_timer
                .schedule_repeating(chrono::Duration::seconds(1), move ||
unsafe {
                    // how to get self and element instance
                })
                .ignore();
        }
        _ => (),
    }
}

i need get element state and element instance's real-time data.
i attempt to use raw pointer, but it not work;

In the code above you have `element` which is the element instance, and `self` which should be the private/implementation state of it.

If you want to pass that to the closure, you could do something like

    let element_clone = element.clone();
    state.inspect_timer.schedule_repeating(chrono::Duration::seconds(1), move || {
        let imp = YourElementType::from_instance(&element_clone); // This is the same as `self` outside the closure
        [...]
    })
    .ignore();

Note that this keeps the element alive until the closure is dropped.


There are also various examples of this pattern in https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs

-- 
Sebastian Dröge, Centricular Ltd · https://www.centricular.com


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [RUST] how to thread fetch element instance

kakakong
Your solution works well ! Thank you a lot for your timely reply.



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel