discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.33k stars 736 forks source link

Remove extension from received audio packets #2721

Closed davidffa closed 2 months ago

davidffa commented 2 months ago

Pull Request Etiquette

Changes

Closes Issue: NaN

Description

With the new update (v5.1.0) that uses the new voice encryption modes, when the bot receives audio from regular users (not bots) it throws opus decoder errors in the debug logs. The issue is that the header extension (present in user's audio packets) is not being stripped from the encoded (but decrypted) audio packet. This PR fixes that by offseting the decrypted audio ByteBuffer by 4 * extension length in the RTP header .

MinnDevelopment commented 2 months ago

Please also adjust the test with these changes

davidffa commented 2 months ago

The CryptoAdapterTest uses the AudioPacket#asEncryptedPacket method that always writes the RTP header flags as 0x80 (without the header extension bit) and never writes the header extension length, so all the tests still pass.