Skip to main content

wallr_core/video/
error.rs

1//! Error types for video wallpaper operations.
2
3use std::path::PathBuf;
4
5pub type VideoResult<T> = Result<T, VideoError>;
6
7#[derive(Debug, thiserror::Error)]
8pub enum VideoError {
9    #[error("failed to open video file: {path}")]
10    FileOpen {
11        path: PathBuf,
12        #[source]
13        source: std::io::Error,
14    },
15
16    #[error("unsupported video format: {0}")]
17    UnsupportedFormat(String),
18
19    #[error("no video stream found in {0}")]
20    NoVideoStream(PathBuf),
21
22    #[error("video codec not supported: {0}")]
23    UnsupportedCodec(String),
24
25    #[error("hardware decoder initialization failed: {backend}")]
26    HardwareDecoderInit {
27        backend: String,
28        #[source]
29        source: anyhow::Error,
30    },
31
32    #[error("all hardware decoders failed, falling back to software")]
33    HardwareDecoderFallback,
34
35    #[error("software decoder initialization failed")]
36    SoftwareDecoderInit(#[source] anyhow::Error),
37
38    #[error("failed to decode video frame")]
39    DecodeFailed(#[source] anyhow::Error),
40
41    #[error("failed to convert frame format")]
42    FormatConversionFailed(#[source] anyhow::Error),
43
44    #[error("failed to upload frame to GPU texture")]
45    TextureUploadFailed(#[source] anyhow::Error),
46
47    #[error("invalid presentation timestamp")]
48    InvalidPts,
49
50    #[error("invalid video duration: {0}")]
51    InvalidDuration(String),
52
53    #[error("video duration could not be determined")]
54    UnknownDuration,
55
56    #[error("failed to seek to timestamp {0:?}")]
57    SeekFailed(std::time::Duration, #[source] anyhow::Error),
58
59    #[error("GPU adapter not found: {0}")]
60    AdapterNotFound(String),
61
62    #[error("failed to create GPU resources")]
63    GpuResourceCreation(#[source] anyhow::Error),
64
65    #[error("video playback channel disconnected")]
66    ChannelDisconnected,
67
68    #[error("video frame queue is full")]
69    QueueFull,
70
71    #[error("end of stream reached")]
72    EndOfStream,
73}
74
75impl VideoError {
76    /// Returns true if this error is recoverable and playback can continue.
77    pub fn is_recoverable(&self) -> bool {
78        matches!(
79            self,
80            VideoError::DecodeFailed(_) | VideoError::QueueFull | VideoError::InvalidPts
81        )
82    }
83
84    /// Returns true if this error indicates hardware acceleration is unavailable.
85    pub fn is_hardware_unavailable(&self) -> bool {
86        matches!(
87            self,
88            VideoError::HardwareDecoderInit { .. } | VideoError::HardwareDecoderFallback
89        )
90    }
91}