diff --git a/Cargo.toml b/Cargo.toml index 32ae470..e3a82af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,23 @@ version = "0.1.0" authors = ["meh. "] 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] libc = "0.1" bitflags = "0.1" -ffmpeg-sys = "2.6.2" + +[dependencies.ffmpeg-sys] +version = "2.6.2" + +default-features = false diff --git a/src/device/extensions.rs b/src/device/extensions.rs new file mode 100644 index 0000000..0e78a7e --- /dev/null +++ b/src/device/extensions.rs @@ -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::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 { + 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<::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))) + } + } + } +} diff --git a/src/device/mod.rs b/src/device/mod.rs index fb06bf2..5bc8ac1 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -1,5 +1,6 @@ pub mod input; pub mod output; +pub mod extensions; use std::ffi::CStr; use std::str::from_utf8_unchecked; diff --git a/src/format/context.rs b/src/format/context.rs index ca904c9..95cd667 100644 --- a/src/format/context.rs +++ b/src/format/context.rs @@ -4,10 +4,9 @@ use std::path::Path; use std::marker::PhantomData; use std::ops::Deref; -use libc::{c_int, c_uint}; +use libc::c_uint; use ffi::*; use ::{Error, Dictionary, Codec, Stream, Format}; -use ::device; pub struct Context { pub ptr: *mut AVFormatContext, @@ -38,10 +37,6 @@ impl Context { StreamIter::new(self.ptr) } - pub fn devices(&self) -> Result { - DeviceIter::new(self.ptr) - } - pub fn probe_score(&self) -> i32 { unsafe { 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 { - 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<::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 { unsafe { let mut ps = ptr::null_mut(); diff --git a/src/lib.rs b/src/lib.rs index b0c118a..fa30851 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,19 +12,32 @@ pub use util::rational::Rational; pub use util::media; pub use util::picture; pub use util::color; +pub use util::chroma; pub use util::frame::{self, Frame}; +#[cfg(feature = "format")] pub mod format; +#[cfg(feature = "format")] pub use format::format::Format; +#[cfg(feature = "format")] pub use format::stream::Stream; +#[cfg(feature = "codec")] pub mod codec; +#[cfg(feature = "codec")] pub use codec::packet::{self, Packet}; +#[cfg(feature = "codec")] pub use codec::subtitle::{self, Subtitle}; +#[cfg(feature = "codec")] pub use codec::picture::Picture; +#[cfg(feature = "codec")] pub use codec::discard::Discard; +#[cfg(feature = "codec")] pub use codec::codec::Codec; +#[cfg(feature = "codec")] pub use codec::encoder::{self, Encode}; +#[cfg(feature = "codec")] pub use codec::decoder::{self, Decode}; +#[cfg(feature = "device")] pub mod device;