From 7cd45c647e5383a53b14e62150025662a04f5bc3 Mon Sep 17 00:00:00 2001 From: tilpner Date: Fri, 21 Apr 2023 14:08:37 +0200 Subject: [PATCH] feat(util/frame): support shallow cloning --- src/util/frame/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index 203850c..29772d4 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -217,6 +217,21 @@ impl Frame { } } } + + #[inline] + pub fn try_clone(&self) -> Result { + unsafe { + // This doesn't use av_frame_clone, because it masks + // any av_frame_ref errors by returning a null pointer. + + let mut frame = Frame::empty(); + + match av_frame_ref(frame.as_mut_ptr(), self.as_ptr()) { + 0 => Ok(frame), + e => Err(Error::from(e)), + } + } + } } impl Drop for Frame {