gstreamer_rtp/
rtp_header_extension.rs

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