codec: add various Codec related stuff
This commit is contained in:
61
src/codec/codec.rs
Normal file
61
src/codec/codec.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user