Commit Graph

71 Commits

Author SHA1 Message Date
Sapphire
c910d7087d Playlist fixes, add YoutubeDl::get_stream function (#279)
* Fix(ytdl): Return all results when querying a URL

* Publicly export `songbird::input::metadata::ytdl::Output`

Closes: https://github.com/serenity-rs/songbird/issues/277

* Make `YoutubeDl::query` public

* Abstract getting streams from YoutubeDl into functions `get_stream` and `get_streams`

* fmt, remove get_streams

* Fix doc comment

* fixup doc comments, export `metadata::ytdl::Output` as `YoutubeDlOutput`

* fmt

* export metadata

* fixup! fixup doc comments, export `metadata::ytdl::Output` as `YoutubeDlOutput`
2025-05-20 18:59:26 +01:00
Gnome!
8956352f13 Fix clippy warnings (#275) 2025-05-05 13:58:15 +01:00
Kyle Simpson
d0b7fbb911 Docs: remove unused link. 2025-02-21 16:14:49 +00:00
Kyle Simpson
47cf0b27eb Chore: clippy appeasement 2025-02-21 14:10:57 +00:00
Kyle Simpson
b39ab98223 Chore: Bump rand->0.9, tokio-tungstenite->0.26 2025-02-21 13:48:56 +00:00
Gnome!
b435e167d2 Remove unnecessary simd-json feature gate (#252)
* Remove unneccessary simd-json feature gate

* Fix redundant closure warning
2025-02-21 12:41:44 +00:00
Erk
c81f2a9578 Remove Simd-json (#228)
This mirrors the serenity pr https://github.com/serenity-rs/serenity/pull/2735.
2025-02-21 12:40:49 +00:00
Gnome!
2bcc5223fe Allow borrowed strings for YoutubeDl (#215) 2025-02-21 12:40:49 +00:00
Gnome!
743a1d262e Deps: Replace OnceCell with std::sync::OnceLock (#207) 2025-02-21 12:40:49 +00:00
Gilles Henaux
71535c5e87 Input: accept additional user arguments for yt-dlp (#268)
This PR makes it possible to give additional user-specified arguments to spawned yt-dlp processes.
2024-11-24 22:43:27 +00:00
Erk
312799d231 fix(source): HLS would not work if used directly. (#262)
This changes HlsRequest to return true in
Compose::should_create_async.

This would otherwise cause it to be spawned on a thread without a
executor causing it to panic.

This would only cause issues if used directly since we otherwise use
Compose::create in a context where we have access to the executor.
2024-11-15 05:47:06 +01:00
tig
10ce458456 feat: v8 encryption modes (#264)
This PR adds support for the new AEAD cryptosystems advertised by Discord, AES256-GCM and XChaCha20Poly1305. These schemes will shortly become mandatory, and provider stronger integrity/authentication guarantees over the cleartext portions of any voice packet by correctly specifying additional authenticated data.

To provide smooth switchover, we've added basic negotiation over the `CryptoMode`. This ensures that any clients who are manually specifying one of the legacy modes will automatically migrate to `Aes256Gcm` when Discord cease to advertise their original preference.

Closes #246.

---------

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2024-11-11 12:30:15 +00:00
rhgndf
fe9b156906 Change HlsStream to a more generic AsyncReadOnlySource (#256) 2024-09-28 17:50:40 +01:00
Gnome!
095feb1065 Fix clippy warnings (#251) 2024-09-09 09:54:17 +00:00
Kyle Simpson
0844537024 Fix(ci): Move problem tests purely to cargo make test (#250)
A few tests are routinely failing on CI because they explicitly
hit YouTube URLs, even if the content in question is CC-licensed.
This PR simply adds the `#[ignore]` attribute, and adds the
`--include-ignored` flag to `cargo make test` so that correct WebM
parsing behaviour can be locally verified.

We could go a bit further and conditionally ignore the tests based
on CI-specific ENV vars, but that's probably overkill given the
scope of the issue.
2024-08-24 23:11:37 +01:00
Kyle Simpson
ec665a8f87 Fix: Ringbuf patch release requires explicit type param
Ringbuf 0.4.2 onwards adds in a new storage type for `SharedRb`.
Unfortunately, this is handled in such a way that we fail to
compile because an explicit type parameter is required to
disambiguate the method in question.
2024-08-17 23:01:51 +01:00
Kyle Simpson
93f2e0b636 chore(deps): Update ringbuf -> 0.4 2024-07-08 11:46:08 +01:00
Erk
8e92c49b2b feat(input): Support HLS streams (#242)
This patch adds support for yt-dl streams with the protocol m3u8_native which includes sites like Soundcloud.

Closes: #241
2024-07-07 19:37:25 +02:00
Gnome!
5bbe80f20c Fix clippy warnings (#236) 2024-04-02 08:57:47 +01:00
Gnome!
1b98c30746 Fix clippy warnings (#214)
* Fix clippy warnings

* Fix implicitly elided lifetimes
2024-01-03 16:45:23 +00:00
Cycle Five
d681b71b1f Input: Add ytdl search (#210)
* Add ytdl search

* fix fmt

* Remove compose, add tests, return AuxMetadata

* fix parsing of AuxMetadata and better test

* Fix playability of `YoutubeDl::new_search`

Refactors such that parsing of (ND)JSON is handled in only one location
now, which allows us to greatly simplify the actual `search` method. The
main change is that any `new_search` is now instantly playable.

---------

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-12-12 08:28:13 +00:00
Gnome!
3d307aaa8b Fix clippy pedantic warnings (#204) 2023-11-20 00:02:58 +00:00
Kyle Simpson
935171df4f Driver: Correct buffer instantiation for Rubato
I had slightly misread the changes from 0.12->0.14, so buffers were
not correctly instantiated for resampling.
2023-11-20 00:02:58 +00:00
Kyle Simpson
67b3b3ec50 Chore: Update Rubato -> 0.14.1 2023-11-20 00:02:58 +00:00
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
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
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
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
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
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
125c803fa7 Chore: Apply latest nightly clippy lints 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
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
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
Gnome!
0beb0f0d76 Input: lazy_static -> once_cell::sync::Lazy (#136) 2023-11-19 23:58:34 +00:00
Victoria Casasampere Fernandez
cb0a74f511 Support simd_json (#105)
This PR adds support for the simd-json library whenever decoding or encoding JSON responses. This may be enabled independently of serenity and twilight support for SIMD acceleration.

Co-authored-by: Kyle Simpson <kyleandrew.simpson@gmail.com>
2023-11-19 23:58:34 +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
4eb95d4b59 Deps: Update to Audiopus v0.3.0-rc.0 (#125)
Tested using `cargo make ready`.

Co-authored-by: André Vennberg <andre.vennberg@gmail.com>
2022-07-22 15:41:18 +01:00
Gnome!
f2cd8a0b6a Driver, Gateway: Remove tokio 0.2 support (#118)
* Remove tokio 0.2 compat
* Remove tokio 0.2 test
* Remove tokio 0.2 CI
2022-07-22 15:41:18 +01:00
Kyle Simpson
b4ce84546b Gateway: Generic Shard and Twilight v0.8 Support (#109)
This PR adds support for twilight v0.8, mainly adapting to significant API changes introduced by v0.7. As a result of these, twilight no longer accepts arbitrary JSON input, so it seemed sensible to adapt our `Shard` design to no longer require the same.

Adding to this, I've added in a trait to allow an arbitrary `Shard` to be installed, given only an implementation of a method to send a `VoiceStateUpdate`. Together, `Sharder::Generic` (songbird::shards::VoiceUpdate) and `Shard::Generic` (songbird::shards::GenericSharder) should allow any library to be hooked in to Songbird.

This PR was tested using `cargo make ready` and by manually testing `examples/twilight`.
2022-07-22 15:41:18 +01:00
Miles Frankel
ecc47d588a Input: add ChildContainer::new (#108) 2022-01-12 10:58:59 +00:00
Lunarmagpie
73323e58dd Docs: added documentation for yt-dlp feature (#106)
* Docs: added documentation for yt-dlp feature
* Docs: remove trailing whitespace
2022-01-04 13:45:39 +00:00
Miezhiko
6fcb196e34 Input: Allows yt-dlp usage as another youtube-dl fork (#90)
Signed-off-by: Miezhiko <Miezhiko@gmail.com>
2021-10-10 20:56:32 +01:00
Vilgot Fredenberg
00c8bc915a Input: Add separate YouTube title and channel to Metadata (#75) 2021-07-01 11:34:30 +01:00
Vilgot Fredenberg
55e1567b90 Input, Driver: Make error messages more idiomatic (#74) 2021-07-01 11:33:51 +01:00
Vilgot Fredenberg
7045e2ec5a Input: Implement StdError for DcaError, input::Error (#73) 2021-07-01 11:33:51 +01:00