*: format code with rustfmt and fix clippy suggestions
* Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore
This commit is contained in:
@ -1,132 +1,123 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::Opened;
|
||||
use ::{packet, Error, AudioService, ChannelLayout};
|
||||
use ::frame;
|
||||
use ::util::format;
|
||||
use ::codec::Context;
|
||||
use codec::Context;
|
||||
use frame;
|
||||
use util::format;
|
||||
use {packet, AudioService, ChannelLayout, Error};
|
||||
|
||||
pub struct Audio(pub Opened);
|
||||
|
||||
impl Audio {
|
||||
pub fn decode<P: packet::Ref>(&mut self, packet: &P, out: &mut frame::Audio) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
pub fn decode<P: packet::Ref>(
|
||||
&mut self,
|
||||
packet: &P,
|
||||
out: &mut frame::Audio,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_decode_audio4(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_decode_audio4(
|
||||
self.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
&mut got,
|
||||
packet.as_ptr(),
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).sample_rate as u32
|
||||
}
|
||||
}
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).sample_rate as u32 }
|
||||
}
|
||||
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).channels as u16
|
||||
}
|
||||
}
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe { (*self.as_ptr()).channels as u16 }
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
format::Sample::from((*self.as_ptr()).sample_fmt)
|
||||
}
|
||||
}
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) }
|
||||
}
|
||||
|
||||
pub fn request_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
pub fn request_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frames(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_number as usize
|
||||
}
|
||||
}
|
||||
pub fn frames(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).frame_number as usize }
|
||||
}
|
||||
|
||||
pub fn align(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).block_align as usize
|
||||
}
|
||||
}
|
||||
pub fn align(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).block_align as usize }
|
||||
}
|
||||
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe {
|
||||
ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout)
|
||||
}
|
||||
}
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) }
|
||||
}
|
||||
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn request_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).request_channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio_service(&mut self) -> AudioService {
|
||||
unsafe {
|
||||
AudioService::from((*self.as_mut_ptr()).audio_service_type)
|
||||
}
|
||||
}
|
||||
pub fn audio_service(&mut self) -> AudioService {
|
||||
unsafe { AudioService::from((*self.as_mut_ptr()).audio_service_type) }
|
||||
}
|
||||
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).rc_max_rate as usize
|
||||
}
|
||||
}
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).rc_max_rate as usize }
|
||||
}
|
||||
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_size as u32
|
||||
}
|
||||
}
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).frame_size as u32 }
|
||||
}
|
||||
|
||||
pub fn frame_start(&self) -> Option<usize> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).timecode_frame_start {
|
||||
-1 => None,
|
||||
n => Some(n as usize)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn frame_start(&self) -> Option<usize> {
|
||||
unsafe {
|
||||
match (*self.as_ptr()).timecode_frame_start {
|
||||
-1 => None,
|
||||
n => Some(n as usize),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Opened;
|
||||
type Target = Opened;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Audio {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Audio {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Audio {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Check: c_int {
|
||||
const CRC = AV_EF_CRCCHECK;
|
||||
const BISTREAM = AV_EF_BITSTREAM;
|
||||
const BUFFER = AV_EF_BUFFER;
|
||||
const EXPLODE = AV_EF_EXPLODE;
|
||||
pub struct Check: c_int {
|
||||
const CRC = AV_EF_CRCCHECK;
|
||||
const BISTREAM = AV_EF_BITSTREAM;
|
||||
const BUFFER = AV_EF_BUFFER;
|
||||
const EXPLODE = AV_EF_EXPLODE;
|
||||
|
||||
const IGNORE_ERROR = AV_EF_IGNORE_ERR;
|
||||
const CAREFUL = AV_EF_CAREFUL;
|
||||
const COMPLIANT = AV_EF_COMPLIANT;
|
||||
const AGGRESSIVE = AV_EF_AGGRESSIVE;
|
||||
}
|
||||
const IGNORE_ERROR = AV_EF_IGNORE_ERR;
|
||||
const CAREFUL = AV_EF_CAREFUL;
|
||||
const COMPLIANT = AV_EF_COMPLIANT;
|
||||
const AGGRESSIVE = AV_EF_AGGRESSIVE;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Conceal: c_int {
|
||||
const GUESS_MVS = FF_EC_GUESS_MVS;
|
||||
const DEBLOCK = FF_EC_DEBLOCK;
|
||||
const FAVOR_INTER = FF_EC_FAVOR_INTER;
|
||||
}
|
||||
pub struct Conceal: c_int {
|
||||
const GUESS_MVS = FF_EC_GUESS_MVS;
|
||||
const DEBLOCK = FF_EC_DEBLOCK;
|
||||
const FAVOR_INTER = FF_EC_FAVOR_INTER;
|
||||
}
|
||||
}
|
||||
|
@ -1,142 +1,139 @@
|
||||
use std::ptr;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
use super::{Audio, Check, Conceal, Opened, Subtitle, Video};
|
||||
use codec::{traits, Context};
|
||||
use ffi::*;
|
||||
use codec::{Context, traits};
|
||||
use super::{Opened, Video, Audio, Subtitle, Conceal, Check};
|
||||
use ::{Error, Discard, Rational, Dictionary};
|
||||
use {Dictionary, Discard, Error, Rational};
|
||||
|
||||
pub struct Decoder(pub Context);
|
||||
|
||||
impl Decoder {
|
||||
pub fn open(mut self) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open(mut self) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as<D: traits::Decoder>(mut self, codec: D) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open_as<D: traits::Decoder>(mut self, codec: D) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as_with<D: traits::Decoder>(mut self, codec: D, options: Dictionary) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
pub fn open_as_with<D: traits::Decoder>(
|
||||
mut self,
|
||||
codec: D,
|
||||
options: Dictionary,
|
||||
) -> Result<Opened, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.decoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Opened(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.video())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.video())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.audio())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.audio())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.subtitle())
|
||||
}
|
||||
else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if let Some(codec) = super::find(self.id()) {
|
||||
self.open_as(codec).and_then(|o| o.subtitle())
|
||||
} else {
|
||||
Err(Error::DecoderNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn conceal(&mut self, value: Conceal) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).error_concealment = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn conceal(&mut self, value: Conceal) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).error_concealment = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check(&mut self, value: Check) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).err_recognition = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn check(&mut self, value: Check) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).err_recognition = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_loop_filter(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_loop_filter = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_loop_filter(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_loop_filter = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_idct(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_idct = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_idct(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_idct = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_frame(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_frame = value.into();
|
||||
}
|
||||
}
|
||||
pub fn skip_frame(&mut self, value: Discard) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_frame = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational::from((*self.as_ptr()).time_base)
|
||||
}
|
||||
}
|
||||
pub fn time_base(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).time_base) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Decoder {
|
||||
type Target = Context;
|
||||
type Target = Context;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Decoder {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Decoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Decoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -23,38 +23,36 @@ pub use self::opened::Opened;
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use ffi::*;
|
||||
use codec::Context;
|
||||
use ::Codec;
|
||||
use codec::Id;
|
||||
use ffi::*;
|
||||
use Codec;
|
||||
|
||||
pub fn new() -> Decoder {
|
||||
Context::new().decoder()
|
||||
Context::new().decoder()
|
||||
}
|
||||
|
||||
pub fn find(id: Id) -> Option<Codec> {
|
||||
unsafe {
|
||||
let ptr = avcodec_find_decoder(id.into());
|
||||
unsafe {
|
||||
let ptr = avcodec_find_decoder(id.into());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_by_name(name: &str) -> Option<Codec> {
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_decoder_by_name(name.as_ptr());
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_decoder_by_name(name.as_ptr());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,109 +1,99 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use super::{Audio, Decoder, Subtitle, Video};
|
||||
use codec::{Context, Profile};
|
||||
use ffi::*;
|
||||
use super::{Video, Audio, Subtitle, Decoder};
|
||||
use ::codec::{Profile, Context};
|
||||
use ::{Error, Rational};
|
||||
use ::media;
|
||||
use media;
|
||||
use {Error, Rational};
|
||||
|
||||
pub struct Opened(pub Decoder);
|
||||
|
||||
impl Opened {
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn video(self) -> Result<Video, Error> {
|
||||
if self.medium() == media::Type::Video {
|
||||
Ok(Video(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn audio(self) -> Result<Audio, Error> {
|
||||
if self.medium() == media::Type::Audio {
|
||||
Ok(Audio(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if self.medium() == media::Type::Subtitle {
|
||||
Ok(Subtitle(self))
|
||||
}
|
||||
else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
pub fn subtitle(self) -> Result<Subtitle, Error> {
|
||||
if self.medium() == media::Type::Subtitle {
|
||||
Ok(Subtitle(self))
|
||||
} else {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_rate(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).bit_rate as usize
|
||||
}
|
||||
}
|
||||
pub fn bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).bit_rate as usize }
|
||||
}
|
||||
|
||||
pub fn delay(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).delay as usize
|
||||
}
|
||||
}
|
||||
pub fn delay(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).delay as usize }
|
||||
}
|
||||
|
||||
pub fn profile(&self) -> Profile {
|
||||
unsafe {
|
||||
Profile::from((self.id(), (*self.as_ptr()).profile))
|
||||
}
|
||||
}
|
||||
pub fn profile(&self) -> Profile {
|
||||
unsafe { Profile::from((self.id(), (*self.as_ptr()).profile)) }
|
||||
}
|
||||
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let value = (*self.as_ptr()).framerate;
|
||||
pub fn frame_rate(&self) -> Option<Rational> {
|
||||
unsafe {
|
||||
let value = (*self.as_ptr()).framerate;
|
||||
|
||||
if value == (AVRational { num: 0, den: 1 }) {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Rational::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
if value == (AVRational { num: 0, den: 1 }) {
|
||||
None
|
||||
} else {
|
||||
Some(Rational::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) {
|
||||
unsafe {
|
||||
avcodec_flush_buffers(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
pub fn flush(&mut self) {
|
||||
unsafe {
|
||||
avcodec_flush_buffers(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Opened {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
avcodec_close(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
avcodec_close(self.as_mut_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Opened {
|
||||
type Target = Decoder;
|
||||
type Target = Decoder;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Opened {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Opened {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Opened {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
bitflags! {
|
||||
pub struct Flags: c_int {
|
||||
const CODED_ORDER = SLICE_FLAG_CODED_ORDER;
|
||||
const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD;
|
||||
const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE;
|
||||
}
|
||||
pub struct Flags: c_int {
|
||||
const CODED_ORDER = SLICE_FLAG_CODED_ORDER;
|
||||
const ALLOW_FIELD = SLICE_FLAG_ALLOW_FIELD;
|
||||
const ALLOW_PLANE = SLICE_FLAG_ALLOW_PLANE;
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,58 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::Opened;
|
||||
use ::{packet, Error};
|
||||
use ::codec::Context;
|
||||
use codec::Context;
|
||||
use {packet, Error};
|
||||
|
||||
pub struct Subtitle(pub Opened);
|
||||
|
||||
impl Subtitle {
|
||||
pub fn decode<P: packet::Ref>(&mut self, packet: &P, out: &mut ::Subtitle) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
pub fn decode<P: packet::Ref>(
|
||||
&mut self,
|
||||
packet: &P,
|
||||
out: &mut ::Subtitle,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_decode_subtitle2(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr() as *mut _) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_decode_subtitle2(
|
||||
self.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
&mut got,
|
||||
packet.as_ptr() as *mut _,
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Subtitle {
|
||||
type Target = Opened;
|
||||
type Target = Opened;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Subtitle {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Subtitle {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Subtitle {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -1,164 +1,147 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::{Opened, slice};
|
||||
use ::{packet, Error, Rational, FieldOrder};
|
||||
use ::frame;
|
||||
use ::util::format;
|
||||
use ::util::chroma;
|
||||
use ::color;
|
||||
use ::codec::Context;
|
||||
use super::{slice, Opened};
|
||||
use codec::Context;
|
||||
use color;
|
||||
use frame;
|
||||
use util::chroma;
|
||||
use util::format;
|
||||
use {packet, Error, FieldOrder, Rational};
|
||||
|
||||
pub struct Video(pub Opened);
|
||||
|
||||
impl Video {
|
||||
pub fn decode<P: packet::Ref>(&mut self, packet: &P, out: &mut frame::Video) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
pub fn decode<P: packet::Ref>(
|
||||
&mut self,
|
||||
packet: &P,
|
||||
out: &mut frame::Video,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_decode_video2(self.as_mut_ptr(), out.as_mut_ptr(), &mut got, packet.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_decode_video2(
|
||||
self.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
&mut got,
|
||||
packet.as_ptr(),
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).width as u32
|
||||
}
|
||||
}
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).width as u32 }
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).height as u32
|
||||
}
|
||||
}
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).height as u32 }
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
format::Pixel::from((*self.as_ptr()).pix_fmt)
|
||||
}
|
||||
}
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) }
|
||||
}
|
||||
|
||||
pub fn has_b_frames(&self) -> bool {
|
||||
unsafe {
|
||||
(*self.as_ptr()).has_b_frames != 0
|
||||
}
|
||||
}
|
||||
pub fn has_b_frames(&self) -> bool {
|
||||
unsafe { (*self.as_ptr()).has_b_frames != 0 }
|
||||
}
|
||||
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe {
|
||||
Rational::from((*self.as_ptr()).sample_aspect_ratio)
|
||||
}
|
||||
}
|
||||
pub fn aspect_ratio(&self) -> Rational {
|
||||
unsafe { Rational::from((*self.as_ptr()).sample_aspect_ratio) }
|
||||
}
|
||||
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe {
|
||||
color::Space::from((*self.as_ptr()).colorspace)
|
||||
}
|
||||
}
|
||||
pub fn color_space(&self) -> color::Space {
|
||||
unsafe { color::Space::from((*self.as_ptr()).colorspace) }
|
||||
}
|
||||
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
color::Range::from((*self.as_ptr()).color_range)
|
||||
}
|
||||
}
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe { color::Range::from((*self.as_ptr()).color_range) }
|
||||
}
|
||||
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe {
|
||||
color::Primaries::from((*self.as_ptr()).color_primaries)
|
||||
}
|
||||
}
|
||||
pub fn color_primaries(&self) -> color::Primaries {
|
||||
unsafe { color::Primaries::from((*self.as_ptr()).color_primaries) }
|
||||
}
|
||||
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe {
|
||||
color::TransferCharacteristic::from((*self.as_ptr()).color_trc)
|
||||
}
|
||||
}
|
||||
pub fn color_transfer_characteristic(&self) -> color::TransferCharacteristic {
|
||||
unsafe { color::TransferCharacteristic::from((*self.as_ptr()).color_trc) }
|
||||
}
|
||||
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe {
|
||||
chroma::Location::from((*self.as_ptr()).chroma_sample_location)
|
||||
}
|
||||
}
|
||||
pub fn chroma_location(&self) -> chroma::Location {
|
||||
unsafe { chroma::Location::from((*self.as_ptr()).chroma_sample_location) }
|
||||
}
|
||||
|
||||
pub fn set_slice_count(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).slice_count = value as c_int;
|
||||
}
|
||||
}
|
||||
pub fn set_slice_count(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).slice_count = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_slice_flags(&mut self, value: slice::Flags) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).slice_flags = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn set_slice_flags(&mut self, value: slice::Flags) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).slice_flags = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_top(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_top = value as c_int;
|
||||
}
|
||||
}
|
||||
pub fn skip_top(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_top = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn skip_bottom(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_bottom = value as c_int;
|
||||
}
|
||||
}
|
||||
pub fn skip_bottom(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).skip_bottom = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn references(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).refs as usize
|
||||
}
|
||||
}
|
||||
pub fn references(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).refs as usize }
|
||||
}
|
||||
|
||||
pub fn set_field_order(&mut self, value: FieldOrder) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).field_order = value.into();
|
||||
}
|
||||
}
|
||||
pub fn set_field_order(&mut self, value: FieldOrder) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).field_order = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
// intra_matrix
|
||||
// inter_matrix
|
||||
// intra_matrix
|
||||
// inter_matrix
|
||||
|
||||
pub fn intra_dc_precision(&self) -> u8 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).intra_dc_precision as u8
|
||||
}
|
||||
}
|
||||
pub fn intra_dc_precision(&self) -> u8 {
|
||||
unsafe { (*self.as_ptr()).intra_dc_precision as u8 }
|
||||
}
|
||||
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe {
|
||||
(*self.as_ptr()).rc_max_rate as usize
|
||||
}
|
||||
}
|
||||
pub fn max_bit_rate(&self) -> usize {
|
||||
unsafe { (*self.as_ptr()).rc_max_rate as usize }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Video {
|
||||
type Target = Opened;
|
||||
type Target = Opened;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Video {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Video {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Video {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user