gstreamer: Implement pad sticky event getter by type

This allows the caller to directly use the specific event type API on
the result instead of first having to match on it first.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/314
This commit is contained in:
Sebastian Dröge 2021-10-17 12:48:21 +03:00
parent 87e7a84a27
commit aab0a45cfc
5 changed files with 367 additions and 230 deletions

View file

@ -1424,6 +1424,11 @@ manual_traits = ["PadExtManual"]
# Complex closure argument handling # Complex closure argument handling
manual = true manual = true
[[object.function]]
name = "get_sticky_event"
# More convenient API
manual = true
[[object.function]] [[object.function]]
name = "add_probe" name = "add_probe"
# Complex closure argument handling # Complex closure argument handling

View file

@ -6,7 +6,6 @@
use crate::Caps; use crate::Caps;
use crate::Element; use crate::Element;
use crate::Event; use crate::Event;
use crate::EventType;
use crate::FlowError; use crate::FlowError;
use crate::FlowSuccess; use crate::FlowSuccess;
use crate::Object; use crate::Object;
@ -117,10 +116,6 @@ pub trait PadExt: 'static {
#[doc(alias = "get_single_internal_link")] #[doc(alias = "get_single_internal_link")]
fn single_internal_link(&self) -> Option<Pad>; fn single_internal_link(&self) -> Option<Pad>;
#[doc(alias = "gst_pad_get_sticky_event")]
#[doc(alias = "get_sticky_event")]
fn sticky_event(&self, event_type: EventType, idx: u32) -> Option<Event>;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
#[doc(alias = "gst_pad_get_stream")] #[doc(alias = "gst_pad_get_stream")]
@ -389,16 +384,6 @@ impl<O: IsA<Pad>> PadExt for O {
} }
} }
fn sticky_event(&self, event_type: EventType, idx: u32) -> Option<Event> {
unsafe {
from_glib_full(ffi::gst_pad_get_sticky_event(
self.as_ref().to_glib_none().0,
event_type.into_glib(),
idx,
))
}
}
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
fn stream(&self) -> Option<Stream> { fn stream(&self) -> Option<Stream> {

View file

@ -123,7 +123,7 @@ pub trait ElementExtManual: 'static {
fn query(&self, query: &mut QueryRef) -> bool; fn query(&self, query: &mut QueryRef) -> bool;
#[doc(alias = "gst_element_send_event")] #[doc(alias = "gst_element_send_event")]
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: impl Into<Event>) -> bool;
#[doc(alias = "get_metadata")] #[doc(alias = "get_metadata")]
fn metadata<'a>(&self, key: &str) -> Option<&'a str>; fn metadata<'a>(&self, key: &str) -> Option<&'a str>;
@ -303,11 +303,11 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn send_event(&self, event: Event) -> bool { fn send_event(&self, event: impl Into<Event>) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_element_send_event( from_glib(ffi::gst_element_send_event(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
event.into_ptr(), event.into().into_ptr(),
)) ))
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -140,11 +140,15 @@ pub trait PadExtManual: 'static {
fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool; fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool;
#[doc(alias = "gst_pad_event_default")] #[doc(alias = "gst_pad_event_default")]
fn event_default<P: IsA<crate::Object>>(&self, parent: Option<&P>, event: Event) -> bool; fn event_default<P: IsA<crate::Object>>(
&self,
parent: Option<&P>,
event: impl Into<Event>,
) -> bool;
#[doc(alias = "gst_pad_push_event")] #[doc(alias = "gst_pad_push_event")]
fn push_event(&self, event: Event) -> bool; fn push_event(&self, event: impl Into<Event>) -> bool;
#[doc(alias = "gst_pad_send_event")] #[doc(alias = "gst_pad_send_event")]
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: impl Into<Event>) -> bool;
#[doc(alias = "gst_pad_iterate_internal_links")] #[doc(alias = "gst_pad_iterate_internal_links")]
fn iterate_internal_links(&self) -> crate::Iterator<Pad>; fn iterate_internal_links(&self) -> crate::Iterator<Pad>;
@ -278,6 +282,10 @@ pub trait PadExtManual: 'static {
func: F, func: F,
); );
#[doc(alias = "gst_pad_get_sticky_event")]
#[doc(alias = "get_sticky_event")]
fn sticky_event<T: crate::event::StickyEventType>(&self, idx: u32) -> Option<T>;
fn set_pad_flags(&self, flags: PadFlags); fn set_pad_flags(&self, flags: PadFlags);
fn unset_pad_flags(&self, flags: PadFlags); fn unset_pad_flags(&self, flags: PadFlags);
@ -482,31 +490,35 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn event_default<P: IsA<crate::Object>>(&self, parent: Option<&P>, event: Event) -> bool { fn event_default<P: IsA<crate::Object>>(
&self,
parent: Option<&P>,
event: impl Into<Event>,
) -> bool {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib(ffi::gst_pad_event_default( from_glib(ffi::gst_pad_event_default(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
event.into_ptr(), event.into().into_ptr(),
)) ))
} }
} }
fn push_event(&self, event: Event) -> bool { fn push_event(&self, event: impl Into<Event>) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_pad_push_event( from_glib(ffi::gst_pad_push_event(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
event.into_ptr(), event.into().into_ptr(),
)) ))
} }
} }
fn send_event(&self, event: Event) -> bool { fn send_event(&self, event: impl Into<Event>) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_pad_send_event( from_glib(ffi::gst_pad_send_event(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
event.into_ptr(), event.into().into_ptr(),
)) ))
} }
} }
@ -1006,6 +1018,22 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn sticky_event<T: crate::event::StickyEventType>(&self, idx: u32) -> Option<T> {
unsafe {
let ptr = ffi::gst_pad_get_sticky_event(
self.as_ref().to_glib_none().0,
T::TYPE.into_glib(),
idx,
);
if ptr.is_null() {
None
} else {
Some(T::from_event(from_glib_full(ptr)))
}
}
}
fn set_pad_flags(&self, flags: PadFlags) { fn set_pad_flags(&self, flags: PadFlags) {
unsafe { unsafe {
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;