*: 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,79 +1,78 @@
use std::ptr;
use std::marker::PhantomData;
use std::ptr;
use device;
use ffi::*;
use ::Error;
use ::format::context::common::Context;
use ::device;
use format::context::common::Context;
use libc::c_int;
use Error;
impl Context {
pub fn devices(&self) -> Result<DeviceIter, Error> {
unsafe {
DeviceIter::wrap(self.as_ptr())
}
}
pub fn devices(&self) -> Result<DeviceIter, Error> {
unsafe { DeviceIter::wrap(self.as_ptr()) }
}
}
pub struct DeviceIter<'a> {
ptr: *mut AVDeviceInfoList,
cur: c_int,
ptr: *mut AVDeviceInfoList,
cur: c_int,
_marker: PhantomData<&'a ()>,
_marker: PhantomData<&'a ()>,
}
impl<'a> DeviceIter<'a> {
pub unsafe fn wrap(ctx: *const AVFormatContext) -> Result<Self, Error> {
let mut ptr: *mut AVDeviceInfoList = ptr::null_mut();
pub unsafe fn wrap(ctx: *const AVFormatContext) -> Result<Self, Error> {
let mut ptr: *mut AVDeviceInfoList = ptr::null_mut();
match avdevice_list_devices(ctx as *mut _, &mut ptr) {
n if n < 0 =>
Err(Error::from(n)),
match avdevice_list_devices(ctx as *mut _, &mut ptr) {
n if n < 0 => Err(Error::from(n)),
_ =>
Ok(DeviceIter { ptr: ptr, cur: 0, _marker: PhantomData })
}
}
_ => Ok(DeviceIter {
ptr: ptr,
cur: 0,
_marker: PhantomData,
}),
}
}
}
impl<'a> DeviceIter<'a> {
pub fn default(&self) -> usize {
unsafe {
(*self.ptr).default_device as usize
}
}
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);
}
}
fn drop(&mut self) {
unsafe {
avdevice_free_list_devices(&mut self.ptr);
}
}
}
impl<'a> Iterator for DeviceIter<'a> {
type Item = device::Info<'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)))
}
}
}
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)))
}
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
unsafe {
let length = (*self.ptr).nb_devices as usize;
fn size_hint(&self) -> (usize, Option<usize>) {
unsafe {
let length = (*self.ptr).nb_devices as usize;
(length - self.cur as usize, Some(length - self.cur as usize))
}
}
(length - self.cur as usize, Some(length - self.cur as usize))
}
}
}
impl<'a> ExactSizeIterator for DeviceIter<'a> { }
impl<'a> ExactSizeIterator for DeviceIter<'a> {}

View File

@ -1,55 +1,53 @@
use std::ptr;
use ffi::*;
use ::format;
use ::Format;
use format;
use Format;
pub struct AudioIter(*mut AVInputFormat);
impl Iterator for AudioIter {
type Item = Format;
type Item = Format;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_input_audio_device_next(self.0);
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_input_audio_device_next(self.0);
if ptr.is_null() && !self.0.is_null() {
None
}
else {
self.0 = ptr;
if ptr.is_null() && !self.0.is_null() {
None
} else {
self.0 = ptr;
Some(Format::Input(format::Input::wrap(ptr)))
}
}
}
Some(Format::Input(format::Input::wrap(ptr)))
}
}
}
}
pub fn audio() -> AudioIter {
AudioIter(ptr::null_mut())
AudioIter(ptr::null_mut())
}
pub struct VideoIter(*mut AVInputFormat);
impl Iterator for VideoIter {
type Item = Format;
type Item = Format;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_input_video_device_next(self.0);
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_input_video_device_next(self.0);
if ptr.is_null() && !self.0.is_null() {
None
}
else {
self.0 = ptr;
if ptr.is_null() && !self.0.is_null() {
None
} else {
self.0 = ptr;
Some(Format::Input(format::Input::wrap(ptr)))
}
}
}
Some(Format::Input(format::Input::wrap(ptr)))
}
}
}
}
pub fn video() -> VideoIter {
VideoIter(ptr::null_mut())
VideoIter(ptr::null_mut())
}

View File

@ -1,67 +1,62 @@
pub mod extensions;
pub mod input;
pub mod output;
pub mod extensions;
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use std::marker::PhantomData;
use std::str::from_utf8_unchecked;
use ffi::*;
pub struct Info<'a> {
ptr: *mut AVDeviceInfo,
ptr: *mut AVDeviceInfo,
_marker: PhantomData<&'a ()>,
_marker: PhantomData<&'a ()>,
}
impl<'a> Info<'a> {
pub unsafe fn wrap(ptr: *mut AVDeviceInfo) -> Self {
Info { ptr: ptr, _marker: PhantomData }
}
pub unsafe fn wrap(ptr: *mut AVDeviceInfo) -> Self {
Info {
ptr: ptr,
_marker: PhantomData,
}
}
pub unsafe fn as_ptr(&self) -> *const AVDeviceInfo {
self.ptr as *const _
}
pub unsafe fn as_ptr(&self) -> *const AVDeviceInfo {
self.ptr as *const _
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVDeviceInfo {
self.ptr
}
pub unsafe fn as_mut_ptr(&mut self) -> *mut AVDeviceInfo {
self.ptr
}
}
impl<'a> Info<'a> {
pub fn name(&self) -> &str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_name).to_bytes())
}
}
pub fn name(&self) -> &str {
unsafe { from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_name).to_bytes()) }
}
pub fn description(&self) -> &str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_description).to_bytes())
}
}
pub fn description(&self) -> &str {
unsafe {
from_utf8_unchecked(CStr::from_ptr((*self.as_ptr()).device_description).to_bytes())
}
}
}
pub fn register_all() {
unsafe {
avdevice_register_all();
}
unsafe {
avdevice_register_all();
}
}
pub fn version() -> u32 {
unsafe {
avdevice_version()
}
unsafe { avdevice_version() }
}
pub fn configuration() -> &'static str {
unsafe {
from_utf8_unchecked(CStr::from_ptr(avdevice_configuration()).to_bytes())
}
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())
}
unsafe { from_utf8_unchecked(CStr::from_ptr(avdevice_license()).to_bytes()) }
}

View File

@ -1,55 +1,53 @@
use std::ptr;
use ffi::*;
use ::format;
use ::Format;
use format;
use Format;
pub struct AudioIter(*mut AVOutputFormat);
impl Iterator for AudioIter {
type Item = Format;
type Item = Format;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_output_audio_device_next(self.0);
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_output_audio_device_next(self.0);
if ptr.is_null() && !self.0.is_null() {
None
}
else {
self.0 = ptr;
if ptr.is_null() && !self.0.is_null() {
None
} else {
self.0 = ptr;
Some(Format::Output(format::Output::wrap(ptr)))
}
}
}
Some(Format::Output(format::Output::wrap(ptr)))
}
}
}
}
pub fn audio() -> AudioIter {
AudioIter(ptr::null_mut())
AudioIter(ptr::null_mut())
}
pub struct VideoIter(*mut AVOutputFormat);
impl Iterator for VideoIter {
type Item = Format;
type Item = Format;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_output_video_device_next(self.0);
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
unsafe {
let ptr = av_output_video_device_next(self.0);
if ptr.is_null() && !self.0.is_null() {
None
}
else {
self.0 = ptr;
if ptr.is_null() && !self.0.is_null() {
None
} else {
self.0 = ptr;
Some(Format::Output(format::Output::wrap(ptr)))
}
}
}
Some(Format::Output(format::Output::wrap(ptr)))
}
}
}
}
pub fn video() -> VideoIter {
VideoIter(ptr::null_mut())
VideoIter(ptr::null_mut())
}