(static_audio_lookup: Option<fn(u64) -> &'static [u8]>)
| 41 | tx: Sender<AudioCommand>, |
| 42 | next_playback_id: Arc<AtomicU64>, |
| 43 | source_pool: Mutex<HashMap<u64, Arc<str>>>, |
| 44 | loaded: Arc<Mutex<AudioLoadedState>>, |
| 45 | } |
| 46 | |
| 47 | #[derive(Default)] |
| 48 | struct AudioLoadedState { |
| 49 | sources: HashSet<Arc<str>>, |
| 50 | soundfonts: HashSet<perro_ids::SoundFontID>, |
| 51 | } |
| 52 | |
| 53 | #[derive(Clone)] |
| 54 | pub struct AudioSourceHandle { |
| 55 | source: Arc<str>, |
| 56 | } |
| 57 | |
| 58 | impl AudioSourceHandle { |
| 59 | #[must_use] |
| 60 | pub fn as_str(&self) -> &str { |
| 61 | &self.source |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | fn run_audio_worker<F>( |
| 66 | static_audio_lookup: Option<fn(u64) -> &'static [u8]>, |
| 67 | player_factory: F, |
| 68 | commands: &Receiver<AudioCommand>, |
| 69 | startup: &Sender<Result<(), String>>, |
| 70 | loaded: &Mutex<AudioLoadedState>, |
| 71 | ) where |
| 72 | F: FnOnce(Option<fn(u64) -> &'static [u8]>) -> Result<BarkPlayer, String>, |
| 73 | { |
| 74 | let player = match player_factory(static_audio_lookup) { |
| 75 | Ok(player) => player, |
| 76 | Err(err) => { |
| 77 | let _ = startup.send(Err(err)); |
| 78 | return; |
| 79 | } |
| 80 | }; |
| 81 | if startup.send(Ok(())).is_err() { |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | while let Ok(command) = commands.recv() { |
| 86 | process_audio_command(&player, command, loaded); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | fn set_source_loaded(loaded: &Mutex<AudioLoadedState>, source: &Arc<str>, value: bool) { |
| 91 | let Ok(mut loaded) = loaded.lock() else { |
| 92 | return; |
| 93 | }; |
| 94 | if value { |
| 95 | loaded.sources.insert(Arc::clone(source)); |
| 96 | } else { |
| 97 | loaded.sources.remove(source); |
| 98 | } |
| 99 | } |
| 100 |
nothing calls this directly
no test coverage detected