codec: add various Codec related stuff

This commit is contained in:
meh
2015-05-12 03:49:55 +02:00
parent 9c8ca6601f
commit 66901497ab
6 changed files with 351 additions and 0 deletions

61
src/codec/codec.rs Normal file
View File

@ -0,0 +1,61 @@
use std::marker::PhantomData;
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use ffi::*;
use super::{Id, Context};
use ::media;
use ::Error;
use ::codec::context::Opened;
pub struct Codec<'a> {
pub ptr: *mut AVCodec,
_marker: PhantomData<&'a i32>,
}
impl<'a> Codec<'a> {
pub fn wrap(ptr: *mut AVCodec) -> Self {
Codec { ptr: ptr, _marker: PhantomData }
}
pub fn open(&self) -> Result<Opened<'a>, Error> {
Context::new().open(self)
}
pub fn is_encoder(&self) -> bool {
unsafe {
av_codec_is_encoder(self.ptr) != 0
}
}
pub fn is_decoder(&self) -> bool {
unsafe {
av_codec_is_decoder(self.ptr) != 0
}
}
pub fn name(&'a self) -> &'a str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.ptr).name).to_bytes())
}
}
pub fn description(&'a self) -> &'a str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.ptr).long_name).to_bytes())
}
}
pub fn kind(&self) -> media::Type {
unsafe {
media::Type::from((*self.ptr).kind)
}
}
pub fn id(&self) -> Id {
unsafe {
Id::from((*self.ptr).id)
}
}
}