fix(codec/packet): clone by referencing packet data

This commit is contained in:
tilpner
2023-05-24 17:22:59 +02:00
committed by Till Höppner
parent 9c659e2072
commit e63a0a5047
+15 -17
View File
@@ -228,6 +228,21 @@ impl Packet {
}
}
}
#[inline]
pub fn try_clone(&self) -> Result<Self, Error> {
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 {