diff --git a/src/codec/packet/packet.rs b/src/codec/packet/packet.rs index 0fe65e4..75259f6 100644 --- a/src/codec/packet/packet.rs +++ b/src/codec/packet/packet.rs @@ -228,6 +228,21 @@ impl Packet { } } } + + #[inline] + pub fn try_clone(&self) -> Result { + unsafe { + // This doesn't use av_packet_clone, because it masks + // any av_packet_ref errors by returning a null pointer. + + let mut frame = Packet::empty(); + + match av_packet_ref(frame.as_mut_ptr(), self.as_ptr()) { + 0 => Ok(frame), + e => Err(Error::from(e)), + } + } + } } impl Ref for Packet { @@ -242,23 +257,6 @@ impl Mut for Packet { } } -impl Clone for Packet { - #[inline] - fn clone(&self) -> Self { - let mut pkt = Packet::empty(); - pkt.clone_from(self); - - pkt - } - - #[inline] - fn clone_from(&mut self, source: &Self) { - unsafe { - av_copy_packet(&mut self.0, &source.0); - } - } -} - impl Drop for Packet { fn drop(&mut self) { unsafe {