cargo: add features
This commit is contained in:
@ -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, Error> {
|
||||
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<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> {
|
||||
unsafe {
|
||||
let mut ps = ptr::null_mut();
|
||||
|
Reference in New Issue
Block a user