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