Driver/Input: Migrate audio backend to Symphonia (#89)
This extensive PR rewrites the internal mixing logic of the driver to use symphonia for parsing and decoding audio data, and rubato to resample audio. Existing logic to decode DCA and Opus formats/data have been reworked as plugins for symphonia. The main benefit is that we no longer need to keep yt-dlp and ffmpeg processes alive, saving a lot of memory and CPU: all decoding can be done in Rust! In exchange, we now need to do a lot of the HTTP handling and resumption ourselves, but this is still a huge net positive. `Input`s have been completely reworked such that all default (non-cached) sources are lazy by default, and are no longer covered by a special-case `Restartable`. These now span a gamut from a `Compose` (lazy), to a live source, to a fully `Parsed` source. As mixing is still sync, this includes adapters for `AsyncRead`/`AsyncSeek`, and HTTP streams. `Track`s have been reworked so that they only contain initialisation state for each track. `TrackHandles` are only created once a `Track`/`Input` has been handed over to the driver, replacing `create_player` and related functions. `TrackHandle::action` now acts on a `View` of (im)mutable state, and can request seeks/readying via `Action`. Per-track event handling has also been improved -- we can now determine and propagate the reason behind individual track errors due to the new backend. Some `TrackHandle` commands (seek etc.) benefit from this, and now use internal callbacks to signal completion. Due to associated PRs on felixmcfelix/songbird from avid testers, this includes general clippy tweaks, API additions, and other repo-wide cleanup. Thanks go out to the below co-authors. Co-authored-by: Gnome! <45660393+GnomedDev@users.noreply.github.com> Co-authored-by: Alakh <36898190+alakhpc@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use super::*;
|
||||
use crate::events::EventData;
|
||||
use flume::Sender;
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
/// A request from external code using a [`TrackHandle`] to modify
|
||||
/// or act upon an [`Track`] object.
|
||||
@@ -21,37 +24,42 @@ pub enum TrackCommand {
|
||||
/// Seek to the given duration.
|
||||
///
|
||||
/// On unsupported input types, this can be fatal.
|
||||
Seek(Duration),
|
||||
Seek(SeekRequest),
|
||||
/// Register an event on this track.
|
||||
AddEvent(EventData),
|
||||
/// Run some closure on this track, with direct access to the core object.
|
||||
Do(Box<dyn FnOnce(&mut Track) + Send + Sync + 'static>),
|
||||
Do(Box<dyn FnOnce(View) -> Option<Action> + Send + Sync + 'static>),
|
||||
/// Request a copy of this track's state.
|
||||
Request(Sender<TrackState>),
|
||||
/// Change the loop count/strategy of this track.
|
||||
Loop(LoopState),
|
||||
/// Prompts a track's input to become live and usable, if it is not already.
|
||||
MakePlayable,
|
||||
MakePlayable(Sender<Result<(), PlayError>>),
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for TrackCommand {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
use TrackCommand::*;
|
||||
impl Debug for TrackCommand {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(
|
||||
f,
|
||||
"TrackCommand::{}",
|
||||
match self {
|
||||
Play => "Play".to_string(),
|
||||
Pause => "Pause".to_string(),
|
||||
Stop => "Stop".to_string(),
|
||||
Volume(vol) => format!("Volume({})", vol),
|
||||
Seek(d) => format!("Seek({:?})", d),
|
||||
AddEvent(evt) => format!("AddEvent({:?})", evt),
|
||||
Do(_f) => "Do([function])".to_string(),
|
||||
Request(tx) => format!("Request({:?})", tx),
|
||||
Loop(loops) => format!("Loop({:?})", loops),
|
||||
MakePlayable => "MakePlayable".to_string(),
|
||||
Self::Play => "Play".to_string(),
|
||||
Self::Pause => "Pause".to_string(),
|
||||
Self::Stop => "Stop".to_string(),
|
||||
Self::Volume(vol) => format!("Volume({})", vol),
|
||||
Self::Seek(s) => format!("Seek({:?})", s.time),
|
||||
Self::AddEvent(evt) => format!("AddEvent({:?})", evt),
|
||||
Self::Do(_f) => "Do([function])".to_string(),
|
||||
Self::Request(tx) => format!("Request({:?})", tx),
|
||||
Self::Loop(loops) => format!("Loop({:?})", loops),
|
||||
Self::MakePlayable(_) => "MakePlayable".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct SeekRequest {
|
||||
pub time: Duration,
|
||||
pub callback: Sender<Result<Duration, PlayError>>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user