2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{
|
|
|
|
mem,
|
|
|
|
num::NonZeroU64,
|
|
|
|
ops::ControlFlow,
|
|
|
|
panic::{self, AssertUnwindSafe},
|
|
|
|
ptr,
|
|
|
|
};
|
|
|
|
|
|
|
|
use glib::{ffi::gpointer, prelude::*, translate::*};
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
format::{FormattedValue, SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic},
|
2023-01-03 19:08:39 +00:00
|
|
|
prelude::*,
|
2023-01-03 18:58:25 +00:00
|
|
|
Buffer, BufferList, Event, FlowError, FlowReturn, FlowSuccess, Format, GenericFormattedValue,
|
|
|
|
LoggableError, Pad, PadFlags, PadProbeReturn, PadProbeType, Query, QueryRef, StaticPadTemplate,
|
2022-10-09 16:37:45 +00:00
|
|
|
};
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2021-09-15 18:12:03 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
2020-01-05 02:38:55 +00:00
|
|
|
pub struct PadProbeId(NonZeroU64);
|
2017-07-24 22:17:50 +00:00
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
impl IntoGlib for PadProbeId {
|
2017-07-24 22:17:50 +00:00
|
|
|
type GlibType = libc::c_ulong;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-27 15:15:46 +00:00
|
|
|
fn into_glib(self) -> libc::c_ulong {
|
2020-01-05 02:38:55 +00:00
|
|
|
self.0.get() as libc::c_ulong
|
2017-07-24 22:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromGlib<libc::c_ulong> for PadProbeId {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe fn from_glib(val: libc::c_ulong) -> PadProbeId {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_ne!(val, 0);
|
2022-12-13 09:28:00 +00:00
|
|
|
PadProbeId(NonZeroU64::new_unchecked(val as _))
|
2017-07-24 22:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2022-05-21 12:26:03 +00:00
|
|
|
impl PadProbeId {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2022-05-21 12:26:03 +00:00
|
|
|
pub fn as_raw(&self) -> libc::c_ulong {
|
|
|
|
self.0.get() as libc::c_ulong
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "GstPadProbeInfo")]
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug)]
|
2017-07-29 15:09:14 +00:00
|
|
|
pub struct PadProbeInfo<'a> {
|
2017-07-24 08:51:14 +00:00
|
|
|
pub mask: PadProbeType,
|
2021-02-28 16:50:44 +00:00
|
|
|
pub id: Option<PadProbeId>,
|
2017-07-24 08:51:14 +00:00
|
|
|
pub offset: u64,
|
|
|
|
pub size: u32,
|
2017-07-29 15:09:14 +00:00
|
|
|
pub data: Option<PadProbeData<'a>>,
|
2020-11-18 15:56:23 +00:00
|
|
|
pub flow_res: Result<FlowSuccess, FlowError>,
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-16 08:28:18 +00:00
|
|
|
impl<'a> PadProbeInfo<'a> {
|
|
|
|
pub fn buffer(&self) -> Option<&Buffer> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Buffer(ref buffer)) => Some(buffer),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn buffer_mut(&mut self) -> Option<&mut Buffer> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Buffer(ref mut buffer)) => Some(buffer),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn buffer_list(&self) -> Option<&BufferList> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::BufferList(ref buffer_list)) => Some(buffer_list),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn buffer_list_mut(&mut self) -> Option<&mut BufferList> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::BufferList(ref mut buffer_list)) => Some(buffer_list),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn query(&self) -> Option<&QueryRef> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Query(ref query)) => Some(*query),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn query_mut(&mut self) -> Option<&mut QueryRef> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Query(ref mut query)) => Some(*query),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn event(&self) -> Option<&Event> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Event(ref event)) => Some(event),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn event_mut(&mut self) -> Option<&mut Event> {
|
|
|
|
match self.data {
|
|
|
|
Some(PadProbeData::Event(ref mut event)) => Some(event),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug)]
|
2017-07-29 15:09:14 +00:00
|
|
|
pub enum PadProbeData<'a> {
|
2017-07-25 12:08:42 +00:00
|
|
|
Buffer(Buffer),
|
2017-07-28 18:18:08 +00:00
|
|
|
BufferList(BufferList),
|
2017-07-29 15:09:14 +00:00
|
|
|
Query(&'a mut QueryRef),
|
2017-07-30 14:11:47 +00:00
|
|
|
Event(Event),
|
2018-07-26 00:14:04 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
__Unknown(*mut ffi::GstMiniObject),
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl<'a> Send for PadProbeData<'a> {}
|
|
|
|
unsafe impl<'a> Sync for PadProbeData<'a> {}
|
|
|
|
|
2019-01-22 15:43:29 +00:00
|
|
|
#[derive(Debug)]
|
2020-02-28 14:29:48 +00:00
|
|
|
#[must_use = "if unused the StreamLock will immediately unlock"]
|
2020-06-22 08:48:56 +00:00
|
|
|
pub struct StreamLock<'a>(&'a Pad);
|
|
|
|
impl<'a> Drop for StreamLock<'a> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2017-08-03 08:09:39 +00:00
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let pad: *mut ffi::GstPad = self.0.to_glib_none().0;
|
|
|
|
glib::ffi::g_rec_mutex_unlock(&mut (*pad).stream_rec_lock);
|
2017-08-03 08:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 17:11:00 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum PadGetRangeSuccess {
|
|
|
|
FilledBuffer,
|
2020-11-21 13:46:48 +00:00
|
|
|
NewBuffer(crate::Buffer),
|
2020-03-29 17:11:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-09 12:19:37 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum EventForeachAction {
|
|
|
|
Keep,
|
|
|
|
Remove,
|
|
|
|
Replace(Event),
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
mod sealed {
|
|
|
|
pub trait Sealed {}
|
|
|
|
impl<T: super::IsA<super::Pad>> Sealed for T {}
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
pub trait PadExtManual: sealed::Sealed + IsA<Pad> + 'static {
|
|
|
|
#[doc(alias = "gst_pad_add_probe")]
|
2018-06-14 12:45:54 +00:00
|
|
|
fn add_probe<F>(&self, mask: PadProbeType, func: F) -> Option<PadProbeId>
|
2017-07-24 08:51:14 +00:00
|
|
|
where
|
2019-01-30 13:02:03 +00:00
|
|
|
F: Fn(&Self, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
2017-07-24 08:51:14 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2019-01-30 13:02:03 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
let id = ffi::gst_pad_add_probe(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
mask.into_glib(),
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(trampoline_pad_probe::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
2017-07-24 08:51:14 +00:00
|
|
|
);
|
|
|
|
|
2018-06-14 12:45:54 +00:00
|
|
|
if id == 0 {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(from_glib(id))
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_remove_probe")]
|
2017-07-24 08:51:14 +00:00
|
|
|
fn remove_probe(&self, id: PadProbeId) {
|
|
|
|
unsafe {
|
2021-04-27 15:15:46 +00:00
|
|
|
ffi::gst_pad_remove_probe(self.as_ref().to_glib_none().0, id.into_glib());
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-25 12:21:03 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_pull_range")]
|
|
|
|
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> {
|
2017-07-25 12:21:03 +00:00
|
|
|
unsafe {
|
|
|
|
let mut buffer = ptr::null_mut();
|
2023-07-05 20:21:43 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_pull_range(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-25 12:21:03 +00:00
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
&mut buffer,
|
2021-04-28 12:34:56 +00:00
|
|
|
))
|
|
|
|
.map(|_| from_glib_full(buffer))
|
2017-07-25 12:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
fn pull_range_fill(
|
2020-03-28 17:57:49 +00:00
|
|
|
&self,
|
|
|
|
offset: u64,
|
2020-11-21 13:46:48 +00:00
|
|
|
buffer: &mut crate::BufferRef,
|
2020-03-28 17:57:49 +00:00
|
|
|
size: u32,
|
|
|
|
) -> Result<(), FlowError> {
|
2021-04-11 19:39:50 +00:00
|
|
|
assert!(buffer.size() >= size as usize);
|
2020-03-28 17:57:49 +00:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let mut buffer_ref = buffer.as_mut_ptr();
|
2023-07-05 20:21:43 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_pull_range(
|
2020-03-28 17:57:49 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
&mut buffer_ref,
|
2021-04-28 12:34:56 +00:00
|
|
|
))
|
|
|
|
.and_then(|_| {
|
|
|
|
if buffer.as_mut_ptr() != buffer_ref {
|
|
|
|
ffi::gst_mini_object_unref(buffer_ref as *mut _);
|
|
|
|
Err(crate::FlowError::Error)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
2020-03-28 17:57:49 +00:00
|
|
|
}
|
2021-04-28 12:34:56 +00:00
|
|
|
})
|
2020-03-28 17:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "get_range")]
|
|
|
|
#[doc(alias = "gst_pad_get_range")]
|
|
|
|
fn range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> {
|
2017-07-25 12:21:03 +00:00
|
|
|
unsafe {
|
|
|
|
let mut buffer = ptr::null_mut();
|
2023-07-05 20:21:43 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_get_range(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-25 12:21:03 +00:00
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
&mut buffer,
|
2021-04-28 12:34:56 +00:00
|
|
|
))
|
|
|
|
.map(|_| from_glib_full(buffer))
|
2017-07-25 12:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:04:34 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "get_range_fill")]
|
|
|
|
fn range_fill(
|
2020-03-28 17:57:49 +00:00
|
|
|
&self,
|
|
|
|
offset: u64,
|
2020-11-21 13:46:48 +00:00
|
|
|
buffer: &mut crate::BufferRef,
|
2020-03-28 17:57:49 +00:00
|
|
|
size: u32,
|
|
|
|
) -> Result<(), FlowError> {
|
2021-04-11 19:39:50 +00:00
|
|
|
assert!(buffer.size() >= size as usize);
|
2020-03-28 17:57:49 +00:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let mut buffer_ref = buffer.as_mut_ptr();
|
2023-07-05 20:21:43 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_get_range(
|
2020-03-28 17:57:49 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
&mut buffer_ref,
|
2021-04-28 12:34:56 +00:00
|
|
|
))
|
|
|
|
.and_then(|_| {
|
|
|
|
if buffer.as_mut_ptr() != buffer_ref {
|
|
|
|
ffi::gst_mini_object_unref(buffer_ref as *mut _);
|
|
|
|
Err(crate::FlowError::Error)
|
|
|
|
} else {
|
|
|
|
Ok(())
|
2020-03-28 17:57:49 +00:00
|
|
|
}
|
2021-04-28 12:34:56 +00:00
|
|
|
})
|
2020-03-28 17:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query")]
|
|
|
|
fn peer_query(&self, query: &mut QueryRef) -> bool {
|
2017-07-29 13:04:34 +00:00
|
|
|
unsafe {
|
2023-07-05 20:21:43 +00:00
|
|
|
from_glib(ffi::gst_pad_peer_query(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query")]
|
|
|
|
fn query(&self, query: &mut QueryRef) -> bool {
|
2017-07-29 13:04:34 +00:00
|
|
|
unsafe {
|
2023-07-05 20:21:43 +00:00
|
|
|
from_glib(ffi::gst_pad_query(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
fn proxy_query_caps(&self, query: &mut QueryRef) -> bool {
|
2017-07-29 13:04:34 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_proxy_query_accept_caps(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_proxy_query_accept_caps")]
|
|
|
|
fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool {
|
2017-07-29 13:04:34 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_proxy_query_accept_caps(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-07-31 11:16:42 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2017-07-29 13:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-01 12:58:50 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_push_event")]
|
2021-10-17 09:48:21 +00:00
|
|
|
fn push_event(&self, event: impl Into<Event>) -> bool {
|
2017-08-01 12:58:50 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_push_event(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
event.into().into_glib_ptr(),
|
2017-08-01 14:28:36 +00:00
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_send_event")]
|
2021-10-17 09:48:21 +00:00
|
|
|
fn send_event(&self, event: impl Into<Event>) -> bool {
|
2017-08-01 12:58:50 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_send_event(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
event.into().into_glib_ptr(),
|
2017-08-01 14:28:36 +00:00
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 08:09:39 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_iterate_internal_links")]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_internal_links(&self) -> crate::Iterator<Pad> {
|
2019-01-16 11:32:58 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_pad_iterate_internal_links(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
2017-09-17 21:24:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 08:09:39 +00:00
|
|
|
fn stream_lock(&self) -> StreamLock {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: &mut ffi::GstPad = &mut *(self.as_ptr() as *mut _);
|
|
|
|
glib::ffi::g_rec_mutex_lock(&mut ptr.stream_rec_lock);
|
2020-06-22 08:48:56 +00:00
|
|
|
StreamLock(self.upcast_ref())
|
2017-08-03 08:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_activate_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_activate_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_activate_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_activate_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_activate_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_activatemode_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_activatemode_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_activatemode_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, crate::PadMode, bool) -> Result<(), LoggableError>
|
2019-01-16 20:23:56 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_activatemode_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_activatemode_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_chain_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_chain_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_chain_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, crate::Buffer) -> Result<FlowSuccess, FlowError>
|
2019-01-08 16:13:37 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_chain_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_chain_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_chain_list_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_chain_list_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_chain_list_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, crate::BufferList) -> Result<FlowSuccess, FlowError>
|
2019-01-08 16:13:37 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_chain_list_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_chain_list_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_event_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_event_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_event_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, crate::Event) -> bool + Send + Sync + 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_event_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_event_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_event_full_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_event_full_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_event_full_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, crate::Event) -> Result<FlowSuccess, FlowError>
|
2019-01-08 16:13:37 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_event_full_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_event_full_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_getrange_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_getrange_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_getrange_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-03-29 17:11:00 +00:00
|
|
|
F: Fn(
|
|
|
|
&Self,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&crate::Object>,
|
2020-03-29 17:11:00 +00:00
|
|
|
u64,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&mut crate::BufferRef>,
|
2020-03-29 17:11:00 +00:00
|
|
|
u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> Result<PadGetRangeSuccess, crate::FlowError>
|
2017-09-16 22:45:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_getrange_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_getrange_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_iterate_internal_links_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_iterate_internal_links_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_iterate_internal_links_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>) -> crate::Iterator<Pad> + Send + Sync + 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_iterate_internal_links_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_iterate_internal_links_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_link_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_link_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_link_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(
|
|
|
|
&Self,
|
|
|
|
Option<&crate::Object>,
|
|
|
|
&Pad,
|
|
|
|
) -> Result<crate::PadLinkSuccess, crate::PadLinkError>
|
2019-01-08 16:13:37 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_link_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_link_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_query_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_query_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_query_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>, &mut crate::QueryRef) -> bool + Send + Sync + 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_query_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_query_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_set_unlink_function")]
|
|
|
|
#[doc(alias = "gst_pad_set_unlink_function_full")]
|
2020-06-21 15:28:04 +00:00
|
|
|
unsafe fn set_unlink_function<F>(&self, func: F)
|
2017-09-16 22:45:21 +00:00
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&Self, Option<&crate::Object>) + Send + Sync + 'static,
|
2017-09-16 22:45:21 +00:00
|
|
|
{
|
2020-06-21 15:28:04 +00:00
|
|
|
let func_box: Box<F> = Box::new(func);
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_set_unlink_function_full(
|
2020-06-21 15:28:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
Some(trampoline_unlink_function::<Self, F>),
|
|
|
|
Box::into_raw(func_box) as gpointer,
|
|
|
|
Some(destroy_closure::<F>),
|
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
2017-09-17 21:32:29 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_start_task")]
|
2017-09-17 22:53:02 +00:00
|
|
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError> {
|
2022-10-09 15:28:17 +00:00
|
|
|
unsafe extern "C" fn trampoline_pad_task<F: FnMut() + Send + 'static>(func: gpointer) {
|
|
|
|
let (func, pad) = &mut *(func as *mut (F, *mut ffi::GstPad));
|
|
|
|
let pad = Pad::from_glib_borrow(*pad);
|
|
|
|
let result = panic::catch_unwind(AssertUnwindSafe(func));
|
|
|
|
|
|
|
|
if let Err(err) = result {
|
|
|
|
let element = match pad.parent_element() {
|
|
|
|
Some(element) => element,
|
|
|
|
None => panic::resume_unwind(err),
|
|
|
|
};
|
|
|
|
|
2023-01-16 08:17:29 +00:00
|
|
|
if pad.pause_task().is_err() {
|
|
|
|
crate::error!(crate::CAT_RUST, "could not stop pad task on panic");
|
|
|
|
}
|
|
|
|
|
|
|
|
crate::subclass::post_panic_error_message(&element, pad.upcast_ref(), Some(err));
|
2022-10-09 15:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn into_raw_pad_task<F: FnMut() + Send + 'static>(
|
|
|
|
func: F,
|
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
) -> gpointer {
|
|
|
|
#[allow(clippy::type_complexity)]
|
|
|
|
let func: Box<(F, *mut ffi::GstPad)> = Box::new((func, pad));
|
|
|
|
Box::into_raw(func) as gpointer
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn destroy_closure_pad_task<F>(ptr: gpointer) {
|
|
|
|
let _ = Box::<(F, *mut ffi::GstPad)>::from_raw(ptr as *mut _);
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:32:29 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_start_task(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2019-01-30 13:02:03 +00:00
|
|
|
Some(trampoline_pad_task::<F>),
|
2022-10-09 15:28:17 +00:00
|
|
|
into_raw_pad_task(func, self.upcast_ref().as_ptr()),
|
2019-03-01 17:49:27 +00:00
|
|
|
Some(destroy_closure_pad_task::<F>),
|
2017-09-17 22:53:02 +00:00
|
|
|
),
|
|
|
|
"Failed to start pad task",
|
|
|
|
)
|
2017-09-17 21:32:29 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_convert")]
|
2022-07-03 16:04:06 +00:00
|
|
|
fn peer_query_convert<U: SpecificFormattedValueFullRange>(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self,
|
2022-07-03 16:04:06 +00:00
|
|
|
src_val: impl FormattedValue,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<U> {
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2020-10-27 17:27:16 +00:00
|
|
|
src_val.into_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
U::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(U::from_raw(U::default_format(), dest_val.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_convert")]
|
2022-07-03 16:04:06 +00:00
|
|
|
fn peer_query_convert_generic(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
2022-07-03 16:04:06 +00:00
|
|
|
src_val: impl FormattedValue,
|
2017-11-11 10:21:55 +00:00
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2020-10-27 17:27:16 +00:00
|
|
|
src_val.into_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
dest_format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(
|
|
|
|
dest_format,
|
|
|
|
dest_val.assume_init(),
|
|
|
|
))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_duration")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn peer_query_duration<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-07-03 16:04:06 +00:00
|
|
|
T::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2020-10-27 17:27:16 +00:00
|
|
|
try_from_glib(duration.assume_init()).ok()
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_duration")]
|
2017-12-09 16:20:21 +00:00
|
|
|
fn peer_query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, duration.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_position")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn peer_query_position<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-07-03 16:04:06 +00:00
|
|
|
T::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2020-10-27 17:27:16 +00:00
|
|
|
try_from_glib(cur.assume_init()).ok()
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query_position")]
|
2017-12-09 16:20:21 +00:00
|
|
|
fn peer_query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_peer_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, cur.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_convert")]
|
2022-07-03 16:04:06 +00:00
|
|
|
fn query_convert<U: SpecificFormattedValueFullRange>(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self,
|
2022-07-03 16:04:06 +00:00
|
|
|
src_val: impl FormattedValue,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<U> {
|
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2020-10-27 17:27:16 +00:00
|
|
|
src_val.into_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
U::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(U::from_raw(U::default_format(), dest_val.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_convert")]
|
2022-07-03 16:04:06 +00:00
|
|
|
fn query_convert_generic(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
2022-07-03 16:04:06 +00:00
|
|
|
src_val: impl FormattedValue,
|
2017-11-11 10:21:55 +00:00
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_convert(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2022-07-03 16:04:06 +00:00
|
|
|
src_val.into_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
dest_format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(
|
|
|
|
dest_format,
|
|
|
|
dest_val.assume_init(),
|
|
|
|
))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_duration")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn query_duration<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-07-03 16:04:06 +00:00
|
|
|
T::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2020-10-27 17:27:16 +00:00
|
|
|
try_from_glib(duration.assume_init()).ok()
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_duration")]
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut duration = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_duration(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
duration.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, duration.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_position")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn query_position<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-07-03 16:04:06 +00:00
|
|
|
T::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-12-09 16:20:21 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2020-10-27 17:27:16 +00:00
|
|
|
try_from_glib(cur.assume_init()).ok()
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_query_position")]
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut cur = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_pad_query_position(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
cur.as_mut_ptr(),
|
2017-11-11 10:21:55 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(GenericFormattedValue::new(format, cur.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-01 16:28:57 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "get_mode")]
|
|
|
|
#[doc(alias = "GST_PAD_MODE")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn mode(&self) -> crate::PadMode {
|
2018-08-01 16:28:57 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: &ffi::GstPad = &*(self.as_ptr() as *const _);
|
2018-08-01 16:28:57 +00:00
|
|
|
from_glib(ptr.mode)
|
|
|
|
}
|
|
|
|
}
|
2018-08-13 16:58:30 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_sticky_events_foreach")]
|
2021-11-09 12:19:37 +00:00
|
|
|
fn sticky_events_foreach<
|
|
|
|
F: FnMut(&Event) -> ControlFlow<EventForeachAction, EventForeachAction>,
|
|
|
|
>(
|
2018-08-13 16:58:30 +00:00
|
|
|
&self,
|
|
|
|
func: F,
|
|
|
|
) {
|
2021-11-09 12:19:37 +00:00
|
|
|
unsafe extern "C" fn trampoline<
|
|
|
|
F: FnMut(&Event) -> ControlFlow<EventForeachAction, EventForeachAction>,
|
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
_pad: *mut ffi::GstPad,
|
|
|
|
event: *mut *mut ffi::GstEvent,
|
|
|
|
user_data: glib::ffi::gpointer,
|
|
|
|
) -> glib::ffi::gboolean {
|
2021-11-09 12:19:37 +00:00
|
|
|
let func = user_data as *mut F;
|
|
|
|
let res = (*func)(&from_glib_borrow(*event));
|
2018-08-13 16:58:30 +00:00
|
|
|
|
2021-11-09 12:19:37 +00:00
|
|
|
let (do_continue, ev_action) = match res {
|
|
|
|
ControlFlow::Continue(ev_action) => (glib::ffi::GTRUE, ev_action),
|
|
|
|
ControlFlow::Break(ev_action) => (glib::ffi::GFALSE, ev_action),
|
|
|
|
};
|
|
|
|
|
|
|
|
use EventForeachAction::*;
|
|
|
|
|
|
|
|
match ev_action {
|
|
|
|
Keep => (), // do nothing
|
|
|
|
Remove => {
|
|
|
|
ffi::gst_mini_object_unref(*event as *mut _);
|
2018-08-13 16:58:30 +00:00
|
|
|
*event = ptr::null_mut();
|
|
|
|
}
|
2021-11-09 12:19:37 +00:00
|
|
|
Replace(ev) => {
|
|
|
|
ffi::gst_mini_object_unref(*event as *mut _);
|
2022-05-06 19:41:15 +00:00
|
|
|
*event = ev.into_glib_ptr();
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 12:19:37 +00:00
|
|
|
|
|
|
|
do_continue
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let mut func = func;
|
2021-11-09 12:19:37 +00:00
|
|
|
let func_ptr = &mut func as *mut F as glib::ffi::gpointer;
|
2018-08-13 16:58:30 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_pad_sticky_events_foreach(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-11-09 12:19:37 +00:00
|
|
|
Some(trampoline::<F>),
|
2019-01-16 11:32:58 +00:00
|
|
|
func_ptr,
|
|
|
|
);
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 16:13:37 +00:00
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "gst_pad_get_sticky_event")]
|
|
|
|
#[doc(alias = "get_sticky_event")]
|
2022-01-18 09:57:22 +00:00
|
|
|
fn sticky_event<T: crate::event::StickyEventType>(&self, idx: u32) -> Option<T::Owned> {
|
2021-10-17 09:48:21 +00:00
|
|
|
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)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 15:23:39 +00:00
|
|
|
fn set_pad_flags(&self, flags: PadFlags) {
|
2019-05-11 10:13:33 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
2023-02-06 08:49:34 +00:00
|
|
|
let _guard = self.as_ref().object_lock();
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags |= flags.into_glib();
|
2019-05-11 12:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 15:23:39 +00:00
|
|
|
fn unset_pad_flags(&self, flags: PadFlags) {
|
2019-05-11 12:51:33 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
2023-02-06 08:49:34 +00:00
|
|
|
let _guard = self.as_ref().object_lock();
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags &= !flags.into_glib();
|
2019-05-11 10:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
#[doc(alias = "get_pad_flags")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn pad_flags(&self) -> PadFlags {
|
2019-05-11 10:13:33 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
|
2023-02-06 08:49:34 +00:00
|
|
|
let _guard = self.as_ref().object_lock();
|
2019-05-11 10:13:33 +00:00
|
|
|
from_glib((*ptr).flags)
|
|
|
|
}
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 20:21:43 +00:00
|
|
|
impl<O: IsA<Pad>> PadExtManual for O {}
|
|
|
|
|
2020-08-05 07:30:05 +00:00
|
|
|
unsafe fn create_probe_info<'a>(
|
2020-11-21 13:46:48 +00:00
|
|
|
info: *mut ffi::GstPadProbeInfo,
|
2020-08-05 07:30:05 +00:00
|
|
|
) -> (PadProbeInfo<'a>, Option<glib::Type>) {
|
2017-07-25 12:08:42 +00:00
|
|
|
let mut data_type = None;
|
2021-05-13 12:54:41 +00:00
|
|
|
let flow_res = try_from_glib((*info).ABI.abi.flow_ret);
|
2020-08-05 07:30:05 +00:00
|
|
|
let info = PadProbeInfo {
|
2017-07-24 08:51:14 +00:00
|
|
|
mask: from_glib((*info).type_),
|
2022-12-13 09:28:00 +00:00
|
|
|
id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as _))),
|
2017-07-24 08:51:14 +00:00
|
|
|
offset: (*info).offset,
|
|
|
|
size: (*info).size,
|
|
|
|
data: if (*info).data.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
let data = (*info).data as *mut ffi::GstMiniObject;
|
2018-07-26 00:14:04 +00:00
|
|
|
(*info).data = ptr::null_mut();
|
2021-04-27 15:15:46 +00:00
|
|
|
if (*data).type_ == Buffer::static_type().into_glib() {
|
2017-07-25 12:08:42 +00:00
|
|
|
data_type = Some(Buffer::static_type());
|
2018-07-26 00:14:04 +00:00
|
|
|
Some(PadProbeData::Buffer(from_glib_full(
|
2020-11-21 13:46:48 +00:00
|
|
|
data as *const ffi::GstBuffer,
|
2017-12-20 17:30:14 +00:00
|
|
|
)))
|
2021-04-27 15:15:46 +00:00
|
|
|
} else if (*data).type_ == BufferList::static_type().into_glib() {
|
2017-07-28 18:18:08 +00:00
|
|
|
data_type = Some(BufferList::static_type());
|
2018-07-26 00:14:04 +00:00
|
|
|
Some(PadProbeData::BufferList(from_glib_full(
|
2020-11-21 13:46:48 +00:00
|
|
|
data as *const ffi::GstBufferList,
|
2017-12-20 17:30:14 +00:00
|
|
|
)))
|
2021-04-27 15:15:46 +00:00
|
|
|
} else if (*data).type_ == Query::static_type().into_glib() {
|
2017-07-29 15:09:14 +00:00
|
|
|
data_type = Some(Query::static_type());
|
2017-12-20 17:30:14 +00:00
|
|
|
Some(PadProbeData::Query(QueryRef::from_mut_ptr(
|
2020-11-21 13:46:48 +00:00
|
|
|
data as *mut ffi::GstQuery,
|
2017-12-20 17:30:14 +00:00
|
|
|
)))
|
2021-04-27 15:15:46 +00:00
|
|
|
} else if (*data).type_ == Event::static_type().into_glib() {
|
2017-07-30 14:11:47 +00:00
|
|
|
data_type = Some(Event::static_type());
|
2018-07-26 00:14:04 +00:00
|
|
|
Some(PadProbeData::Event(from_glib_full(
|
2020-11-21 13:46:48 +00:00
|
|
|
data as *const ffi::GstEvent,
|
2017-12-20 17:30:14 +00:00
|
|
|
)))
|
2017-07-25 12:08:42 +00:00
|
|
|
} else {
|
2018-07-26 00:14:04 +00:00
|
|
|
Some(PadProbeData::__Unknown(data))
|
2017-07-25 12:08:42 +00:00
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
},
|
2021-04-28 12:34:56 +00:00
|
|
|
flow_res,
|
2017-07-24 08:51:14 +00:00
|
|
|
};
|
2020-08-05 07:30:05 +00:00
|
|
|
(info, data_type)
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2020-08-05 07:30:05 +00:00
|
|
|
unsafe fn update_probe_info(
|
|
|
|
ret: PadProbeReturn,
|
|
|
|
probe_info: PadProbeInfo,
|
|
|
|
data_type: Option<glib::Type>,
|
2020-11-21 13:46:48 +00:00
|
|
|
info: *mut ffi::GstPadProbeInfo,
|
2020-08-05 07:30:05 +00:00
|
|
|
) {
|
2019-05-12 13:03:16 +00:00
|
|
|
if ret == PadProbeReturn::Handled {
|
|
|
|
// Handled queries need to be returned
|
2022-12-23 12:18:17 +00:00
|
|
|
// Handled buffers and buffer lists are consumed
|
2019-05-12 13:03:16 +00:00
|
|
|
// No other types can safely be used here
|
|
|
|
|
|
|
|
match probe_info.data {
|
|
|
|
Some(PadProbeData::Query(query)) => {
|
|
|
|
assert_eq!(data_type, Some(Query::static_type()));
|
|
|
|
(*info).data = query.as_mut_ptr() as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
Some(PadProbeData::Buffer(_)) => {
|
|
|
|
assert_eq!(data_type, Some(Buffer::static_type()));
|
|
|
|
// Buffer not consumed by probe; consume it here
|
|
|
|
}
|
2022-12-23 12:18:17 +00:00
|
|
|
Some(PadProbeData::BufferList(_)) => {
|
|
|
|
assert_eq!(data_type, Some(BufferList::static_type()));
|
|
|
|
// BufferList not consumed by probe; consume it here
|
|
|
|
}
|
2020-11-18 13:16:59 +00:00
|
|
|
Some(PadProbeData::Event(_)) => {
|
|
|
|
assert_eq!(data_type, Some(Event::static_type()));
|
|
|
|
// Event not consumed by probe; consume it here
|
|
|
|
}
|
|
|
|
None if data_type == Some(Buffer::static_type())
|
2022-12-23 12:18:17 +00:00
|
|
|
|| data_type == Some(BufferList::static_type())
|
2020-11-18 13:16:59 +00:00
|
|
|
|| data_type == Some(Event::static_type()) =>
|
|
|
|
{
|
|
|
|
// Buffer or Event consumed by probe
|
2019-05-12 13:03:16 +00:00
|
|
|
}
|
2023-01-25 08:09:45 +00:00
|
|
|
other => panic!("Bad data for {data_type:?} pad probe returning Handled: {other:?}"),
|
2017-07-30 14:11:47 +00:00
|
|
|
}
|
2019-05-12 13:03:16 +00:00
|
|
|
} else {
|
|
|
|
match probe_info.data {
|
|
|
|
Some(PadProbeData::Buffer(buffer)) => {
|
|
|
|
assert_eq!(data_type, Some(Buffer::static_type()));
|
2022-05-06 19:41:15 +00:00
|
|
|
(*info).data = buffer.into_glib_ptr() as *mut libc::c_void;
|
2019-05-12 13:03:16 +00:00
|
|
|
}
|
|
|
|
Some(PadProbeData::BufferList(bufferlist)) => {
|
|
|
|
assert_eq!(data_type, Some(BufferList::static_type()));
|
2022-05-06 19:41:15 +00:00
|
|
|
(*info).data = bufferlist.into_glib_ptr() as *mut libc::c_void;
|
2019-05-12 13:03:16 +00:00
|
|
|
}
|
|
|
|
Some(PadProbeData::Event(event)) => {
|
|
|
|
assert_eq!(data_type, Some(Event::static_type()));
|
2022-05-06 19:41:15 +00:00
|
|
|
(*info).data = event.into_glib_ptr() as *mut libc::c_void;
|
2019-05-12 13:03:16 +00:00
|
|
|
}
|
|
|
|
Some(PadProbeData::Query(query)) => {
|
|
|
|
assert_eq!(data_type, Some(Query::static_type()));
|
|
|
|
(*info).data = query.as_mut_ptr() as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
Some(PadProbeData::__Unknown(ptr)) => {
|
|
|
|
assert_eq!(data_type, None);
|
|
|
|
(*info).data = ptr as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
assert_eq!(data_type, None);
|
|
|
|
}
|
2017-07-25 12:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2020-11-18 15:56:23 +00:00
|
|
|
let flow_ret: FlowReturn = probe_info.flow_res.into();
|
2021-04-27 15:15:46 +00:00
|
|
|
(*info).ABI.abi.flow_ret = flow_ret.into_glib();
|
2020-08-05 07:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn trampoline_pad_probe<
|
|
|
|
T,
|
|
|
|
F: Fn(&T, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static,
|
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
info: *mut ffi::GstPadProbeInfo,
|
2020-08-05 07:30:05 +00:00
|
|
|
func: gpointer,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> ffi::GstPadProbeReturn
|
2020-08-05 07:30:05 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
|
|
|
let func: &F = &*(func as *const F);
|
|
|
|
|
|
|
|
let (mut probe_info, data_type) = create_probe_info(info);
|
|
|
|
|
|
|
|
let ret = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-08-05 07:30:05 +00:00
|
|
|
&mut probe_info,
|
|
|
|
);
|
|
|
|
|
|
|
|
update_probe_info(ret, probe_info, data_type, info);
|
2019-05-12 09:59:59 +00:00
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
ret.into_glib()
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_activate_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).activatedata as *const F);
|
2019-01-16 20:23:56 +00:00
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
match func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2019-01-30 13:02:03 +00:00
|
|
|
) {
|
2019-01-16 20:23:56 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*Pad::from_glib_borrow(pad));
|
2019-01-16 20:23:56 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_activatemode_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::PadMode, bool) -> Result<(), LoggableError>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
mode: ffi::GstPadMode,
|
|
|
|
active: glib::ffi::gboolean,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).activatemodedata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2019-01-24 21:11:43 +00:00
|
|
|
match func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
from_glib(mode),
|
|
|
|
from_glib(active),
|
2019-01-24 21:11:43 +00:00
|
|
|
) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*Pad::from_glib_borrow(pad));
|
2019-01-24 21:11:43 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_chain_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Buffer) -> Result<FlowSuccess, FlowError>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
buffer: *mut ffi::GstBuffer,
|
|
|
|
) -> ffi::GstFlowReturn
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).chaindata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
let res: FlowReturn = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
from_glib_full(buffer),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2019-01-08 16:13:37 +00:00
|
|
|
.into();
|
2021-04-27 15:15:46 +00:00
|
|
|
res.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_chain_list_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::BufferList) -> Result<FlowSuccess, FlowError>
|
2019-01-30 13:02:03 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
list: *mut ffi::GstBufferList,
|
|
|
|
) -> ffi::GstFlowReturn
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).chainlistdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
let res: FlowReturn = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
from_glib_full(list),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2019-01-08 16:13:37 +00:00
|
|
|
.into();
|
2021-04-27 15:15:46 +00:00
|
|
|
res.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_event_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Event) -> bool + Send + Sync + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
event: *mut ffi::GstEvent,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).eventdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
|
|
|
func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
from_glib_full(event),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_event_full_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Event) -> Result<FlowSuccess, FlowError>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
event: *mut ffi::GstEvent,
|
|
|
|
) -> ffi::GstFlowReturn
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).eventdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
let res: FlowReturn = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
from_glib_full(event),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2019-01-08 16:13:37 +00:00
|
|
|
.into();
|
2021-04-27 15:15:46 +00:00
|
|
|
res.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 15:52:23 +00:00
|
|
|
#[allow(clippy::needless_option_as_deref)]
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_getrange_function<
|
|
|
|
T,
|
2020-03-29 17:11:00 +00:00
|
|
|
F: Fn(
|
|
|
|
&T,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&crate::Object>,
|
2020-03-29 17:11:00 +00:00
|
|
|
u64,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&mut crate::BufferRef>,
|
2020-03-29 17:11:00 +00:00
|
|
|
u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> Result<PadGetRangeSuccess, crate::FlowError>
|
2020-03-29 17:11:00 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
2017-09-16 22:45:21 +00:00
|
|
|
offset: u64,
|
|
|
|
length: u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
buffer: *mut *mut ffi::GstBuffer,
|
|
|
|
) -> ffi::GstFlowReturn
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).getrangedata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert!(!buffer.is_null());
|
2020-03-29 17:11:00 +00:00
|
|
|
|
2020-04-05 14:52:56 +00:00
|
|
|
let pad = Pad::from_glib_borrow(pad);
|
|
|
|
let pad = pad.unsafe_cast_ref();
|
2020-03-29 17:11:00 +00:00
|
|
|
let mut passed_buffer = if (*buffer).is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
Some(crate::BufferRef::from_mut_ptr(*buffer))
|
2020-03-29 17:11:00 +00:00
|
|
|
};
|
|
|
|
|
2017-09-16 22:45:21 +00:00
|
|
|
match func(
|
2021-07-30 10:19:24 +00:00
|
|
|
pad,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
offset,
|
2020-04-20 15:16:23 +00:00
|
|
|
passed_buffer.as_deref_mut(),
|
2017-09-16 22:45:21 +00:00
|
|
|
length,
|
|
|
|
) {
|
2020-03-29 17:11:00 +00:00
|
|
|
Ok(PadGetRangeSuccess::NewBuffer(new_buffer)) => {
|
|
|
|
if let Some(passed_buffer) = passed_buffer {
|
2022-02-21 17:56:06 +00:00
|
|
|
crate::debug!(
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::CAT_PERFORMANCE,
|
2020-03-29 17:11:00 +00:00
|
|
|
obj: pad.unsafe_cast_ref::<glib::Object>(),
|
|
|
|
"Returned new buffer from getrange function, copying into passed buffer"
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut map = match passed_buffer.map_writable() {
|
|
|
|
Ok(map) => map,
|
|
|
|
Err(_) => {
|
2022-02-21 17:56:06 +00:00
|
|
|
crate::error!(
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::CAT_RUST,
|
2020-03-29 17:11:00 +00:00
|
|
|
obj: pad.unsafe_cast_ref::<glib::Object>(),
|
|
|
|
"Failed to map passed buffer writable"
|
|
|
|
);
|
2020-11-21 13:46:48 +00:00
|
|
|
return ffi::GST_FLOW_ERROR;
|
2020-03-29 17:11:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-01 09:10:57 +00:00
|
|
|
let copied_size = new_buffer.copy_to_slice(0, &mut map);
|
2020-03-29 17:11:00 +00:00
|
|
|
drop(map);
|
|
|
|
|
|
|
|
if let Err(copied_size) = copied_size {
|
|
|
|
passed_buffer.set_size(copied_size);
|
|
|
|
}
|
|
|
|
|
2023-12-10 18:35:43 +00:00
|
|
|
match new_buffer.copy_into(passed_buffer, crate::BUFFER_COPY_METADATA, ..) {
|
2021-04-27 15:15:46 +00:00
|
|
|
Ok(_) => FlowReturn::Ok.into_glib(),
|
2020-03-29 17:11:00 +00:00
|
|
|
Err(_) => {
|
2022-02-21 17:56:06 +00:00
|
|
|
crate::error!(
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::CAT_RUST,
|
2020-03-29 17:11:00 +00:00
|
|
|
obj: pad.unsafe_cast_ref::<glib::Object>(),
|
|
|
|
"Failed to copy buffer metadata"
|
|
|
|
);
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
FlowReturn::Error.into_glib()
|
2020-03-29 17:11:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-06 19:41:15 +00:00
|
|
|
*buffer = new_buffer.into_glib_ptr();
|
2021-04-27 15:15:46 +00:00
|
|
|
FlowReturn::Ok.into_glib()
|
2020-03-29 17:11:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(PadGetRangeSuccess::FilledBuffer) => {
|
|
|
|
assert!(passed_buffer.is_some());
|
2021-04-27 15:15:46 +00:00
|
|
|
FlowReturn::Ok.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
2021-04-27 15:15:46 +00:00
|
|
|
Err(ret) => FlowReturn::from_error(ret).into_glib(),
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_iterate_internal_links_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) -> crate::Iterator<Pad> + Send + Sync + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
) -> *mut ffi::GstIterator
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).iterintlinkdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
|
|
|
// Steal the iterator and return it
|
2019-01-30 13:02:03 +00:00
|
|
|
let ret = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2019-01-30 13:02:03 +00:00
|
|
|
);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2022-05-06 19:41:15 +00:00
|
|
|
ret.into_glib_ptr()
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_link_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(
|
|
|
|
&T,
|
|
|
|
Option<&crate::Object>,
|
|
|
|
&crate::Pad,
|
|
|
|
) -> Result<crate::PadLinkSuccess, crate::PadLinkError>
|
2019-01-30 13:02:03 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
peer: *mut ffi::GstPad,
|
|
|
|
) -> ffi::GstPadLinkReturn
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).linkdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let res: crate::PadLinkReturn = func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2017-09-16 22:45:21 +00:00
|
|
|
&from_glib_borrow(peer),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2019-01-08 16:13:37 +00:00
|
|
|
.into();
|
2021-04-27 15:15:46 +00:00
|
|
|
res.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_query_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, &mut crate::QueryRef) -> bool + Send + Sync + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
|
|
|
query: *mut ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-01-30 13:02:03 +00:00
|
|
|
where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).querydata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
|
|
|
func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::QueryRef::from_mut_ptr(query),
|
2018-10-08 12:02:23 +00:00
|
|
|
)
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_unlink_function<
|
|
|
|
T,
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) + Send + Sync + 'static,
|
2019-01-30 13:02:03 +00:00
|
|
|
>(
|
2020-11-21 13:46:48 +00:00
|
|
|
pad: *mut ffi::GstPad,
|
|
|
|
parent: *mut ffi::GstObject,
|
2019-01-30 13:02:03 +00:00
|
|
|
) where
|
|
|
|
T: IsA<Pad>,
|
|
|
|
{
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &F = &*((*pad).unlinkdata as *const F);
|
2017-09-16 22:45:21 +00:00
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
func(
|
2021-07-30 10:19:24 +00:00
|
|
|
Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<crate::Object>::from_glib_borrow(parent)
|
2020-04-05 14:52:56 +00:00
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2019-01-30 13:02:03 +00:00
|
|
|
)
|
2017-09-16 22:45:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn destroy_closure<F>(ptr: gpointer) {
|
2022-08-10 09:27:00 +00:00
|
|
|
let _ = Box::<F>::from_raw(ptr as *mut _);
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
2017-09-17 21:32:29 +00:00
|
|
|
|
2020-06-21 16:43:21 +00:00
|
|
|
impl Pad {
|
2023-04-28 19:35:15 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
2023-05-12 08:49:22 +00:00
|
|
|
/// Creates a new [`Pad`] with the specified [`PadDirection`](crate::PadDirection).
|
2023-04-28 19:35:15 +00:00
|
|
|
///
|
2023-05-12 08:49:22 +00:00
|
|
|
/// An automatically generated name will be assigned.
|
|
|
|
///
|
|
|
|
/// Use [`Pad::builder()`] to get a [`PadBuilder`] and define options.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn new(direction: crate::PadDirection) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
Self::builder(direction).build()
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a [`PadBuilder`] with the specified [`PadDirection`](crate::PadDirection).
|
|
|
|
///
|
|
|
|
/// An automatically generated name will be assigned.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn builder(direction: crate::PadDirection) -> PadBuilder<Self> {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
PadBuilder::new(direction)
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
2023-05-12 08:49:22 +00:00
|
|
|
/// Creates a new [`Pad`] from the [`StaticPadTemplate`](crate::StaticPadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`StaticPadTemplate`](crate::StaticPadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the `name_template` is a wildcard-name.
|
2023-04-28 19:35:15 +00:00
|
|
|
///
|
2023-05-12 08:49:22 +00:00
|
|
|
/// Use [`Pad::builder_from_static_template()`] to get a [`PadBuilder`] and define options.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_static_template")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn from_static_template(templ: &StaticPadTemplate) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
Self::builder_from_static_template(templ).build()
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a new [`PadBuilder`] from the [`StaticPadTemplate`](crate::StaticPadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`StaticPadTemplate`](crate::StaticPadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// Use [`PadBuilder::name`] or [`PadBuilder::maybe_name`] to specify a different name.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_static_template")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn builder_from_static_template(templ: &StaticPadTemplate) -> PadBuilder<Self> {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
PadBuilder::from_static_template(templ)
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
2023-05-12 08:49:22 +00:00
|
|
|
/// Creates a new [`Pad`] from the [`PadTemplate`](crate::PadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`PadTemplate`](crate::PadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// # Panics
|
2023-04-28 19:35:15 +00:00
|
|
|
///
|
2023-05-12 08:49:22 +00:00
|
|
|
/// Panics if the `name_template` is a wildcard-name.
|
|
|
|
///
|
|
|
|
/// Use [`Pad::builder_from_template()`] to get a [`PadBuilder`] and define options.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_template")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn from_template(templ: &crate::PadTemplate) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
Self::builder_from_template(templ).build()
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a new [`PadBuilder`] from the [`PadTemplate`](crate::PadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`PadTemplate`](crate::PadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// Use [`PadBuilder::name`] or [`PadBuilder::maybe_name`] to specify a different name.
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_template")]
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn builder_from_template(templ: &crate::PadTemplate) -> PadBuilder<Self> {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2023-04-28 19:35:15 +00:00
|
|
|
PadBuilder::from_template(templ)
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
2022-10-12 14:27:04 +00:00
|
|
|
|
|
|
|
#[doc(alias = "gst_pad_query_default")]
|
|
|
|
pub fn query_default<O: IsA<Pad>>(
|
|
|
|
pad: &O,
|
|
|
|
parent: Option<&impl IsA<crate::Object>>,
|
|
|
|
query: &mut QueryRef,
|
|
|
|
) -> bool {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
from_glib(ffi::gst_pad_query_default(
|
|
|
|
pad.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.as_ref()).to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_pad_event_default")]
|
|
|
|
pub fn event_default<O: IsA<Pad>>(
|
|
|
|
pad: &O,
|
|
|
|
parent: Option<&impl IsA<crate::Object>>,
|
|
|
|
event: impl Into<Event>,
|
|
|
|
) -> bool {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
from_glib(ffi::gst_pad_event_default(
|
|
|
|
pad.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.as_ref()).to_glib_none().0,
|
|
|
|
event.into().into_glib_ptr(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_pad_iterate_internal_links_default")]
|
|
|
|
pub fn iterate_internal_links_default<O: IsA<Pad>>(
|
|
|
|
pad: &O,
|
|
|
|
parent: Option<&impl IsA<crate::Object>>,
|
|
|
|
) -> crate::Iterator<Pad> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_pad_iterate_internal_links_default(
|
|
|
|
pad.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.as_ref()).to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "The builder must be built to be used"]
|
2023-05-12 08:49:22 +00:00
|
|
|
pub struct PadBuilder<T> {
|
|
|
|
pub(crate) pad: T,
|
|
|
|
pub(crate) needs_specific_name: bool,
|
|
|
|
}
|
2020-06-21 16:43:21 +00:00
|
|
|
|
2021-03-14 08:29:44 +00:00
|
|
|
impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a `PadBuilder` with the specified [`PadDirection`](crate::PadDirection).
|
|
|
|
///
|
|
|
|
/// An automatically generated name will be assigned. Use [`PadBuilder::name`] or
|
|
|
|
/// [`PadBuilder::maybe_name`] to define a specific name.
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn new(direction: crate::PadDirection) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2023-01-22 07:48:51 +00:00
|
|
|
let pad = glib::Object::builder::<T>()
|
|
|
|
.property("direction", direction)
|
|
|
|
.build();
|
2020-06-21 16:43:21 +00:00
|
|
|
|
|
|
|
// Ghost pads are a bit special
|
2020-11-21 13:46:48 +00:00
|
|
|
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
|
2020-06-21 16:43:21 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let res = ffi::gst_ghost_pad_construct(pad.to_glib_none().0);
|
2020-06-21 16:43:21 +00:00
|
|
|
// This can't really fail...
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_ne!(res, glib::ffi::GFALSE, "Failed to construct ghost pad");
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
PadBuilder {
|
|
|
|
pad,
|
|
|
|
needs_specific_name: false,
|
|
|
|
}
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a `PadBuilder` from the specified [`StaticPadTemplate`](crate::StaticPadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`StaticPadTemplate`](crate::StaticPadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// Use [`PadBuilder::name`] or [`PadBuilder::maybe_name`] to specify a different name.
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn from_static_template(templ: &StaticPadTemplate) -> Self {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2020-06-21 16:43:21 +00:00
|
|
|
|
|
|
|
let templ = templ.get();
|
2023-04-28 19:35:15 +00:00
|
|
|
Self::from_template(&templ)
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Creates a `PadBuilder` from the specified [`PadTemplate`](crate::PadTemplate).
|
|
|
|
///
|
|
|
|
/// If the [`PadTemplate`](crate::PadTemplate) has a specific `name_template`,
|
|
|
|
/// i.e. if it's not a wildcard-name containing `%u`, `%s` or `%d`,
|
|
|
|
/// the `Pad` will automatically be named after the `name_template`.
|
|
|
|
///
|
|
|
|
/// Use [`PadBuilder::name`] or [`PadBuilder::maybe_name`] to specify a different name.
|
2023-04-28 19:35:15 +00:00
|
|
|
pub fn from_template(templ: &crate::PadTemplate) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
|
|
|
let mut type_ = T::static_type();
|
|
|
|
|
|
|
|
// Since 1.14 templates can keep a pad GType with them, so we need to do some
|
|
|
|
// additional checks here now
|
|
|
|
if templ.has_property("gtype", Some(glib::Type::static_type())) {
|
2021-11-06 17:09:27 +00:00
|
|
|
let gtype = templ.property::<glib::Type>("gtype");
|
2020-06-21 16:43:21 +00:00
|
|
|
|
2021-02-25 10:38:10 +00:00
|
|
|
if gtype == glib::Type::UNIT {
|
2020-06-21 16:43:21 +00:00
|
|
|
// Nothing to be done, we can create any kind of pad
|
2021-02-25 10:38:10 +00:00
|
|
|
} else if gtype.is_a(type_) {
|
2020-06-21 16:43:21 +00:00
|
|
|
// We were asked to create a parent type of the template type, e.g. a gst::Pad for
|
|
|
|
// a template that wants a gst_base::AggregatorPad. Not a problem: update the type
|
|
|
|
type_ = gtype;
|
|
|
|
} else {
|
|
|
|
// Otherwise the requested type must be a subclass of the template pad type
|
2021-02-25 10:38:10 +00:00
|
|
|
assert!(type_.is_a(gtype));
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-22 07:48:51 +00:00
|
|
|
let mut properties = [
|
|
|
|
("direction", templ.direction().into()),
|
|
|
|
("template", templ.into()),
|
|
|
|
];
|
|
|
|
|
|
|
|
let pad =
|
|
|
|
unsafe { glib::Object::with_mut_values(type_, &mut properties).unsafe_cast::<T>() };
|
2020-06-21 16:43:21 +00:00
|
|
|
|
|
|
|
// Ghost pads are a bit special
|
2020-11-21 13:46:48 +00:00
|
|
|
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
|
2020-06-21 16:43:21 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let res = ffi::gst_ghost_pad_construct(pad.to_glib_none().0);
|
2020-06-21 16:43:21 +00:00
|
|
|
// This can't really fail...
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_ne!(res, glib::ffi::GFALSE, "Failed to construct ghost pad");
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
let needs_specific_name = if templ.name().find('%').is_some() {
|
|
|
|
// Pad needs a specific name
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
pad.set_property("name", templ.name());
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
PadBuilder {
|
|
|
|
pad,
|
|
|
|
needs_specific_name,
|
|
|
|
}
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Sets the name of the Pad.
|
|
|
|
pub fn name(mut self, name: impl glib::IntoGStr) -> Self {
|
|
|
|
name.run_with_gstr(|name| self.pad.set_property("name", name));
|
|
|
|
self.needs_specific_name = false;
|
2023-04-28 19:35:15 +00:00
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Optionally sets the name of the Pad.
|
|
|
|
///
|
|
|
|
/// This method is convenient when the `name` is provided as an `Option`.
|
|
|
|
/// If the `name` is `None`, this has no effect.
|
|
|
|
pub fn maybe_name<N: glib::IntoGStr>(self, name: Option<N>) -> Self {
|
|
|
|
if let Some(name) = name {
|
|
|
|
self.name(name)
|
|
|
|
} else {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_activate_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn activate_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) -> Result<(), LoggableError> + Send + Sync + 'static,
|
2020-06-21 16:43:21 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_activate_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_activatemode_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn activatemode_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::PadMode, bool) -> Result<(), LoggableError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_activatemode_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_chain_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn chain_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Buffer) -> Result<FlowSuccess, FlowError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_chain_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_chain_list_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn chain_list_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::BufferList) -> Result<FlowSuccess, FlowError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_chain_list_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_event_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn event_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Event) -> bool + Send + Sync + 'static,
|
2020-06-21 16:43:21 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_event_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_event_full_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn event_full_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, crate::Event) -> Result<FlowSuccess, FlowError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_event_full_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_getrange_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn getrange_function<F>(self, func: F) -> Self
|
|
|
|
where
|
|
|
|
F: Fn(
|
|
|
|
&T,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&crate::Object>,
|
2020-06-21 16:43:21 +00:00
|
|
|
u64,
|
2020-11-21 13:46:48 +00:00
|
|
|
Option<&mut crate::BufferRef>,
|
2020-06-21 16:43:21 +00:00
|
|
|
u32,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> Result<PadGetRangeSuccess, crate::FlowError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_getrange_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_iterate_internal_links_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn iterate_internal_links_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) -> crate::Iterator<Pad> + Send + Sync + 'static,
|
2020-06-21 16:43:21 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_iterate_internal_links_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_link_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn link_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(
|
|
|
|
&T,
|
|
|
|
Option<&crate::Object>,
|
|
|
|
&Pad,
|
|
|
|
) -> Result<crate::PadLinkSuccess, crate::PadLinkError>
|
2020-06-21 16:43:21 +00:00
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_link_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_query_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn query_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>, &mut crate::QueryRef) -> bool + Send + Sync + 'static,
|
2020-06-21 16:43:21 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_query_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_set_unlink_function")]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn unlink_function<F>(self, func: F) -> Self
|
|
|
|
where
|
2020-11-21 13:46:48 +00:00
|
|
|
F: Fn(&T, Option<&crate::Object>) + Send + Sync + 'static,
|
2020-06-21 16:43:21 +00:00
|
|
|
{
|
|
|
|
unsafe {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_unlink_function(func);
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn flags(self, flags: PadFlags) -> Self {
|
2023-05-12 08:49:22 +00:00
|
|
|
self.pad.set_pad_flags(flags);
|
2020-06-21 16:43:21 +00:00
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// rustdoc-stripper-ignore-next
|
|
|
|
/// Builds the [`Pad`].
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// Panics if the [`Pad`] was built from a [`PadTemplate`](crate::PadTemplate)
|
|
|
|
/// with a wildcard-name `name_template` (i.e. containing `%u`, `%s` or `%d`)
|
|
|
|
/// and no specific `name` was provided using [`PadBuilder::name`]
|
|
|
|
/// or [`PadBuilder::maybe_name`], or for [`GhostPad`s](crate::GhostPad),
|
|
|
|
/// by defining a `target`.
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "Building the pad without using it has no effect"]
|
2023-05-12 08:49:22 +00:00
|
|
|
#[track_caller]
|
2020-06-21 16:43:21 +00:00
|
|
|
pub fn build(self) -> T {
|
2023-05-12 08:49:22 +00:00
|
|
|
if self.needs_specific_name {
|
|
|
|
panic!(concat!(
|
|
|
|
"Attempt to build a Pad from a wildcard-name template",
|
|
|
|
" or with a target Pad with an incompatible name.",
|
|
|
|
" Make sure to define a specific name using PadBuilder.",
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
self.pad
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:45:39 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::sync::{atomic::AtomicUsize, mpsc::channel, Arc, Mutex};
|
|
|
|
|
2017-09-17 22:45:39 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_event_chain_functions() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-09-17 22:45:39 +00:00
|
|
|
|
|
|
|
let events = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
let events_clone = events.clone();
|
|
|
|
let buffers = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
let buffers_clone = buffers.clone();
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink")
|
2020-06-21 16:43:21 +00:00
|
|
|
.event_function(move |_, _, event| {
|
|
|
|
let mut events = events_clone.lock().unwrap();
|
|
|
|
events.push(event);
|
|
|
|
|
|
|
|
true
|
|
|
|
})
|
|
|
|
.chain_function(move |_, _, buffer| {
|
|
|
|
let mut buffers = buffers_clone.lock().unwrap();
|
|
|
|
buffers.push(buffer);
|
2017-09-17 22:45:39 +00:00
|
|
|
|
2020-06-21 16:43:21 +00:00
|
|
|
Ok(FlowSuccess::Ok)
|
|
|
|
})
|
|
|
|
.build();
|
2017-09-17 22:45:39 +00:00
|
|
|
|
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
assert!(pad.send_event(crate::event::StreamStart::new("test")));
|
|
|
|
let segment = crate::FormattedSegment::<crate::ClockTime>::new();
|
|
|
|
assert!(pad.send_event(crate::event::Segment::new(segment.as_ref())));
|
2017-09-17 22:45:39 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pad.chain(crate::Buffer::new()), Ok(FlowSuccess::Ok));
|
2017-09-17 22:45:39 +00:00
|
|
|
|
|
|
|
let events = events.lock().unwrap();
|
|
|
|
let buffers = buffers.lock().unwrap();
|
|
|
|
assert_eq!(events.len(), 2);
|
|
|
|
assert_eq!(buffers.len(), 1);
|
|
|
|
|
|
|
|
match events[0].view() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::EventView::StreamStart(..) => (),
|
2017-09-17 22:45:39 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
match events[1].view() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::EventView::Segment(..) => (),
|
2017-09-17 22:45:39 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
2017-09-17 22:53:02 +00:00
|
|
|
|
2020-03-28 18:00:11 +00:00
|
|
|
#[test]
|
|
|
|
fn test_getrange_function() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2020-03-28 18:00:11 +00:00
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Src)
|
|
|
|
.name("src")
|
2020-06-21 16:43:21 +00:00
|
|
|
.activate_function(|pad, _parent| {
|
2020-11-21 13:46:48 +00:00
|
|
|
pad.activate_mode(crate::PadMode::Pull, true)
|
2020-06-21 16:43:21 +00:00
|
|
|
.map_err(|err| err.into())
|
|
|
|
})
|
|
|
|
.getrange_function(|_pad, _parent, offset, _buffer, size| {
|
|
|
|
assert_eq!(offset, 0);
|
|
|
|
assert_eq!(size, 5);
|
2020-11-21 13:46:48 +00:00
|
|
|
let buffer = crate::Buffer::from_slice(b"abcde");
|
2020-06-21 16:43:21 +00:00
|
|
|
Ok(PadGetRangeSuccess::NewBuffer(buffer))
|
|
|
|
})
|
|
|
|
.build();
|
2020-03-28 18:00:11 +00:00
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
2021-04-20 10:24:17 +00:00
|
|
|
let buffer = pad.range(0, 5).unwrap();
|
2020-03-28 18:00:11 +00:00
|
|
|
let map = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(&*map, b"abcde");
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let mut buffer = crate::Buffer::with_size(5).unwrap();
|
2021-04-20 10:24:17 +00:00
|
|
|
pad.range_fill(0, buffer.get_mut().unwrap(), 5).unwrap();
|
2020-03-28 18:00:11 +00:00
|
|
|
let map = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(&*map, b"abcde");
|
|
|
|
|
|
|
|
pad.set_active(false).unwrap();
|
|
|
|
drop(pad);
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Src)
|
|
|
|
.name("src")
|
2020-06-21 16:43:21 +00:00
|
|
|
.activate_function(|pad, _parent| {
|
2020-11-21 13:46:48 +00:00
|
|
|
pad.activate_mode(crate::PadMode::Pull, true)
|
2020-06-21 16:43:21 +00:00
|
|
|
.map_err(|err| err.into())
|
|
|
|
})
|
|
|
|
.getrange_function(|_pad, _parent, offset, buffer, size| {
|
|
|
|
assert_eq!(offset, 0);
|
|
|
|
assert_eq!(size, 5);
|
|
|
|
if let Some(buffer) = buffer {
|
|
|
|
buffer.copy_from_slice(0, b"fghij").unwrap();
|
|
|
|
Ok(PadGetRangeSuccess::FilledBuffer)
|
|
|
|
} else {
|
2020-11-21 13:46:48 +00:00
|
|
|
let buffer = crate::Buffer::from_slice(b"abcde");
|
2020-06-21 16:43:21 +00:00
|
|
|
Ok(PadGetRangeSuccess::NewBuffer(buffer))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.build();
|
2020-03-28 18:00:11 +00:00
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
2021-04-20 10:24:17 +00:00
|
|
|
let buffer = pad.range(0, 5).unwrap();
|
2020-03-28 18:00:11 +00:00
|
|
|
let map = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(&*map, b"abcde");
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let mut buffer = crate::Buffer::with_size(5).unwrap();
|
2021-04-20 10:24:17 +00:00
|
|
|
pad.range_fill(0, buffer.get_mut().unwrap(), 5).unwrap();
|
2020-03-28 18:00:11 +00:00
|
|
|
let map = buffer.map_readable().unwrap();
|
|
|
|
assert_eq!(&*map, b"fghij");
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:53:02 +00:00
|
|
|
#[test]
|
|
|
|
fn test_task() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2017-09-17 22:53:02 +00:00
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink")
|
|
|
|
.build();
|
2017-09-17 22:53:02 +00:00
|
|
|
let (sender, receiver) = channel();
|
|
|
|
|
|
|
|
let mut i = 0;
|
|
|
|
let pad_clone = pad.clone();
|
|
|
|
pad.start_task(move || {
|
|
|
|
i += 1;
|
|
|
|
if i == 3 {
|
|
|
|
sender.send(i).unwrap();
|
|
|
|
pad_clone.pause_task().unwrap();
|
|
|
|
}
|
2018-10-08 12:02:23 +00:00
|
|
|
})
|
|
|
|
.unwrap();
|
2017-09-17 22:53:02 +00:00
|
|
|
|
|
|
|
assert_eq!(receiver.recv().unwrap(), 3);
|
|
|
|
}
|
2019-05-12 14:48:46 +00:00
|
|
|
|
2021-02-28 16:50:44 +00:00
|
|
|
#[test]
|
|
|
|
fn test_remove_probe_from_probe() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let src_pad = crate::Pad::builder(crate::PadDirection::Src)
|
|
|
|
.name("src")
|
|
|
|
.build();
|
|
|
|
let sink_pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink")
|
2021-02-28 16:50:44 +00:00
|
|
|
.chain_function(|_pad, _parent, _buffer| Ok(crate::FlowSuccess::Ok))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
src_pad.link(&sink_pad).unwrap();
|
|
|
|
|
|
|
|
let counter = Arc::new(AtomicUsize::new(0));
|
|
|
|
let counter_clone = counter.clone();
|
|
|
|
src_pad.add_probe(crate::PadProbeType::BUFFER, move |pad, info| {
|
|
|
|
if let Some(PadProbeData::Buffer(_)) = info.data {
|
|
|
|
counter_clone.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
|
|
pad.remove_probe(info.id.take().expect("no pad probe id"));
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
|
|
|
crate::PadProbeReturn::Handled
|
|
|
|
});
|
|
|
|
|
|
|
|
sink_pad.set_active(true).unwrap();
|
|
|
|
src_pad.set_active(true).unwrap();
|
|
|
|
|
|
|
|
assert!(src_pad.push_event(crate::event::StreamStart::new("test")));
|
|
|
|
let segment = crate::FormattedSegment::<crate::ClockTime>::new();
|
|
|
|
assert!(src_pad.push_event(crate::event::Segment::new(segment.as_ref())));
|
|
|
|
|
|
|
|
assert_eq!(src_pad.push(crate::Buffer::new()), Ok(FlowSuccess::Ok));
|
|
|
|
assert_eq!(src_pad.push(crate::Buffer::new()), Ok(FlowSuccess::Ok));
|
|
|
|
|
|
|
|
assert_eq!(counter.load(std::sync::atomic::Ordering::SeqCst), 1);
|
|
|
|
}
|
|
|
|
|
2019-05-12 14:48:46 +00:00
|
|
|
#[test]
|
|
|
|
fn test_probe() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2019-05-12 14:48:46 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let (major, minor, micro, _) = crate::version();
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Src)
|
|
|
|
.name("src")
|
|
|
|
.build();
|
2019-05-12 14:48:46 +00:00
|
|
|
let events = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
let buffers = Arc::new(Mutex::new(Vec::new()));
|
|
|
|
|
|
|
|
let flow_override = if (major, minor, micro) >= (1, 16, 1) {
|
2020-11-18 15:56:23 +00:00
|
|
|
Err(FlowError::Eos)
|
2019-05-12 14:48:46 +00:00
|
|
|
} else {
|
|
|
|
// Broken on 1.16.0
|
|
|
|
// https://gitlab.freedesktop.org/gstreamer/gstreamer/merge_requests/151
|
2020-11-18 15:56:23 +00:00
|
|
|
Ok(FlowSuccess::Ok)
|
2019-05-12 14:48:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
let events = events.clone();
|
2020-11-21 13:46:48 +00:00
|
|
|
pad.add_probe(crate::PadProbeType::EVENT_DOWNSTREAM, move |_, info| {
|
2019-05-12 14:48:46 +00:00
|
|
|
if let Some(PadProbeData::Event(event)) = &info.data {
|
|
|
|
let mut events = events.lock().unwrap();
|
|
|
|
events.push(event.clone());
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::PadProbeReturn::Ok
|
2019-05-12 14:48:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-18 13:16:59 +00:00
|
|
|
{
|
|
|
|
let events = events.clone();
|
2020-11-21 13:46:48 +00:00
|
|
|
pad.add_probe(crate::PadProbeType::EVENT_UPSTREAM, move |_, info| {
|
2020-11-18 13:16:59 +00:00
|
|
|
if let Some(PadProbeData::Event(event)) = info.data.take() {
|
|
|
|
let mut events = events.lock().unwrap();
|
|
|
|
events.push(event);
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::PadProbeReturn::Handled
|
2020-11-18 13:16:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-12 14:48:46 +00:00
|
|
|
{
|
|
|
|
let buffers = buffers.clone();
|
2020-11-21 13:46:48 +00:00
|
|
|
pad.add_probe(crate::PadProbeType::BUFFER, move |_, info| {
|
2019-05-12 14:48:46 +00:00
|
|
|
if let Some(PadProbeData::Buffer(buffer)) = info.data.take() {
|
|
|
|
let mut buffers = buffers.lock().unwrap();
|
2020-11-18 15:56:23 +00:00
|
|
|
info.flow_res = if buffers.is_empty() {
|
|
|
|
Ok(FlowSuccess::Ok)
|
2019-05-12 14:48:46 +00:00
|
|
|
} else {
|
|
|
|
flow_override
|
|
|
|
};
|
|
|
|
buffers.push(buffer);
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
}
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::PadProbeReturn::Handled
|
2019-05-12 14:48:46 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
assert!(
|
|
|
|
pad.send_event(crate::event::Latency::new(crate::ClockTime::from_nseconds(
|
|
|
|
10
|
|
|
|
)))
|
|
|
|
);
|
|
|
|
assert!(pad.push_event(crate::event::StreamStart::new("test")));
|
|
|
|
let segment = crate::FormattedSegment::<crate::ClockTime>::new();
|
|
|
|
assert!(pad.push_event(crate::event::Segment::new(segment.as_ref())));
|
2019-05-12 14:48:46 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_eq!(pad.push(crate::Buffer::new()), Ok(FlowSuccess::Ok));
|
|
|
|
assert_eq!(pad.push(crate::Buffer::new()), flow_override);
|
2019-05-12 14:48:46 +00:00
|
|
|
|
|
|
|
let events = events.lock().unwrap();
|
|
|
|
let buffers = buffers.lock().unwrap();
|
2020-11-18 13:16:59 +00:00
|
|
|
assert_eq!(events.len(), 3);
|
2019-05-12 14:48:46 +00:00
|
|
|
assert_eq!(buffers.len(), 2);
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
assert_eq!(events[0].type_(), crate::EventType::Latency);
|
|
|
|
assert_eq!(events[1].type_(), crate::EventType::StreamStart);
|
|
|
|
assert_eq!(events[2].type_(), crate::EventType::Segment);
|
2019-05-12 14:48:46 +00:00
|
|
|
|
|
|
|
assert!(
|
|
|
|
buffers.iter().all(|b| b.is_writable()),
|
|
|
|
"A buffer ref leaked!"
|
|
|
|
);
|
|
|
|
|
|
|
|
drop(pad); // Need to drop the pad first to unref sticky events
|
|
|
|
assert!(
|
|
|
|
events.iter().all(|e| e.is_writable()),
|
|
|
|
"An event ref leaked!"
|
|
|
|
);
|
|
|
|
}
|
2021-11-09 12:19:37 +00:00
|
|
|
|
2022-01-18 09:57:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_sticky_events() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink")
|
|
|
|
.build();
|
2022-01-18 09:57:22 +00:00
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
|
|
|
// Send some sticky events
|
|
|
|
assert!(pad.send_event(crate::event::StreamStart::new("test")));
|
|
|
|
|
|
|
|
let caps = crate::Caps::builder("some/x-caps").build();
|
|
|
|
assert!(pad.send_event(crate::event::Caps::new(&caps)));
|
|
|
|
|
|
|
|
let segment = crate::FormattedSegment::<crate::ClockTime>::new();
|
|
|
|
assert!(pad.send_event(crate::event::Segment::new(segment.as_ref())));
|
|
|
|
|
|
|
|
let stream_start = pad.sticky_event::<crate::event::StreamStart>(0).unwrap();
|
|
|
|
assert_eq!(stream_start.stream_id(), "test");
|
|
|
|
|
|
|
|
let caps2 = pad.sticky_event::<crate::event::Caps>(0).unwrap();
|
|
|
|
assert_eq!(&*caps, caps2.caps());
|
|
|
|
|
|
|
|
let segment = pad.sticky_event::<crate::event::Segment>(0).unwrap();
|
|
|
|
assert_eq!(segment.segment().format(), crate::Format::Time);
|
|
|
|
}
|
|
|
|
|
2021-11-09 12:19:37 +00:00
|
|
|
#[test]
|
|
|
|
fn test_sticky_events_foreach() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink")
|
|
|
|
.build();
|
2021-11-09 12:19:37 +00:00
|
|
|
pad.set_active(true).unwrap();
|
|
|
|
|
|
|
|
// Send some sticky events
|
|
|
|
assert!(pad.send_event(crate::event::StreamStart::new("test")));
|
|
|
|
|
|
|
|
let caps = crate::Caps::builder("some/x-caps").build();
|
|
|
|
assert!(pad.send_event(crate::event::Caps::new(&caps)));
|
|
|
|
|
|
|
|
let segment = crate::FormattedSegment::<crate::ClockTime>::new();
|
|
|
|
assert!(pad.send_event(crate::event::Segment::new(segment.as_ref())));
|
|
|
|
|
|
|
|
let mut sticky_events = Vec::new();
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
sticky_events.push(event.clone());
|
|
|
|
ControlFlow::Continue(EventForeachAction::Keep)
|
|
|
|
});
|
|
|
|
assert_eq!(sticky_events.len(), 3);
|
|
|
|
|
|
|
|
// Test early exit from foreach loop
|
|
|
|
let mut sticky_events2 = Vec::new();
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
sticky_events2.push(event.clone());
|
|
|
|
if event.type_() == crate::EventType::Caps {
|
|
|
|
ControlFlow::Break(EventForeachAction::Keep)
|
|
|
|
} else {
|
|
|
|
ControlFlow::Continue(EventForeachAction::Keep)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
assert_eq!(sticky_events2.len(), 2);
|
|
|
|
|
|
|
|
let mut sticky_events3 = Vec::new();
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
sticky_events3.push(event.clone());
|
|
|
|
ControlFlow::Continue(EventForeachAction::Keep)
|
|
|
|
});
|
|
|
|
assert_eq!(sticky_events3.len(), 3);
|
|
|
|
|
|
|
|
for (e1, e2) in sticky_events.iter().zip(sticky_events3.iter()) {
|
|
|
|
assert_eq!(e1.as_ref() as *const _, e2.as_ref() as *const _);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace segment event
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
let action = if event.type_() == crate::EventType::Segment {
|
|
|
|
let byte_segment = crate::FormattedSegment::<crate::format::Bytes>::new();
|
|
|
|
EventForeachAction::Replace(crate::event::Segment::new(&byte_segment))
|
|
|
|
} else {
|
|
|
|
EventForeachAction::Keep
|
|
|
|
};
|
|
|
|
ControlFlow::Continue(action)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check that segment event is different now
|
|
|
|
let mut sticky_events4 = Vec::new();
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
sticky_events4.push(event.clone());
|
|
|
|
ControlFlow::Continue(EventForeachAction::Keep)
|
|
|
|
});
|
|
|
|
assert_eq!(sticky_events4.len(), 3);
|
|
|
|
assert_eq!(
|
|
|
|
sticky_events[0].as_ref() as *const _,
|
|
|
|
sticky_events4[0].as_ref() as *const _
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
sticky_events[1].as_ref() as *const _,
|
|
|
|
sticky_events4[1].as_ref() as *const _
|
|
|
|
);
|
|
|
|
assert_ne!(
|
|
|
|
sticky_events[2].as_ref() as *const _,
|
|
|
|
sticky_events4[2].as_ref() as *const _
|
|
|
|
);
|
|
|
|
|
|
|
|
// Drop caps event
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
let action = if event.type_() == crate::EventType::Caps {
|
|
|
|
EventForeachAction::Remove
|
|
|
|
} else {
|
|
|
|
EventForeachAction::Keep
|
|
|
|
};
|
|
|
|
ControlFlow::Continue(action)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check that caps event actually got removed
|
|
|
|
let mut sticky_events5 = Vec::new();
|
|
|
|
pad.sticky_events_foreach(|event| {
|
|
|
|
sticky_events5.push(event.clone());
|
|
|
|
ControlFlow::Continue(EventForeachAction::Keep)
|
|
|
|
});
|
|
|
|
assert_eq!(sticky_events5.len(), 2);
|
|
|
|
assert_eq!(
|
|
|
|
sticky_events4[0].as_ref() as *const _,
|
|
|
|
sticky_events5[0].as_ref() as *const _
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
sticky_events4[2].as_ref() as *const _,
|
|
|
|
sticky_events5[1].as_ref() as *const _
|
|
|
|
);
|
|
|
|
}
|
2023-04-28 19:35:15 +00:00
|
|
|
|
|
|
|
#[test]
|
2023-05-12 08:49:22 +00:00
|
|
|
fn naming() {
|
2023-04-28 19:35:15 +00:00
|
|
|
crate::init().unwrap();
|
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink).build();
|
|
|
|
assert!(pad.name().starts_with("pad"));
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Src).build();
|
|
|
|
assert!(pad.name().starts_with("pad"));
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Unknown).build();
|
|
|
|
assert!(pad.name().starts_with("pad"));
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Unknown)
|
|
|
|
.maybe_name(None::<&str>)
|
|
|
|
.build();
|
|
|
|
assert!(pad.name().starts_with("pad"));
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Sink)
|
|
|
|
.name("sink_0")
|
|
|
|
.build();
|
|
|
|
assert_eq!(pad.name(), "sink_0");
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Src)
|
|
|
|
.name("src_0")
|
|
|
|
.build();
|
|
|
|
assert_eq!(pad.name(), "src_0");
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Unknown)
|
|
|
|
.name("test")
|
|
|
|
.build();
|
|
|
|
assert_eq!(pad.name(), "test");
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(crate::PadDirection::Unknown)
|
|
|
|
.maybe_name(Some("test"))
|
|
|
|
.build();
|
|
|
|
assert_eq!(pad.name(), "test");
|
|
|
|
|
2023-04-28 19:35:15 +00:00
|
|
|
let caps = crate::Caps::new_any();
|
|
|
|
let templ = crate::PadTemplate::new(
|
|
|
|
"sink",
|
|
|
|
crate::PadDirection::Sink,
|
|
|
|
crate::PadPresence::Always,
|
|
|
|
&caps,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let pad = Pad::from_template(&templ);
|
2023-05-12 08:49:22 +00:00
|
|
|
assert!(pad.name().starts_with("sink"));
|
2023-04-28 19:35:15 +00:00
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
let pad = Pad::builder_from_template(&templ)
|
|
|
|
.name("audio_sink")
|
|
|
|
.build();
|
|
|
|
assert!(pad.name().starts_with("audio_sink"));
|
|
|
|
|
|
|
|
let templ = crate::PadTemplate::new(
|
|
|
|
"audio_%u",
|
|
|
|
crate::PadDirection::Sink,
|
|
|
|
crate::PadPresence::Request,
|
|
|
|
&caps,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let pad = Pad::builder_from_template(&templ).name("audio_0").build();
|
|
|
|
assert!(pad.name().starts_with("audio_0"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn missing_name() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let caps = crate::Caps::new_any();
|
|
|
|
let templ = crate::PadTemplate::new(
|
|
|
|
"audio_%u",
|
|
|
|
crate::PadDirection::Sink,
|
|
|
|
crate::PadPresence::Request,
|
|
|
|
&caps,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2023-04-28 19:35:15 +00:00
|
|
|
|
2023-05-12 08:49:22 +00:00
|
|
|
// Panic: attempt to build from a wildcard-named template
|
|
|
|
// without providing a name.
|
|
|
|
let _pad = Pad::from_template(&templ);
|
2023-04-28 19:35:15 +00:00
|
|
|
}
|
2017-09-17 22:45:39 +00:00
|
|
|
}
|