From 573055cb1ee510f08c5042b820848caf5840461c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 18 Dec 2019 18:42:40 +0200 Subject: [PATCH] gstreamer-video: Require &mut self for VideoCodecFrame functions that modify it And add non-mutable getters for input/output buffer --- gstreamer-video/src/video_codec_frame.rs | 25 +++++++++++++++++------- gstreamer-video/src/video_decoder.rs | 4 ++-- gstreamer-video/src/video_encoder.rs | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/gstreamer-video/src/video_codec_frame.rs b/gstreamer-video/src/video_codec_frame.rs index 657b76544..109981e9b 100644 --- a/gstreamer-video/src/video_codec_frame.rs +++ b/gstreamer-video/src/video_codec_frame.rs @@ -79,11 +79,11 @@ impl<'a> VideoCodecFrame<'a> { VideoCodecFrameFlags::from_bits_truncate(flags) } - pub fn set_flags(&self, flags: VideoCodecFrameFlags) { + pub fn set_flags(&mut self, flags: VideoCodecFrameFlags) { unsafe { (*self.to_glib_none().0).flags |= flags.bits() } } - pub fn unset_flags(&self, flags: VideoCodecFrameFlags) { + pub fn unset_flags(&mut self, flags: VideoCodecFrameFlags) { unsafe { (*self.to_glib_none().0).flags &= !flags.bits() } } @@ -103,7 +103,7 @@ impl<'a> VideoCodecFrame<'a> { unsafe { from_glib((*self.to_glib_none().0).dts) } } - pub fn set_dts(&self, dts: gst::ClockTime) { + pub fn set_dts(&mut self, dts: gst::ClockTime) { unsafe { (*self.to_glib_none().0).dts = dts.to_glib(); } @@ -113,7 +113,7 @@ impl<'a> VideoCodecFrame<'a> { unsafe { from_glib((*self.to_glib_none().0).pts) } } - pub fn set_pts(&self, pts: gst::ClockTime) { + pub fn set_pts(&mut self, pts: gst::ClockTime) { unsafe { (*self.to_glib_none().0).pts = pts.to_glib(); } @@ -123,7 +123,7 @@ impl<'a> VideoCodecFrame<'a> { unsafe { from_glib((*self.to_glib_none().0).duration) } } - pub fn set_duration(&self, duration: gst::ClockTime) { + pub fn set_duration(&mut self, duration: gst::ClockTime) { unsafe { (*self.to_glib_none().0).duration = duration.to_glib(); } @@ -144,7 +144,18 @@ impl<'a> VideoCodecFrame<'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).output_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).output_buffer; if ptr.is_null() { @@ -160,7 +171,7 @@ impl<'a> VideoCodecFrame<'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).output_buffer; diff --git a/gstreamer-video/src/video_decoder.rs b/gstreamer-video/src/video_decoder.rs index e02dfd5ed..71d070f5d 100644 --- a/gstreamer-video/src/video_decoder.rs +++ b/gstreamer-video/src/video_decoder.rs @@ -39,7 +39,7 @@ pub trait VideoDecoderExtManual: 'static { #[cfg(any(feature = "v1_12", feature = "dox"))] fn allocate_output_frame( &self, - frame: &VideoCodecFrame, + frame: &mut VideoCodecFrame, params: Option<&gst::BufferPoolAcquireParams>, ) -> Result; @@ -97,7 +97,7 @@ impl> VideoDecoderExtManual for O { #[cfg(any(feature = "v1_12", feature = "dox"))] fn allocate_output_frame( &self, - frame: &VideoCodecFrame, + frame: &mut VideoCodecFrame, params: Option<&gst::BufferPoolAcquireParams>, ) -> Result { let ret: gst::FlowReturn = unsafe { diff --git a/gstreamer-video/src/video_encoder.rs b/gstreamer-video/src/video_encoder.rs index 056db34b4..3d9643f24 100644 --- a/gstreamer-video/src/video_encoder.rs +++ b/gstreamer-video/src/video_encoder.rs @@ -23,7 +23,7 @@ pub trait VideoEncoderExtManual: 'static { #[cfg(any(feature = "v1_12", feature = "dox"))] fn allocate_output_frame( &self, - frame: &VideoCodecFrame, + frame: &mut VideoCodecFrame, size: usize, ) -> Result; @@ -58,7 +58,7 @@ impl> VideoEncoderExtManual for O { #[cfg(any(feature = "v1_12", feature = "dox"))] fn allocate_output_frame( &self, - frame: &VideoCodecFrame, + frame: &mut VideoCodecFrame, size: usize, ) -> Result { let ret: gst::FlowReturn = unsafe {