Commit Graph

10 Commits

Author SHA1 Message Date
Gnome!
509743fd40 Fix compiling with latest serenity (#199) 2023-11-20 00:02:58 +00:00
Kyle Simpson
3daf11f5d1 Driver: Implement audio scheduler (#179)
This PR implements a custom scheduler for audio threads, which reduces thread use and (often) memory consumption.

To save threads and memory (e.g., packet buffer allocations), Songbird parks Mixer tasks which do not have any live Tracks.
These are now all co-located on a single async 'Idle' task.
This task is responsible for managing UDP keepalive messages for each task, maintaining event state, and executing any Mixer task messages.
Whenever any message arrives which adds a `Track`, the mixer task is moved to a live thread.
The Idle task inspects task counts and execution time on each thread, choosing the first live thread with room, and creating a new one if needed.

Each live thread is responsible for running as many live mixers as it can in a single tick every 20ms: this currently defaults to 16 mixers per thread, but is user-configurable.
A live thread also stores RTP packet blocks to be written into by each sub-task.
Each live thread has a conservative limit of 18ms that it will aim to stay under: if all work takes longer than this, it will offload the task with the highest mixing cost once per tick onto another (possibly new) live worker thread.
2023-11-20 00:02:57 +00:00
Kyle Simpson
f2fbbfeb25 Gateway: Simplify return value of join/join_gateway (#157)
Replaces the annoying dual-return (i.e., created `Call` *and* `Result<x>`) with a single `Return<Call/ConnectionInfo>`. Users are now informed via that a `Call` is created -- thus, cleanup in event of connection failure is now their responsibility.

Tested using `cargo make ready`.

Closes #65.
2023-11-20 00:02:55 +00:00
Kyle Simpson
646190eaf8 Deps: Update Twilight -> v0.14 2023-11-20 00:02:55 +00:00
Kyle Simpson
8cc7a22b0b 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>
2023-11-19 23:58:34 +00:00
Kyle Simpson
d3a40fe691 Examples: support new Serenity Intents init
Fixes up the serenity examples to account for a bunch of API changes on `next`/v0.11.

Tested using `cargo make ready`.
2022-07-22 15:41:18 +01:00
Kyle Simpson
f1ed41ea28 Examples: Fix serenity-next cache accesses (#99)
Serenity's cache design has changed, this (finally) prevents the examples from failing to compile on CI.
2022-07-22 15:41:18 +01:00
Luukas Pörtfors
62ecfe68d6 Examples: Fix unmatched quotation mark in comment. (#101) 2021-10-18 10:59:57 +01:00
Kyle Simpson
dad48ca835 Driver: Fix incorrect leave behaviour in Drop handler
Sending poison messages should suffice to kill the voice session: attempting to `.leave()`. Fixes #88.

This was tested using `cargo make ready` and the modified `serenity/voice/` example.
2021-08-17 12:14:50 +01:00
Alex M. M
f5bf54a63d Move examples from the Serenity repository 2020-11-13 16:20:57 +01:00