ffmpeg_the_third/util/log/
level.rs1use crate::ffi::*;
2use libc::c_int;
3#[cfg(feature = "serialize")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Eq, PartialEq, Clone, Copy, Debug)]
7#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
8pub enum Level {
9 Quiet,
10 Panic,
11 Fatal,
12 Error,
13 Warning,
14 Info,
15 Verbose,
16 Debug,
17 Trace,
18}
19
20pub struct LevelError;
21
22impl TryFrom<c_int> for Level {
23 type Error = &'static str;
24
25 fn try_from(value: c_int) -> Result<Self, &'static str> {
26 match value {
27 AV_LOG_QUIET => Ok(Level::Quiet),
28 AV_LOG_PANIC => Ok(Level::Panic),
29 AV_LOG_FATAL => Ok(Level::Fatal),
30 AV_LOG_ERROR => Ok(Level::Error),
31 AV_LOG_WARNING => Ok(Level::Warning),
32 AV_LOG_INFO => Ok(Level::Info),
33 AV_LOG_VERBOSE => Ok(Level::Verbose),
34 AV_LOG_DEBUG => Ok(Level::Debug),
35 AV_LOG_TRACE => Ok(Level::Trace),
36 _ => Err("illegal log level"),
37 }
38 }
39}
40
41impl From<Level> for c_int {
42 fn from(value: Level) -> c_int {
43 match value {
44 Level::Quiet => AV_LOG_QUIET,
45 Level::Panic => AV_LOG_PANIC,
46 Level::Fatal => AV_LOG_FATAL,
47 Level::Error => AV_LOG_ERROR,
48 Level::Warning => AV_LOG_WARNING,
49 Level::Info => AV_LOG_INFO,
50 Level::Verbose => AV_LOG_VERBOSE,
51 Level::Debug => AV_LOG_DEBUG,
52 Level::Trace => AV_LOG_TRACE,
53 }
54 }
55}