Kyle Simpson af95296ee1 Receive: Fix handling for large timestamp/sequence jumps (#266)
This PR addresses some issues which have cropped up on voice receive at scale:

* In unknown circumstances, we can be left with adjacent packets queued which have very different timestamps. The playout buffer would withhold its held packets, leading to the loss of many subsequent packets if the timestamp jump is larger than 64 frames. This seems to occur for some specific clients which join before a bot, suggesting the DAVE -> legacy switchover is involved.
* Some loss patterns can leave us unable to correctly track the next expected sequence number (i.e., large loss runs), leaving the playout buffer unable to accept any packets if the packet sequence differed by over 64 entries.

The fixes are fallbacks which treat sufficiently large desynchronisation, and allow the playout to get back into a consistent state in both cases. Large timestamp jumps on adjacent packets now update the next expected TS (noting that we only want to withhold a few playout delays at most ). Failure to insert 0.25s of packets (or attempting to add a new sequence number into an empty buffer) can now take precedence.

Closes #261.
2024-11-22 12:52:11 +00:00
2024-11-11 12:30:15 +00:00
2023-11-20 00:02:54 +00:00
2024-11-11 12:41:02 +00:00
2024-11-11 12:41:02 +00:00
2020-11-13 16:45:59 +01:00
2023-11-20 02:53:33 +00:00

docs-badge next-docs-badge build badge guild-badge crates.io version rust badge

Songbird

Songbird is an async, cross-library compatible voice system for Discord, written in Rust. The library offers:

  • A standalone gateway frontend compatible with serenity and twilight using the "gateway" and "[serenity/twilight]" plus "[rustls/native]" features. You can even run driverless, to help manage your lavalink sessions.
  • A standalone driver for voice calls, via the "driver" feature. If you can create a ConnectionInfo using any other gateway, or language for your bot, then you can run the songbird voice driver.
  • Voice receive and RT(C)P packet handling via the "receive" feature.
  • SIMD-accelerated JSON decoding via the "simd-json" feature.
  • And, by default, a fully featured voice system featuring events, queues, seeking on compatible streams, shared multithreaded audio stream caches, and direct Opus data passthrough from DCA files.

Intents

Songbird's gateway functionality requires you to specify the GUILD_VOICE_STATES intent.

Codec support

Songbird supports all codecs and formats provided by Symphonia (pure-Rust), with Opus support provided by audiopus (an FFI wrapper for libopus).

By default, Songbird will not request any codecs from Symphonia. To change this, in your own project you will need to depend on Symphonia as well.

# Including songbird alone gives you support for Opus via the DCA file format.
[dependencies.songbird]
version = "0.4"
features = ["builtin-queue"]

# To get additional codecs, you *must* add Symphonia yourself.
# This includes the default formats (MKV/WebM, Ogg, Wave) and codecs (FLAC, PCM, Vorbis)...
[dependencies.symphonia]
version = "0.5.2"
features = ["aac", "mp3", "isomp4", "alac"] # ...as well as any extras you need!

Dependencies

Songbird needs a few system dependencies before you can use it.

  • Opus - Audio codec that Discord uses. audiopus will use installed libopus binaries if available via pkgconf on Linux/MacOS, otherwise you will need to install cmake to build opus from source. This is always the case on Windows. For Unix systems, you can install the library with apt install libopus-dev on Ubuntu or pacman -S opus on Arch Linux. If you do not have it installed it will be built for you. However, you will need a C compiler and the GNU autotools installed. Again, these can be installed with apt install build-essential autoconf automake libtool m4 on Ubuntu or pacman -S base-devel on Arch Linux.

This is a required dependency. Songbird cannot work without it.

  • yt-dlp / youtube-dl / (similar forks) - Audio/Video download tool. yt-dlp can be installed according to the installation instructions on the main repo. You can install youtube-dl with Python's package manager, pip, which we recommend for youtube-dl. You can do it with the command pip install youtube_dl. Alternatively, you can install it with your system's package manager, apt install youtube-dl on Ubuntu or pacman -S youtube-dl on Arch Linux.

This is an optional dependency for users, but is required as a dev-dependency. It allows Songbird to download audio/video sources from the Internet from a variety of webpages, which it will convert to the Opus audio format Discord uses.

Examples

Full examples showing various types of functionality and integrations can be found in this crate's examples directory.

Contributing

If you want to help out or file an issue, please look over our contributor guidelines!

Attribution

Songbird's logo is based upon the copyright-free image "Black-Capped Chickadee" by George Gorgas White.

Description
No description provided
Readme 22 MiB
Languages
Rust 100%