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
|
|
|
|
2022-10-09 15:28:17 +00:00
|
|
|
use crate::element::ElementExtManual;
|
2022-10-09 16:37:45 +00:00
|
|
|
use crate::format::{
|
|
|
|
FormattedValue, SpecificFormattedValueFullRange, SpecificFormattedValueIntrinsic,
|
|
|
|
};
|
2022-10-09 15:28:17 +00:00
|
|
|
use crate::prelude::PadExt;
|
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::LoggableError;
|
|
|
|
use crate::Pad;
|
|
|
|
use crate::PadFlags;
|
|
|
|
use crate::PadProbeReturn;
|
|
|
|
use crate::PadProbeType;
|
|
|
|
use crate::Query;
|
|
|
|
use crate::QueryRef;
|
|
|
|
use crate::StaticPadTemplate;
|
2022-10-09 16:37:45 +00:00
|
|
|
use crate::{Format, GenericFormattedValue};
|
2017-07-24 08:51:14 +00:00
|
|
|
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::mem;
|
2020-01-05 02:38:55 +00:00
|
|
|
use std::num::NonZeroU64;
|
2021-11-09 12:19:37 +00:00
|
|
|
use std::ops::ControlFlow;
|
2022-10-09 15:28:17 +00:00
|
|
|
use std::panic::{self, AssertUnwindSafe};
|
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
|
|
|
|
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;
|
|
|
|
|
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);
|
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 {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-11-09 12:19:37 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum EventForeachAction {
|
|
|
|
Keep,
|
|
|
|
Remove,
|
|
|
|
Replace(Event),
|
|
|
|
}
|
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait PadExtManual: 'static {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[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;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_remove_probe")]
|
2017-07-24 08:51:14 +00:00
|
|
|
fn remove_probe(&self, id: PadProbeId);
|
2017-07-25 12:21:03 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_chain")]
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_push")]
|
2019-01-08 16:13:37 +00:00
|
|
|
fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
|
2017-07-25 12:21:03 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_chain_list")]
|
2019-01-08 16:13:37 +00:00
|
|
|
fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_push_list")]
|
2019-01-08 16:13:37 +00:00
|
|
|
fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
|
2017-08-14 19:21:11 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_pull_range")]
|
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-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_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
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_peer_query")]
|
2017-07-29 13:04:34 +00:00
|
|
|
fn peer_query(&self, query: &mut QueryRef) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_query")]
|
2017-07-29 13:04:34 +00:00
|
|
|
fn query(&self, query: &mut QueryRef) -> bool;
|
|
|
|
fn proxy_query_caps(&self, query: &mut QueryRef) -> bool;
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_proxy_query_accept_caps")]
|
2017-07-29 13:04:34 +00:00
|
|
|
fn proxy_query_accept_caps(&self, query: &mut QueryRef) -> bool;
|
2017-08-01 12:58:50 +00:00
|
|
|
|
2021-05-19 20:35:47 +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;
|
2021-05-19 20:35:47 +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-03 08:09:39 +00:00
|
|
|
|
2021-05-19 20:35:47 +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>;
|
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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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;
|
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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
|
|
|
|
2021-12-12 15:52:32 +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-17 21:32:29 +00:00
|
|
|
|
2021-05-19 20:35:47 +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>;
|
2017-11-11 10:21:55 +00:00
|
|
|
|
2021-05-19 20:35:47 +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>;
|
2021-12-12 15:52:32 +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>;
|
|
|
|
|
2021-05-19 20:35:47 +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>;
|
2021-12-12 15:52:32 +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>;
|
|
|
|
|
2021-05-19 20:35:47 +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>;
|
2021-12-12 15:52:32 +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>;
|
|
|
|
|
2021-05-19 20:35:47 +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>;
|
2021-12-12 15:52:32 +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>;
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_query_duration")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn query_duration<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T>;
|
2021-12-12 15:52:32 +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>;
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_pad_query_position")]
|
2020-10-27 17:27:16 +00:00
|
|
|
fn query_position<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T>;
|
2021-12-12 15:52:32 +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>;
|
2018-08-01 16:28:57 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_mode")]
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "GST_PAD_MODE")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn mode(&self) -> crate::PadMode;
|
2021-12-12 15:52:32 +00:00
|
|
|
|
2021-05-19 20:35:47 +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,
|
|
|
|
);
|
2019-01-08 16:13:37 +00:00
|
|
|
|
2021-10-17 09:48:21 +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
|
|
|
|
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-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_pad_chain(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
buffer.into_glib_ptr(),
|
2019-01-16 11:32:58 +00:00
|
|
|
))
|
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-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_pad_push(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
buffer.into_glib_ptr(),
|
2019-01-16 11:32:58 +00:00
|
|
|
))
|
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-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_pad_chain_list(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
list.into_glib_ptr(),
|
2017-09-10 11:55:29 +00:00
|
|
|
))
|
|
|
|
}
|
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-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_pad_push_list(
|
2019-01-16 11:32:58 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
list.into_glib_ptr(),
|
2017-09-10 11:55:29 +00:00
|
|
|
))
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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> {
|
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),
|
|
|
|
};
|
|
|
|
|
|
|
|
let maybe_couldnt_stop = if pad.pause_task().is_err() {
|
|
|
|
", could not stop task"
|
|
|
|
} else {
|
|
|
|
""
|
|
|
|
};
|
|
|
|
let cause = if let Some(cause) = err.downcast_ref::<&str>() {
|
|
|
|
cause
|
|
|
|
} else if let Some(cause) = err.downcast_ref::<String>() {
|
|
|
|
cause
|
|
|
|
} else {
|
|
|
|
"Panicked"
|
|
|
|
};
|
|
|
|
let _ = element.post_message(
|
|
|
|
crate::message::Error::builder(
|
|
|
|
crate::LibraryError::Failed,
|
|
|
|
&format!("Panicked: {}{}", cause, maybe_couldnt_stop),
|
|
|
|
)
|
|
|
|
.src(&*pad)
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2017-11-11 10:21:55 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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 _;
|
|
|
|
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-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
|
|
|
|
// 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()));
|
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
|
|
|
|
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(
|
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);
|
|
|
|
}
|
|
|
|
|
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(_) => {
|
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 {
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new")]
|
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()
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new")]
|
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)
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_static_template")]
|
2020-06-21 16:43:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_static_template")]
|
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)
|
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_template")]
|
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
|
|
|
}
|
|
|
|
|
2021-12-12 15:52:32 +00:00
|
|
|
#[doc(alias = "gst_pad_new_from_template")]
|
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)
|
|
|
|
}
|
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"]
|
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!();
|
|
|
|
|
2022-10-07 17:39:11 +00:00
|
|
|
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)]);
|
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())) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.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)
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
self.0.set_activate_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_activatemode_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_chain_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_chain_list_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_event_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_event_full_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_getrange_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_iterate_internal_links_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_link_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_query_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
self.0.set_unlink_function(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn flags(self, flags: PadFlags) -> Self {
|
|
|
|
self.0.set_pad_flags(flags);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "Building the pad without using it has no effect"]
|
2020-06-21 16:43:21 +00:00
|
|
|
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!"
|
|
|
|
);
|
|
|
|
}
|
2021-11-09 12:19:37 +00:00
|
|
|
|
2022-01-18 09:57:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_sticky_events() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(Some("sink"), crate::PadDirection::Sink).build();
|
|
|
|
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();
|
|
|
|
|
|
|
|
let pad = crate::Pad::builder(Some("sink"), crate::PadDirection::Sink).build();
|
|
|
|
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 _
|
|
|
|
);
|
|
|
|
}
|
2017-09-17 22:45:39 +00:00
|
|
|
}
|