Skip to main content

nv_view/
validity.rs

1//! Context validity and degradation reasons.
2
3/// Whether temporal state is valid under the current camera view.
4///
5/// Stages and output consumers use this to decide how much to trust
6/// spatial relationships derived from temporal state.
7#[derive(Clone, Debug, PartialEq)]
8pub enum ContextValidity {
9    /// View is stable; all temporal state within this epoch is valid.
10    Valid,
11
12    /// View is changing; temporal state is degraded.
13    ///
14    /// Tracks and trajectories from earlier in this epoch may be unreliable
15    /// for direct spatial comparison with current-frame positions.
16    Degraded { reason: DegradationReason },
17
18    /// View has changed so much that prior context is invalid.
19    ///
20    /// A new epoch has been (or should be) opened.
21    Invalid,
22}
23
24/// Why temporal context is degraded.
25#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
26pub enum DegradationReason {
27    /// Camera is performing a PTZ move.
28    PtzMoving,
29    /// A large sudden jump was detected.
30    LargeJump,
31    /// The zoom level changed significantly.
32    ZoomChange,
33    /// Occlusion or blur degraded the frame.
34    OcclusionOrBlur,
35    /// Motion was inferred from video with low confidence.
36    InferredMotionLowConfidence,
37    /// Reason is unspecified or could not be determined.
38    Unknown,
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn valid_is_not_degraded() {
47        let v = ContextValidity::Valid;
48        assert!(!matches!(v, ContextValidity::Degraded { .. }));
49        assert!(!matches!(v, ContextValidity::Invalid));
50    }
51
52    #[test]
53    fn degraded_carries_reason() {
54        let v = ContextValidity::Degraded {
55            reason: DegradationReason::PtzMoving,
56        };
57        match v {
58            ContextValidity::Degraded { reason } => {
59                assert_eq!(reason, DegradationReason::PtzMoving);
60            }
61            _ => panic!("expected Degraded"),
62        }
63    }
64
65    #[test]
66    fn degradation_reasons_are_distinct() {
67        assert_ne!(DegradationReason::PtzMoving, DegradationReason::LargeJump);
68        assert_ne!(DegradationReason::ZoomChange, DegradationReason::Unknown);
69    }
70
71    #[test]
72    fn invalid_is_terminal() {
73        let v = ContextValidity::Invalid;
74        assert!(matches!(v, ContextValidity::Invalid));
75    }
76}