From 29806617e26e12ff6ceeae5f288e09fcb4bbdd05 Mon Sep 17 00:00:00 2001 From: meh Date: Fri, 12 Mar 2021 22:21:57 +0100 Subject: [PATCH] chore: run cargo fmt --- .rustfmt.toml | 2 +- src/codec/encoder/video.rs | 8 ++--- src/format/context/input.rs | 9 ++++-- src/format/io.rs | 59 ++++++++++++++++++++++++++----------- src/util/error.rs | 11 +++---- src/util/log.rs | 37 ++++++++++------------- 6 files changed, 72 insertions(+), 54 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 67408f5..c2fd1a0 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -5,7 +5,7 @@ hard_tabs = true tab_spaces = 2 merge_derives = false -merge_imports = true +imports_granularity = "Crate" normalize_comments = true normalize_doc_attributes = true diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index 2a8bef0..e0a4358 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -424,11 +424,7 @@ pub struct Encoder(pub Video); impl Encoder { #[inline] - pub fn encode( - &mut self, - frame: &frame::Video, - out: &mut P, - ) -> Result<(), Error> { + pub fn encode(&mut self, frame: &frame::Video, out: &mut P) -> Result<(), Error> { unsafe { if self.format() != frame.format() || self.width() != frame.width() @@ -456,7 +452,7 @@ impl Encoder { unsafe { match avcodec_receive_packet(self.0.as_mut_ptr(), out.as_mut_ptr()) { e if e < 0 => Err(Error::from(e)), - _ => Ok(()) + _ => Ok(()), } } } diff --git a/src/format/context/input.rs b/src/format/context/input.rs index 7e365b1..0797d3a 100644 --- a/src/format/context/input.rs +++ b/src/format/context/input.rs @@ -6,12 +6,17 @@ use std::{ }; use super::{common::Context, destructor}; -use crate::{ffi::*, format::{self, io::Io}, util::range::Range, Codec, Error, Packet, Stream}; +use crate::{ + ffi::*, + format::{self, io::Io}, + util::range::Range, + Codec, Error, Packet, Stream, +}; pub struct Input { ptr: *mut AVFormatContext, ctx: Context, - _io: Option + _io: Option, } unsafe impl Send for Input {} diff --git a/src/format/io.rs b/src/format/io.rs index 49da4ea..8f4b3c7 100644 --- a/src/format/io.rs +++ b/src/format/io.rs @@ -1,5 +1,11 @@ -use std::{slice, convert::TryInto, io::{self, Read, Write, Seek, SeekFrom}, ptr}; -use libc::{c_void, c_int, SEEK_CUR, SEEK_END, SEEK_SET, EINVAL}; +use std::{ + convert::TryInto, + io::{self, Read, Seek, SeekFrom, Write}, + ptr, slice, +}; + +use libc::{c_int, c_void, EINVAL, SEEK_CUR, SEEK_END, SEEK_SET}; + use crate::{ffi::*, format::context, Error}; pub enum Proxy { @@ -38,14 +44,14 @@ pub struct Io { proxy: *mut Proxy, } -pub trait InputIo: Read + Seek { } -impl InputIo for T { } +pub trait InputIo: Read + Seek {} +impl InputIo for T {} -pub trait StreamIo: Read { } -impl StreamIo for T { } +pub trait StreamIo: Read {} +impl StreamIo for T {} -pub trait OutputIo: Write { } -impl OutputIo for T { } +pub trait OutputIo: Write {} +impl OutputIo for T {} impl Io { pub unsafe fn as_ptr(&self) -> *const AVIOContext { @@ -128,8 +134,15 @@ impl Io { pub fn input(value: impl Read + Seek + 'static) -> Self { unsafe { let proxy = Box::into_raw(Box::new(Proxy::Input(Box::new(value)))); - let ptr = avio_alloc_context(ptr::null_mut(), 0, AVIO_FLAG_READ & AVIO_FLAG_DIRECT, proxy.cast(), - Some(read_packet), None, Some(seek)); + let ptr = avio_alloc_context( + ptr::null_mut(), + 0, + AVIO_FLAG_READ & AVIO_FLAG_DIRECT, + proxy.cast(), + Some(read_packet), + None, + Some(seek), + ); Io { proxy, ptr } } @@ -138,8 +151,15 @@ impl Io { pub fn stream(value: impl Read + 'static) -> Self { unsafe { let proxy = Box::into_raw(Box::new(Proxy::Stream(Box::new(value)))); - let ptr = avio_alloc_context(ptr::null_mut(), 0, AVIO_FLAG_READ & AVIO_FLAG_DIRECT, proxy.cast(), - Some(read_packet), None, None); + let ptr = avio_alloc_context( + ptr::null_mut(), + 0, + AVIO_FLAG_READ & AVIO_FLAG_DIRECT, + proxy.cast(), + Some(read_packet), + None, + None, + ); Io { proxy, ptr } } @@ -148,8 +168,15 @@ impl Io { pub fn output(value: impl Write + 'static) -> Self { unsafe { let proxy = Box::into_raw(Box::new(Proxy::Output(Box::new(value)))); - let ptr = avio_alloc_context(ptr::null_mut(), 0, AVIO_FLAG_WRITE & AVIO_FLAG_DIRECT, proxy.cast(), - None, Some(write_packet), None); + let ptr = avio_alloc_context( + ptr::null_mut(), + 0, + AVIO_FLAG_WRITE & AVIO_FLAG_DIRECT, + proxy.cast(), + None, + Some(write_packet), + None, + ); Io { proxy, ptr } } @@ -173,9 +200,7 @@ pub fn input(io: impl Read + Seek + 'static) -> Result { match avformat_open_input(&mut ps, ptr::null_mut(), ptr::null_mut(), ptr::null_mut()) { 0 => match avformat_find_stream_info(ps, ptr::null_mut()) { - r if r >= 0 => { - Ok(context::Input::wrap_with(ps, io)) - } + r if r >= 0 => Ok(context::Input::wrap_with(ps, io)), e => { avformat_close_input(&mut ps); diff --git a/src/util/error.rs b/src/util/error.rs index 313774c..39594c7 100644 --- a/src/util/error.rs +++ b/src/util/error.rs @@ -82,11 +82,9 @@ impl Into for Error { impl From for io::Error { fn from(value: Error) -> io::Error { match value { - Error::Io(err) => - err, + Error::Io(err) => err, - value => - io::Error::new(io::ErrorKind::Other, value) + value => io::Error::new(io::ErrorKind::Other, value), } } } @@ -94,12 +92,11 @@ impl From for io::Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { match self { - Error::Io(err) => - err.fmt(f), + Error::Io(err) => err.fmt(f), err => f.write_str(unsafe { from_utf8_unchecked(CStr::from_ptr(STRINGS[index(err)].as_ptr()).to_bytes()) - }) + }), } } } diff --git a/src/util/log.rs b/src/util/log.rs index 5f059e1..f6fc02a 100644 --- a/src/util/log.rs +++ b/src/util/log.rs @@ -1,6 +1,7 @@ -use libc::{c_void, c_int, c_char}; -use vsprintf::vsprintf; +use libc::{c_char, c_int, c_void}; use log; +use vsprintf::vsprintf; + use crate::ffi::*; pub fn set_level(level: log::Level) { @@ -15,26 +16,20 @@ pub fn set_level(level: log::Level) { } } -unsafe extern "C" fn callback(_ptr: *mut c_void, level: c_int, fmt: *const c_char, args: *mut __va_list_tag) { +unsafe extern "C" fn callback( + _ptr: *mut c_void, + level: c_int, + fmt: *const c_char, + args: *mut __va_list_tag, +) { let string = vsprintf(fmt, args).unwrap(); let level = match level { - AV_LOG_PANIC | AV_LOG_FATAL | AV_LOG_ERROR => - log::LevelFilter::Error, - - AV_LOG_WARNING => - log::LevelFilter::Warn, - - AV_LOG_INFO => - log::LevelFilter::Info, - - AV_LOG_VERBOSE | AV_LOG_DEBUG => - log::LevelFilter::Debug, - - AV_LOG_TRACE => - log::LevelFilter::Trace, - - _ => - log::LevelFilter::Off, + AV_LOG_PANIC | AV_LOG_FATAL | AV_LOG_ERROR => log::LevelFilter::Error, + AV_LOG_WARNING => log::LevelFilter::Warn, + AV_LOG_INFO => log::LevelFilter::Info, + AV_LOG_VERBOSE | AV_LOG_DEBUG => log::LevelFilter::Debug, + AV_LOG_TRACE => log::LevelFilter::Trace, + _ => log::LevelFilter::Off, }; if let Some(level) = level.to_level() { @@ -46,7 +41,7 @@ pub fn register() { unsafe { av_log_set_callback(Some(callback)); } - + if let Some(level) = log::max_level().to_level() { set_level(level); }