gstreamer_rtp/
rtp_base_payload.rs
1use std::ptr;
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, RTPBasePayload};
6
7mod sealed {
8 pub trait Sealed {}
9 impl<T: super::IsA<super::RTPBasePayload>> Sealed for T {}
10}
11
12pub trait RTPBasePayloadExtManual: sealed::Sealed + IsA<RTPBasePayload> + 'static {
13 #[cfg(feature = "v1_20")]
21 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
22 #[doc(alias = "gst_rtp_base_payload_set_outcaps_structure")]
23 #[doc(alias = "gst_rtp_base_payload_set_outcaps")]
24 fn set_outcaps(&self, s: Option<&gst::StructureRef>) -> Result<(), glib::error::BoolError> {
25 unsafe {
26 glib::result_from_gboolean!(
27 ffi::gst_rtp_base_payload_set_outcaps_structure(
28 self.as_ref().to_glib_none().0,
29 s.as_ref()
30 .map(|s| s.as_ptr() as *mut _)
31 .unwrap_or(ptr::null_mut()),
32 ),
33 "Failed to negotiate by setting outcaps structure"
34 )
35 }
36 }
37
38 #[cfg(feature = "v1_24")]
39 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
40 fn extensions(&self) -> Vec<crate::RTPHeaderExtension> {
41 let extensions = self.as_ref().property::<gst::Array>("extensions");
42
43 extensions
44 .iter()
45 .map(|v| v.get::<crate::RTPHeaderExtension>().unwrap())
46 .collect()
47 }
48
49 #[cfg(feature = "v1_24")]
50 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
51 #[doc(alias = "extensions")]
52 fn connect_extensions_notify<F: Fn(&Self) + Send + Sync + 'static>(
53 &self,
54 f: F,
55 ) -> glib::SignalHandlerId {
56 unsafe extern "C" fn notify_extensions_trampoline<
57 P: IsA<RTPBasePayload>,
58 F: Fn(&P) + Send + Sync + 'static,
59 >(
60 this: *mut ffi::GstRTPBasePayload,
61 _param_spec: glib::ffi::gpointer,
62 f: glib::ffi::gpointer,
63 ) {
64 let f: &F = &*(f as *const F);
65 f(RTPBasePayload::from_glib_borrow(this).unsafe_cast_ref())
66 }
67 unsafe {
68 let f: Box<F> = Box::new(f);
69 glib::signal::connect_raw(
70 self.as_ptr() as *mut _,
71 b"notify::extensions\0".as_ptr() as *const _,
72 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
73 notify_extensions_trampoline::<Self, F> as *const (),
74 )),
75 Box::into_raw(f),
76 )
77 }
78 }
79
80 fn sink_pad(&self) -> &gst::Pad {
81 unsafe {
82 let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload);
83 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
84 }
85 }
86
87 fn src_pad(&self) -> &gst::Pad {
88 unsafe {
89 let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload);
90 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
91 }
92 }
93}
94
95impl<O: IsA<RTPBasePayload>> RTPBasePayloadExtManual for O {}