Coverage Report

Created: 2026-04-12 07:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/av-scenechange-0.14.1/src/decoder.rs
Line
Count
Source
1
use std::io::Read;
2
3
use num_rational::Rational32;
4
use v_frame::{
5
    frame::Frame,
6
    pixel::{ChromaSampling, Pixel},
7
};
8
9
#[cfg(feature = "ffmpeg")]
10
use crate::ffmpeg::FfmpegDecoder;
11
#[cfg(feature = "vapoursynth")]
12
use crate::vapoursynth::VapoursynthDecoder;
13
14
pub enum Decoder<R: Read> {
15
    Y4m(y4m::Decoder<R>),
16
    #[cfg(feature = "vapoursynth")]
17
    Vapoursynth(VapoursynthDecoder),
18
    #[cfg(feature = "ffmpeg")]
19
    Ffmpeg(FfmpegDecoder),
20
}
21
22
impl<R: Read> Decoder<R> {
23
    /// # Errors
24
    ///
25
    /// - If using a Vapoursynth script that contains an unsupported video
26
    ///   format.
27
    #[inline]
28
0
    pub fn get_video_details(&self) -> anyhow::Result<VideoDetails> {
29
0
        match self {
30
0
            Decoder::Y4m(dec) => Ok(crate::y4m::get_video_details(dec)),
31
            #[cfg(feature = "vapoursynth")]
32
            Decoder::Vapoursynth(dec) => dec.get_video_details(),
33
            #[cfg(feature = "ffmpeg")]
34
            Decoder::Ffmpeg(dec) => Ok(dec.video_details),
35
        }
36
0
    }
37
38
    /// # Errors
39
    ///
40
    /// - If a frame cannot be read.
41
    #[inline]
42
0
    pub fn read_video_frame<T: Pixel>(
43
0
        &mut self,
44
0
        video_details: &VideoDetails,
45
0
    ) -> anyhow::Result<Frame<T>> {
46
0
        match self {
47
0
            Decoder::Y4m(dec) => crate::y4m::read_video_frame::<R, T>(dec, video_details),
48
            #[cfg(feature = "vapoursynth")]
49
            Decoder::Vapoursynth(dec) => dec.read_video_frame::<T>(video_details),
50
            #[cfg(feature = "ffmpeg")]
51
            Decoder::Ffmpeg(dec) => dec.read_video_frame::<T>(),
52
        }
53
0
    }
54
}
55
56
#[derive(Debug, Clone, Copy)]
57
pub struct VideoDetails {
58
    pub width: usize,
59
    pub height: usize,
60
    pub bit_depth: usize,
61
    pub chroma_sampling: ChromaSampling,
62
    pub time_base: Rational32,
63
}
64
65
impl Default for VideoDetails {
66
    #[inline]
67
0
    fn default() -> Self {
68
0
        VideoDetails {
69
0
            width: 640,
70
0
            height: 480,
71
0
            bit_depth: 8,
72
0
            chroma_sampling: ChromaSampling::Cs420,
73
0
            time_base: Rational32::new(1, 30),
74
0
        }
75
0
    }
76
}