arturoc / gstreamer1.0-rs

Idiomatic bindings for Gstreamer on Rust.
MIT License
36 stars 14 forks source link

Using the GstVideoOverlay interface #31

Open superlou opened 6 years ago

superlou commented 6 years ago

I am trying to render from Gstreamer onto a GTK DrawingArea. Is there a way to use the gst_video_overlay_set_window_handle function on an element (https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/GstVideoOverlay.html#gst-video-overlay-set-window-handle)?

superlou commented 6 years ago

I had some luck using FFI by adding the following:

extern {
    fn gst_video_overlay_set_window_handle(
        GstXOverlay: *mut gst::ffi::Struct__GstElement,
        xwindow_id: u32
    );
}

... some code to create an XImageSink

unsafe {
    gst_video_overlay_set_window_handle(videosink.gst_element_mut(), 104857607)
}

The magic number is coming from yet another FFI hack on a GTK drawing area. The video is displayed, though it's not sized for the DrawingArea. It's scaled properly if I use an xvimagesink, though there may be a better way to handle that.

However, this seems pretty brittle. If the resource ID is wrong, it actually breaks something deep in GStreamer and doesn't work again until a computer restart.