mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
Update for glib interface API changes
This commit is contained in:
parent
5cf6cd2e1d
commit
27385104d8
7 changed files with 204 additions and 24 deletions
|
@ -11,7 +11,7 @@ pub trait PlayerVideoRendererImpl: ObjectImpl {
|
|||
}
|
||||
|
||||
unsafe impl<T: PlayerVideoRendererImpl> IsImplementable<T> for PlayerVideoRenderer {
|
||||
fn interface_init(iface: &mut glib::Class<Self>) {
|
||||
fn interface_init(iface: &mut glib::Interface<Self>) {
|
||||
let iface = iface.as_mut();
|
||||
|
||||
iface.create_video_sink = Some(video_renderer_create_video_sink::<T>);
|
||||
|
@ -20,6 +20,42 @@ unsafe impl<T: PlayerVideoRendererImpl> IsImplementable<T> for PlayerVideoRender
|
|||
fn instance_init(_instance: &mut glib::subclass::InitializingObject<T>) {}
|
||||
}
|
||||
|
||||
pub trait PlayerVideoRendererImplExt: ObjectSubclass {
|
||||
fn parent_create_video_sink(
|
||||
&self,
|
||||
video_renderer: &Self::Type,
|
||||
player: &Player,
|
||||
) -> gst::Element;
|
||||
}
|
||||
|
||||
impl<T: PlayerVideoRendererImpl> PlayerVideoRendererImplExt for T {
|
||||
fn parent_create_video_sink(
|
||||
&self,
|
||||
video_renderer: &Self::Type,
|
||||
player: &Player,
|
||||
) -> gst::Element {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data
|
||||
.as_ref()
|
||||
.get_parent_interface::<PlayerVideoRenderer>()
|
||||
as *const ffi::GstPlayerVideoRendererInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.create_video_sink
|
||||
.expect("no parent \"create_video_sink\" implementation");
|
||||
let ret = func(
|
||||
video_renderer
|
||||
.unsafe_cast_ref::<PlayerVideoRenderer>()
|
||||
.to_glib_none()
|
||||
.0,
|
||||
player.to_glib_none().0,
|
||||
);
|
||||
from_glib_none(ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn video_renderer_create_video_sink<T: PlayerVideoRendererImpl>(
|
||||
video_renderer: *mut ffi::GstPlayerVideoRenderer,
|
||||
player: *mut ffi::GstPlayer,
|
||||
|
|
|
@ -878,7 +878,7 @@ pub unsafe trait ElementClassExt {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: IsA<Element>> ElementClassExt for glib::object::Class<T> {}
|
||||
unsafe impl<T: IsA<Element> + glib::object::IsClass> ElementClassExt for glib::object::Class<T> {}
|
||||
|
||||
pub static ELEMENT_METADATA_AUTHOR: Lazy<&'static str> = Lazy::new(|| unsafe {
|
||||
CStr::from_ptr(ffi::GST_ELEMENT_METADATA_AUTHOR)
|
||||
|
|
|
@ -1624,7 +1624,7 @@ impl Pad {
|
|||
|
||||
pub struct PadBuilder<T>(pub(crate) T);
|
||||
|
||||
impl<T: IsA<Pad> + IsA<glib::Object>> PadBuilder<T> {
|
||||
impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
|
||||
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
|
|
|
@ -8,32 +8,113 @@ use crate::ChildProxy;
|
|||
|
||||
pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
|
||||
fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
|
||||
unsafe {
|
||||
let type_ = ffi::gst_child_proxy_get_type();
|
||||
let iface = glib::gobject_ffi::g_type_default_interface_ref(type_)
|
||||
as *mut ffi::GstChildProxyInterface;
|
||||
assert!(!iface.is_null());
|
||||
|
||||
let ret = ((*iface).get_child_by_name.as_ref().unwrap())(
|
||||
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
||||
name.to_glib_none().0,
|
||||
);
|
||||
|
||||
glib::gobject_ffi::g_type_default_interface_unref(iface as glib::ffi::gpointer);
|
||||
|
||||
from_glib_full(ret)
|
||||
}
|
||||
self.parent_get_child_by_name(object, name)
|
||||
}
|
||||
|
||||
fn get_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>;
|
||||
fn get_children_count(&self, object: &Self::Type) -> u32;
|
||||
|
||||
fn child_added(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
|
||||
fn child_removed(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
|
||||
fn child_added(&self, object: &Self::Type, child: &glib::Object, name: &str) {
|
||||
self.parent_child_added(object, child, name);
|
||||
}
|
||||
fn child_removed(&self, object: &Self::Type, child: &glib::Object, name: &str) {
|
||||
self.parent_child_removed(object, child, name);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ChildProxyImplExt: ObjectSubclass {
|
||||
fn parent_get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object>;
|
||||
|
||||
fn parent_get_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>;
|
||||
fn parent_get_children_count(&self, object: &Self::Type) -> u32;
|
||||
|
||||
fn parent_child_added(&self, _object: &Self::Type, _child: &glib::Object, _name: &str);
|
||||
fn parent_child_removed(&self, _object: &Self::Type, _child: &glib::Object, _name: &str);
|
||||
}
|
||||
|
||||
impl<T: ChildProxyImpl> ChildProxyImplExt for T {
|
||||
fn parent_get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<ChildProxy>()
|
||||
as *const ffi::GstChildProxyInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.get_child_by_name
|
||||
.expect("no parent \"get_child_by_name\" implementation");
|
||||
let ret = func(
|
||||
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
||||
name.to_glib_none().0,
|
||||
);
|
||||
from_glib_full(ret)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_get_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object> {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<ChildProxy>()
|
||||
as *const ffi::GstChildProxyInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.get_child_by_index
|
||||
.expect("no parent \"get_child_by_index\" implementation");
|
||||
let ret = func(
|
||||
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
||||
index,
|
||||
);
|
||||
from_glib_full(ret)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_get_children_count(&self, object: &Self::Type) -> u32 {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<ChildProxy>()
|
||||
as *const ffi::GstChildProxyInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.get_children_count
|
||||
.expect("no parent \"get_children_count\" implementation");
|
||||
func(object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_child_added(&self, object: &Self::Type, child: &glib::Object, name: &str) {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<ChildProxy>()
|
||||
as *const ffi::GstChildProxyInterface;
|
||||
|
||||
if let Some(func) = (*parent_iface).child_added {
|
||||
func(
|
||||
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
||||
child.to_glib_none().0,
|
||||
name.to_glib_none().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_child_removed(&self, object: &Self::Type, child: &glib::Object, name: &str) {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<ChildProxy>()
|
||||
as *const ffi::GstChildProxyInterface;
|
||||
|
||||
if let Some(func) = (*parent_iface).child_removed {
|
||||
func(
|
||||
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
|
||||
child.to_glib_none().0,
|
||||
name.to_glib_none().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
|
||||
fn interface_init(iface: &mut glib::Class<Self>) {
|
||||
fn interface_init(iface: &mut glib::Interface<Self>) {
|
||||
let iface = iface.as_mut();
|
||||
|
||||
iface.get_child_by_name = Some(child_proxy_get_child_by_name::<T>);
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::Preset;
|
|||
pub trait PresetImpl: super::element::ElementImpl {}
|
||||
|
||||
unsafe impl<T: PresetImpl> IsImplementable<T> for Preset {
|
||||
fn interface_init(_iface: &mut glib::Class<Self>) {}
|
||||
fn interface_init(_iface: &mut glib::Interface<Self>) {}
|
||||
|
||||
fn instance_init(_instance: &mut glib::subclass::InitializingObject<T>) {}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ use crate::TagSetter;
|
|||
pub trait TagSetterImpl: super::element::ElementImpl {}
|
||||
|
||||
unsafe impl<T: TagSetterImpl> IsImplementable<T> for TagSetter {
|
||||
fn interface_init(_iface: &mut glib::Class<Self>) {}
|
||||
fn interface_init(_iface: &mut glib::Interface<Self>) {}
|
||||
fn instance_init(_instance: &mut glib::subclass::InitializingObject<T>) {}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ use glib::subclass::prelude::*;
|
|||
use crate::URIHandler;
|
||||
use crate::URIType;
|
||||
|
||||
use std::ptr;
|
||||
|
||||
pub trait URIHandlerImpl: super::element::ElementImpl {
|
||||
const URI_TYPE: URIType;
|
||||
fn get_protocols() -> &'static [&'static str];
|
||||
|
@ -15,13 +17,74 @@ pub trait URIHandlerImpl: super::element::ElementImpl {
|
|||
fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>;
|
||||
}
|
||||
|
||||
pub trait URIHandlerImplExt: ObjectSubclass {
|
||||
fn parent_get_protocols() -> Vec<String>;
|
||||
fn parent_get_uri(&self, element: &Self::Type) -> Option<String>;
|
||||
fn parent_set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>;
|
||||
}
|
||||
|
||||
impl<T: URIHandlerImpl> URIHandlerImplExt for T {
|
||||
fn parent_get_protocols() -> Vec<String> {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<URIHandler>()
|
||||
as *const ffi::GstURIHandlerInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.get_protocols
|
||||
.expect("no parent \"get_protocols\" implementation");
|
||||
let ret = func(Self::ParentType::static_type().to_glib());
|
||||
FromGlibPtrContainer::from_glib_none(ret)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_get_uri(&self, element: &Self::Type) -> Option<String> {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<URIHandler>()
|
||||
as *const ffi::GstURIHandlerInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.get_uri
|
||||
.expect("no parent \"get_uri\" implementation");
|
||||
let ret = func(element.unsafe_cast_ref::<URIHandler>().to_glib_none().0);
|
||||
from_glib_full(ret)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error> {
|
||||
unsafe {
|
||||
let type_data = Self::type_data();
|
||||
let parent_iface = type_data.as_ref().get_parent_interface::<URIHandler>()
|
||||
as *const ffi::GstURIHandlerInterface;
|
||||
|
||||
let func = (*parent_iface)
|
||||
.set_uri
|
||||
.expect("no parent \"set_uri\" implementation");
|
||||
|
||||
let mut err = ptr::null_mut();
|
||||
func(
|
||||
element.unsafe_cast_ref::<URIHandler>().to_glib_none().0,
|
||||
uri.to_glib_none().0,
|
||||
&mut err,
|
||||
);
|
||||
|
||||
if !err.is_null() {
|
||||
Err(from_glib_full(err))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send+Sync wrapper around a NULL-terminated C string array
|
||||
struct CStrV(*const *const libc::c_char);
|
||||
unsafe impl Send for CStrV {}
|
||||
unsafe impl Sync for CStrV {}
|
||||
|
||||
unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
|
||||
fn interface_init(iface: &mut glib::Class<Self>) {
|
||||
fn interface_init(iface: &mut glib::Interface<Self>) {
|
||||
let iface = iface.as_mut();
|
||||
|
||||
// Store the protocols in the interface data for later use
|
||||
|
|
Loading…
Reference in a new issue