servo_media_audio/
sink.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::sync::mpsc::Sender;
6
7use servo_media_streams::MediaSocket;
8
9use crate::block::Chunk;
10use crate::render_thread::{AudioRenderThreadMsg, SinkEosCallback};
11
12#[derive(Debug, PartialEq)]
13pub enum AudioSinkError {
14    /// Backend specific error.
15    Backend(String),
16    /// Could not push buffer into the audio sink.
17    BufferPushFailed,
18    /// Could not move to a different state.
19    StateChangeFailed,
20}
21
22pub trait AudioSink: Send {
23    fn init(
24        &self,
25        sample_rate: f32,
26        render_thread_channel: Sender<AudioRenderThreadMsg>,
27    ) -> Result<(), AudioSinkError>;
28    fn init_stream(
29        &self,
30        channels: u8,
31        sample_rate: f32,
32        socket: Box<dyn MediaSocket>,
33    ) -> Result<(), AudioSinkError>;
34    fn play(&self) -> Result<(), AudioSinkError>;
35    fn stop(&self) -> Result<(), AudioSinkError>;
36    fn has_enough_data(&self) -> bool;
37    fn push_data(&self, chunk: Chunk) -> Result<(), AudioSinkError>;
38    fn set_eos_callback(&self, callback: SinkEosCallback);
39}