From ffa9697edda554c5e5b8e34aba9f4050e4323301 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 28 Jun 2021 14:17:13 +0200 Subject: [PATCH] rtp/gir: Manually implement RtpHeaderExtension read() and write() The array size is now provided since [1], yet mutability and `*Ref` makes it impossible to generate these functions properly. Implement them by hand. [1]: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1190 --- gstreamer-rtp/Gir.toml | 6 +-- gstreamer-rtp/src/lib.rs | 6 +++ gstreamer-rtp/src/rtp_header_extension.rs | 63 +++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 gstreamer-rtp/src/rtp_header_extension.rs diff --git a/gstreamer-rtp/Gir.toml b/gstreamer-rtp/Gir.toml index 048a00094..8e7d3dc39 100644 --- a/gstreamer-rtp/Gir.toml +++ b/gstreamer-rtp/Gir.toml @@ -65,11 +65,11 @@ status = "manual" [[object]] name = "GstRtp.RTPHeaderExtension" status = "generate" +manual_traits = ["RTPHeaderExtensionExtManual"] [[object.function]] pattern = "read|write" - # Until 1.19.2: `data` field lacks`array size` annotation: - # https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1190 - ignore = true + # Mutability of BufferRef + manual = true [[object.function]] name = "get_sdp_caps_field_name" diff --git a/gstreamer-rtp/src/lib.rs b/gstreamer-rtp/src/lib.rs index 851f277ee..5c2231a2f 100644 --- a/gstreamer-rtp/src/lib.rs +++ b/gstreamer-rtp/src/lib.rs @@ -28,6 +28,9 @@ pub use crate::auto::*; pub mod rtp_buffer; pub use crate::rtp_buffer::{compare_seqnum, RTPBuffer}; +#[cfg(any(feature = "v1_20", feature = "dox"))] +#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] +pub mod rtp_header_extension; // Re-export all the traits in a prelude module, so that applications // can always "use gst_rtp::prelude::*" without getting conflicts @@ -38,4 +41,7 @@ pub mod prelude { pub use crate::auto::traits::*; pub use crate::rtp_buffer::RTPBufferExt; + #[cfg(any(feature = "v1_20", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] + pub use crate::rtp_header_extension::RTPHeaderExtensionExtManual; } diff --git a/gstreamer-rtp/src/rtp_header_extension.rs b/gstreamer-rtp/src/rtp_header_extension.rs new file mode 100644 index 000000000..12ebd8ba1 --- /dev/null +++ b/gstreamer-rtp/src/rtp_header_extension.rs @@ -0,0 +1,63 @@ +use crate::RTPHeaderExtension; +use crate::RTPHeaderExtensionFlags; +use glib::object::IsA; +use glib::translate::*; + +pub trait RTPHeaderExtensionExtManual: 'static { + #[doc(alias = "gst_rtp_header_extension_read")] + fn read( + &self, + read_flags: RTPHeaderExtensionFlags, + data: &[u8], + buffer: &mut gst::BufferRef, + ) -> bool; + + #[doc(alias = "gst_rtp_header_extension_write")] + fn write( + &self, + input_meta: &gst::Buffer, + write_flags: RTPHeaderExtensionFlags, + output: &mut gst::BufferRef, + data: &mut [u8], + ) -> usize; +} + +impl> RTPHeaderExtensionExtManual for O { + fn read( + &self, + read_flags: RTPHeaderExtensionFlags, + data: &[u8], + buffer: &mut gst::BufferRef, + ) -> bool { + let size = data.len() as usize; + unsafe { + from_glib(ffi::gst_rtp_header_extension_read( + self.as_ref().to_glib_none().0, + read_flags.into_glib(), + data.to_glib_none().0, + size, + buffer.as_mut_ptr(), + )) + } + } + + fn write( + &self, + input_meta: &gst::Buffer, + write_flags: RTPHeaderExtensionFlags, + output: &mut gst::BufferRef, + data: &mut [u8], + ) -> usize { + let size = data.len() as usize; + unsafe { + ffi::gst_rtp_header_extension_write( + self.as_ref().to_glib_none().0, + input_meta.to_glib_none().0, + write_flags.into_glib(), + output.as_mut_ptr(), + data.to_glib_none().0, + size, + ) + } + } +}