From 3e5316c869f6665d0fdd609e5847876223eb498a Mon Sep 17 00:00:00 2001 From: Anders Hellerup Madsen Date: Sun, 1 Oct 2023 11:21:21 +0200 Subject: [PATCH] gl: implement Debug for GL video frames Part-of: --- gstreamer-gl/src/gl_video_frame.rs | 32 ++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/gstreamer-gl/src/gl_video_frame.rs b/gstreamer-gl/src/gl_video_frame.rs index 224c91f71..9cb578169 100644 --- a/gstreamer-gl/src/gl_video_frame.rs +++ b/gstreamer-gl/src/gl_video_frame.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::{marker::PhantomData, mem, ptr}; +use std::{fmt::Debug, marker::PhantomData, mem, ptr}; use crate::GLMemoryRef; use glib::translate::{from_glib, Borrowed, ToGlibPtr}; @@ -9,8 +9,8 @@ use gst_video::{video_frame::IsVideoFrame, VideoFrameExt}; pub enum Readable {} pub enum Writable {} -// TODO: implement copy for videoframes. This would need to go through all the individual -// memories and copy them. Some GL textures can be copied, others cannot. +// TODO: implement copy for videoframes. This would need to go through all the individual memories +// and copy them. Some GL textures can be copied, others cannot. pub trait IsGLVideoFrame: IsVideoFrame + Sized {} @@ -80,8 +80,6 @@ pub struct GLVideoFrame { unsafe impl Send for GLVideoFrame {} unsafe impl Sync for GLVideoFrame {} -// TODO implement Debug for GLVideoFrame - impl IsVideoFrame for GLVideoFrame { #[inline] fn as_raw(&self) -> &gst_video::ffi::GstVideoFrame { @@ -91,6 +89,17 @@ impl IsVideoFrame for GLVideoFrame { impl IsGLVideoFrame for GLVideoFrame {} +impl Debug for GLVideoFrame { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("GLVideoFrame") + .field("flags", &self.flags()) + .field("id", &self.id()) + .field("buffer", &self.buffer()) + .field("info", &self.info()) + .finish() + } +} + impl GLVideoFrame { #[inline] pub fn into_buffer(self) -> gst::Buffer { @@ -272,7 +281,18 @@ impl IsVideoFrame for GLVideoFrameRef { impl IsGLVideoFrame for GLVideoFrameRef {} -// TODO implement Debug for GLVideoFrameRef +impl Debug for GLVideoFrameRef { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.debug_struct("GLVideoFrameRef") + .field("flags", &self.flags()) + .field("id", &self.id()) + .field("buffer", &unsafe { + gst::BufferRef::from_ptr(self.frame.buffer) + }) + .field("info", &self.info()) + .finish() + } +} impl<'a> GLVideoFrameRef<&'a gst::BufferRef> { #[inline]