2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-07-30 08:54:06 +00:00
|
|
|
|
2020-11-21 17:59:22 +00:00
|
|
|
use crate::Aggregator;
|
2019-04-23 15:47:13 +00:00
|
|
|
use glib::prelude::*;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2019-04-23 15:47:13 +00:00
|
|
|
use glib::signal::{connect_raw, SignalHandlerId};
|
2018-07-30 08:54:06 +00:00
|
|
|
use glib::translate::*;
|
2022-10-09 16:37:45 +00:00
|
|
|
use gst::format::FormattedValue;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2019-04-23 15:47:13 +00:00
|
|
|
use std::boxed::Box as Box_;
|
2020-03-29 19:37:56 +00:00
|
|
|
use std::mem;
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2020-04-13 16:18:57 +00:00
|
|
|
use std::mem::transmute;
|
2020-03-29 19:37:56 +00:00
|
|
|
use std::ptr;
|
2018-07-30 08:54:06 +00:00
|
|
|
|
2018-12-08 09:22:42 +00:00
|
|
|
pub trait AggregatorExtManual: 'static {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_allocator")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_aggregator_get_allocator")]
|
2021-04-11 19:39:50 +00:00
|
|
|
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams);
|
2020-03-29 19:37:56 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_aggregator_finish_buffer")]
|
2019-01-08 16:13:37 +00:00
|
|
|
fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
|
2020-08-11 07:04:09 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_aggregator_finish_buffer_list")]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn finish_buffer_list(
|
|
|
|
&self,
|
|
|
|
bufferlist: gst::BufferList,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-05-03 18:40:21 +00:00
|
|
|
#[doc(alias = "min-upstream-latency")]
|
2021-04-14 20:30:38 +00:00
|
|
|
fn min_upstream_latency(&self) -> gst::ClockTime;
|
2019-04-23 15:47:13 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-05-03 18:40:21 +00:00
|
|
|
#[doc(alias = "min-upstream-latency")]
|
2021-04-14 20:30:38 +00:00
|
|
|
fn set_min_upstream_latency(&self, min_upstream_latency: gst::ClockTime);
|
2019-04-23 15:47:13 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-05-03 18:40:21 +00:00
|
|
|
#[doc(alias = "min-upstream-latency")]
|
|
|
|
fn connect_min_upstream_latency_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
2019-04-23 15:47:13 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId;
|
2020-05-02 19:11:53 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_aggregator_update_segment")]
|
2022-10-09 16:37:45 +00:00
|
|
|
fn update_segment<F: gst::format::FormattedValueIntrinsic>(
|
|
|
|
&self,
|
|
|
|
segment: &gst::FormattedSegment<F>,
|
|
|
|
);
|
2020-08-11 07:04:09 +00:00
|
|
|
|
2022-07-03 16:04:06 +00:00
|
|
|
fn set_position(&self, position: impl FormattedValue);
|
2021-11-24 09:44:04 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_aggregator_selected_samples")]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn selected_samples(
|
|
|
|
&self,
|
2021-04-28 22:29:13 +00:00
|
|
|
pts: impl Into<Option<gst::ClockTime>>,
|
|
|
|
dts: impl Into<Option<gst::ClockTime>>,
|
|
|
|
duration: impl Into<Option<gst::ClockTime>>,
|
2020-08-11 07:04:09 +00:00
|
|
|
info: Option<&gst::StructureRef>,
|
|
|
|
);
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn connect_samples_selected<
|
|
|
|
F: Fn(
|
2022-03-22 16:50:57 +00:00
|
|
|
&Self,
|
2020-08-11 07:04:09 +00:00
|
|
|
&gst::Segment,
|
2021-04-28 22:29:13 +00:00
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
2020-08-11 07:04:09 +00:00
|
|
|
Option<&gst::StructureRef>,
|
|
|
|
) + Send
|
|
|
|
+ 'static,
|
|
|
|
>(
|
|
|
|
&self,
|
|
|
|
f: F,
|
2022-03-22 16:50:57 +00:00
|
|
|
) -> SignalHandlerId;
|
2022-05-03 22:04:08 +00:00
|
|
|
|
2022-05-05 10:24:46 +00:00
|
|
|
fn src_pad(&self) -> &gst::Pad;
|
2018-07-30 08:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<O: IsA<Aggregator>> AggregatorExtManual for O {
|
2021-04-11 19:39:50 +00:00
|
|
|
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
|
2020-03-29 19:37:56 +00:00
|
|
|
unsafe {
|
|
|
|
let mut allocator = ptr::null_mut();
|
|
|
|
let mut params = mem::zeroed();
|
2020-11-21 17:59:22 +00:00
|
|
|
ffi::gst_aggregator_get_allocator(
|
2020-03-29 19:37:56 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
&mut allocator,
|
|
|
|
&mut params,
|
|
|
|
);
|
|
|
|
(from_glib_full(allocator), params.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2021-04-28 12:34:56 +00:00
|
|
|
unsafe {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_aggregator_finish_buffer(
|
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(),
|
2018-07-30 08:54:06 +00:00
|
|
|
))
|
2021-04-28 12:34:56 +00:00
|
|
|
}
|
2018-07-30 08:54:06 +00:00
|
|
|
}
|
2019-04-23 15:47:13 +00:00
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn finish_buffer_list(
|
|
|
|
&self,
|
|
|
|
bufferlist: gst::BufferList,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2021-04-28 12:34:56 +00:00
|
|
|
unsafe {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(ffi::gst_aggregator_finish_buffer_list(
|
2020-08-11 07:04:09 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
bufferlist.into_glib_ptr(),
|
2020-08-11 07:04:09 +00:00
|
|
|
))
|
2021-04-28 12:34:56 +00:00
|
|
|
}
|
2020-08-11 07:04:09 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-04-14 20:30:38 +00:00
|
|
|
fn min_upstream_latency(&self) -> gst::ClockTime {
|
2021-11-06 17:09:27 +00:00
|
|
|
self.as_ref().property("min-upstream-latency")
|
2019-04-23 15:47:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-04-14 20:30:38 +00:00
|
|
|
fn set_min_upstream_latency(&self, min_upstream_latency: gst::ClockTime) {
|
2021-11-06 17:09:27 +00:00
|
|
|
self.as_ref()
|
|
|
|
.set_property("min-upstream-latency", &min_upstream_latency);
|
2019-04-23 15:47:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2021-05-03 18:40:21 +00:00
|
|
|
fn connect_min_upstream_latency_notify<F: Fn(&Self) + Send + Sync + 'static>(
|
2019-04-23 15:47:13 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
|
|
|
unsafe {
|
|
|
|
let f: Box_<F> = Box_::new(f);
|
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"notify::min-upstream-latency\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
notify_min_upstream_latency_trampoline::<Self, F> as *const (),
|
|
|
|
)),
|
2019-04-23 15:47:13 +00:00
|
|
|
Box_::into_raw(f),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2022-10-09 16:37:45 +00:00
|
|
|
fn update_segment<F: gst::format::FormattedValueIntrinsic>(
|
|
|
|
&self,
|
|
|
|
segment: &gst::FormattedSegment<F>,
|
|
|
|
) {
|
2020-05-02 19:11:53 +00:00
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
ffi::gst_aggregator_update_segment(
|
2020-05-02 19:11:53 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
mut_override(segment.to_glib_none().0),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-08-11 07:04:09 +00:00
|
|
|
|
2022-07-03 16:04:06 +00:00
|
|
|
fn set_position(&self, position: impl FormattedValue) {
|
2021-11-24 09:44:04 +00:00
|
|
|
unsafe {
|
|
|
|
let ptr: *mut ffi::GstAggregator = self.as_ref().to_glib_none().0;
|
|
|
|
let ptr = &mut *ptr;
|
|
|
|
let _guard = crate::utils::MutexGuard::lock(&ptr.parent.object.lock);
|
|
|
|
|
|
|
|
// gstaggregator.c asserts that the src pad is always of type GST_TYPE_AGGREGATOR_PAD,
|
|
|
|
// so the pointer cast here should be safe.
|
|
|
|
let srcpad = &mut *(ptr.srcpad as *mut ffi::GstAggregatorPad);
|
|
|
|
|
|
|
|
assert_eq!(srcpad.segment.format, position.format().into_glib());
|
|
|
|
srcpad.segment.position = position.into_raw_value() as u64;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn selected_samples(
|
|
|
|
&self,
|
2021-04-28 22:29:13 +00:00
|
|
|
pts: impl Into<Option<gst::ClockTime>>,
|
|
|
|
dts: impl Into<Option<gst::ClockTime>>,
|
|
|
|
duration: impl Into<Option<gst::ClockTime>>,
|
2020-08-11 07:04:09 +00:00
|
|
|
info: Option<&gst::StructureRef>,
|
|
|
|
) {
|
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
ffi::gst_aggregator_selected_samples(
|
2020-08-11 07:04:09 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-28 22:29:13 +00:00
|
|
|
pts.into().into_glib(),
|
|
|
|
dts.into().into_glib(),
|
|
|
|
duration.into().into_glib(),
|
2020-08-11 07:04:09 +00:00
|
|
|
info.as_ref()
|
|
|
|
.map(|s| s.as_ptr() as *mut _)
|
|
|
|
.unwrap_or(ptr::null_mut()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
2020-08-11 07:04:09 +00:00
|
|
|
fn connect_samples_selected<
|
|
|
|
F: Fn(
|
2022-03-22 16:50:57 +00:00
|
|
|
&Self,
|
2020-08-11 07:04:09 +00:00
|
|
|
&gst::Segment,
|
2021-04-28 22:29:13 +00:00
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
2020-08-11 07:04:09 +00:00
|
|
|
Option<&gst::StructureRef>,
|
|
|
|
) + Send
|
|
|
|
+ 'static,
|
|
|
|
>(
|
|
|
|
&self,
|
|
|
|
f: F,
|
2022-03-22 16:50:57 +00:00
|
|
|
) -> SignalHandlerId {
|
2020-08-11 07:04:09 +00:00
|
|
|
unsafe extern "C" fn samples_selected_trampoline<
|
|
|
|
P,
|
|
|
|
F: Fn(
|
|
|
|
&P,
|
|
|
|
&gst::Segment,
|
2021-04-28 22:29:13 +00:00
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
|
|
|
Option<gst::ClockTime>,
|
2020-08-11 07:04:09 +00:00
|
|
|
Option<&gst::StructureRef>,
|
|
|
|
) + Send
|
|
|
|
+ 'static,
|
|
|
|
>(
|
2020-11-21 17:59:22 +00:00
|
|
|
this: *mut ffi::GstAggregator,
|
|
|
|
segment: *mut gst::ffi::GstSegment,
|
|
|
|
pts: gst::ffi::GstClockTime,
|
|
|
|
dts: gst::ffi::GstClockTime,
|
|
|
|
duration: gst::ffi::GstClockTime,
|
|
|
|
info: *mut gst::ffi::GstStructure,
|
|
|
|
f: glib::ffi::gpointer,
|
2020-08-11 07:04:09 +00:00
|
|
|
) where
|
|
|
|
P: IsA<Aggregator>,
|
|
|
|
{
|
|
|
|
let f: &F = &*(f as *const F);
|
|
|
|
f(
|
2021-07-30 10:19:24 +00:00
|
|
|
Aggregator::from_glib_borrow(this).unsafe_cast_ref(),
|
2022-06-27 19:19:42 +00:00
|
|
|
gst::Segment::from_ptr(segment),
|
2020-08-11 07:04:09 +00:00
|
|
|
from_glib(pts),
|
|
|
|
from_glib(dts),
|
|
|
|
from_glib(duration),
|
|
|
|
if info.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(gst::StructureRef::from_glib_borrow(info))
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let f: Box_<F> = Box_::new(f);
|
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"samples-selected\0".as_ptr() as *const _,
|
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
2022-03-22 16:50:57 +00:00
|
|
|
samples_selected_trampoline::<Self, F> as *const (),
|
2020-08-11 07:04:09 +00:00
|
|
|
)),
|
|
|
|
Box_::into_raw(f),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-05-03 22:04:08 +00:00
|
|
|
|
2022-05-05 10:24:46 +00:00
|
|
|
fn src_pad(&self) -> &gst::Pad {
|
2022-05-03 22:04:08 +00:00
|
|
|
unsafe {
|
2022-05-05 10:24:46 +00:00
|
|
|
let elt = &*(self.as_ptr() as *const ffi::GstAggregator);
|
|
|
|
&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
|
2022-05-03 22:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-23 15:47:13 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 13:37:49 +00:00
|
|
|
#[cfg(any(feature = "v1_16", feature = "dox"))]
|
|
|
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
|
2019-04-23 15:47:13 +00:00
|
|
|
unsafe extern "C" fn notify_min_upstream_latency_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
|
2020-11-21 17:59:22 +00:00
|
|
|
this: *mut ffi::GstAggregator,
|
|
|
|
_param_spec: glib::ffi::gpointer,
|
|
|
|
f: glib::ffi::gpointer,
|
2019-04-23 15:47:13 +00:00
|
|
|
) where
|
|
|
|
P: IsA<Aggregator>,
|
|
|
|
{
|
|
|
|
let f: &F = &*(f as *const F);
|
2021-07-30 10:19:24 +00:00
|
|
|
f(Aggregator::from_glib_borrow(this).unsafe_cast_ref())
|
2018-07-30 08:54:06 +00:00
|
|
|
}
|