kithara_audio/worker/
traits.rs1use kithara_decode::PcmChunk;
2use kithara_stream::Timeline;
3
4use crate::{pipeline::track_fsm, traits::AudioEffect};
5
6mod kithara {
7 pub(crate) use kithara_test_macros::mock;
8}
9
10#[kithara::mock(api = MockAudioWorkerSource, type Chunk = PcmChunk;)]
16pub trait AudioWorkerSource: Send + 'static {
17 type Chunk: Send + 'static;
18
19 fn step_track(&mut self) -> track_fsm::TrackStep<Self::Chunk>;
29
30 fn timeline(&self) -> &Timeline;
32}
33
34pub(crate) fn apply_effects(
36 effects: &mut [Box<dyn AudioEffect>],
37 mut chunk: PcmChunk,
38) -> Option<PcmChunk> {
39 for effect in &mut *effects {
40 chunk = effect.process(chunk)?;
41 }
42 Some(chunk)
43}
44
45pub(crate) fn flush_effects(effects: &mut [Box<dyn AudioEffect>]) -> Option<PcmChunk> {
47 let mut chunk: Option<PcmChunk> = None;
48 for effect in &mut *effects {
49 chunk = match chunk.take() {
50 Some(input) => effect.process(input),
51 None => effect.flush(),
52 };
53 }
54 chunk
55}
56
57pub(crate) fn reset_effects(effects: &mut [Box<dyn AudioEffect>]) {
59 for effect in &mut *effects {
60 effect.reset();
61 }
62}