1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! `av_metrics` is a collection of quality metrics for audio and video files.
//! Currently only includes video metrics. Audio metrics will likely be added
//! in the future.

#![allow(clippy::cast_lossless)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::unreadable_literal)]
#![deny(missing_docs)]

#[macro_use]
extern crate err_derive;
#[macro_use]
extern crate itertools;

pub mod video;

/// Possible errors that may occur during processing of a metric.
///
/// This enum may be added to in the future and should not be assumed to be exhaustive.
#[derive(Debug, Error)]
pub enum MetricsError {
    /// Indicates an input file could not be read for some reason.
    #[error(display = "Could not read input file: {}", reason)]
    MalformedInput {
        #[doc(hidden)]
        reason: &'static str,
    },
    /// Indicates an input file could be read, but is not supported by the current metric.
    #[error(display = "Input type not supported: {}", reason)]
    UnsupportedInput {
        #[doc(hidden)]
        reason: &'static str,
    },
    /// Indicates two inputs did not have matching formats or resolutions.
    #[error(display = "Input videos must have matching formats: {}", reason)]
    InputMismatch {
        #[doc(hidden)]
        reason: &'static str,
    },
    /// Placeholder
    #[doc(hidden)]
    #[error(display = "Unreachable")]
    NonExhaustive,
}

#[cfg(test)]
#[inline(always)]
fn assert_metric_eq(expected: f64, value: f64) {
    assert!(
        (expected - value).abs() < 0.01,
        "Expected {}, got {}",
        expected,
        value
    );
}