codec: introduce Parameters
As of ffmpeg 3.1, a new `AVCodecParameters` type and related API introduced. This commit contains minimal changes to support new API.
This commit is contained in:
@ -4,8 +4,8 @@ use std::rc::Rc;
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use ::media;
|
||||
use ::Codec;
|
||||
use super::{Flags, Id, Debug, Compliance, threading};
|
||||
use ::{Codec, Error};
|
||||
use super::{Flags, Id, Debug, Compliance, threading, Parameters};
|
||||
use super::decoder::Decoder;
|
||||
use super::encoder::Encoder;
|
||||
|
||||
@ -103,6 +103,15 @@ impl Context {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_parameters(&mut self, params: &Parameters) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_parameters_to_context(self.as_mut_ptr(), params.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Context {
|
||||
|
@ -20,6 +20,9 @@ pub use self::capabilities::Capabilities;
|
||||
|
||||
pub mod codec;
|
||||
|
||||
pub mod parameters;
|
||||
pub use self::parameters::Parameters;
|
||||
|
||||
pub mod video;
|
||||
pub use self::video::Video;
|
||||
|
||||
|
57
src/codec/parameters.rs
Normal file
57
src/codec/parameters.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use ffi::*;
|
||||
|
||||
pub struct Parameters {
|
||||
ptr: *mut AVCodecParameters,
|
||||
owner: Option<Rc<Drop>>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Parameters { }
|
||||
|
||||
impl Parameters {
|
||||
pub unsafe fn wrap(ptr: *mut AVCodecParameters, owner: Option<Rc<Drop>>) -> Self {
|
||||
Parameters { ptr: ptr, owner: owner }
|
||||
}
|
||||
|
||||
pub unsafe fn as_ptr(&self) -> *const AVCodecParameters {
|
||||
self.ptr as *const _
|
||||
}
|
||||
|
||||
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters {
|
||||
self.ptr
|
||||
}
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
Parameters { ptr: avcodec_parameters_alloc(), owner: None }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Parameters {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
if self.owner.is_none() {
|
||||
avcodec_parameters_free(&mut self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Parameters {
|
||||
fn clone(&self) -> Self {
|
||||
let mut ctx = Parameters::new();
|
||||
ctx.clone_from(self);
|
||||
|
||||
ctx
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, source: &Self) {
|
||||
unsafe {
|
||||
avcodec_parameters_copy(self.as_mut_ptr(), source.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,12 @@ impl<'a> Stream<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn codec_parameters(&self) -> codec::Parameters {
|
||||
unsafe {
|
||||
codec::Parameters::wrap((*self.as_ptr()).codecpar, Some(self.context.destructor()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).index as usize
|
||||
|
@ -2,7 +2,7 @@ use std::ops::Deref;
|
||||
use std::mem;
|
||||
|
||||
use ffi::*;
|
||||
use ::Rational;
|
||||
use ::{Rational, Error};
|
||||
use super::Stream;
|
||||
use format::context::common::Context;
|
||||
|
||||
@ -40,6 +40,15 @@ impl<'a> StreamMut<'a> {
|
||||
av_stream_set_r_frame_rate(self.as_mut_ptr(), value.into().into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_codec_parameters_from(&mut self, context: &::codec::Context) -> Result<(), Error> {
|
||||
unsafe {
|
||||
match avcodec_parameters_from_context((*self.as_mut_ptr()).codecpar, context.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for StreamMut<'a> {
|
||||
|
Reference in New Issue
Block a user