codec/parameters: make api more flexible and consistent
This commit is contained in:
@ -2,7 +2,7 @@ use std::rc::Rc;
|
||||
|
||||
use ffi::*;
|
||||
use media;
|
||||
use super::Id;
|
||||
use super::{Id, Context};
|
||||
|
||||
pub struct Parameters {
|
||||
ptr: *mut AVCodecParameters,
|
||||
@ -69,3 +69,13 @@ impl Clone for Parameters {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Context> for Parameters {
|
||||
fn from(context: &'a Context) -> Parameters {
|
||||
let mut parameters = Parameters::new();
|
||||
unsafe {
|
||||
avcodec_parameters_from_context(parameters.as_mut_ptr(), context.as_ptr());
|
||||
}
|
||||
parameters
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ impl<'a> Stream<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn codec_parameters(&self) -> codec::Parameters {
|
||||
pub fn parameters(&self) -> codec::Parameters {
|
||||
unsafe {
|
||||
codec::Parameters::wrap((*self.as_ptr()).codecpar, Some(self.context.destructor()))
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::ops::Deref;
|
||||
use std::mem;
|
||||
|
||||
use ffi::*;
|
||||
use ::{Rational, Error};
|
||||
use ::{Rational, codec};
|
||||
use super::Stream;
|
||||
use format::context::common::Context;
|
||||
|
||||
@ -41,12 +41,11 @@ impl<'a> StreamMut<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_codec_parameters_from(&mut self, context: &::codec::Context) -> Result<(), Error> {
|
||||
pub fn set_parameters<P: Into<codec::Parameters>>(&mut self, parameters: P) {
|
||||
let parameters = parameters.into();
|
||||
|
||||
unsafe {
|
||||
match avcodec_parameters_from_context((*self.as_mut_ptr()).codecpar, context.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
avcodec_parameters_copy((*self.as_mut_ptr()).codecpar, parameters.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user