pub struct FakeVisionEngine { /* private fields */ }Expand description
In-process stand-in for the vision engine + plugin host bridge.
Owns a synthetic frame ring and a queue of pending frames. A test registers
a FrameCallback with on_frame, enqueues synthetic
frames, then calls deliver_all (or
deliver_one) to drive them through the resolver into
the callback. Detections the plugin publishes are captured via the sink
detection_sink returns.
Implementations§
Source§impl FakeVisionEngine
impl FakeVisionEngine
Sourcepub fn new(
camera_id: &str,
width: u32,
height: u32,
format: FrameFormat,
) -> Self
pub fn new( camera_id: &str, width: u32, height: u32, format: FrameFormat, ) -> Self
A fake engine for one camera at a fixed frame size and format. The ring
is sized to hold full width x height frames.
Sourcepub fn with_slot_count(
camera_id: &str,
width: u32,
height: u32,
format: FrameFormat,
slot_count: u32,
) -> Self
pub fn with_slot_count( camera_id: &str, width: u32, height: u32, format: FrameFormat, slot_count: u32, ) -> Self
As new but with an explicit slot count, for tests that
want to force slot recycling and exercise the torn/stale-read drop path.
Sourcepub fn frame_bytes(&self) -> usize
pub fn frame_bytes(&self) -> usize
The frame size of one full frame in this ring’s format.
Sourcepub fn on_frame<F>(&mut self, callback: F)
pub fn on_frame<F>(&mut self, callback: F)
Register the per-frame callback the plugin under test would pass to
ctx.vision.subscribe_frames. Replaces any prior callback.
Sourcepub fn on_frame_arc(&mut self, callback: FrameCallback)
pub fn on_frame_arc(&mut self, callback: FrameCallback)
Register a callback as a pre-built FrameCallback (e.g. the exact
Arc a plugin handed to the SDK).
Sourcepub fn push_frame(&mut self, pixels: Vec<u8>)
pub fn push_frame(&mut self, pixels: Vec<u8>)
Enqueue a raw pixel frame. The bytes must be at most one full frame
(frame_bytes); a shorter slice is delivered as a partial frame, which
is what a real engine does for a truncated capture.
Sourcepub fn push_solid(&mut self, value: u8)
pub fn push_solid(&mut self, value: u8)
Enqueue a frame filled with one byte value (a flat colour), sized to a full frame. Handy for asserting the callback sees the right bytes.
Sourcepub fn push_dir(&mut self, dir: impl AsRef<Path>) -> Result<usize>
pub fn push_dir(&mut self, dir: impl AsRef<Path>) -> Result<usize>
Enqueue every *.bin / *.raw file in dir (sorted by name) as a
frame, reading each file’s bytes verbatim. Returns the count enqueued.
Sourcepub fn deliver_one(&mut self) -> bool
pub fn deliver_one(&mut self) -> bool
Deliver the next pending frame: write it into the ring, build its
descriptor, resolve it through the seqlock, and invoke the callback.
Returns true if a frame was delivered (a frame existed and resolved),
false if the queue was empty. A frame that fails to resolve (a forced
torn read) returns true for “consumed” but does not fire the callback.
Sourcepub fn deliver_all(&mut self) -> usize
pub fn deliver_all(&mut self) -> usize
Deliver every pending frame in order. Returns the number delivered.
Sourcepub fn detection_sink(&self) -> Arc<Mutex<Vec<CapturedDetection>>> ⓘ
pub fn detection_sink(&self) -> Arc<Mutex<Vec<CapturedDetection>>> ⓘ
The shared detection sink. Pass this into a plugin (or call
capture directly) so detections the plugin would
publish via ctx.vision.publish_detection are recorded here.
Sourcepub fn capture(&self, batch: DetectionBatch)
pub fn capture(&self, batch: DetectionBatch)
Record a detection batch the plugin under test published, as if the engine received it. A test that cannot route the real publish call can invoke this from a stubbed publish path.
Sourcepub fn captured_detections(&self) -> Vec<CapturedDetection> ⓘ
pub fn captured_detections(&self) -> Vec<CapturedDetection> ⓘ
The captured detections in publish order. Returns a copy.
Sourcepub fn clear_captured(&self)
pub fn clear_captured(&self)
Clear the captured detections.