skua_voice/input/
compose.rs

1use super::{AudioStream, AudioStreamError, AuxMetadata};
2
3use symphonia_core::io::MediaSource;
4
5/// Data and behaviour required to instantiate a lazy audio source.
6#[async_trait::async_trait]
7pub trait Compose: Send {
8    /// Create a source synchronously.
9    ///
10    /// If [`should_create_async`] returns `false`, this method will chosen at runtime.
11    ///
12    /// [`should_create_async`]: Self::should_create_async
13    fn create(&mut self) -> Result<AudioStream<Box<dyn MediaSource>>, AudioStreamError>;
14
15    /// Create a source asynchronously.
16    ///
17    /// If [`should_create_async`] returns `true`, this method will chosen at runtime.
18    ///
19    /// [`should_create_async`]: Self::should_create_async
20    async fn create_async(&mut self)
21        -> Result<AudioStream<Box<dyn MediaSource>>, AudioStreamError>;
22
23    /// Determines whether this source will be instantiated using [`create`] or [`create_async`].
24    ///
25    /// Songbird will create the audio stream using either a dynamically sized thread pool,
26    /// or a task on the async runtime it was spawned in respectively. Users do not need to
27    /// support both these methods.
28    ///
29    /// [`create_async`]: Self::create_async
30    /// [`create`]: Self::create
31    fn should_create_async(&self) -> bool;
32
33    /// Requests auxiliary metadata which can be accessed without parsing the file.
34    ///
35    /// This method will never be called by songbird but allows, for instance, access to metadata
36    /// which might only be visible to a web crawler e.g., uploader or source URL.
37    async fn aux_metadata(&mut self) -> Result<AuxMetadata, AudioStreamError> {
38        Err(AudioStreamError::Unsupported)
39    }
40}