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("video duration could not be determined")]
51    UnknownDuration,
52
53    #[error("failed to seek to timestamp {0:?}")]
54    SeekFailed(std::time::Duration, #[source] anyhow::Error),
55
56    #[error("GPU adapter not found: {0}")]
57    AdapterNotFound(String),
58
59    #[error("failed to create GPU resources")]
60    GpuResourceCreation(#[source] anyhow::Error),
61
62    #[error("video playback channel disconnected")]
63    ChannelDisconnected,
64
65    #[error("video frame queue is full")]
66    QueueFull,
67
68    #[error("end of stream reached")]
69    EndOfStream,
70}
71
72impl VideoError {
73    /// Returns true if this error is recoverable and playback can continue.
74    pub fn is_recoverable(&self) -> bool {
75        matches!(
76            self,
77            VideoError::DecodeFailed(_) | VideoError::QueueFull | VideoError::InvalidPts
78        )
79    }
80
81    /// Returns true if this error indicates hardware acceleration is unavailable.
82    pub fn is_hardware_unavailable(&self) -> bool {
83        matches!(
84            self,
85            VideoError::HardwareDecoderInit { .. } | VideoError::HardwareDecoderFallback
86        )
87    }
88}