Skip to main content

flexaudio_core/
vad_error.rs

1//! Stable optional-processor failure codes, independent of inference dependencies.
2
3/// Typed cause of an isolated VAD failure.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum VadErrorCode {
6    /// A segmentation parameter is outside the supported domain.
7    InvalidParameter,
8    /// An inference probability is not finite or normalized.
9    InvalidProbability,
10    /// PCM is not finite or normalized.
11    InvalidPcm,
12    /// Checked arithmetic or storage capacity was exceeded.
13    Overflow,
14    /// Processing followed a completed session without reset.
15    SessionFinished,
16    /// Inference or model reset failed.
17    Inference,
18    /// The embedded model could not be constructed.
19    ModelLoad,
20    /// A previous failure requires a successful reset.
21    FailedSession,
22    /// Capture input did not contain complete stereo frames.
23    InvalidStereoLength,
24    /// A capture sample count exceeded the supported domain.
25    CaptureSampleOverflow,
26    /// The capture timestamp exceeded its supported domain.
27    PtsOutOfRange,
28    /// The requested capture tap is unavailable for this binding or configuration.
29    UnsupportedTap,
30    /// Conversion could not establish an exact sample-aligned clock.
31    UnsupportedConversionClock,
32    /// Capture conversion failed.
33    Conversion,
34    /// Processing followed stopped capture intake.
35    Stopped,
36}
37
38impl VadErrorCode {
39    /// Stable code spelling shared by language bindings.
40    pub fn as_str(self) -> &'static str {
41        match self {
42            Self::InvalidParameter => "InvalidParameter",
43            Self::InvalidProbability => "InvalidProbability",
44            Self::InvalidPcm => "InvalidPcm",
45            Self::Overflow => "Overflow",
46            Self::SessionFinished => "SessionFinished",
47            Self::Inference => "Inference",
48            Self::ModelLoad => "ModelLoad",
49            Self::FailedSession => "FailedSession",
50            Self::InvalidStereoLength => "InvalidStereoLength",
51            Self::CaptureSampleOverflow => "CaptureSampleOverflow",
52            Self::PtsOutOfRange => "PtsOutOfRange",
53            Self::UnsupportedTap => "UnsupportedTap",
54            Self::UnsupportedConversionClock => "UnsupportedConversionClock",
55            Self::Conversion => "Conversion",
56            Self::Stopped => "Stopped",
57        }
58    }
59
60    /// Safe explanation of why this processor failed; contains no input or device details.
61    pub fn explanation(self) -> &'static str {
62        match self {
63            Self::InvalidParameter => "a segmentation parameter is outside the supported domain",
64            Self::InvalidProbability => "an inference probability is not finite or normalized",
65            Self::InvalidPcm => "PCM contains a nonfinite or out-of-range sample",
66            Self::Overflow => "checked arithmetic or storage exceeds the supported domain",
67            Self::SessionFinished => {
68                "the completed session requires a successful reset before processing"
69            }
70            Self::Inference => "model inference or reset could not complete",
71            Self::ModelLoad => "the embedded model could not be constructed",
72            Self::FailedSession => "a previous processor failure requires a successful reset",
73            Self::InvalidStereoLength => "capture input does not contain complete stereo frames",
74            Self::CaptureSampleOverflow => "the capture sample count exceeds the supported domain",
75            Self::PtsOutOfRange => "the capture timestamp exceeds the supported domain",
76            Self::UnsupportedTap => "the requested capture tap is unavailable",
77            Self::UnsupportedConversionClock => {
78                "conversion cannot establish an exact sample-aligned clock"
79            }
80            Self::Conversion => "capture conversion could not preserve the valid sample timeline",
81            Self::Stopped => "capture intake has already stopped",
82        }
83    }
84}