1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::RTPHeaderExtensionFlags;
use glib::object::IsA;
use glib::translate::*;

glib::wrapper! {
    /// Instance struct for a RTP Audio/Video header extension.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`RTPHeaderExtensionExt`][trait@crate::prelude::RTPHeaderExtensionExt]
    #[doc(alias = "GstRTPHeaderExtension")]
    pub struct RTPHeaderExtension(Object<ffi::GstRTPHeaderExtension, ffi::GstRTPHeaderExtensionClass>);

    match fn {
        type_ => || ffi::gst_rtp_header_extension_get_type(),
    }
}

impl RTPHeaderExtension {
    /// ## `uri`
    /// the rtp header extension URI to search for
    ///
    /// # Returns
    ///
    /// the [`RTPHeaderExtension`][crate::RTPHeaderExtension] for `uri` or [`None`]
    #[doc(alias = "gst_rtp_header_extension_create_from_uri")]
    pub fn create_from_uri(uri: &str) -> Option<RTPHeaderExtension> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_rtp_header_extension_create_from_uri(
                uri.to_glib_none().0,
            ))
        }
    }
}

unsafe impl Send for RTPHeaderExtension {}
unsafe impl Sync for RTPHeaderExtension {}

pub const NONE_RTP_HEADER_EXTENSION: Option<&RTPHeaderExtension> = None;

/// Trait containing all [`struct@RTPHeaderExtension`] methods.
///
/// # Implementors
///
/// [`RTPHeaderExtension`][struct@crate::RTPHeaderExtension]
pub trait RTPHeaderExtensionExt: 'static {
    ///
    /// # Returns
    ///
    /// the RTP extension id configured on `self`
    #[doc(alias = "gst_rtp_header_extension_get_id")]
    #[doc(alias = "get_id")]
    fn id(&self) -> u32;

    /// This is used to know how much data a certain header extension will need for
    /// both allocating the resulting data, and deciding how much payload data can
    /// be generated.
    ///
    /// Implementations should return as accurate a value as is possible using the
    /// information given in the input `buffer`.
    /// ## `input_meta`
    /// a [`gst::Buffer`][crate::gst::Buffer]
    ///
    /// # Returns
    ///
    /// the maximum size of the data written by this extension
    #[doc(alias = "gst_rtp_header_extension_get_max_size")]
    #[doc(alias = "get_max_size")]
    fn max_size(&self, input_meta: &gst::Buffer) -> usize;

    ///
    /// # Returns
    ///
    /// the [`gst::Structure`][crate::gst::Structure] field name used in SDP-like [`gst::Caps`][crate::gst::Caps] for this `self` configuration
    #[doc(alias = "gst_rtp_header_extension_get_sdp_caps_field_name")]
    #[doc(alias = "get_sdp_caps_field_name")]
    fn sdp_caps_field_name(&self) -> glib::GString;

    ///
    /// # Returns
    ///
    /// the flags supported by this instance of `self`
    #[doc(alias = "gst_rtp_header_extension_get_supported_flags")]
    #[doc(alias = "get_supported_flags")]
    fn supported_flags(&self) -> RTPHeaderExtensionFlags;

    ///
    /// # Returns
    ///
    /// the RTP extension URI for this object
    #[doc(alias = "gst_rtp_header_extension_get_uri")]
    #[doc(alias = "get_uri")]
    fn uri(&self) -> Option<glib::GString>;

    /// [`set_id()`][Self::set_id()] must have been called with a valid
    /// extension id that is contained in these caps.
    ///
    /// The only current known caps format is based on the SDP standard as produced
    /// by `gst_sdp_media_attributes_to_caps()`.
    /// ## `caps`
    /// the [`gst::Caps`][crate::gst::Caps] to configure this extension with
    ///
    /// # Returns
    ///
    /// whether the `caps` could be successfully set on `self`.
    #[doc(alias = "gst_rtp_header_extension_set_attributes_from_caps")]
    fn set_attributes_from_caps(&self, caps: &gst::Caps) -> bool;

    /// Helper implementation for GstRTPExtensionClass::set_attributes_from_caps
    /// that retrieves the configured extension id and checks that the
    /// corresponding field in the sdp caps is configured for this extension uri.
    /// Requires that the extension does not have any attributes or direction
    /// advertised in the caps.
    /// ## `caps`
    /// [`gst::Caps`][crate::gst::Caps] to read attributes from
    ///
    /// # Returns
    ///
    /// whether the attributes in the `caps` could be set on `self` successfully
    #[doc(alias = "gst_rtp_header_extension_set_attributes_from_caps_simple_sdp")]
    fn set_attributes_from_caps_simple_sdp(&self, caps: &gst::Caps) -> bool;

    /// [`set_id()`][Self::set_id()] must have been called with a valid
    /// extension id that is contained in these caps.
    ///
    /// The only current known caps format is based on the SDP standard as produced
    /// by `gst_sdp_media_attributes_to_caps()`.
    /// ## `caps`
    /// writable [`gst::Caps`][crate::gst::Caps] to modify
    ///
    /// # Returns
    ///
    /// whether the configured attributes on `self` can successfully be set on
    ///     `caps`
    #[doc(alias = "gst_rtp_header_extension_set_caps_from_attributes")]
    fn set_caps_from_attributes(&self, caps: &mut gst::Caps) -> bool;

    /// Helper implementation for GstRTPExtensionClass::set_caps_from_attributes
    /// that sets the `self` uri on caps with the specified extension id as required
    /// for sdp [`gst::Caps`][crate::gst::Caps].
    ///
    /// Requires that the extension does not have any attributes or direction
    /// advertised in `caps`.
    /// ## `caps`
    /// [`gst::Caps`][crate::gst::Caps] to write fields into
    ///
    /// # Returns
    ///
    /// whether the `self` attributes could be set on `caps`.
    #[doc(alias = "gst_rtp_header_extension_set_caps_from_attributes_simple_sdp")]
    fn set_caps_from_attributes_simple_sdp(&self, caps: &mut gst::Caps) -> bool;

    /// sets the RTP extension id on `self`
    /// ## `ext_id`
    /// The id of this extension
    #[doc(alias = "gst_rtp_header_extension_set_id")]
    fn set_id(&self, ext_id: u32);

    /// Passes RTP payloader's sink (i.e. not payloaded) `caps` to the header
    /// extension.
    /// ## `caps`
    /// sink [`gst::Caps`][crate::gst::Caps]
    ///
    /// # Returns
    ///
    /// Whether `caps` could be read successfully
    #[doc(alias = "gst_rtp_header_extension_set_non_rtp_sink_caps")]
    fn set_non_rtp_sink_caps(&self, caps: &gst::Caps) -> bool;

    /// Call this function in a subclass from `GstRTPHeaderExtensionClass::read` to
    /// tell the depayloader whether the data just parsed from RTP packet require
    /// updating its src (non-RTP) caps. If `state` is TRUE, `GstRTPBaseDepayload` will
    /// eventually invoke [`update_non_rtp_src_caps()`][Self::update_non_rtp_src_caps()] to
    /// have the caps update applied. Applying the update also flips the internal
    /// "wants update" flag back to FALSE.
    /// ## `state`
    /// TRUE if caps update is needed
    #[doc(alias = "gst_rtp_header_extension_set_wants_update_non_rtp_src_caps")]
    fn set_wants_update_non_rtp_src_caps(&self, state: bool);

    /// Updates depayloader src caps based on the information received in RTP header.
    /// `caps` must be writable as this function may modify them.
    /// ## `caps`
    /// src [`gst::Caps`][crate::gst::Caps] to modify
    ///
    /// # Returns
    ///
    /// whether `caps` were modified successfully
    #[doc(alias = "gst_rtp_header_extension_update_non_rtp_src_caps")]
    fn update_non_rtp_src_caps(&self, caps: &mut gst::Caps) -> bool;

    /// Call this function after `gst_rtp_header_extension_read()` to check if
    /// the depayloader's src caps need updating with data received in the last RTP
    /// packet.
    ///
    /// # Returns
    ///
    /// Whether `self` wants to update depayloader's src caps.
    #[doc(alias = "gst_rtp_header_extension_wants_update_non_rtp_src_caps")]
    fn wants_update_non_rtp_src_caps(&self) -> bool;
}

impl<O: IsA<RTPHeaderExtension>> RTPHeaderExtensionExt for O {
    fn id(&self) -> u32 {
        unsafe { ffi::gst_rtp_header_extension_get_id(self.as_ref().to_glib_none().0) }
    }

    fn max_size(&self, input_meta: &gst::Buffer) -> usize {
        unsafe {
            ffi::gst_rtp_header_extension_get_max_size(
                self.as_ref().to_glib_none().0,
                input_meta.to_glib_none().0,
            )
        }
    }

    fn sdp_caps_field_name(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::gst_rtp_header_extension_get_sdp_caps_field_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn supported_flags(&self) -> RTPHeaderExtensionFlags {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_get_supported_flags(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn uri(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gst_rtp_header_extension_get_uri(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_attributes_from_caps(&self, caps: &gst::Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_set_attributes_from_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    fn set_attributes_from_caps_simple_sdp(&self, caps: &gst::Caps) -> bool {
        unsafe {
            from_glib(
                ffi::gst_rtp_header_extension_set_attributes_from_caps_simple_sdp(
                    self.as_ref().to_glib_none().0,
                    caps.to_glib_none().0,
                ),
            )
        }
    }

    fn set_caps_from_attributes(&self, caps: &mut gst::Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_set_caps_from_attributes(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none_mut().0,
            ))
        }
    }

    fn set_caps_from_attributes_simple_sdp(&self, caps: &mut gst::Caps) -> bool {
        unsafe {
            from_glib(
                ffi::gst_rtp_header_extension_set_caps_from_attributes_simple_sdp(
                    self.as_ref().to_glib_none().0,
                    caps.to_glib_none_mut().0,
                ),
            )
        }
    }

    fn set_id(&self, ext_id: u32) {
        unsafe {
            ffi::gst_rtp_header_extension_set_id(self.as_ref().to_glib_none().0, ext_id);
        }
    }

    fn set_non_rtp_sink_caps(&self, caps: &gst::Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_set_non_rtp_sink_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
            ))
        }
    }

    fn set_wants_update_non_rtp_src_caps(&self, state: bool) {
        unsafe {
            ffi::gst_rtp_header_extension_set_wants_update_non_rtp_src_caps(
                self.as_ref().to_glib_none().0,
                state.into_glib(),
            );
        }
    }

    fn update_non_rtp_src_caps(&self, caps: &mut gst::Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_update_non_rtp_src_caps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none_mut().0,
            ))
        }
    }

    fn wants_update_non_rtp_src_caps(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_rtp_header_extension_wants_update_non_rtp_src_caps(
                self.as_ref().to_glib_none().0,
            ))
        }
    }
}