forked from mirrors/gstreamer-rs
player: PlayerVideoRenderer::create_sink_element() is transfer none
This commit is contained in:
parent
71a3354226
commit
1523382b18
2 changed files with 29 additions and 3 deletions
|
@ -20,6 +20,7 @@ ffi = { package = "gstreamer-player-sys", path = "sys" }
|
||||||
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
|
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
|
||||||
gst = { package = "gstreamer", path = "../gstreamer", features = ["v1_12"] }
|
gst = { package = "gstreamer", path = "../gstreamer", features = ["v1_12"] }
|
||||||
gst-video = { package = "gstreamer-video", path = "../gstreamer-video", features = ["v1_12"] }
|
gst-video = { package = "gstreamer-video", path = "../gstreamer-video", features = ["v1_12"] }
|
||||||
|
once_cell = "1.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
gstreamer-rs-lgpl-docs = { path = "../docs", optional = true }
|
gstreamer-rs-lgpl-docs = { path = "../docs", optional = true }
|
||||||
|
|
|
@ -25,12 +25,37 @@ unsafe extern "C" fn video_renderer_create_video_sink<T: PlayerVideoRendererImpl
|
||||||
video_renderer: *mut ffi::GstPlayerVideoRenderer,
|
video_renderer: *mut ffi::GstPlayerVideoRenderer,
|
||||||
player: *mut ffi::GstPlayer,
|
player: *mut ffi::GstPlayer,
|
||||||
) -> *mut gst::ffi::GstElement {
|
) -> *mut gst::ffi::GstElement {
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
static VIDEO_SINK_QUARK: Lazy<glib::Quark> =
|
||||||
|
Lazy::new(|| glib::Quark::from_string("gstreamer-rs-player-video-sink"));
|
||||||
|
|
||||||
let instance = &*(video_renderer as *mut T::Instance);
|
let instance = &*(video_renderer as *mut T::Instance);
|
||||||
let imp = instance.get_impl();
|
let imp = instance.get_impl();
|
||||||
|
|
||||||
imp.create_video_sink(
|
let sink = imp.create_video_sink(
|
||||||
from_glib_borrow::<_, PlayerVideoRenderer>(video_renderer).unsafe_cast_ref(),
|
from_glib_borrow::<_, PlayerVideoRenderer>(video_renderer).unsafe_cast_ref(),
|
||||||
&Player::from_glib_borrow(player),
|
&Player::from_glib_borrow(player),
|
||||||
)
|
);
|
||||||
.to_glib_full()
|
|
||||||
|
let sink_ptr: *mut gst::ffi::GstElement = sink.to_glib_none().0;
|
||||||
|
|
||||||
|
let old_sink_ptr =
|
||||||
|
glib::gobject_ffi::g_object_get_qdata(video_renderer as *mut _, VIDEO_SINK_QUARK.to_glib())
|
||||||
|
as *mut gst::ffi::GstElement;
|
||||||
|
if !old_sink_ptr.is_null() && old_sink_ptr != sink_ptr {
|
||||||
|
panic!("Video sink must not change");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn unref(ptr: glib::ffi::gpointer) {
|
||||||
|
glib::gobject_ffi::g_object_unref(ptr as *mut _);
|
||||||
|
}
|
||||||
|
|
||||||
|
glib::gobject_ffi::g_object_set_qdata_full(
|
||||||
|
video_renderer as *mut _,
|
||||||
|
VIDEO_SINK_QUARK.to_glib(),
|
||||||
|
glib::gobject_ffi::g_object_ref(sink_ptr as *mut _) as *mut _,
|
||||||
|
Some(unref),
|
||||||
|
);
|
||||||
|
|
||||||
|
sink_ptr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue