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:
@@ -94,21 +94,21 @@ impl From<Elapsed> for Error {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "failed to connect to Discord RTP server: ")?;
|
||||
use Error::*;
|
||||
match self {
|
||||
AttemptDiscarded => write!(f, "connection attempt was aborted/discarded"),
|
||||
Crypto(e) => e.fmt(f),
|
||||
CryptoModeInvalid => write!(f, "server changed negotiated encryption mode"),
|
||||
CryptoModeUnavailable => write!(f, "server did not offer chosen encryption mode"),
|
||||
EndpointUrl => write!(f, "endpoint URL received from gateway was invalid"),
|
||||
ExpectedHandshake => write!(f, "voice initialisation protocol was violated"),
|
||||
IllegalDiscoveryResponse => write!(f, "IP discovery/NAT punching response was invalid"),
|
||||
IllegalIp => write!(f, "IP discovery/NAT punching response had bad IP value"),
|
||||
Io(e) => e.fmt(f),
|
||||
Json(e) => e.fmt(f),
|
||||
InterconnectFailure(e) => write!(f, "failed to contact other task ({:?})", e),
|
||||
Ws(e) => write!(f, "websocket issue ({:?}).", e),
|
||||
TimedOut => write!(f, "connection attempt timed out"),
|
||||
Self::AttemptDiscarded => write!(f, "connection attempt was aborted/discarded"),
|
||||
Self::Crypto(e) => e.fmt(f),
|
||||
Self::CryptoModeInvalid => write!(f, "server changed negotiated encryption mode"),
|
||||
Self::CryptoModeUnavailable => write!(f, "server did not offer chosen encryption mode"),
|
||||
Self::EndpointUrl => write!(f, "endpoint URL received from gateway was invalid"),
|
||||
Self::ExpectedHandshake => write!(f, "voice initialisation protocol was violated"),
|
||||
Self::IllegalDiscoveryResponse =>
|
||||
write!(f, "IP discovery/NAT punching response was invalid"),
|
||||
Self::IllegalIp => write!(f, "IP discovery/NAT punching response had bad IP value"),
|
||||
Self::Io(e) => e.fmt(f),
|
||||
Self::Json(e) => e.fmt(f),
|
||||
Self::InterconnectFailure(e) => write!(f, "failed to contact other task ({:?})", e),
|
||||
Self::Ws(e) => write!(f, "websocket issue ({:?}).", e),
|
||||
Self::TimedOut => write!(f, "connection attempt timed out"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,19 +116,19 @@ impl fmt::Display for Error {
|
||||
impl StdError for Error {
|
||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||
match self {
|
||||
Error::AttemptDiscarded => None,
|
||||
Error::AttemptDiscarded
|
||||
| Error::CryptoModeInvalid
|
||||
| Error::CryptoModeUnavailable
|
||||
| Error::EndpointUrl
|
||||
| Error::ExpectedHandshake
|
||||
| Error::IllegalDiscoveryResponse
|
||||
| Error::IllegalIp
|
||||
| Error::InterconnectFailure(_)
|
||||
| Error::Ws(_)
|
||||
| Error::TimedOut => None,
|
||||
Error::Crypto(e) => e.source(),
|
||||
Error::CryptoModeInvalid => None,
|
||||
Error::CryptoModeUnavailable => None,
|
||||
Error::EndpointUrl => None,
|
||||
Error::ExpectedHandshake => None,
|
||||
Error::IllegalDiscoveryResponse => None,
|
||||
Error::IllegalIp => None,
|
||||
Error::Io(e) => e.source(),
|
||||
Error::Json(e) => e.source(),
|
||||
Error::InterconnectFailure(_) => None,
|
||||
Error::Ws(_) => None,
|
||||
Error::TimedOut => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user