From 049e8a6cdd577db23548262b92b364cf2a73b885 Mon Sep 17 00:00:00 2001 From: meh Date: Wed, 27 May 2015 18:57:57 +0200 Subject: [PATCH] util/frame/audio: rename new to empty and make new allocate the buffers --- src/util/frame/audio.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/util/frame/audio.rs b/src/util/frame/audio.rs index 3259eb1..620e623 100644 --- a/src/util/frame/audio.rs +++ b/src/util/frame/audio.rs @@ -9,10 +9,24 @@ use super::Frame; pub struct Audio(Frame); impl Audio { - pub fn new() -> Self { + pub fn empty() -> Self { Audio(Frame::new()) } + pub fn new(format: format::Sample, samples: usize, layout: i64) -> Self { + unsafe { + let mut frame = Audio(Frame::new()); + + frame.set_format(format); + frame.set_samples(samples); + frame.set_channel_layout(layout); + + av_frame_get_buffer(frame.ptr, 1); + + frame + } + } + pub fn format(&self) -> format::Sample { unsafe { if (*self.ptr).format == -1 { @@ -24,6 +38,12 @@ impl Audio { } } + pub fn set_format(&mut self, value: format::Sample) { + unsafe { + (*self.ptr).format = mem::transmute::(value.into()); + } + } + pub fn channel_layout(&self) -> i64 { unsafe { av_frame_get_channel_layout(self.ptr)