pub trait StreamingFingerprinter {
type Frame;
// Required methods
fn push(&mut self, samples: &[f32]) -> Vec<(TimestampMs, Self::Frame)>;
fn flush(&mut self) -> Vec<(TimestampMs, Self::Frame)>;
fn latency_ms(&self) -> u32;
}Expand description
Streaming fingerprinter that emits zero-or-more frames per push.
Implementations must be non-blocking and bounded-allocation:
any buffers needed for sustained operation are allocated at construction,
not inside StreamingFingerprinter::push. This makes them suitable
for invocation from realtime audio callbacks (when invoked through
audiofp’s streaming orchestrator).
§Example
use audiofp::{StreamingFingerprinter, TimestampMs};
struct EveryThird { count: usize }
impl StreamingFingerprinter for EveryThird {
type Frame = u32;
fn push(&mut self, samples: &[f32]) -> Vec<(TimestampMs, u32)> {
let mut out = Vec::new();
for s in samples {
self.count += 1;
if self.count % 3 == 0 {
out.push((TimestampMs(self.count as u64), s.to_bits()));
}
}
out
}
fn flush(&mut self) -> Vec<(TimestampMs, u32)> { Vec::new() }
fn latency_ms(&self) -> u32 { 0 }
}
let mut fp = EveryThird { count: 0 };
assert_eq!(fp.push(&[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).len(), 2);Required Associated Types§
Required Methods§
Sourcefn push(&mut self, samples: &[f32]) -> Vec<(TimestampMs, Self::Frame)>
fn push(&mut self, samples: &[f32]) -> Vec<(TimestampMs, Self::Frame)>
Feed PCM samples and return any fingerprints that became available during this push.
Must not block and must not allocate beyond the per-instance budget set at construction.
Sourcefn flush(&mut self) -> Vec<(TimestampMs, Self::Frame)>
fn flush(&mut self) -> Vec<(TimestampMs, Self::Frame)>
Drain any pending fingerprint material at end-of-stream.
Sourcefn latency_ms(&self) -> u32
fn latency_ms(&self) -> u32
Conservative upper bound on emission latency: from the time a
sample enters push to the time the fingerprint covering it
is returned.