From 70688fd6a98fc844cf0b75bb52f0a27985435835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 16 Dec 2017 11:41:48 +0200 Subject: [PATCH] Clean-up VideoFrame API There's a buffer() for immutable references on all types now, and a buffer_mut() for getting a mutable reference on the writable videoframe Also some minor other cleanup --- gstreamer-video/src/video_frame.rs | 23 +++++------------------ gstreamer-video/src/video_info.rs | 15 ++++++++++----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/gstreamer-video/src/video_frame.rs b/gstreamer-video/src/video_frame.rs index f825ab88a..865781dd0 100644 --- a/gstreamer-video/src/video_frame.rs +++ b/gstreamer-video/src/video_frame.rs @@ -37,19 +37,6 @@ impl VideoFrame { from_glib(self.0.flags) } - pub fn mut_buffer(&self) -> Option<&mut gst::BufferRef> { - unsafe { - let writable: bool = from_glib(gst_ffi::gst_mini_object_is_writable( - self.0.buffer as *const _, - )); - if !writable { - return None; - } - - Some(gst::BufferRef::from_mut_ptr(self.0.buffer)) - } - } - pub fn id(&self) -> i32 { self.0.id } @@ -138,6 +125,10 @@ impl VideoFrame { self.info().offset() } + pub fn buffer(&self) -> &gst::BufferRef { + unsafe { gst::BufferRef::from_ptr(self.0.buffer) } + } + pub fn plane_data(&self, plane: u32) -> Option<&[u8]> { if plane >= self.n_planes() { return None; @@ -228,10 +219,6 @@ impl VideoFrame { } } } - - pub fn buffer(&self) -> &gst::BufferRef { - unsafe { gst::BufferRef::from_ptr(self.0.buffer) } - } } impl VideoFrame { @@ -291,7 +278,7 @@ impl VideoFrame { } } - pub fn buffer(&mut self) -> &mut gst::BufferRef { + pub fn buffer_mut(&mut self) -> &mut gst::BufferRef { unsafe { gst::BufferRef::from_mut_ptr(self.0.buffer) } } diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index bc4087df3..4d4b93552 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -152,7 +152,12 @@ impl str::FromStr for ::VideoColorimetry { impl fmt::Debug for ::VideoColorimetry { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - f.write_str(&self.to_string()) + f.debug_struct("VideoColorimetry") + .field("range", &self.0.range) + .field("matrix", &self.0.matrix) + .field("transfer", &self.0.transfer) + .field("primaries", &self.0.primaries) + .finish() } } @@ -169,7 +174,9 @@ impl From<::VideoMultiviewFramePacking> for ::VideoMultiviewMode { } impl ::VideoMultiviewFramePacking { - pub fn try_from(v: ::VideoMultiviewMode) -> Result<::VideoMultiviewFramePacking, ::VideoMultiviewMode> { + pub fn try_from( + v: ::VideoMultiviewMode, + ) -> Result<::VideoMultiviewFramePacking, ::VideoMultiviewMode> { let v2 = from_glib(v.to_glib()); if let ::VideoMultiviewFramePacking::__Unknown(_) = v2 { @@ -445,9 +452,7 @@ impl VideoInfo { } pub fn to_caps(&self) -> Option { - unsafe { - from_glib_full(ffi::gst_video_info_to_caps(&self.0 as *const _ as *mut _)) - } + unsafe { from_glib_full(ffi::gst_video_info_to_caps(&self.0 as *const _ as *mut _)) } } pub fn format(&self) -> ::VideoFormat {