util/frame/audio: rename new to empty and make new allocate the buffers

This commit is contained in:
meh 2015-05-27 18:57:57 +02:00
parent aa5d34ad8e
commit 049e8a6cdd

View File

@ -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::<AVSampleFormat, c_int>(value.into());
}
}
pub fn channel_layout(&self) -> i64 {
unsafe {
av_frame_get_channel_layout(self.ptr)