cargo: add features

This commit is contained in:
meh 2015-05-15 21:28:03 +02:00
parent 5c402a1256
commit 96563ed391
5 changed files with 99 additions and 60 deletions

View File

@ -4,7 +4,23 @@ version = "0.1.0"
authors = ["meh. <meh@schizofreni.co>"] authors = ["meh. <meh@schizofreni.co>"]
license = "WTFPL" license = "WTFPL"
[features]
default = ["codec", "device", "filter", "format", "resample", "postprocessing", "software-resample", "software-scaling"]
codec = ["ffmpeg-sys/avcodec"]
device = ["ffmpeg-sys/avdevice", "format"]
filter = ["ffmpeg-sys/avfilter"]
format = ["ffmpeg-sys/avformat", "codec"]
resample = ["ffmpeg-sys/avresample"]
postprocessing = ["ffmpeg-sys/postproc"]
software-resample = ["ffmpeg-sys/swresample"]
software-scaling = ["ffmpeg-sys/swscale"]
[dependencies] [dependencies]
libc = "0.1" libc = "0.1"
bitflags = "0.1" bitflags = "0.1"
ffmpeg-sys = "2.6.2"
[dependencies.ffmpeg-sys]
version = "2.6.2"
default-features = false

67
src/device/extensions.rs Normal file
View File

@ -0,0 +1,67 @@
use std::ptr;
use std::marker::PhantomData;
use ffi::*;
use ::Error;
use ::format::Context;
use ::device;
use libc::c_int;
impl Context {
pub fn devices(&self) -> Result<DeviceIter, Error> {
DeviceIter::new(self.ptr)
}
}
pub struct DeviceIter<'a> {
ptr: *mut AVDeviceInfoList,
cur: c_int,
_marker: PhantomData<&'a ()>,
}
impl<'a> DeviceIter<'a> {
pub fn new(ctx: *mut AVFormatContext) -> Result<Self, Error> {
unsafe {
let mut ptr: *mut AVDeviceInfoList = ptr::null_mut();
match avdevice_list_devices(ctx, &mut ptr) {
n if n < 0 =>
Err(Error::new(n)),
_ =>
Ok(DeviceIter { ptr: ptr, cur: 0, _marker: PhantomData })
}
}
}
pub fn default(&self) -> usize {
unsafe {
(*self.ptr).default_device as usize
}
}
}
impl<'a> Drop for DeviceIter<'a> {
fn drop(&mut self) {
unsafe {
avdevice_free_list_devices(&mut self.ptr);
}
}
}
impl<'a> Iterator for DeviceIter<'a> {
type Item = device::Info<'a>;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
if self.cur >= (*self.ptr).nb_devices {
None
}
else {
self.cur += 1;
Some(device::Info::wrap(*(*self.ptr).devices.offset((self.cur - 1) as isize)))
}
}
}
}

View File

@ -1,5 +1,6 @@
pub mod input; pub mod input;
pub mod output; pub mod output;
pub mod extensions;
use std::ffi::CStr; use std::ffi::CStr;
use std::str::from_utf8_unchecked; use std::str::from_utf8_unchecked;

View File

@ -4,10 +4,9 @@ use std::path::Path;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::Deref; use std::ops::Deref;
use libc::{c_int, c_uint}; use libc::c_uint;
use ffi::*; use ffi::*;
use ::{Error, Dictionary, Codec, Stream, Format}; use ::{Error, Dictionary, Codec, Stream, Format};
use ::device;
pub struct Context { pub struct Context {
pub ptr: *mut AVFormatContext, pub ptr: *mut AVFormatContext,
@ -38,10 +37,6 @@ impl Context {
StreamIter::new(self.ptr) StreamIter::new(self.ptr)
} }
pub fn devices(&self) -> Result<DeviceIter, Error> {
DeviceIter::new(self.ptr)
}
pub fn probe_score(&self) -> i32 { pub fn probe_score(&self) -> i32 {
unsafe { unsafe {
av_format_get_probe_score(self.ptr) av_format_get_probe_score(self.ptr)
@ -217,59 +212,6 @@ impl<'a> Iterator for StreamIter<'a> {
} }
} }
pub struct DeviceIter<'a> {
ptr: *mut AVDeviceInfoList,
cur: c_int,
_marker: PhantomData<&'a ()>,
}
impl<'a> DeviceIter<'a> {
pub fn new(ctx: *mut AVFormatContext) -> Result<Self, Error> {
unsafe {
let mut ptr: *mut AVDeviceInfoList = ptr::null_mut();
match avdevice_list_devices(ctx, &mut ptr) {
n if n < 0 =>
Err(Error::new(n)),
_ =>
Ok(DeviceIter { ptr: ptr, cur: 0, _marker: PhantomData })
}
}
}
pub fn default(&self) -> usize {
unsafe {
(*self.ptr).default_device as usize
}
}
}
impl<'a> Drop for DeviceIter<'a> {
fn drop(&mut self) {
unsafe {
avdevice_free_list_devices(&mut self.ptr);
}
}
}
impl<'a> Iterator for DeviceIter<'a> {
type Item = device::Info<'a>;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
if self.cur >= (*self.ptr).nb_devices {
None
}
else {
self.cur += 1;
Some(device::Info::wrap(*(*self.ptr).devices.offset((self.cur - 1) as isize)))
}
}
}
}
pub fn open(path: &Path) -> Result<Context, Error> { pub fn open(path: &Path) -> Result<Context, Error> {
unsafe { unsafe {
let mut ps = ptr::null_mut(); let mut ps = ptr::null_mut();

View File

@ -12,19 +12,32 @@ pub use util::rational::Rational;
pub use util::media; pub use util::media;
pub use util::picture; pub use util::picture;
pub use util::color; pub use util::color;
pub use util::chroma;
pub use util::frame::{self, Frame}; pub use util::frame::{self, Frame};
#[cfg(feature = "format")]
pub mod format; pub mod format;
#[cfg(feature = "format")]
pub use format::format::Format; pub use format::format::Format;
#[cfg(feature = "format")]
pub use format::stream::Stream; pub use format::stream::Stream;
#[cfg(feature = "codec")]
pub mod codec; pub mod codec;
#[cfg(feature = "codec")]
pub use codec::packet::{self, Packet}; pub use codec::packet::{self, Packet};
#[cfg(feature = "codec")]
pub use codec::subtitle::{self, Subtitle}; pub use codec::subtitle::{self, Subtitle};
#[cfg(feature = "codec")]
pub use codec::picture::Picture; pub use codec::picture::Picture;
#[cfg(feature = "codec")]
pub use codec::discard::Discard; pub use codec::discard::Discard;
#[cfg(feature = "codec")]
pub use codec::codec::Codec; pub use codec::codec::Codec;
#[cfg(feature = "codec")]
pub use codec::encoder::{self, Encode}; pub use codec::encoder::{self, Encode};
#[cfg(feature = "codec")]
pub use codec::decoder::{self, Decode}; pub use codec::decoder::{self, Decode};
#[cfg(feature = "device")]
pub mod device; pub mod device;