device: add handling
This commit is contained in:
parent
b7a015c79a
commit
1150527c35
55
src/device/input.rs
Normal file
55
src/device/input.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use std::ptr;
|
||||
|
||||
use ffi::*;
|
||||
use ::format;
|
||||
use ::Format;
|
||||
|
||||
pub struct AudioIter(*mut AVInputFormat);
|
||||
|
||||
impl Iterator for AudioIter {
|
||||
type Item = Format;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
let ptr = av_input_audio_device_next(self.0);
|
||||
|
||||
if ptr == ptr::null_mut() && self.0 != ptr::null_mut() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
self.0 = ptr;
|
||||
|
||||
Some(Format::Input(format::Input::wrap(ptr)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio() -> AudioIter {
|
||||
AudioIter(ptr::null_mut())
|
||||
}
|
||||
|
||||
pub struct VideoIter(*mut AVInputFormat);
|
||||
|
||||
impl Iterator for VideoIter {
|
||||
type Item = Format;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
let ptr = av_input_video_device_next(self.0);
|
||||
|
||||
if ptr == ptr::null_mut() && self.0 != ptr::null_mut() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
self.0 = ptr;
|
||||
|
||||
Some(Format::Input(format::Input::wrap(ptr)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video() -> VideoIter {
|
||||
VideoIter(ptr::null_mut())
|
||||
}
|
56
src/device/mod.rs
Normal file
56
src/device/mod.rs
Normal file
@ -0,0 +1,56 @@
|
||||
pub mod input;
|
||||
pub mod output;
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::str::from_utf8_unchecked;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use ffi::*;
|
||||
|
||||
pub struct Info<'a> {
|
||||
ptr: *mut AVDeviceInfo,
|
||||
|
||||
_marker: PhantomData<&'a i32>,
|
||||
}
|
||||
|
||||
impl<'a> Info<'a> {
|
||||
pub fn wrap(ptr: *mut AVDeviceInfo) -> Self {
|
||||
Info { ptr: ptr, _marker: PhantomData }
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'a str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr((*self.ptr).device_name).to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn description(&self) -> &'a str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr((*self.ptr).device_description).to_bytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_all() {
|
||||
unsafe {
|
||||
avdevice_register_all();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn version() -> u32 {
|
||||
unsafe {
|
||||
avdevice_version()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn configuration() -> &'static str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr(avdevice_configuration()).to_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn license() -> &'static str {
|
||||
unsafe {
|
||||
from_utf8_unchecked(CStr::from_ptr(avdevice_license()).to_bytes())
|
||||
}
|
||||
}
|
51
src/device/output.rs
Normal file
51
src/device/output.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use std::ptr;
|
||||
|
||||
use ffi::*;
|
||||
use ::format;
|
||||
use ::Format;
|
||||
|
||||
pub struct AudioIter(*mut AVOutputFormat);
|
||||
|
||||
impl Iterator for AudioIter {
|
||||
type Item = Format;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
let ptr = av_output_audio_device_next(self.0);
|
||||
|
||||
if ptr == ptr::null_mut() && self.0 != ptr::null_mut() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Format::Output(format::Output::wrap(ptr)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio() -> AudioIter {
|
||||
AudioIter(ptr::null_mut())
|
||||
}
|
||||
|
||||
pub struct VideoIter(*mut AVOutputFormat);
|
||||
|
||||
impl Iterator for VideoIter {
|
||||
type Item = Format;
|
||||
|
||||
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
|
||||
unsafe {
|
||||
let ptr = av_output_video_device_next(self.0);
|
||||
|
||||
if ptr == ptr::null_mut() && self.0 != ptr::null_mut() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Format::Output(format::Output::wrap(ptr)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video() -> VideoIter {
|
||||
VideoIter(ptr::null_mut())
|
||||
}
|
@ -25,3 +25,5 @@ pub use codec::discard::Discard;
|
||||
pub use codec::codec::Codec;
|
||||
pub use codec::encoder::{self, Encode};
|
||||
pub use codec::decoder::{self, Decode};
|
||||
|
||||
pub mod device;
|
||||
|
Loading…
x
Reference in New Issue
Block a user