mirror of
https://github.com/encounter/rust-ffmpeg.git
synced 2026-07-10 21:18:39 -07:00
chore: run cargo fmt
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -424,11 +424,7 @@ pub struct Encoder(pub Video);
|
||||
|
||||
impl Encoder {
|
||||
#[inline]
|
||||
pub fn encode<P: packet::Mut>(
|
||||
&mut self,
|
||||
frame: &frame::Video,
|
||||
out: &mut P,
|
||||
) -> Result<(), Error> {
|
||||
pub fn encode<P: packet::Mut>(&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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
_io: Option<Io>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Input {}
|
||||
|
||||
+42
-17
@@ -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<T: Read + Seek> InputIo for T { }
|
||||
pub trait InputIo: Read + Seek {}
|
||||
impl<T: Read + Seek> InputIo for T {}
|
||||
|
||||
pub trait StreamIo: Read { }
|
||||
impl<T: Read> StreamIo for T { }
|
||||
pub trait StreamIo: Read {}
|
||||
impl<T: Read> StreamIo for T {}
|
||||
|
||||
pub trait OutputIo: Write { }
|
||||
impl<T: Write> OutputIo for T { }
|
||||
pub trait OutputIo: Write {}
|
||||
impl<T: Write> 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<context::Input, Error> {
|
||||
|
||||
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);
|
||||
|
||||
+4
-7
@@ -82,11 +82,9 @@ impl Into<c_int> for Error {
|
||||
impl From<Error> 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<Error> 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())
|
||||
})
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-21
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user