util/frame: fix cloning
This commit is contained in:
parent
46a5f863c8
commit
97b6100810
@ -10,12 +10,14 @@ pub struct Audio(Frame);
|
|||||||
|
|
||||||
impl Audio {
|
impl Audio {
|
||||||
pub fn empty() -> Self {
|
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 {
|
pub fn new(format: format::Sample, samples: usize, layout: i64) -> Self {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = Audio(Frame::new());
|
let mut frame = Audio::empty();
|
||||||
|
|
||||||
frame.set_format(format);
|
frame.set_format(format);
|
||||||
frame.set_samples(samples);
|
frame.set_samples(samples);
|
||||||
@ -111,22 +113,16 @@ impl DerefMut for Audio {
|
|||||||
|
|
||||||
impl Clone for Audio {
|
impl Clone for Audio {
|
||||||
fn clone(&self) -> Self {
|
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) {
|
fn clone_from(&mut self, source: &Self) {
|
||||||
self.0.clone_from(&source.0);
|
unsafe {
|
||||||
}
|
av_frame_copy(self.ptr, source.ptr);
|
||||||
}
|
av_frame_copy_props(self.ptr, source.ptr);
|
||||||
|
}
|
||||||
impl Into<Frame> for Audio {
|
|
||||||
fn into(self) -> Frame {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Audio> for Frame {
|
|
||||||
fn into(self) -> Audio {
|
|
||||||
Audio(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,18 +32,6 @@ pub struct Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn is_key(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
(*self.ptr).key_frame == 1
|
(*self.ptr).key_frame == 1
|
||||||
@ -141,22 +129,6 @@ impl Frame {
|
|||||||
|
|
||||||
unsafe impl Send for 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 {
|
impl Drop for Frame {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -14,12 +14,14 @@ pub struct Video(Frame);
|
|||||||
|
|
||||||
impl Video {
|
impl Video {
|
||||||
pub fn empty() -> Self {
|
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 {
|
pub fn new(format: format::Pixel, width: u32, height: u32) -> Self {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut frame = Video(Frame::new());
|
let mut frame = Video::empty();
|
||||||
|
|
||||||
frame.set_format(format);
|
frame.set_format(format);
|
||||||
frame.set_width(width);
|
frame.set_width(width);
|
||||||
@ -201,22 +203,16 @@ impl DerefMut for Video {
|
|||||||
|
|
||||||
impl Clone for Video {
|
impl Clone for Video {
|
||||||
fn clone(&self) -> Self {
|
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) {
|
fn clone_from(&mut self, source: &Self) {
|
||||||
self.0.clone_from(&source.0);
|
unsafe {
|
||||||
}
|
av_frame_copy(self.ptr, source.ptr);
|
||||||
}
|
av_frame_copy_props(self.ptr, source.ptr);
|
||||||
|
}
|
||||||
impl Into<Video> for Frame {
|
|
||||||
fn into(self) -> Video {
|
|
||||||
Video(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Frame> for Video {
|
|
||||||
fn into(self) -> Frame {
|
|
||||||
self.0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user