*: 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:
Tadas Barzdžius
2018-04-10 17:06:42 +03:00
committed by meh
parent 20c7ef399a
commit 0bcd4550b8
128 changed files with 10643 additions and 10233 deletions

View File

@ -1,68 +1,67 @@
use std::marker::PhantomData;
use super::{Sink, Source};
use ffi::*;
use libc::c_void;
use ::{option, format, ChannelLayout};
use super::{Source, Sink};
use {format, option, ChannelLayout};
pub struct Context<'a> {
ptr: *mut AVFilterContext,
ptr: *mut AVFilterContext,
_marker: PhantomData<&'a ()>,
_marker: PhantomData<&'a ()>,
}
impl<'a> Context<'a> {
pub unsafe fn wrap(ptr: *mut AVFilterContext) -> Self {
Context { ptr: ptr, _marker: PhantomData }
}
pub unsafe fn wrap(ptr: *mut AVFilterContext) -> Self {
Context {
ptr: ptr,
_marker: PhantomData,
}
}
pub unsafe fn as_ptr(&self) -> *const AVFilterContext {
self.ptr as *const _
}
pub unsafe fn as_ptr(&self) -> *const AVFilterContext {
self.ptr as *const _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterContext {
self.ptr
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterContext {
self.ptr
}
}
impl<'a> Context<'a> {
pub fn source(&'a mut self) -> Source<'a> {
unsafe {
Source::wrap(self)
}
}
pub fn source(&'a mut self) -> Source<'a> {
unsafe { Source::wrap(self) }
}
pub fn sink(&'a mut self) -> Sink<'a> {
unsafe {
Sink::wrap(self)
}
}
pub fn sink(&'a mut self) -> Sink<'a> {
unsafe { Sink::wrap(self) }
}
pub fn set_pixel_format(&mut self, value: format::Pixel) {
let _ = option::Settable::set::<AVPixelFormat>(self, "pix_fmts", &value.into());
}
pub fn set_pixel_format(&mut self, value: format::Pixel) {
let _ = option::Settable::set::<AVPixelFormat>(self, "pix_fmts", &value.into());
}
pub fn set_sample_format(&mut self, value: format::Sample) {
let _ = option::Settable::set::<AVSampleFormat>(self, "sample_fmts", &value.into());
}
pub fn set_sample_format(&mut self, value: format::Sample) {
let _ = option::Settable::set::<AVSampleFormat>(self, "sample_fmts", &value.into());
}
pub fn set_sample_rate(&mut self, value: u32) {
let _ = option::Settable::set(self, "sample_rates", &(value as i64));
}
pub fn set_sample_rate(&mut self, value: u32) {
let _ = option::Settable::set(self, "sample_rates", &i64::from(value));
}
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
let _ = option::Settable::set(self, "channel_layouts", &value.bits());
}
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
let _ = option::Settable::set(self, "channel_layouts", &value.bits());
}
}
unsafe impl<'a> option::Target for Context<'a> {
fn as_ptr(&self) -> *const c_void {
self.ptr as *const _
}
fn as_ptr(&self) -> *const c_void {
self.ptr as *const _
}
fn as_mut_ptr(&mut self) -> *mut c_void {
self.ptr as *mut _
}
fn as_mut_ptr(&mut self) -> *mut c_void {
self.ptr as *mut _
}
}
impl<'a> option::Settable for Context<'a> { }
impl<'a> option::Settable for Context<'a> {}

View File

@ -1,40 +1,44 @@
use super::Context;
use ffi::*;
use libc::c_int;
use ::{Frame, Error};
use super::Context;
use {Error, Frame};
pub struct Sink<'a> {
ctx: &'a mut Context<'a>,
ctx: &'a mut Context<'a>,
}
impl<'a> Sink<'a> {
pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Sink<'b> {
Sink { ctx: ctx }
}
pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Sink<'b> {
Sink { ctx: ctx }
}
}
impl<'a> Sink<'a> {
pub fn frame(&mut self, frame: &mut Frame) -> Result<(), Error> {
unsafe {
match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) {
n if n >= 0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn frame(&mut self, frame: &mut Frame) -> Result<(), Error> {
unsafe {
match av_buffersink_get_frame(self.ctx.as_mut_ptr(), frame.as_mut_ptr()) {
n if n >= 0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> {
unsafe {
match av_buffersink_get_samples(self.ctx.as_mut_ptr(), frame.as_mut_ptr(), samples as c_int) {
n if n >= 0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn samples(&mut self, frame: &mut Frame, samples: usize) -> Result<(), Error> {
unsafe {
match av_buffersink_get_samples(
self.ctx.as_mut_ptr(),
frame.as_mut_ptr(),
samples as c_int,
) {
n if n >= 0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn set_frame_size(&mut self, value: u32) {
unsafe {
av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value);
}
}
pub fn set_frame_size(&mut self, value: u32) {
unsafe {
av_buffersink_set_frame_size(self.ctx.as_mut_ptr(), value);
}
}
}

View File

@ -1,38 +1,34 @@
use std::ptr;
use ffi::*;
use ::{Error, Frame};
use super::Context;
use ffi::*;
use {Error, Frame};
pub struct Source<'a> {
ctx: &'a mut Context<'a>,
ctx: &'a mut Context<'a>,
}
impl<'a> Source<'a> {
pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Source<'b> {
Source { ctx: ctx }
}
pub unsafe fn wrap<'b>(ctx: &'b mut Context<'b>) -> Source<'b> {
Source { ctx: ctx }
}
}
impl<'a> Source<'a> {
pub fn failed_requests(&self) -> usize {
unsafe {
av_buffersrc_get_nb_failed_requests(self.ctx.as_ptr() as *mut _) as usize
}
}
pub fn failed_requests(&self) -> usize {
unsafe { av_buffersrc_get_nb_failed_requests(self.ctx.as_ptr() as *mut _) as usize }
}
pub fn add(&mut self, frame: &Frame) -> Result<(), Error> {
unsafe {
match av_buffersrc_add_frame(self.ctx.as_mut_ptr(), frame.as_ptr() as *mut _) {
0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn add(&mut self, frame: &Frame) -> Result<(), Error> {
unsafe {
match av_buffersrc_add_frame(self.ctx.as_mut_ptr(), frame.as_ptr() as *mut _) {
0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn flush(&mut self) -> Result<(), Error> {
unsafe {
self.add(&Frame::wrap(ptr::null_mut()))
}
}
pub fn flush(&mut self) -> Result<(), Error> {
unsafe { self.add(&Frame::wrap(ptr::null_mut())) }
}
}

View File

@ -1,107 +1,104 @@
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use std::marker::PhantomData;
use std::str::from_utf8_unchecked;
use super::{Flags, Pad};
use ffi::*;
use super::{Pad, Flags};
pub struct Filter {
ptr: *mut AVFilter,
ptr: *mut AVFilter,
}
impl Filter {
pub unsafe fn wrap(ptr: *mut AVFilter) -> Self {
Filter { ptr: ptr }
}
pub unsafe fn wrap(ptr: *mut AVFilter) -> Self {
Filter { ptr: ptr }
}
pub unsafe fn as_ptr(&self) -> *const AVFilter {
self.ptr as *const _
}
pub unsafe fn as_ptr(&self) -> *const AVFilter {
self.ptr as *const _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilter {
self.ptr
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilter {
self.ptr
}
}
impl Filter {
pub fn name(&self) -> &str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes())
}
}
pub fn name(&self) -> &str {
unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).name).to_bytes()) }
}
pub fn description(&self) -> Option<&str> {
unsafe {
let ptr = (*self.as_ptr()).description;
pub fn description(&self) -> Option<&str> {
unsafe {
let ptr = (*self.as_ptr()).description;
if ptr.is_null() {
None
}
else {
Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
}
}
}
if ptr.is_null() {
None
} else {
Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
}
}
}
pub fn inputs(&self) -> Option<PadIter> {
unsafe {
let ptr = (*self.as_ptr()).inputs;
pub fn inputs(&self) -> Option<PadIter> {
unsafe {
let ptr = (*self.as_ptr()).inputs;
if ptr.is_null() {
None
}
else {
Some(PadIter::new((*self.as_ptr()).inputs))
}
}
}
if ptr.is_null() {
None
} else {
Some(PadIter::new((*self.as_ptr()).inputs))
}
}
}
pub fn outputs(&self) -> Option<PadIter> {
unsafe {
let ptr = (*self.as_ptr()).outputs;
pub fn outputs(&self) -> Option<PadIter> {
unsafe {
let ptr = (*self.as_ptr()).outputs;
if ptr.is_null() {
None
}
else {
Some(PadIter::new((*self.as_ptr()).outputs))
}
}
}
if ptr.is_null() {
None
} else {
Some(PadIter::new((*self.as_ptr()).outputs))
}
}
}
pub fn flags(&self) -> Flags {
unsafe {
Flags::from_bits_truncate((*self.as_ptr()).flags)
}
}
pub fn flags(&self) -> Flags {
unsafe { Flags::from_bits_truncate((*self.as_ptr()).flags) }
}
}
pub struct PadIter<'a> {
ptr: *const AVFilterPad,
cur: isize,
ptr: *const AVFilterPad,
cur: isize,
_marker: PhantomData<&'a ()>,
_marker: PhantomData<&'a ()>,
}
impl<'a> PadIter<'a> {
pub fn new(ptr: *const AVFilterPad) -> Self {
PadIter { ptr: ptr, cur: 0, _marker: PhantomData }
}
pub fn new(ptr: *const AVFilterPad) -> Self {
PadIter {
ptr: ptr,
cur: 0,
_marker: PhantomData,
}
}
}
impl<'a> Iterator for PadIter<'a> {
type Item = Pad<'a>;
type Item = Pad<'a>;
fn next(&mut self) -> Option<Self::Item> {
unsafe {
if self.cur >= avfilter_pad_count(self.ptr) as isize {
return None;
}
fn next(&mut self) -> Option<Self::Item> {
unsafe {
if self.cur >= avfilter_pad_count(self.ptr) as isize {
return None;
}
let pad = Pad::wrap(self.ptr.offset(self.cur));
self.cur += 1;
let pad = Pad::wrap(self.ptr.offset(self.cur));
self.cur += 1;
Some(pad)
}
}
Some(pad)
}
}
}

View File

@ -1,13 +1,13 @@
use libc::c_int;
use ffi::*;
use libc::c_int;
bitflags! {
pub struct Flags: c_int {
const DYNAMIC_INPUTS = AVFILTER_FLAG_DYNAMIC_INPUTS;
const DYNAMIC_OUTPUTS = AVFILTER_FLAG_DYNAMIC_OUTPUTS;
const SLICE_THREADS = AVFILTER_FLAG_SLICE_THREADS;
const SUPPORT_TIMELINE_GENERIC = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC;
const SUPPORT_TIMELINE_INTERNAL = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL;
const SUPPORT_TIMELINE = AVFILTER_FLAG_SUPPORT_TIMELINE;
}
pub struct Flags: c_int {
const DYNAMIC_INPUTS = AVFILTER_FLAG_DYNAMIC_INPUTS;
const DYNAMIC_OUTPUTS = AVFILTER_FLAG_DYNAMIC_OUTPUTS;
const SLICE_THREADS = AVFILTER_FLAG_SLICE_THREADS;
const SUPPORT_TIMELINE_GENERIC = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC;
const SUPPORT_TIMELINE_INTERNAL = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL;
const SUPPORT_TIMELINE = AVFILTER_FLAG_SUPPORT_TIMELINE;
}
}

View File

@ -1,205 +1,224 @@
use std::ffi::{CStr, CString};
use std::ptr;
use std::ffi::{CString, CStr};
use std::str::from_utf8_unchecked;
use super::{Context, Filter};
use ffi::*;
use libc::c_int;
use ::Error;
use super::{Context, Filter};
use Error;
pub struct Graph {
ptr: *mut AVFilterGraph,
ptr: *mut AVFilterGraph,
}
unsafe impl Send for Graph { }
unsafe impl Sync for Graph { }
unsafe impl Send for Graph {}
unsafe impl Sync for Graph {}
impl Graph {
pub unsafe fn wrap(ptr: *mut AVFilterGraph) -> Self {
Graph { ptr: ptr }
}
pub unsafe fn wrap(ptr: *mut AVFilterGraph) -> Self {
Graph { ptr: ptr }
}
pub unsafe fn as_ptr(&self) -> *const AVFilterGraph {
self.ptr as *const _
}
pub unsafe fn as_ptr(&self) -> *const AVFilterGraph {
self.ptr as *const _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterGraph {
self.ptr
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterGraph {
self.ptr
}
}
impl Graph {
pub fn new() -> Self {
unsafe {
let ptr = avfilter_graph_alloc();
pub fn new() -> Self {
unsafe {
let ptr = avfilter_graph_alloc();
if ptr.is_null() {
panic!("out of memory");
}
if ptr.is_null() {
panic!("out of memory");
}
Graph::wrap(ptr)
}
}
Graph::wrap(ptr)
}
}
pub fn validate(&mut self) -> Result<(), Error> {
unsafe {
match avfilter_graph_config(self.as_mut_ptr(), ptr::null_mut()) {
0 => Ok(()),
e => Err(Error::from(e))
}
}
}
pub fn validate(&mut self) -> Result<(), Error> {
unsafe {
match avfilter_graph_config(self.as_mut_ptr(), ptr::null_mut()) {
0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
pub fn add<'a, 'b>(&'a mut self, filter: &Filter, name: &str, args: &str) -> Result<Context<'b>, Error> where 'a: 'b {
unsafe {
let name = CString::new(name).unwrap();
let args = CString::new(args).unwrap();
let mut context = ptr::null_mut();
pub fn add<'a, 'b>(
&'a mut self,
filter: &Filter,
name: &str,
args: &str,
) -> Result<Context<'b>, Error>
where
'a: 'b,
{
unsafe {
let name = CString::new(name).unwrap();
let args = CString::new(args).unwrap();
let mut context = ptr::null_mut();
match avfilter_graph_create_filter(&mut context as *mut *mut AVFilterContext,
filter.as_ptr(),
name.as_ptr(),
args.as_ptr(),
ptr::null_mut(),
self.as_mut_ptr())
{
n if n >= 0 => Ok(Context::wrap(context)),
e => Err(Error::from(e)),
}
}
}
match avfilter_graph_create_filter(
&mut context as *mut *mut AVFilterContext,
filter.as_ptr(),
name.as_ptr(),
args.as_ptr(),
ptr::null_mut(),
self.as_mut_ptr(),
) {
n if n >= 0 => Ok(Context::wrap(context)),
e => Err(Error::from(e)),
}
}
}
pub fn get<'a, 'b>(&'b mut self, name: &str) -> Option<Context<'b>> where 'a: 'b {
unsafe {
let name = CString::new(name).unwrap();
let ptr = avfilter_graph_get_filter(self.as_mut_ptr(), name.as_ptr());
pub fn get<'a, 'b>(&'b mut self, name: &str) -> Option<Context<'b>>
where
'a: 'b,
{
unsafe {
let name = CString::new(name).unwrap();
let ptr = avfilter_graph_get_filter(self.as_mut_ptr(), name.as_ptr());
if ptr.is_null() {
None
}
else {
Some(Context::wrap(ptr))
}
}
}
if ptr.is_null() {
None
} else {
Some(Context::wrap(ptr))
}
}
}
pub fn dump(&self) -> String {
unsafe {
let ptr = avfilter_graph_dump(self.as_ptr() as *mut _, ptr::null());
let cstr = from_utf8_unchecked(CStr::from_ptr((ptr)).to_bytes());
let string = cstr.to_owned();
pub fn dump(&self) -> String {
unsafe {
let ptr = avfilter_graph_dump(self.as_ptr() as *mut _, ptr::null());
let cstr = from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes());
let string = cstr.to_owned();
av_free(ptr as *mut _);
av_free(ptr as *mut _);
string
}
}
string
}
}
pub fn input(&mut self, name: &str, pad: usize) -> Result<Parser, Error> {
Parser::new(self).input(name, pad)
}
pub fn input(&mut self, name: &str, pad: usize) -> Result<Parser, Error> {
Parser::new(self).input(name, pad)
}
pub fn output(&mut self, name: &str, pad: usize) -> Result<Parser, Error> {
Parser::new(self).output(name, pad)
}
pub fn output(&mut self, name: &str, pad: usize) -> Result<Parser, Error> {
Parser::new(self).output(name, pad)
}
pub fn parse(&mut self, spec: &str) -> Result<(), Error> {
Parser::new(self).parse(spec)
}
pub fn parse(&mut self, spec: &str) -> Result<(), Error> {
Parser::new(self).parse(spec)
}
}
impl Drop for Graph {
fn drop(&mut self) {
unsafe {
avfilter_graph_free(&mut self.as_mut_ptr());
}
}
fn drop(&mut self) {
unsafe {
avfilter_graph_free(&mut self.as_mut_ptr());
}
}
}
pub struct Parser<'a> {
graph: &'a mut Graph,
inputs: *mut AVFilterInOut,
outputs: *mut AVFilterInOut,
graph: &'a mut Graph,
inputs: *mut AVFilterInOut,
outputs: *mut AVFilterInOut,
}
impl<'a> Parser<'a> {
pub fn new(graph: &mut Graph) -> Parser {
Parser {
graph: graph,
inputs: ptr::null_mut(),
outputs: ptr::null_mut(),
}
}
pub fn new(graph: &mut Graph) -> Parser {
Parser {
graph: graph,
inputs: ptr::null_mut(),
outputs: ptr::null_mut(),
}
}
pub fn input(mut self, name: &str, pad: usize) -> Result<Self, Error> {
unsafe {
let mut context = try!(self.graph.get(name).ok_or(Error::InvalidData));
let input = avfilter_inout_alloc();
pub fn input(mut self, name: &str, pad: usize) -> Result<Self, Error> {
unsafe {
let mut context = self.graph.get(name).ok_or(Error::InvalidData)?;
let input = avfilter_inout_alloc();
if input.is_null() {
panic!("out of memory");
}
if input.is_null() {
panic!("out of memory");
}
let name = CString::new(name).unwrap();
let name = CString::new(name).unwrap();
(*input).name = av_strdup(name.as_ptr());
(*input).filter_ctx = context.as_mut_ptr();
(*input).pad_idx = pad as c_int;
(*input).next = ptr::null_mut();
(*input).name = av_strdup(name.as_ptr());
(*input).filter_ctx = context.as_mut_ptr();
(*input).pad_idx = pad as c_int;
(*input).next = ptr::null_mut();
if self.inputs.is_null() {
self.inputs = input;
}
else {
(*self.inputs).next = input;
}
}
if self.inputs.is_null() {
self.inputs = input;
} else {
(*self.inputs).next = input;
}
}
Ok(self)
}
Ok(self)
}
pub fn output(mut self, name: &str, pad: usize) -> Result<Self, Error> {
unsafe {
let mut context = try!(self.graph.get(name).ok_or(Error::InvalidData));
let output = avfilter_inout_alloc();
pub fn output(mut self, name: &str, pad: usize) -> Result<Self, Error> {
unsafe {
let mut context = self.graph.get(name).ok_or(Error::InvalidData)?;
let output = avfilter_inout_alloc();
if output.is_null() {
panic!("out of memory");
}
if output.is_null() {
panic!("out of memory");
}
let name = CString::new(name).unwrap();
let name = CString::new(name).unwrap();
(*output).name = av_strdup(name.as_ptr());
(*output).filter_ctx = context.as_mut_ptr();
(*output).pad_idx = pad as c_int;
(*output).next = ptr::null_mut();
(*output).name = av_strdup(name.as_ptr());
(*output).filter_ctx = context.as_mut_ptr();
(*output).pad_idx = pad as c_int;
(*output).next = ptr::null_mut();
if self.outputs.is_null() {
self.outputs = output;
}
else {
(*self.outputs).next = output;
}
}
if self.outputs.is_null() {
self.outputs = output;
} else {
(*self.outputs).next = output;
}
}
Ok(self)
}
Ok(self)
}
pub fn parse(mut self, spec: &str) -> Result<(), Error> {
unsafe {
let spec = CString::new(spec).unwrap();
pub fn parse(mut self, spec: &str) -> Result<(), Error> {
unsafe {
let spec = CString::new(spec).unwrap();
let result = avfilter_graph_parse_ptr(self.graph.as_mut_ptr(),
spec.as_ptr(), &mut self.inputs, &mut self.outputs,
ptr::null_mut());
let result = avfilter_graph_parse_ptr(
self.graph.as_mut_ptr(),
spec.as_ptr(),
&mut self.inputs,
&mut self.outputs,
ptr::null_mut(),
);
avfilter_inout_free(&mut self.inputs);
avfilter_inout_free(&mut self.outputs);
avfilter_inout_free(&mut self.inputs);
avfilter_inout_free(&mut self.outputs);
match result {
n if n >= 0 => Ok(()),
e => Err(Error::from(e))
}
}
}
match result {
n if n >= 0 => Ok(()),
e => Err(Error::from(e)),
}
}
}
}
impl Default for Graph {
fn default() -> Self {
Self::new()
}
}

View File

@ -8,60 +8,53 @@ pub mod filter;
pub use self::filter::Filter;
pub mod context;
pub use self::context::{Context, Source, Sink};
pub use self::context::{Context, Sink, Source};
pub mod graph;
pub use self::graph::Graph;
use std::ffi::{CString, CStr};
use std::ffi::{CStr, CString};
use std::str::from_utf8_unchecked;
use ffi::*;
use ::Error;
use Error;
pub fn register_all() {
unsafe {
avfilter_register_all();
}
unsafe {
avfilter_register_all();
}
}
pub fn register(filter: &Filter) -> Result<(), Error> {
unsafe {
match avfilter_register(filter.as_ptr() as *mut _) {
0 => Ok(()),
_ => Err(Error::InvalidData),
}
}
unsafe {
match avfilter_register(filter.as_ptr() as *mut _) {
0 => Ok(()),
_ => Err(Error::InvalidData),
}
}
}
pub fn version() -> u32 {
unsafe {
avfilter_version()
}
unsafe { avfilter_version() }
}
pub fn configuration() -> &'static str {
unsafe {
from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes())
}
unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_configuration()).to_bytes()) }
}
pub fn license() -> &'static str {
unsafe {
from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes())
}
unsafe { from_utf8_unchecked(CStr::from_ptr(avfilter_license()).to_bytes()) }
}
pub fn find(name: &str) -> Option<Filter> {
unsafe {
let name = CString::new(name).unwrap();
let ptr = avfilter_get_by_name(name.as_ptr());
unsafe {
let name = CString::new(name).unwrap();
let ptr = avfilter_get_by_name(name.as_ptr());
if ptr.is_null() {
None
}
else {
Some(Filter::wrap(ptr))
}
}
if ptr.is_null() {
None
} else {
Some(Filter::wrap(ptr))
}
}
}

View File

@ -1,47 +1,47 @@
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use std::marker::PhantomData;
use std::str::from_utf8_unchecked;
use ffi::*;
use ::media;
use media;
pub struct Pad<'a> {
ptr: *const AVFilterPad,
ptr: *const AVFilterPad,
_marker: PhantomData<&'a ()>,
_marker: PhantomData<&'a ()>,
}
impl<'a> Pad<'a> {
pub unsafe fn wrap(ptr: *const AVFilterPad) -> Self {
Pad { ptr: ptr, _marker: PhantomData }
}
pub unsafe fn wrap(ptr: *const AVFilterPad) -> Self {
Pad {
ptr: ptr,
_marker: PhantomData,
}
}
pub unsafe fn as_ptr(&self) -> *const AVFilterPad {
self.ptr
}
pub unsafe fn as_ptr(&self) -> *const AVFilterPad {
self.ptr
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterPad {
self.ptr as *mut _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVFilterPad {
self.ptr as *mut _
}
}
impl<'a> Pad<'a> {
pub fn name(&self) -> Option<&str> {
unsafe {
let ptr = avfilter_pad_get_name(self.ptr, 0);
pub fn name(&self) -> Option<&str> {
unsafe {
let ptr = avfilter_pad_get_name(self.ptr, 0);
if ptr.is_null() {
None
}
else {
Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
}
}
}
if ptr.is_null() {
None
} else {
Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
}
}
}
pub fn medium(&self) -> media::Type {
unsafe {
media::Type::from(avfilter_pad_get_type(self.ptr, 0))
}
}
pub fn medium(&self) -> media::Type {
unsafe { media::Type::from(avfilter_pad_get_type(self.ptr, 0)) }
}
}