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