util/frame: fix cloning

This commit is contained in:
meh 2015-05-31 18:57:37 +02:00
parent 46a5f863c8
commit 97b6100810
3 changed files with 24 additions and 60 deletions

View File

@ -10,12 +10,14 @@ pub struct Audio(Frame);
impl Audio {
pub fn empty() -> Self {
Audio(Frame::new())
unsafe {
Audio(Frame { ptr: av_frame_alloc() })
}
}
pub fn new(format: format::Sample, samples: usize, layout: i64) -> Self {
unsafe {
let mut frame = Audio(Frame::new());
let mut frame = Audio::empty();
frame.set_format(format);
frame.set_samples(samples);
@ -111,22 +113,16 @@ impl DerefMut for Audio {
impl Clone for Audio {
fn clone(&self) -> Self {
Audio(self.0.clone())
let mut cloned = Audio::new(self.format(), self.samples(), self.channel_layout());
cloned.clone_from(self);
cloned
}
fn clone_from(&mut self, source: &Self) {
self.0.clone_from(&source.0);
}
}
impl Into<Frame> for Audio {
fn into(self) -> Frame {
self.0
}
}
impl Into<Audio> for Frame {
fn into(self) -> Audio {
Audio(self)
unsafe {
av_frame_copy(self.ptr, source.ptr);
av_frame_copy_props(self.ptr, source.ptr);
}
}
}

View File

@ -32,18 +32,6 @@ pub struct Frame {
}
impl Frame {
pub fn new() -> Self {
unsafe {
Frame { ptr: av_frame_alloc() }
}
}
pub fn copy(&mut self, source: &Frame) {
unsafe {
av_frame_copy_props(self.ptr, source.ptr);
}
}
pub fn is_key(&self) -> bool {
unsafe {
(*self.ptr).key_frame == 1
@ -141,22 +129,6 @@ impl Frame {
unsafe impl Send for Frame { }
impl Clone for Frame {
fn clone(&self) -> Self {
let mut frame = Frame::new();
frame.clone_from(self);
frame
}
fn clone_from(&mut self, source: &Self) {
unsafe {
av_frame_copy(self.ptr, source.ptr);
av_frame_copy_props(self.ptr, source.ptr);
}
}
}
impl Drop for Frame {
fn drop(&mut self) {
unsafe {

View File

@ -14,12 +14,14 @@ pub struct Video(Frame);
impl Video {
pub fn empty() -> Self {
Video(Frame::new())
unsafe {
Video(Frame { ptr: av_frame_alloc() })
}
}
pub fn new(format: format::Pixel, width: u32, height: u32) -> Self {
unsafe {
let mut frame = Video(Frame::new());
let mut frame = Video::empty();
frame.set_format(format);
frame.set_width(width);
@ -201,22 +203,16 @@ impl DerefMut for Video {
impl Clone for Video {
fn clone(&self) -> Self {
Video(self.0.clone())
let mut cloned = Video::new(self.format(), self.width(), self.height());
cloned.clone_from(self);
cloned
}
fn clone_from(&mut self, source: &Self) {
self.0.clone_from(&source.0);
}
}
impl Into<Video> for Frame {
fn into(self) -> Video {
Video(self)
}
}
impl Into<Frame> for Video {
fn into(self) -> Frame {
self.0
unsafe {
av_frame_copy(self.ptr, source.ptr);
av_frame_copy_props(self.ptr, source.ptr);
}
}
}