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>
71 lines
2.0 KiB
Rust
71 lines
2.0 KiB
Rust
use super::*;
|
|
|
|
/// State of an [`Track`] object, designed to be passed to event handlers
|
|
/// and retrieved remotely via [`TrackHandle::get_info`].
|
|
///
|
|
/// [`Track`]: Track
|
|
/// [`TrackHandle::get_info`]: TrackHandle::get_info
|
|
#[derive(Clone, Debug, Default, PartialEq)]
|
|
pub struct TrackState {
|
|
/// Play status (e.g., active, paused, stopped) of this track.
|
|
pub playing: PlayMode,
|
|
|
|
/// Current volume of this track.
|
|
pub volume: f32,
|
|
|
|
/// Current playback position in the source.
|
|
///
|
|
/// This is altered by loops and seeks, and represents this track's
|
|
/// position in its underlying input stream.
|
|
pub position: Duration,
|
|
|
|
/// Total playback time, increasing monotonically.
|
|
pub play_time: Duration,
|
|
|
|
/// Remaining loops on this track.
|
|
pub loops: LoopState,
|
|
|
|
/// Whether this track has been made live, is being processed, or is
|
|
/// currently uninitialised.
|
|
pub ready: ReadyState,
|
|
}
|
|
|
|
impl TrackState {
|
|
pub(crate) fn step_frame(&mut self) {
|
|
self.position += TIMESTEP_LENGTH;
|
|
self.play_time += TIMESTEP_LENGTH;
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::{
|
|
constants::test_data::YTDL_TARGET,
|
|
driver::Driver,
|
|
input::YoutubeDl,
|
|
tracks::Track,
|
|
Config,
|
|
};
|
|
use reqwest::Client;
|
|
|
|
#[tokio::test]
|
|
#[ntest::timeout(10_000)]
|
|
async fn times_unchanged_while_not_ready() {
|
|
let (t_handle, config) = Config::test_cfg(true);
|
|
let mut driver = Driver::new(config.clone());
|
|
|
|
let file = YoutubeDl::new(Client::new(), YTDL_TARGET.into());
|
|
let handle = driver.play(Track::from(file));
|
|
|
|
let state = t_handle
|
|
.ready_track(&handle, Some(Duration::from_millis(5)))
|
|
.await;
|
|
|
|
// As state is `play`, the instant we ready we'll have playout.
|
|
// Naturally, fetching a ytdl request takes far longer than this.
|
|
assert_eq!(state.position, Duration::from_millis(20));
|
|
assert_eq!(state.play_time, Duration::from_millis(20));
|
|
}
|
|
}
|