gstreamer_rtp/
rtp_base_payload.rs1use std::ptr;
2
3use glib::{prelude::*, translate::*};
4
5use crate::{RTPBasePayload, ffi};
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 unsafe {
53 let f: &F = &*(f as *const F);
54 f(RTPBasePayload::from_glib_borrow(this).unsafe_cast_ref())
55 }
56 }
57 unsafe {
58 let f: Box<F> = Box::new(f);
59 glib::signal::connect_raw(
60 self.as_ptr() as *mut _,
61 b"notify::extensions\0".as_ptr() as *const _,
62 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
63 notify_extensions_trampoline::<Self, F> as *const (),
64 )),
65 Box::into_raw(f),
66 )
67 }
68 }
69
70 fn sink_pad(&self) -> &gst::Pad {
71 unsafe {
72 let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload);
73 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
74 }
75 }
76
77 fn src_pad(&self) -> &gst::Pad {
78 unsafe {
79 let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload);
80 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
81 }
82 }
83}
84
85impl<O: IsA<RTPBasePayload>> RTPBasePayloadExtManual for O {}