Add log::util module
This commit is contained in:
parent
75b8fbbcfa
commit
d3270133be
9
src/util/log/flag.rs
Normal file
9
src/util/log/flag.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
use ffi::*;
|
||||||
|
use libc::c_int;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
pub struct Flags: c_int {
|
||||||
|
const SKIP_REPEATED = AV_LOG_SKIP_REPEATED;
|
||||||
|
const PRINT_LEVEL = AV_LOG_PRINT_LEVEL;
|
||||||
|
}
|
||||||
|
}
|
54
src/util/log/level.rs
Normal file
54
src/util/log/level.rs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use ffi::*;
|
||||||
|
use libc::c_int;
|
||||||
|
|
||||||
|
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||||
|
pub enum Level {
|
||||||
|
Quiet,
|
||||||
|
Panic,
|
||||||
|
Fatal,
|
||||||
|
Error,
|
||||||
|
Warning,
|
||||||
|
Info,
|
||||||
|
Verbose,
|
||||||
|
Debug,
|
||||||
|
Trace,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LevelError;
|
||||||
|
|
||||||
|
impl TryFrom<c_int> for Level {
|
||||||
|
type Error = &'static str;
|
||||||
|
|
||||||
|
fn try_from(value: c_int) -> Result<Self, &'static str> {
|
||||||
|
match value {
|
||||||
|
AV_LOG_QUIET => Ok(Level::Quiet),
|
||||||
|
AV_LOG_PANIC => Ok(Level::Panic),
|
||||||
|
AV_LOG_FATAL => Ok(Level::Fatal),
|
||||||
|
AV_LOG_ERROR => Ok(Level::Error),
|
||||||
|
AV_LOG_WARNING => Ok(Level::Warning),
|
||||||
|
AV_LOG_INFO => Ok(Level::Info),
|
||||||
|
AV_LOG_VERBOSE => Ok(Level::Verbose),
|
||||||
|
AV_LOG_DEBUG => Ok(Level::Debug),
|
||||||
|
AV_LOG_TRACE => Ok(Level::Trace),
|
||||||
|
_ => Err("illegal log level"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<c_int> for Level {
|
||||||
|
fn into(self) -> c_int {
|
||||||
|
match self {
|
||||||
|
Level::Quiet => AV_LOG_QUIET,
|
||||||
|
Level::Panic => AV_LOG_PANIC,
|
||||||
|
Level::Fatal => AV_LOG_FATAL,
|
||||||
|
Level::Error => AV_LOG_ERROR,
|
||||||
|
Level::Warning => AV_LOG_WARNING,
|
||||||
|
Level::Info => AV_LOG_INFO,
|
||||||
|
Level::Verbose => AV_LOG_VERBOSE,
|
||||||
|
Level::Debug => AV_LOG_DEBUG,
|
||||||
|
Level::Trace => AV_LOG_TRACE,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
src/util/log/mod.rs
Normal file
24
src/util/log/mod.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
pub mod level;
|
||||||
|
pub use self::level::Level;
|
||||||
|
|
||||||
|
pub mod flag;
|
||||||
|
pub use self::flag::Flags;
|
||||||
|
|
||||||
|
use ffi::*;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
pub fn set_level(value: Level) {
|
||||||
|
unsafe { av_log_set_level(value.into()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_level() -> Result<Level, &'static str> {
|
||||||
|
unsafe { av_log_get_level().try_into() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_flags(value: Flags) {
|
||||||
|
unsafe { av_log_set_flags(value.bits()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_flags() -> Flags {
|
||||||
|
unsafe { Flags::from_bits_truncate(av_log_get_flags()) }
|
||||||
|
}
|
@ -7,6 +7,7 @@ pub mod error;
|
|||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod frame;
|
pub mod frame;
|
||||||
pub mod interrupt;
|
pub mod interrupt;
|
||||||
|
pub mod log;
|
||||||
pub mod mathematics;
|
pub mod mathematics;
|
||||||
pub mod media;
|
pub mod media;
|
||||||
pub mod option;
|
pub mod option;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user