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
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Buffer;
|
|
|
|
use crate::BufferList;
|
|
|
|
use crate::Event;
|
|
|
|
use crate::FlowError;
|
|
|
|
use crate::FlowReturn;
|
|
|
|
use crate::FlowSuccess;
|
|
|
|
use crate::Format;
|
|
|
|
use crate::FormattedValue;
|
|
|
|
use crate::GenericFormattedValue;
|
|
|
|
use crate::LoggableError;
|
|
|
|
use crate::Pad;
|
|
|
|
use crate::PadFlags;
|
|
|
|
use crate::PadProbeReturn;
|
|
|
|
use crate::PadProbeType;
|
|
|
|
use crate::Query;
|
|
|
|
use crate::QueryRef;
|
|
|
|
use crate::SpecificFormattedValue;
|
|
|
|
use crate::StaticPadTemplate;
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::mem;
|
2020-01-05 02:38:55 +00:00
|
|
|
use std::num::NonZeroU64;
|
2017-07-25 12:21:03 +00:00
|
|
|
use std::ptr;
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use glib::ffi::gpointer;
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2021-04-28 12:34:56 +00:00
|
|
|
use glib::translate::*;
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2018-01-25 19:06:39 +00:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
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;
|
|
|
|
|
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 {
|
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!();
|
2018-01-25 19:06:39 +00:00
|
|
|
assert_ne!(val, 0);
|
2020-12-08 14:07:12 +00:00
|
|
|
PadProbeId(NonZeroU64::new_unchecked(val as u64))
|
2017-07-24 22:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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> {
|
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
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait PadExtManual: 'static {
|
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
|
|
|
fn remove_probe(&self, id: PadProbeId);
|
2017-07-25 12:21:03 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
|
|
|
fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
2017-07-25 12:21:03 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
|
|
|
|
fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
|
2017-08-14 19:21:11 +00:00
|
|
|
|
2018-10-28 22:57:21 +00:00
|
|
|
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
|
2020-03-28 17:57:49 +00:00
|
|
|
fn pull_range_fill(
|
|
|
|
&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-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_range")]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_range_fill")]
|
2021-04-20 10:23:24 +00:00
|
|
|
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>;
|
2017-07-29 13:04:34 +00:00
|
|
|
|
|
|
|
fn peer_query(&self, query: &mut QueryRef) -> bool;
|
|
|
|
fn query(&self, query: &mut QueryRef) -> bool;
|
2020-11-21 13:46:48 +00:00
|
|
|
fn query_default<P: IsA<crate::Object>>(
|
|
|
|
&self,
|
|
|
|
parent: Option<&P>,
|
|
|
|
query: &mut QueryRef,
|
|
|
|
) -> bool;
|
2017-07-29 13:04:34 +00:00
|
|
|
fn proxy_query_caps(&self, query: &mut QueryRef) -> bool;
|
|
|
|
fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool;
|
2017-08-01 12:58:50 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn event_default<P: IsA<crate::Object>>(&self, parent: Option<&P>, event: Event) -> bool;
|
2017-08-01 12:58:50 +00:00
|
|
|
fn push_event(&self, event: Event) -> bool;
|
|
|
|
fn send_event(&self, event: Event) -> bool;
|
2017-08-03 08:09:39 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_internal_links(&self) -> crate::Iterator<Pad>;
|
|
|
|
fn iterate_internal_links_default<P: IsA<crate::Object>>(
|
2017-09-17 21:24:36 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
parent: Option<&P>,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> crate::Iterator<Pad>;
|
2017-09-17 21:24:36 +00:00
|
|
|
|
2017-08-03 08:09:39 +00:00
|
|
|
fn stream_lock(&self) -> StreamLock;
|
2017-09-16 22:45:21 +00:00
|
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
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-17 21:32:29 +00:00
|
|
|
|
2017-09-17 22:53:02 +00:00
|
|
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError>;
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn peer_query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
) -> Option<U>;
|
|
|
|
fn peer_query_convert_generic<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn peer_query_duration<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn peer_query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn peer_query_position<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn peer_query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
) -> Option<U>;
|
|
|
|
fn query_convert_generic<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
|
|
|
|
|
|
|
fn query_position<T: SpecificFormattedValue>(&self) -> Option<T>;
|
|
|
|
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue>;
|
2018-08-01 16:28:57 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_mode")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn mode(&self) -> crate::PadMode;
|
2018-08-13 16:58:30 +00:00
|
|
|
|
|
|
|
fn sticky_events_foreach<F: FnMut(Event) -> Result<Option<Event>, Option<Event>>>(
|
|
|
|
&self,
|
|
|
|
func: F,
|
|
|
|
);
|
2019-01-08 16:13:37 +00:00
|
|
|
|
2020-01-06 15:23:39 +00:00
|
|
|
fn set_pad_flags(&self, flags: PadFlags);
|
2019-05-11 10:13: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
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_pad_flags")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn pad_flags(&self) -> PadFlags;
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<Pad>> PadExtManual for O {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
|
|
|
|
unsafe {
|
2021-04-28 12:34:56 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_chain(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
buffer.into_ptr(),
|
|
|
|
))
|
2019-01-08 16:13:37 +00:00
|
|
|
}
|
2017-07-25 12:21:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
|
|
|
|
unsafe {
|
2021-04-28 12:34:56 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_push(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
buffer.into_ptr(),
|
|
|
|
))
|
2019-01-08 16:13:37 +00:00
|
|
|
}
|
2017-07-25 12:21:03 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
|
2017-09-10 11:55:29 +00:00
|
|
|
unsafe {
|
2021-04-28 12:34:56 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_chain_list(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-09-10 11:55:29 +00:00
|
|
|
list.into_ptr(),
|
|
|
|
))
|
|
|
|
}
|
2017-08-14 19:21:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
|
2017-09-10 11:55:29 +00:00
|
|
|
unsafe {
|
2021-04-28 12:34:56 +00:00
|
|
|
FlowSuccess::try_from_glib(ffi::gst_pad_push_list(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2017-09-10 11:55:29 +00:00
|
|
|
list.into_ptr(),
|
|
|
|
))
|
|
|
|
}
|
2017-08-14 19:21:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:23:24 +00:00
|
|
|
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();
|
2021-04-28 12:34:56 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 10:23:24 +00:00
|
|
|
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();
|
2021-04-28 12:34:56 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 22:57:21 +00:00
|
|
|
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();
|
2021-04-28 12:34:56 +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
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:04:34 +00:00
|
|
|
|
2020-03-28 17:57:49 +00:00
|
|
|
fn pull_range_fill(
|
|
|
|
&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();
|
2021-04-28 12:34:56 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 13:04:34 +00:00
|
|
|
fn query(&self, query: &mut QueryRef) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn peer_query(&self, query: &mut QueryRef) -> bool {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn query_default<P: IsA<crate::Object>>(
|
|
|
|
&self,
|
|
|
|
parent: Option<&P>,
|
|
|
|
query: &mut QueryRef,
|
|
|
|
) -> bool {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-07-29 13:04:34 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_query_default(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn proxy_query_caps(&self, query: &mut QueryRef) -> bool {
|
|
|
|
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
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn event_default<P: IsA<crate::Object>>(&self, parent: Option<&P>, event: Event) -> bool {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-01 12:58:50 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib(ffi::gst_pad_event_default(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.as_ref()).to_glib_none().0,
|
2017-08-01 14:28:36 +00:00
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn push_event(&self, event: Event) -> bool {
|
|
|
|
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,
|
2017-08-01 14:28:36 +00:00
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn send_event(&self, event: Event) -> bool {
|
|
|
|
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,
|
2017-08-01 14:28:36 +00:00
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2017-08-01 12:58:50 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 08:09:39 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn iterate_internal_links_default<P: IsA<crate::Object>>(
|
2017-09-17 21:24:36 +00:00
|
|
|
&self,
|
2019-05-23 18:19:24 +00:00
|
|
|
parent: Option<&P>,
|
2020-11-21 13:46:48 +00:00
|
|
|
) -> crate::Iterator<Pad> {
|
2017-09-17 21:24:36 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib_full(ffi::gst_pad_iterate_internal_links_default(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
parent.map(|p| p.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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-09-17 22:53:02 +00:00
|
|
|
fn start_task<F: FnMut() + Send + 'static>(&self, func: F) -> Result<(), glib::BoolError> {
|
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>),
|
2017-09-17 22:53:02 +00:00
|
|
|
into_raw_pad_task(func),
|
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
|
|
|
}
|
|
|
|
}
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn peer_query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
) -> Option<U> {
|
|
|
|
let src_val = src_val.into();
|
|
|
|
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(),
|
2017-12-10 10:10:25 +00:00
|
|
|
src_val.to_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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn peer_query_convert_generic<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
let src_val = src_val.into();
|
|
|
|
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(),
|
2017-12-10 10:10:25 +00:00
|
|
|
src_val.to_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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn peer_query_duration<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
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
|
|
|
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 {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(T::from_raw(T::default_format(), duration.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn peer_query_position<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
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
|
|
|
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 {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(T::from_raw(T::default_format(), cur.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_convert<V: Into<GenericFormattedValue>, U: SpecificFormattedValue>(
|
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
) -> Option<U> {
|
|
|
|
let src_val = src_val.into();
|
|
|
|
|
|
|
|
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(),
|
2017-12-10 10:10:25 +00:00
|
|
|
src_val.to_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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_convert_generic<V: Into<GenericFormattedValue>>(
|
2017-11-11 10:21:55 +00:00
|
|
|
&self,
|
|
|
|
src_val: V,
|
|
|
|
dest_format: Format,
|
2017-12-09 16:20:21 +00:00
|
|
|
) -> Option<GenericFormattedValue> {
|
2017-11-11 10:21:55 +00:00
|
|
|
let src_val = src_val.into();
|
|
|
|
|
|
|
|
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(),
|
2021-04-11 19:39:50 +00:00
|
|
|
src_val.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
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
|
|
|
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 {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(T::from_raw(T::default_format(), duration.assume_init()))
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn query_position<T: SpecificFormattedValue>(&self) -> Option<T> {
|
|
|
|
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
|
|
|
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 {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(T::from_raw(T::default_format(), cur.assume_init()))
|
2017-11-11 10:21:55 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
fn sticky_events_foreach<F: FnMut(Event) -> Result<Option<Event>, Option<Event>>>(
|
|
|
|
&self,
|
|
|
|
func: F,
|
|
|
|
) {
|
|
|
|
unsafe extern "C" fn trampoline(
|
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 {
|
2018-08-13 16:58:30 +00:00
|
|
|
let func =
|
2019-06-06 06:09:34 +00:00
|
|
|
user_data as *mut &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>);
|
2018-08-13 16:58:30 +00:00
|
|
|
let res = (*func)(from_glib_full(*event));
|
|
|
|
|
|
|
|
match res {
|
|
|
|
Ok(Some(ev)) => {
|
|
|
|
*event = ev.into_ptr();
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::GTRUE
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
Err(Some(ev)) => {
|
|
|
|
*event = ev.into_ptr();
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::GFALSE
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
Ok(None) => {
|
|
|
|
*event = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::GTRUE
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
Err(None) => {
|
|
|
|
*event = ptr::null_mut();
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::GFALSE
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let mut func = func;
|
2019-06-06 06:09:34 +00:00
|
|
|
let func_obj: &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>) =
|
|
|
|
&mut func;
|
2018-08-13 16:58:30 +00:00
|
|
|
let func_ptr = &func_obj
|
2019-06-06 06:09:34 +00:00
|
|
|
as *const &mut (dyn FnMut(Event) -> Result<Option<Event>, Option<Event>>)
|
2020-11-21 13:46:48 +00:00
|
|
|
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,
|
|
|
|
Some(trampoline),
|
|
|
|
func_ptr,
|
|
|
|
);
|
2018-08-13 16:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 16:13:37 +00:00
|
|
|
|
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 _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).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 _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2021-04-27 15:15:46 +00:00
|
|
|
(*ptr).flags &= !flags.into_glib();
|
2019-05-11 10:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 _;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
|
2019-05-11 10:13:33 +00:00
|
|
|
from_glib((*ptr).flags)
|
|
|
|
}
|
|
|
|
}
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
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-04-28 12:34:56 +00:00
|
|
|
let flow_res = FlowSuccess::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_),
|
2021-02-28 16:50:44 +00:00
|
|
|
id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as u64))),
|
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
|
|
|
|
// Handled buffers are consumed
|
|
|
|
// 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
|
|
|
|
}
|
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())
|
|
|
|
|| data_type == Some(Event::static_type()) =>
|
|
|
|
{
|
|
|
|
// Buffer or Event consumed by probe
|
2019-05-12 13:03:16 +00:00
|
|
|
}
|
|
|
|
other => panic!(
|
|
|
|
"Bad data for {:?} pad probe returning Handled: {:?}",
|
|
|
|
data_type, 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()));
|
|
|
|
(*info).data = buffer.into_ptr() as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
Some(PadProbeData::BufferList(bufferlist)) => {
|
|
|
|
assert_eq!(data_type, Some(BufferList::static_type()));
|
|
|
|
(*info).data = bufferlist.into_ptr() as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
Some(PadProbeData::Event(event)) => {
|
|
|
|
assert_eq!(data_type, Some(Event::static_type()));
|
|
|
|
(*info).data = event.into_ptr() as *mut libc::c_void;
|
|
|
|
}
|
|
|
|
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(
|
|
|
|
&Pad::from_glib_borrow(pad).unsafe_cast_ref(),
|
|
|
|
&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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-03-29 17:11:00 +00:00
|
|
|
assert!(!buffer.is_null());
|
|
|
|
|
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(
|
2020-03-29 17:11:00 +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 {
|
|
|
|
gst_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(_) => {
|
|
|
|
gst_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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let copied_size = new_buffer.copy_to_slice(0, &mut *map);
|
|
|
|
drop(map);
|
|
|
|
|
|
|
|
if let Err(copied_size) = copied_size {
|
|
|
|
passed_buffer.set_size(copied_size);
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
match new_buffer.copy_into(passed_buffer, crate::BUFFER_COPY_METADATA, 0, None) {
|
2021-04-27 15:15:46 +00:00
|
|
|
Ok(_) => FlowReturn::Ok.into_glib(),
|
2020-03-29 17:11:00 +00:00
|
|
|
Err(_) => {
|
|
|
|
gst_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 {
|
|
|
|
*buffer = new_buffer.into_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(
|
2020-04-05 14:52:56 +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
|
|
|
|
2020-03-09 10:55:14 +00:00
|
|
|
ret.into_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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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(
|
2020-04-05 14:52:56 +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) {
|
|
|
|
Box::<F>::from_raw(ptr as *mut _);
|
2017-07-24 08:51:14 +00:00
|
|
|
}
|
2017-09-17 21:32:29 +00:00
|
|
|
|
2019-01-30 13:02:03 +00:00
|
|
|
unsafe extern "C" fn trampoline_pad_task<F: FnMut() + Send + 'static>(func: gpointer) {
|
2019-02-21 17:30:36 +00:00
|
|
|
let func: &RefCell<F> = &*(func as *const RefCell<F>);
|
2017-09-17 21:32:29 +00:00
|
|
|
(&mut *func.borrow_mut())()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn into_raw_pad_task<F: FnMut() + Send + 'static>(func: F) -> gpointer {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2019-01-30 13:02:03 +00:00
|
|
|
let func: Box<RefCell<F>> = Box::new(RefCell::new(func));
|
2017-09-17 21:32:29 +00:00
|
|
|
Box::into_raw(func) as gpointer
|
|
|
|
}
|
2017-09-17 22:45:39 +00:00
|
|
|
|
2019-03-01 17:49:27 +00:00
|
|
|
unsafe extern "C" fn destroy_closure_pad_task<F>(ptr: gpointer) {
|
|
|
|
Box::<RefCell<F>>::from_raw(ptr as *mut _);
|
|
|
|
}
|
|
|
|
|
2020-06-21 16:43:21 +00:00
|
|
|
impl Pad {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self::builder(name, direction).build()
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn builder(name: Option<&str>, direction: crate::PadDirection) -> PadBuilder<Self> {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
PadBuilder::new(name, direction)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_static_template(templ: &StaticPadTemplate, name: Option<&str>) -> Self {
|
|
|
|
skip_assert_initialized!();
|
2020-06-22 08:26:24 +00:00
|
|
|
Self::builder_with_static_template(templ, name).build()
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 08:26:24 +00:00
|
|
|
pub fn builder_with_static_template(
|
2020-06-21 16:43:21 +00:00
|
|
|
templ: &StaticPadTemplate,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> PadBuilder<Self> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
PadBuilder::from_static_template(templ, name)
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn from_template(templ: &crate::PadTemplate, name: Option<&str>) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
2020-06-22 08:26:24 +00:00
|
|
|
Self::builder_with_template(templ, name).build()
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn builder_with_template(
|
|
|
|
templ: &crate::PadTemplate,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> PadBuilder<Self> {
|
2020-06-21 16:43:21 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
PadBuilder::from_template(templ, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 12:04:23 +00:00
|
|
|
pub struct PadBuilder<T>(pub(crate) T);
|
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> {
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
|
2020-06-21 16:43:21 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2020-12-17 15:26:47 +00:00
|
|
|
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)])
|
|
|
|
.expect("Failed to create pad");
|
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...
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_ne!(res, glib::ffi::GFALSE, "Failed to construct ghost pad");
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PadBuilder(pad)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from_static_template(templ: &StaticPadTemplate, name: Option<&str>) -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
|
|
|
let templ = templ.get();
|
|
|
|
Self::from_template(&templ, name)
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn from_template(templ: &crate::PadTemplate, name: Option<&str>) -> 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())) {
|
|
|
|
let gtype = templ
|
2021-04-20 10:24:17 +00:00
|
|
|
.property("gtype")
|
2020-06-21 16:43:21 +00:00
|
|
|
.unwrap()
|
2021-04-20 07:19:02 +00:00
|
|
|
.get::<glib::Type>()
|
2020-06-21 16:43:21 +00:00
|
|
|
.unwrap();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-17 15:26:47 +00:00
|
|
|
let pad = glib::Object::with_type(
|
2020-06-21 16:43:21 +00:00
|
|
|
type_,
|
|
|
|
&[
|
|
|
|
("name", &name),
|
2021-04-12 10:01:22 +00:00
|
|
|
("direction", &templ.direction()),
|
2020-06-21 16:43:21 +00:00
|
|
|
("template", templ),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.expect("Failed to create pad")
|
|
|
|
.downcast::<T>()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// 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...
|
2020-11-21 13:46:48 +00:00
|
|
|
assert_ne!(res, glib::ffi::GFALSE, "Failed to construct ghost pad");
|
2020-06-21 16:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PadBuilder(pad)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_activate_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_activatemode_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_chain_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_chain_list_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_event_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_event_full_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_getrange_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_iterate_internal_links_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_link_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_query_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_unlink_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn flags(self, flags: PadFlags) -> Self {
|
|
|
|
self.0.set_pad_flags(flags);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build(self) -> T {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:45:39 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::prelude::*;
|
2021-02-28 16:50:44 +00:00
|
|
|
use std::sync::{atomic::AtomicUsize, mpsc::channel};
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
2017-09-17 22:45:39 +00:00
|
|
|
|
|
|
|
#[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();
|
2020-11-21 13:46:48 +00:00
|
|
|
let pad = crate::Pad::builder(Some("sink"), crate::PadDirection::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
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let pad = crate::Pad::builder(Some("src"), crate::PadDirection::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);
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let pad = crate::Pad::builder(Some("src"), crate::PadDirection::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
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let pad = crate::Pad::new(Some("sink"), crate::PadDirection::Sink);
|
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();
|
|
|
|
|
|
|
|
let src_pad = crate::Pad::new(Some("src"), crate::PadDirection::Src);
|
|
|
|
let sink_pad = crate::Pad::builder(Some("sink"), crate::PadDirection::Sink)
|
|
|
|
.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();
|
|
|
|
let pad = crate::Pad::new(Some("src"), crate::PadDirection::Src);
|
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();
|
|
|
|
let flow_override = flow_override;
|
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!"
|
|
|
|
);
|
|
|
|
}
|
2017-09-17 22:45:39 +00:00
|
|
|
}
|