codec/parameters: impl AsRef for all codec::Context wrappers

This commit is contained in:
Tae-il Lim 2016-12-01 15:30:31 +09:00 committed by meh
parent 36ac2513c1
commit 4df56b516f
11 changed files with 82 additions and 7 deletions

View File

@ -75,7 +75,7 @@ fn transcoder<P: AsRef<Path>>(ictx: &mut format::context::Input, octx: &mut form
output.set_time_base((1, decoder.rate() as i32));
let encoder = try!(encoder.open_as(codec));
output.set_parameters(&***encoder);
output.set_parameters(&encoder);
let filter = try!(filter(filter_spec, &decoder, &encoder));

View File

@ -7,6 +7,7 @@ use super::Opened;
use ::{packet, Error, AudioService, ChannelLayout};
use ::frame;
use ::util::format;
use ::codec::Context;
pub struct Audio(pub Opened);
@ -117,3 +118,9 @@ impl DerefMut for Audio {
&mut self.0
}
}
impl AsRef<Context> for Audio {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -128,3 +128,9 @@ impl DerefMut for Decoder {
&mut self.0
}
}
impl AsRef<Context> for Decoder {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -2,7 +2,7 @@ use std::ops::{Deref, DerefMut};
use ffi::*;
use super::{Video, Audio, Subtitle, Decoder};
use ::codec::Profile;
use ::codec::{Profile, Context};
use ::{Error, Rational};
use ::media;
@ -95,3 +95,9 @@ impl DerefMut for Opened {
&mut self.0
}
}
impl AsRef<Context> for Opened {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -5,6 +5,7 @@ use ffi::*;
use super::Opened;
use ::{packet, Error};
use ::codec::Context;
pub struct Subtitle(pub Opened);
@ -34,3 +35,9 @@ impl DerefMut for Subtitle {
&mut self.0
}
}
impl AsRef<Context> for Subtitle {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -9,6 +9,7 @@ use ::frame;
use ::util::format;
use ::util::chroma;
use ::color;
use ::codec::Context;
pub struct Video(pub Opened);
@ -150,3 +151,8 @@ impl DerefMut for Video {
}
}
impl AsRef<Context> for Video {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -7,7 +7,7 @@ use ffi::*;
use super::Encoder as Super;
use ::{packet, Error, Dictionary, ChannelLayout, frame};
use ::util::format;
use codec::traits;
use codec::{traits, Context};
pub struct Audio(pub Super);
@ -131,6 +131,12 @@ impl DerefMut for Audio {
}
}
impl AsRef<Context> for Audio {
fn as_ref(&self) -> &Context {
&self
}
}
pub struct Encoder(pub Audio);
impl Encoder {
@ -174,3 +180,9 @@ impl Deref for Encoder {
&self.0
}
}
impl AsRef<Context> for Encoder {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -135,3 +135,9 @@ impl DerefMut for Encoder {
&mut self.0
}
}
impl AsRef<Context> for Encoder {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -6,7 +6,7 @@ use ffi::*;
use super::Encoder as Super;
use ::{Error, Dictionary};
use codec::traits;
use codec::{traits, Context};
pub struct Subtitle(pub Super);
@ -68,6 +68,12 @@ impl DerefMut for Subtitle {
}
}
impl AsRef<Context> for Subtitle {
fn as_ref(&self) -> &Context {
&self
}
}
pub struct Encoder(pub Subtitle);
impl Encoder {
@ -88,3 +94,9 @@ impl Deref for Encoder {
&self.0
}
}
impl AsRef<Context> for Encoder {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -7,7 +7,7 @@ use ffi::*;
use super::Encoder as Super;
use super::{MotionEstimation, Prediction, Comparison, Decision};
use ::{packet, Error, Rational, Dictionary, frame, format};
use codec::traits;
use codec::{traits, Context};
pub struct Video(pub Super);
@ -382,6 +382,12 @@ impl DerefMut for Video {
}
}
impl AsRef<Context> for Video {
fn as_ref(&self) -> &Context {
&self
}
}
pub struct Encoder(pub Video);
impl Encoder {
@ -436,3 +442,9 @@ impl DerefMut for Encoder {
&mut self.0
}
}
impl AsRef<Context> for Encoder {
fn as_ref(&self) -> &Context {
&self
}
}

View File

@ -70,9 +70,10 @@ impl Clone for Parameters {
}
}
impl<'a> From<&'a Context> for Parameters {
fn from(context: &'a Context) -> Parameters {
impl<C: AsRef<Context>> From<C> for Parameters {
fn from(context: C) -> Parameters {
let mut parameters = Parameters::new();
let context = context.as_ref();
unsafe {
avcodec_parameters_from_context(parameters.as_mut_ptr(), context.as_ptr());
}