codec: refactor decoder and encoder

This commit is contained in:
meh
2015-05-16 17:28:25 +02:00
parent bdc4c427a8
commit 757088f46c
13 changed files with 567 additions and 288 deletions

View File

@ -0,0 +1,31 @@
use std::ops::Deref;
use libc::c_int;
use ffi::*;
use super::Encoder;
use ::{Packet, Error};
use ::frame;
pub struct Audio(pub Encoder);
impl Audio {
pub fn encode(&self, frame: &frame::Audio, out: &mut Packet) -> Result<bool, Error> {
unsafe {
let mut got: c_int = 0;
match avcodec_encode_audio2(self.ptr, &mut out.val, frame.ptr, &mut got) {
e if e < 0 => Err(Error::new(e)),
_ => Ok(got != 0)
}
}
}
}
impl Deref for Audio {
type Target = Encoder;
fn deref(&self) -> &<Self as Deref>::Target {
&self.0
}
}