gstreamer_rtp/rtp_header_extension.rs
1use glib::{object::IsA, translate::*};
2
3use crate::{ffi, RTPHeaderExtension, RTPHeaderExtensionFlags};
4
5mod sealed {
6 pub trait Sealed {}
7 impl<T: super::IsA<super::RTPHeaderExtension>> Sealed for T {}
8}
9
10pub trait RTPHeaderExtensionExtManual: sealed::Sealed + IsA<RTPHeaderExtension> + 'static {
11 /// Read the RTP header extension from `data`.
12 /// ## `read_flags`
13 /// [`RTPHeaderExtensionFlags`][crate::RTPHeaderExtensionFlags] for how the extension should
14 /// be written
15 /// ## `data`
16 /// location to read the rtp header extension from
17 /// ## `buffer`
18 /// a [`gst::Buffer`][crate::gst::Buffer] to modify if necessary
19 ///
20 /// # Returns
21 ///
22 /// whether the extension could be read from `data`
23 #[doc(alias = "gst_rtp_header_extension_read")]
24 fn read(
25 &self,
26 read_flags: RTPHeaderExtensionFlags,
27 data: &[u8],
28 buffer: &mut gst::BufferRef,
29 ) -> bool {
30 let size = data.len();
31 unsafe {
32 from_glib(ffi::gst_rtp_header_extension_read(
33 self.as_ref().to_glib_none().0,
34 read_flags.into_glib(),
35 data.to_glib_none().0,
36 size,
37 buffer.as_mut_ptr(),
38 ))
39 }
40 }
41
42 /// Writes the RTP header extension to `data` using information available from
43 /// the `input_meta`. `data` will be sized to be at least the value returned
44 /// from [`RTPHeaderExtensionExt::max_size()`][crate::prelude::RTPHeaderExtensionExt::max_size()].
45 /// ## `input_meta`
46 /// the input [`gst::Buffer`][crate::gst::Buffer] to read information from if necessary
47 /// ## `write_flags`
48 /// [`RTPHeaderExtensionFlags`][crate::RTPHeaderExtensionFlags] for how the extension should
49 /// be written
50 /// ## `output`
51 /// output RTP [`gst::Buffer`][crate::gst::Buffer]
52 /// ## `data`
53 /// location to write the rtp header extension into
54 ///
55 /// # Returns
56 ///
57 /// the size of the data written, < 0 on failure
58 #[doc(alias = "gst_rtp_header_extension_write")]
59 fn write(
60 &self,
61 input_meta: &gst::Buffer,
62 write_flags: RTPHeaderExtensionFlags,
63 output: &gst::BufferRef,
64 data: &mut [u8],
65 ) -> Result<usize, glib::BoolError> {
66 let size = data.len();
67 unsafe {
68 let res = ffi::gst_rtp_header_extension_write(
69 self.as_ref().to_glib_none().0,
70 input_meta.to_glib_none().0,
71 write_flags.into_glib(),
72 mut_override(output.as_ptr()),
73 data.to_glib_none().0,
74 size,
75 );
76
77 if res < 0 {
78 Err(glib::bool_error!("Failed to write header extension"))
79 } else {
80 Ok(res as usize)
81 }
82 }
83 }
84
85 /// [`RTPHeaderExtensionExt::set_id()`][crate::prelude::RTPHeaderExtensionExt::set_id()] must have been called with a valid
86 /// extension id that is contained in these caps.
87 ///
88 /// The only current known caps format is based on the SDP standard as produced
89 /// by `gst_sdp_media_attributes_to_caps()`.
90 /// ## `caps`
91 /// writable [`gst::Caps`][crate::gst::Caps] to modify
92 ///
93 /// # Returns
94 ///
95 /// whether the configured attributes on `self` can successfully be set on
96 /// `caps`
97 #[doc(alias = "gst_rtp_header_extension_set_caps_from_attributes")]
98 fn set_caps_from_attributes(&self, caps: &mut gst::CapsRef) -> bool {
99 unsafe {
100 from_glib(ffi::gst_rtp_header_extension_set_caps_from_attributes(
101 self.as_ref().to_glib_none().0,
102 caps.as_mut_ptr(),
103 ))
104 }
105 }
106
107 /// Helper implementation for GstRTPExtensionClass::set_caps_from_attributes
108 /// that sets the `self` uri on caps with the specified extension id as required
109 /// for sdp [`gst::Caps`][crate::gst::Caps].
110 ///
111 /// Requires that the extension does not have any attributes or direction
112 /// advertised in `caps`.
113 /// ## `caps`
114 /// [`gst::Caps`][crate::gst::Caps] to write fields into
115 ///
116 /// # Returns
117 ///
118 /// whether the `self` attributes could be set on `caps`.
119 #[doc(alias = "gst_rtp_header_extension_set_caps_from_attributes_helper")]
120 fn set_caps_from_attributes_helper(&self, caps: &mut gst::CapsRef, attributes: &str) -> bool {
121 unsafe {
122 from_glib(
123 ffi::gst_rtp_header_extension_set_caps_from_attributes_helper(
124 self.as_ref().to_glib_none().0,
125 caps.as_mut_ptr(),
126 attributes.to_glib_none().0,
127 ),
128 )
129 }
130 }
131
132 /// Updates depayloader src caps based on the information received in RTP header.
133 /// `caps` must be writable as this function may modify them.
134 /// ## `caps`
135 /// src [`gst::Caps`][crate::gst::Caps] to modify
136 ///
137 /// # Returns
138 ///
139 /// whether `caps` were modified successfully
140 #[doc(alias = "gst_rtp_header_extension_update_non_rtp_src_caps")]
141 fn update_non_rtp_src_caps(&self, caps: &mut gst::CapsRef) -> bool {
142 unsafe {
143 from_glib(ffi::gst_rtp_header_extension_update_non_rtp_src_caps(
144 self.as_ref().to_glib_none().0,
145 caps.as_mut_ptr(),
146 ))
147 }
148 }
149}
150
151impl<O: IsA<RTPHeaderExtension>> RTPHeaderExtensionExtManual for O {}