Skip to main content

gstreamer_rtp/
rtp_base_depayload.rs

1use glib::prelude::*;
2#[cfg(feature = "v1_24")]
3#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
4use glib::translate::*;
5
6use crate::{RTPBaseDepayload, ffi};
7
8pub trait RTPBaseDepayloadExtManual: IsA<RTPBaseDepayload> + 'static {
9    #[cfg(feature = "v1_24")]
10    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
11    fn extensions(&self) -> Vec<crate::RTPHeaderExtension> {
12        let extensions = self.as_ref().property::<gst::Array>("extensions");
13
14        extensions
15            .iter()
16            .map(|v| v.get::<crate::RTPHeaderExtension>().unwrap())
17            .collect()
18    }
19
20    #[cfg(feature = "v1_24")]
21    #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
22    #[doc(alias = "extensions")]
23    fn connect_extensions_notify<F: Fn(&Self) + Send + Sync + 'static>(
24        &self,
25        f: F,
26    ) -> glib::SignalHandlerId {
27        unsafe extern "C" fn notify_extensions_trampoline<
28            P: IsA<RTPBaseDepayload>,
29            F: Fn(&P) + Send + Sync + 'static,
30        >(
31            this: *mut ffi::GstRTPBaseDepayload,
32            _param_spec: glib::ffi::gpointer,
33            f: glib::ffi::gpointer,
34        ) {
35            unsafe {
36                let f: &F = &*(f as *const F);
37                f(RTPBaseDepayload::from_glib_borrow(this).unsafe_cast_ref())
38            }
39        }
40        unsafe {
41            let f: Box<F> = Box::new(f);
42            glib::signal::connect_raw(
43                self.as_ptr() as *mut _,
44                b"notify::extensions\0".as_ptr() as *const _,
45                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
46                    notify_extensions_trampoline::<Self, F> as *const (),
47                )),
48                Box::into_raw(f),
49            )
50        }
51    }
52
53    fn sink_pad(&self) -> &gst::Pad {
54        unsafe {
55            let elt = &*(self.as_ptr() as *const ffi::GstRTPBaseDepayload);
56            &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
57        }
58    }
59
60    fn src_pad(&self) -> &gst::Pad {
61        unsafe {
62            let elt = &*(self.as_ptr() as *const ffi::GstRTPBaseDepayload);
63            &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
64        }
65    }
66}
67
68impl<O: IsA<RTPBaseDepayload>> RTPBaseDepayloadExtManual for O {}