From 668a9bbf58b1a7f93f158bd23fa5c1078054fc5f Mon Sep 17 00:00:00 2001 From: Santiago Carot-Nemesio Date: Wed, 1 Dec 2021 15:13:51 +0100 Subject: [PATCH] rtp_buffer: Add methods to manipulate padding Open Rust APIs for: * gst_rtp_buffer_get_padding * gst_rtp_buffer_set_padding --- gstreamer-rtp/src/rtp_buffer.rs | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gstreamer-rtp/src/rtp_buffer.rs b/gstreamer-rtp/src/rtp_buffer.rs index 5ac8255e7..6595c0c89 100644 --- a/gstreamer-rtp/src/rtp_buffer.rs +++ b/gstreamer-rtp/src/rtp_buffer.rs @@ -184,6 +184,11 @@ impl<'a> RTPBuffer<'a, Writable> { ffi::gst_rtp_buffer_remove_extension_data(&mut self.rtp_buffer); } } + + #[doc(alias = "gst_rtp_buffer_set_padding")] + pub fn set_padding(&mut self, padding: bool) { + unsafe { ffi::gst_rtp_buffer_set_padding(&mut self.rtp_buffer, padding.into_glib()) } + } } impl<'a, T> RTPBuffer<'a, T> { @@ -345,6 +350,16 @@ impl<'a, T> RTPBuffer<'a, T> { } } } + + #[doc(alias = "get_padding")] + #[doc(alias = "gst_rtp_buffer_get_padding")] + pub fn has_padding(&self) -> bool { + unsafe { + from_glib(ffi::gst_rtp_buffer_get_padding( + glib::translate::mut_override(&self.rtp_buffer), + )) + } + } } impl<'a, T> Drop for RTPBuffer<'a, T> { @@ -542,4 +557,28 @@ mod tests { assert_eq!(appbits, extracted_appbits); assert_eq!(data, &extension_data); } + + #[test] + fn test_padding() { + gst::init().unwrap(); + + let csrc_count = 2; + let payload_size = 16; + let mut buffer = gst::Buffer::new_rtp_with_sizes(payload_size, 4, csrc_count).unwrap(); + { + let rtp_buffer = RTPBuffer::from_buffer_readable(&buffer).unwrap(); + assert!(rtp_buffer.has_padding()); + } + { + let buffer = buffer.get_mut().unwrap(); + let mut rtp_buffer = RTPBuffer::from_buffer_writable(buffer).unwrap(); + + rtp_buffer.set_padding(false); + } + + { + let rtp_buffer = RTPBuffer::from_buffer_readable(&buffer).unwrap(); + assert!(!rtp_buffer.has_padding()); + } + } }