use std::time::Duration;
use moq_audio::playback::Input;
use super::window::Event;
pub(super) trait Output: Clone + Send + Sync + 'static {
type Speaker: Speaker;
fn speaker(&self) -> impl Future<Output = anyhow::Result<Self::Speaker>> + Send;
fn send(&self, event: Event);
}
pub(super) trait Speaker: Clone + Send + Sync + 'static {
type Sink: Sink;
fn sink(&self, input: Input) -> anyhow::Result<Self::Sink>;
}
pub(super) trait Sink: Send + Sync + 'static {
fn write(&mut self, samples: &[u8]) -> anyhow::Result<()>;
fn buffered(&self) -> Duration;
}
impl Speaker for moq_audio::playback::Engine {
type Sink = moq_audio::playback::Sink;
fn sink(&self, input: Input) -> anyhow::Result<Self::Sink> {
Ok(moq_audio::playback::Engine::sink(self, input)?)
}
}
impl Sink for moq_audio::playback::Sink {
fn write(&mut self, samples: &[u8]) -> anyhow::Result<()> {
let _ = moq_audio::playback::Sink::write(self, samples)?;
Ok(())
}
fn buffered(&self) -> Duration {
moq_audio::playback::Sink::buffered(self)
}
}