hypetrigger/
trigger.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::{
    async_trigger::{AsyncTrigger, TriggerCommand},
    error::Result,
};
use image::RgbImage;
use std::sync::mpsc::SyncSender;

/// Represents a single frame of the input, including the raw image pixels as
/// well as the time it appears in the input (frame_num and/or timestamp)
#[derive(Clone, Debug, PartialEq)]
pub struct Frame {
    pub image: RgbImage,
    pub frame_num: u64,
    pub timestamp: f64,
}

//// Triggers
pub trait Trigger: Send + Sync {
    fn on_frame(&self, frame: &Frame) -> Result<()>;

    /// Convert this Trigger into a `AsyncTrigger`, running on a separate thread.
    fn into_async(self, runner_tx: SyncSender<TriggerCommand>) -> AsyncTrigger
    where
        Self: Sized + 'static,
    {
        AsyncTrigger::from_trigger(self, runner_tx)
    }
}