Skip to main content

nv_runtime/
backpressure.rs

1//! Backpressure policy configuration.
2
3/// Controls queue behavior between pipeline stages.
4///
5/// Applied to the bounded channel between the GStreamer decode thread
6/// and the stage execution thread.
7#[derive(Debug, Clone)]
8pub enum BackpressurePolicy {
9    /// Drop the oldest frame in the queue to make room for new ones.
10    ///
11    /// This is the default — real-time perception prefers fresh frames
12    /// over stale ones.
13    DropOldest {
14        /// Maximum number of frames in the queue.
15        queue_depth: usize,
16    },
17
18    /// Drop the incoming frame if the queue is full.
19    DropNewest {
20        /// Maximum number of frames in the queue.
21        queue_depth: usize,
22    },
23
24    /// Block the producer until space is available.
25    ///
26    /// Use with caution — can cause GStreamer buffer buildup.
27    Block {
28        /// Maximum number of frames in the queue.
29        queue_depth: usize,
30    },
31}
32
33impl BackpressurePolicy {
34    /// Returns the configured queue depth.
35    #[must_use]
36    pub fn queue_depth(&self) -> usize {
37        match self {
38            Self::DropOldest { queue_depth }
39            | Self::DropNewest { queue_depth }
40            | Self::Block { queue_depth } => *queue_depth,
41        }
42    }
43}
44
45impl Default for BackpressurePolicy {
46    fn default() -> Self {
47        Self::DropOldest { queue_depth: 4 }
48    }
49}