codec: add magic traits to get codecs by name and id
This commit is contained in:
@ -5,7 +5,8 @@ use libc::c_int;
|
||||
use ffi::*;
|
||||
|
||||
use super::Encoder as Super;
|
||||
use ::{Error, Dictionary, Codec};
|
||||
use ::{Error, Dictionary};
|
||||
use codec::traits;
|
||||
|
||||
pub struct Subtitle(pub Super);
|
||||
|
||||
@ -19,23 +20,23 @@ impl Subtitle {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as(mut self, codec: &Codec) -> Result<Encoder, Error> {
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if codec.is_encoder() {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as_with(mut self, codec: &Codec, options: Dictionary) -> Result<Encoder, Error> {
|
||||
pub fn open_as_with<E: traits::Encoder>(mut self, codec: E, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if codec.is_encoder() {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
@ -47,7 +48,7 @@ impl Subtitle {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user