Commit Graph

198 Commits

Author SHA1 Message Date
Kyle Simpson
6f801563e5 Chore: Rust 1.72.0 Clippy lints, adjust MSRV
MSRV was bumped by serenity-next, and so we too must follow suit.
2023-11-20 00:02:58 +00:00
Sebbl0508
77a9b4626c Driver: Replace xsalsa20poly1305 with crypto_secretbox (#198)
As of v0.9.1, `xsalsa20poly1305` has been deprecated. This is a mostly seamless replacement, as it appears to be the same crate authors / code / etc.

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-20 00:02:57 +00:00
Jonathan
5ddc8f4448 Chore(ci): Update rust, cargo and cache actions (#177)
* chore(ci): Update rust setup and cache action
* chore(ci): Remove legacy-tokio from test matrix

This was removed as it doesn't seem to be used any more.
2023-11-20 00:02:57 +00:00
Jonathan
4eadeb6834 chore(docs): Update rust setup action and cache (#176)
This PR changes the following things in the docs workflow:
- Move from the deprecated actions-rs action to the maintained alternative of dtolnay https://github.com/dtolnay/rust-toolchain
- Instead of manually defining the cache paths and the cache keys, I moved to an action that handles this for us: https://github.com/Swatinem/rust-cache
- As github decided at some point that the generated `GITHUB_TOKEN` secret will only have read-only permissions (for new repos), unless you tell them to be different, I added the `permissions` key to the job. This will not affect this repository, but will affect e.g. new forks (the workflow will not throw an permissions error any more - Read more here: https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ )
2023-11-20 00:02:57 +00:00
Jonathan
841224ee7a chore(workflows): Update checkout action to v3 (#175)
This change was done as the v2 version still used the node v12 runtime.
This runtime is deprecated by github. There are no other breaking
changes done by the action. With the update to v3 now node v16 is used
as runtime.

You can read more about the changes from v2 to v3 here:
https://github.com/actions/checkout/releases/tag/v3.0.0
2023-11-20 00:02:57 +00:00
Kyle Simpson
9ab5be8c9f Driver: Retune threadpool keepalive time 2023-11-20 00:02:57 +00:00
Kyle Simpson
c55a3130d6 Chore: Update test URL for playlist.
One of our tests had begun to fail on account of a change Youtube-side.
2023-11-20 00:02:57 +00:00
Kyle Simpson
019ac27a85 Driver: Don't trim recv_buffer on MacOS
This should fix #193 -- it seems that a zero-size recv buffer is an invalid argument as far as darwin is concerned.

Tested with `cargo make ready`.
2023-11-20 00:02:57 +00:00
Kyle Simpson
02c9812c3e Driver: Downgrade failed scheduler message delivery to info 2023-11-20 00:02:57 +00:00
Kyle Simpson
77e3916bdc Driver: Fix scheduler crash after task closure
A removed audio task could still have one or more driver messages left in its queue, leading to a crash when the id->mixer lookup failed. This removes an unwrap which is invalid under these assumptions and includes an extra cleanup measure for message forwarders under the same circumstances.

This was tested using `cargo make ready`.
2023-11-20 00:02:57 +00:00
Max Campbell
c976d50cc5 Input: Add HTTP Status Code Checks (#190)
`HttpRequest`s will now return an `AudioStreamError::Fail` on receipt of a non-2xx status code from a server. This has the advantage of making it clearer *why* a failure occurred rather than leaving users to piece the truth together from a Symphonia parsing error.

Closes #184.
2023-11-20 00:02:57 +00:00
Kyle Simpson
9fa063ff0e Chore: Clippy fixes to match new MSRV. 2023-11-20 00:02:57 +00:00
Kyle Simpson
1bf17d128e Chore: Update dependencies, MSRV.
Tested using `cargo make ready`.
2023-11-20 00:02:57 +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
a5f7d3f488 Chore: Update dependencies.
Updates simd-json -> 0.8, socket2 -> 0.5.

Tested using `cargo make ready`.
2023-11-20 00:02:56 +00:00
Erk
500d679ae5 Fix: Move WS error handling (#174)
Moves all WS handling of unexpected payloads into the stream to prevent code duplication.

This also prevents non-{Hello,Resumed,Ready} messages from causing a handshake failure, as it seems Discord do not prevent such messages from appearing.

---------

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-20 00:02:56 +00:00
0/0
4d0c1c030d Gateway: Fix serenity breaking changes (#173)
Fix issues caused by serenity-rs/serenity#2372 and serenity-rs/serenity#2380.

Additionally, this Boxes the TrySendError from Serenity at Clippy's behest (causing a ~330B Result type).

---------

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-20 00:02:56 +00:00
Alex M. M
7f519d0503 Chore: Release v0.3.2 2023-11-20 00:02:56 +00:00
Erk
c73f4988c8 fix(ws): Songbird would fail if it could not deserialize ws payload. (#170)
Receiving a new opcode while connecting to a voice channel was causing the connection to fail, while this was handled correctly elsewhere. Unfortunately, Discord added such a payload during every connection.

This PR moves the logging and conversion to no-op (and log) to catch both locations.
2023-11-20 00:02:56 +00:00
Kyle Simpson
5eeeee4f37 Chore: Release v0.3.1 2023-11-20 00:02:56 +00:00
Kyle Simpson
50dbc62a6a Chore: Fix README.md CI badge (#161) 2023-11-20 00:02:56 +00:00
Kyle Simpson
6cd3097da0 Repo: Update issue templates 2023-11-20 00:02:56 +00:00
Erk
b2507f34f1 Gateway: Twilight 0.15 support (#171)
This patch changes around quite a few things.
The main entrypoint for twilight besides process will now be the
TwilightMap which concists of command senders for each shard.

This simplifies parts of the code as there is not any difference
between shards and clusters anymore.
2023-11-20 00:02:56 +00:00
fee1-dead
3f6114c53c Docs: Fix a link in constant docstring (#169) 2023-11-20 00:02:56 +00:00
fee1-dead
296f0e552c Input: Pass --no-playlist for YoutubeDl (#168)
If a link such as [this](https://www.youtube.com/watch?v=ygY2qObZv24&list=RDygY2qObZv24)
is passed to `YoutubeDl` without the option, it would cause a deadlock
in my bot.

There were many videos where it produced a `Silent` packet first instead
of mixed or passthrough. The URL I added was one that produced a
passthrough packet so I used that. Please let me know if this is wrong.
2023-11-20 00:02:56 +00:00
fee1-dead
6e6d8e7ebf Chore: Fix clippy warnings (#167) 2023-11-20 00:02:56 +00:00
fee1-dead
5bc843047f Gateway: Add Songbird::iter (#166)
This PR allows users to iterate over all existing `Call`s via the `Songbird::iter` method.

Closes #165.
2023-11-20 00:02:56 +00:00
Kyle Simpson
2de071f921 CI: Disable Windows, MacOS Testing
Windows CI runners appear to be very slow wrt. the time limits we've set for many of the tests, so fail for tests involving longer files. At the same time, MacOS tests aren't likely to add much value over Linux.

This commit disables *test* runners for these environments to remove a lot of commit/PR noise. Builds are still run on these platforms.
2023-11-20 00:02:56 +00:00
Kyle Simpson
50fa17fb59 Input: Fix high CPU use when initialising long files over HTTP (#163)
Fixes the possibility of a spinlock while reading bytes from an async->sync adapter. This case can be observed with long (e.g., 10 hours of silence) videos which seem to be served slower than we would like to parse their headers.

The fix moves most communication to blocking: `read` calls first parse all messages form the async context in a non-blocking way, then swap to blocking if no bytes are available.

Tested using `cargo make ready` and "examples/serenity/voice" against the URL https://www.youtube.com/watch?v=g4mHPeMGTJM.
2023-11-20 00:02:56 +00:00
Kyle Simpson
53ebc3c637 Input: Clarify YoutubeDl error if command missing (#160)
Converts any `io::ErrorKind::NotFound` from `TokioCommand` into a more useful string for users, e.g., `"could not find executable 'yt-dlp' on path"`.

Tested using `cargo make ready`.
2023-11-20 00:02:56 +00:00
Kyle Simpson
ed4be7c607 Docs: Correct version for symphonia codec support 2023-11-20 00:02:56 +00:00
Kyle Simpson
fdd0d830c7 Deps: Move to published symphonia v0.5.2 from git
Symphonia v0.5.2 has all the API changes and fixes we were depending on, which leaves next one step closer to publishable.

Tested using `cargo make ready`.
2023-11-20 00:02:56 +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
5d06a429a8 Chore: Update tokio-tungstenite, typemap_rev 2023-11-20 00:02:55 +00:00
Kyle Simpson
125c803fa7 Chore: Apply latest nightly clippy lints 2023-11-20 00:02:55 +00:00
Kyle Simpson
c60c454cf5 Driver/receive: Implement audio reorder/jitter buffer (#156)
This PR Introduces a new `VoiceTick` event which collects and reorders all RTP packets to smooth over network instability, as well as to synchronise user audio streams. Raw packet events have been moved to `RtpPacket`, while `SpeakingUpdate`s have been removed as they can be easily computed using the `silent`/`speaking` audio maps included in each event.

Closes #146.
2023-11-20 00:02:55 +00:00
Kyle Simpson
ab18f9e092 Driver: remove copy to receive &mut for softclip (#143)
This PR makes use of `SampleBuffer::samples_mut` to remove a 7680B stack allocation in general, and memcopy when softclip is used. This appears to offer ~1.5% performance boost according to `cargo make bench`.
2023-11-20 00:02:55 +00:00
Kyle Simpson
b7e40ab5e4 Deps: Move symphonia back to mainline repo.
Temporary measure until symphonia 0.5.2 is released. Should allow us to merge #143 now that all our API additions and fixes are in.
2023-11-20 00:02:55 +00:00
Kyle Simpson
f72175b799 Deps: Update dev-dependencies 2023-11-20 00:02:55 +00:00
Kyle Simpson
6a38fc82f4 Deps: Update Ringbuf, Serde-Aux, Simd-Json, Typemap 2023-11-20 00:02:55 +00:00
Kyle Simpson
662debd414 Chore: Fix new(er) Clippy lints 2023-11-20 00:02:55 +00:00
Kyle Simpson
646190eaf8 Deps: Update Twilight -> v0.14 2023-11-20 00:02:55 +00:00
Gnome!
be3a4e9b24 Avoid spawning a disposal thread per driver (#151)
Adds a new field to Config, disposer, an Option<Sender<DisposalMessage>> responsible for dropping the DisposalMessage on a separate thread.

If this is not set, and the Config is passed into manager::Songbird, a thread is spawned for this purpose (which previously was spawned per driver).
If this is not set, and the Config is passed directly into Driver or Call, a thread is spawned locally, which is the current behavior as there is no where to store the Sender.

This disposer is then used in Driver as previously, to run possibly blocking destructors (which should only block the disposal thread). I cannot see this disposal thread getting overloaded, but if it is the DisposalMessages will simply be queued in the flume channel until it can be dropped.

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-20 00:02:55 +00:00
Kyle Simpson
03b0803a1d Input: Fix audio stream selection for video files. (#150)
`youtube-dl` has a tendency to return mp4 files containing video and audio data vs `yt-dlp`. Naturally, the default stream in such cases will be the video data, so we fail to create a decoder.

This PR changes `LiveInput::promote` to first attempt to instantiate a decoder for the default track. If this fails to do so, then we reattempt this for all available tracks until one can be found. Previously, this method chose the default (or first available) track ID, and then failed if *that* track could not be decoded even if a compatible stream existed.

This was tested using `cargo make ready`, as well as manually verifying and adding a test case with a simple mp4 file.
2023-11-20 00:02:54 +00:00
Erk
372156e638 Deps: Update twilight to 0.13 (#147)
* update twilight to 0.13

* Update src/manager.rs

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-20 00:02:54 +00:00
Kyle Simpson
48db45ffd8 Chore: Update xsalsa20poly1305 -> 0.9
A few extra error types needed adding and handling due to the new `KeyInit::new_from_slice` returning a non-exported error.
2023-11-20 00:02:54 +00:00
Kyle Simpson
893dbaae34 Driver: Prune SsrcState after timeout/disconnect (#145)
`SsrcState` objects are created on a per-user basis when "receive" is enabled, but were previously never destroyed. This PR adds some shared dashmaps for the WS task to communicate SSRC-to-ID mappings to the UDP Rx task, as well as any disconnections. Additionally, decoder state is pruned a default 1 minute after a user last speaks.

This was tested using `cargo make ready` and via `examples/serenity/voice_receive/`.

Closes #133
2023-11-20 00:02:54 +00:00
0/0
6769131fa2 Events: Fix typo in docs for VoiceData (#142) 2023-11-20 00:02:54 +00:00
Kyle Simpson
2277595be4 Driver: Split receive into its own feature (#141)
Adds the "receive" feature, which is disabled by default. When this is disabled, the UDP receive task is not compiled and not run, and as an optimisation the UDP receive buffer size is set to 0. All related events are also removed.

This also removes the UDP Tx task, and moves packet and keepalive sends back into the mixer thread. This allows us to entirely remove channels and various allocations between the mixer and an async task created only for sending data (i.e., fewer memcopies).

If "receive" is enabled, UDP sends are now non-blocking due to technical constraints -- failure to send is non-fatal, but *will* drop affected packets. Given that blocking on a UDP send indicates that the OS cannot clear send buffers fast enough, this should alleviate OS load.

Closes #131.
2023-11-20 00:02:54 +00:00
Kyle Simpson
c1d93f790c Docs: Fix module docs for songbird::tracks.
Module docs mistakenly used the old doc-link format, so removing `create_player` never fired an error! These have also been partially rewritten to explain the role of `Track` and `TrackHandle`.

Includes some other misc fixes to links, mention of `TrackHandle::action` for metadata handling, etc.

Closes #140.
2023-11-20 00:02:54 +00:00