mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
fix(codec/packet): clone by referencing packet data
This commit is contained in:
+15
-17
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user