Commit Graph

68 Commits

Author SHA1 Message Date
Kyle Simpson
a88b185676 Deps: Prevent MSRV breakage via spinning_top (#64)
The upstream crate `spinning_top` used newer elements of rustc's std in a patch release, unknowingly bumping its MSRV to 1.49.0. This patch reverts to the older, compatible, version.

This has been tested by manually building `examples/serenity/voice` using rustc v1.48.0.

Closes #62.
2021-04-10 22:56:30 +01:00
Kyle Simpson
24d8da69c0 Driver: Fix crash on .leave() (#63)
Leaving (rather than removing) a call would cause the driver to crash as it would try to use a non-existent connection immediately after it had been invalidated.

This has been tested using a modified `examples/serenity/voice_storage`, felyne, and via `cargo make ready`.
2021-04-10 22:44:17 +01:00
Douman
22214a0f89 Gateway: Introduce Call::current_channel (#60)
* Introduce Call::current_channel

* Add note on channel id
2021-04-10 13:19:59 +01:00
Kyle Simpson
df64ad92e5 Release v0.1.5 2021-03-23 09:09:09 +00:00
Kyle Simpson
f230b41110 Deps: Update async-tungstenite -> 0.13 (#50)
Updates to the latest async-tungstenite version. This was tested by `cargo make ready` and by testing driver/gateway function via `examples/serenity/voice_storage`.
2021-03-23 08:22:38 +00:00
Kyle Simpson
db7994087a Gateway: Allow connection info to be retrieved (#49)
This is a simple addition to allow current connection state to be retrieved *after* establishment, even when using the voice driver.

This has been tested using `cargo make ready`, as it is fairly simple functionality.
2021-03-22 20:50:35 +00:00
Kyle Simpson
a3f86ad34d Driver: Reduce logging level in general (#48)
This change reduces many log levels to debug, particularly where errors are likely to be triggered by undocumented Discord messages or by threads exiting in an unpredictable way. This also reduces the task entry/exit messages to `trace`.

This PR has been tested via `cargo make ready`, and by manually inspecting logs at `debug` and `info` levels running `examples/serenity/voice`.
2021-03-22 19:00:19 +00:00
Kyle Simpson
1fcc8c0eb9 Repo: Organise and document processes and architecture (#43)
* Add Makefile for common contributor tasks

Narrows down a few commands to automatically format when building, and neatly expose testing/benching.

Empty files added to describe contributor guidelines, overall architecture.

* First draft of contributor guidelines

* Simple architecture diagrams

* Add PNG variants of architecture diagrams

Swapping to these because not having Fira Sans installed on a viewing machine leads to terrible kerning.

* Architecture description.

* MD cross-refs.
2021-03-18 20:54:07 +00:00
Kyle Simpson
a9b4cb7715 Prevent mixer thread from waking while inactive (#46)
This change prevents mixer threads from waking every 20ms without an active voice connection. This was leading to unacceptably high CPU usage in cases where users needed to preserve this state between many active connections. Additionally, this modifies the documentation of `Songbird::leave` to emphasise why users would prefer to `remove` their calls.

This was tested by examining the CPU usage in task manager before and after the change was made, using a control of 10k manually created `Driver` instances. After creation is finished, the Drivers no longer saturate a 6-core laptop Intel i7 (while they very much did so before).

Closes #42.
2021-03-14 17:18:24 +00:00
DasEtwas
c488ce3dc9 Fix input source timestamp pre-input argument decimal formatting (#45) 2021-03-13 10:17:26 +00:00
Kyle Simpson
b9a926c125 Break reference cycle in voice storage example (#44)
Changes a stored `Arc` pointer to the call (used to queue up further tracks in response to events) into a `Weak`, as the event handler's strong pointer would keep the Call and Driver objects alive. This would have caused an unintentional resource leak of threads/tasks. This was found by some internal profiling in search of #42.
2021-03-11 22:58:30 +00:00
Kyle Simpson
dd49c5d99f Release v0.1.4 2021-02-10 16:53:20 +00:00
Kyle Simpson
f3f52427ea Events: Add SsrcKnown event
Knowing your own SSRC is useful for handling RTCP packets, which may detail information about *ourselves* rather than another host. In theory, at least: this confirms that Discord just sends ReceiverReports containing your own packet stats.

This would have been better to fit into Driver(Re)Connect, but that would be a breaking change: when this change is made, `SsrcKnown` shall be deprecated.
2021-02-10 14:33:34 +00:00
Kyle Simpson
a40fac3109 Deps: Update async-tungstenite -> 0.12
This is a non-breaking change, since WsError is private.
2021-02-10 14:00:03 +00:00
Kyle Simpson
0e860dc29d Chore: Add missing changelog notes for 0.1.3
It seems like these were accidentally unstaged.
2021-02-10 13:42:00 +00:00
Kyle Simpson
fa9de67ac2 Release v0.1.3 2021-02-04 02:46:05 +00:00
Kyle Simpson
1863d39356 Chore + Deps: Add the log feature to tracing 2021-02-04 02:38:09 +00:00
Kyle Simpson
aaab97511d Library: Add compatibility for legacy Tokio 0.2 (#40)
Adds support to the library for tokio 0.2 backward-compatibility. This should hopefully benefit, and prevent lavalink-rs from being blocked on this feature.

These can be reached using, e.g., `gateway-tokio-02`, `driver-tokio-02`, `serenity-rustls-tokio-02`, and `serenity-native-tokio-02` features.

Naturally, this requires some jiggering about with features and the underlying CI, which has been taken care of. Twilight can't be handled in this way, as their last tokio 0.2 version uses the deprecated Discord Gateway v6.
2021-02-04 02:34:07 +00:00
Kyle Simpson
b2453091e7 Fix: hand off process killing to blocking thread, await all children.
This should make dropping `ChildContainer`s and their parent `Input`s safer in async contexts.

It seems like SIGINT is insufficient to make wait terminate, but SIGKILL suffices. This introduced a new problem, namely that we have to remember and wait on *every* pid we create. This should, hopefully, put the issue of zombie processes to bed for good.
2021-02-01 13:43:26 +00:00
Kyle Simpson
7d4891d32c Release v0.1.2 2021-01-26 21:32:02 +00:00
Kyle Simpson
fe2282cfde Input & Driver: Fix zombie processes on Unix (#39)
Linux/Unix requires that processes be waited, which is unfortunate as Windows lets us abandon them to the murderous whims of the OS. This PR adds Unix-specific behaviour to send a SIGINT before waiting on the process, and adds an additional thread per call for asset disposal on all platforms.

Closes #38.

---

* Close processes by SIGINT and wait on Unix

This seems to remedy the Linux-specific zombie processes. Addition of
nix as a dependency *should* be fine on Windows, since I believe it
compiles to an empty crate.

* Dispose of Tracks on auxiliary thread

This adds a mechanism for the mixer threads to perform potentially expensive deallocation/cleanup outside of the main loop, preventing deadline misses etc. This should make misbehaving `wait`s a bit more friendly.
2021-01-26 20:19:51 +00:00
Kyle Simpson
a0e905a83f Gateway: Move from RwLock<HashMap> to DashMap
Moves to the faster dashmap in the Songbird management struct, as the final v4 brought back the `entry` API that I was needing to use it safely.

Also handles some new clippy lints.
2021-01-26 14:23:07 +00:00
Kyle Simpson
658fd830c1 Fix: Prevent ytdl treating warnings as errors.
Simple enough change to handle this for now, in that it just tells ytdl to silence errors.

Closes #37.
2021-01-24 00:40:34 +00:00
Kyle Simpson
196d5be3d2 Chore: Categorise v0.1.1 commits 2021-01-18 09:49:41 +00:00
Kyle Simpson
21226af43a Release v0.1.1 2021-01-17 23:28:40 +00:00
Kyle Simpson
868c44c19f Events: Add Play/Pause events.
Uses much of the existing machinery to add some more PlayMode state change events—all in all, a pretty simple change.

Closes #29.
2021-01-17 23:10:57 +00:00
Kyle Simpson
cb2398f182 Events: Add (re)connect success/fail events.
These should allow bots to hook up events to a variety of important connection events as required. This was primarily motivated by the user who raised dcb6ad9.

Although I really would have liked to squeeze in (finite) reconnection attempts with exponential backoff, so that automated repeat attempts could be neatly handled, `Config` was accidentally *not* made non-exhaustive. Adding this and its needed configuration would then be a breaking change. This should warn users about an accidentally dead connection, until the next version can be put forth.
2021-01-17 22:22:23 +00:00
Kyle Simpson
55b8e7fb4e Driver: Add ability to clear all global event handlers.
Closes #32. This should make event handler cleanup considerably easier depending on use case.
2021-01-17 21:29:19 +00:00
Kyle Simpson
dcb6ad97b2 Driver: Fix noisy errors, UDP message send failure spam.
Closes #26.

This will also prevent a full reconnect failure from endlessly spamming attempts and error logs. I'll follow this up by looking into decent reconnection strategies, although sadly these won't be configurable until the next semver break due to an oversight on my part.
2021-01-17 20:12:55 +00:00
Kyle Simpson
12776fc6f8 Release v0.1.0 (#34)
* Update dependencies, draft initial structure for changelog.

* Full changelog!
2021-01-08 11:42:07 +00:00
Kyle Simpson
7d767d2919 Chore: Bump to published twilight. 2021-01-08 10:27:25 +00:00
Kyle Simpson
53ab9dac03 Chore: Bump to published serenity. 2021-01-06 23:12:24 +00:00
Kyle Simpson
f05b7414a0 Songbird: Tokio 1.0 (#36)
Migrates to the new version of tokio, requiring channel and sleep changes in a few locations. Additionally points to the in-tree v0.3 version of twilight.
2021-01-06 13:01:14 +00:00
Kyle Simpson
d42e09f72b Tracks: Add TypeMap to Handles.
Adds a shared TypeMap per TrackHandle. This should greatly simplify the user experience for attaching additional per-track state which the driver does not care for.
2021-01-02 23:43:28 +00:00
baguette
873458d288 Tracks: Allow custom UUID setting (#33) 2020-12-30 10:09:44 +00:00
Kyle Simpson
03ae0e7628 Input: Allow Restartable sources to be lazy
This change is made with queue users in mind. Since sources
of this kind *know* how to (re)create themselves, they can
avoid being created at all until needed.

This also adds machinery to preload tracks *before* they are
needed, for gapless playback on queues and so on. Queues
make use of the event system to do this.
2020-12-28 17:17:57 +00:00
Kyle Simpson
c0d3cb3113 Docs: Warn about twilight task deadlock
Potential deadlock (identified by a user) has now been warned about. The way the example is structured prevents this from occurring, but it's worth making this more explicit due to the more free-form nature of twilight.

The design of serenity's event handling and framework should prevent this issue from cropping up when using it as a gateway backend.
2020-12-27 00:16:05 +00:00
Kyle Simpson
504b8dfaef Driver, Input: Performance & Benchmarks (#27)
* Driver Benchmarks

Benchmarks driver use cases for single packet send,
multiple packet send, float vs opus, and the cost of
head-of-queue track removal.

Mix costs for large packet counts are also included.

This is a prelude to the optimisations discussed in
#21.

* Typo in benchmark

* Place Opus packet directly into packet buffer

Cleans up some other logic surrounding this, too. Gets a 16.9% perf improvement on opus packet passthrough (sub 5us here).

* Better track removal

In theory this should be faster, but it aint. Keeping in case
reducing struct sizes down the line magically makes this
faster.

* Reduce size of Input, TrackHandle

Metadata is now boxed away. Similarly, TrackHandles are neatly Arc'd to reduce their size to pointer length (and mitigate the impact of copies if we add in more fields).
2020-12-26 23:08:35 +00:00
Kyle Simpson
2fc88a6ef1 Deps: Patch flume.
Addresses security advisory in downstream nanorand.
2020-12-19 13:18:46 +00:00
Maspenguin
8d6bd4fd63 Input: Json parsing errors now contain the parsed text (#31) 2020-12-13 12:19:49 +00:00
Saanu Reghunadh
700f20dff9 Metadata: Add source_url and thumbnail fields (#28) 2020-12-07 14:54:29 +00:00
Kyle Simpson
f222ce9969 Driver, Tracks: Cleanup of leaky types (#20)
Main goal: a lot of nested future/result folding.

This mainly modifies error handling for Tracks and TrackHandles to be
more consistent, and hides the underlying channel result passing in
get_info. Errors returned should be far clearer, and are domain
specific rather than falling back to a very opaque use of the underlying
channel error. It should be clearer to users why their handle commands
failed, or why they can't make a ytdl track loop or similar.

Also fixed/cleaned up Songbird::join(_gateway) to return in a single
await, sparing the user from the underlying channel details and repeated
Errs. I was trying for some time to extend the same graces to `Call`,
but could not figure out a sane way to get a 'static version of the
first future in the chain (i.e., the gateway send) so that the whole
thing could happen after dropping the lock around the Call. I really
wanted to fix this to happen as a single folded await too, but I think
this might need some crazy hack or redesign.
2020-12-04 15:13:43 +00:00
Kyle Simpson
9fdbcd77be Driver: Handle receiving large non-standard packets (#23)
Discord's web client on Firefox seems to send very large packets,
ranging from 20ms to 60ms at different times and systems. This adapts
the UDP Rx task to remember the largest packet needed for any SSRC
in a call and preallocate that much, which also allows it to decode
such packets.
2020-12-04 13:55:22 +00:00
baguette
57df3fe53a TrackHandle: add metadata field (#25)
* Adds metadata field to TrackHandle.

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2020-12-04 13:43:35 +00:00
Kyle Simpson
94157b12bc Docs: Move to new intra-doc links, make events non-exhaustive. (#19)
Far cleaner and more reliable than the old doc-link pattern. Also allowed me to spot some event types and sources which should have been made non_exhaustive.
2020-11-24 19:52:23 +00:00
Maspenguin
1ada46d24b Fix: Remove serenity default features (#18)
Allows use of songbird without serenity's framework.
2020-11-23 10:43:24 +00:00
baguette
69acea8664 TrackQueue: Add current_queue method (#16) 2020-11-19 00:33:00 +00:00
Kyle Simpson
2da5901930 Input: Make restartable sources fully async. (#15)
Redresses a previous holdover from an attempt to get Restartable sources to work more neatly inside the synchronous mixer thread. This prevents `Restartable::*` from blocking without warning.

The initial fix at the time was to perform the restart work on a task provided by the tokio runtime as `executor::block_on` needs to be run from within a valid async runtime. Naturally, this completely missed the point that these closures should/could be async, without any need to fudge async functions into a sync wrapper.

Also removes the `From` for normal closures, as this will probably act as a footgun for folks on a single-threaded executor.
2020-11-18 20:48:34 +00:00
( ͡° ͜ʖ ͡°)
cb7d8cc618 Lint: Clippy warning cleanup (#8) 2020-11-16 15:54:29 +00:00
Kyle Simpson
de652250d8 TrackQueues: Convenience methods and extension (#7)
* Adds a uuid field to tracks and handles to make it easier to identify and match event sources after the fact.
* Adds optional feature "builtin-queue" to expose a queue on every driver, as a convenience for users who can guarantee they'll need a queue for every driver/call.
* Adds methods to queues to allow access to the currently running track handle, remove a specified queue entry, as well as to mutate the underlying queue from a closure.
2020-11-16 08:57:54 +00:00