From 12416a4031b8a14b3efaac81a952c4529b68d675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 Dec 2019 17:59:30 +0200 Subject: [PATCH] gstreamer-base: Require &mut self for BaseParseFrame functions that modify it And add non-mutable getters for input/output buffer --- gstreamer-base/src/base_parse_frame.rs | 34 +++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/gstreamer-base/src/base_parse_frame.rs b/gstreamer-base/src/base_parse_frame.rs index 4154d981b..43b9a2c3a 100644 --- a/gstreamer-base/src/base_parse_frame.rs +++ b/gstreamer-base/src/base_parse_frame.rs @@ -98,7 +98,18 @@ impl<'a> BaseParseFrame<'a> { BaseParseFrame(ptr::NonNull::new_unchecked(frame), PhantomData) } - pub fn get_buffer(&self) -> Option<&mut gst::BufferRef> { + pub fn get_buffer(&self) -> Option<&gst::BufferRef> { + unsafe { + let ptr = (*self.to_glib_none().0).buffer; + if ptr.is_null() { + None + } else { + Some(gst::BufferRef::from_ptr(ptr)) + } + } + } + + pub fn get_buffer_mut(&mut self) -> Option<&mut gst::BufferRef> { unsafe { let ptr = (*self.to_glib_none().0).buffer; if ptr.is_null() { @@ -114,7 +125,18 @@ impl<'a> BaseParseFrame<'a> { } } - pub fn get_output_buffer(&self) -> Option<&mut gst::BufferRef> { + pub fn get_output_buffer(&self) -> Option<&gst::BufferRef> { + unsafe { + let ptr = (*self.to_glib_none().0).out_buffer; + if ptr.is_null() { + None + } else { + Some(gst::BufferRef::from_ptr(ptr)) + } + } + } + + pub fn get_output_buffer_mut(&mut self) -> Option<&mut gst::BufferRef> { unsafe { let ptr = (*self.to_glib_none().0).out_buffer; if ptr.is_null() { @@ -130,7 +152,7 @@ impl<'a> BaseParseFrame<'a> { } } - pub fn set_output_buffer(&self, output_buffer: gst::Buffer) { + pub fn set_output_buffer(&mut self, output_buffer: gst::Buffer) { unsafe { let prev = (*self.to_glib_none().0).out_buffer; @@ -153,11 +175,11 @@ impl<'a> BaseParseFrame<'a> { BaseParseFrameFlags::from_bits_truncate(flags) } - pub fn set_flags(&self, flags: BaseParseFrameFlags) { + pub fn set_flags(&mut self, flags: BaseParseFrameFlags) { unsafe { (*self.to_glib_none().0).flags |= flags.bits() } } - pub fn unset_flags(&self, flags: BaseParseFrameFlags) { + pub fn unset_flags(&mut self, flags: BaseParseFrameFlags) { unsafe { (*self.to_glib_none().0).flags &= !flags.bits() } } @@ -169,7 +191,7 @@ impl<'a> BaseParseFrame<'a> { unsafe { from_glib((*self.to_glib_none().0).overhead) } } - pub fn set_overhead(&self, overhead: Overhead) { + pub fn set_overhead(&mut self, overhead: Overhead) { unsafe { (*self.to_glib_none().0).overhead = overhead.to_glib(); }