Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extension from received audio packets #2721

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove extension from received audio packets
davidffa committed Aug 22, 2024

Verified

This commit was signed with the committer’s verified signature.
davidffa David Amorim
commit c49129bab5473664772a046ad7db536a619e5e0a
15 changes: 13 additions & 2 deletions src/main/java/net/dv8tion/jda/internal/audio/AudioPacket.java
Original file line number Diff line number Diff line change
@@ -84,7 +84,16 @@ public AudioPacket(byte[] rawPacket)
for (int i = 0; i < cc; i++)
this.csrc[i] = buffer.getInt();

this.extension = this.hasExtension ? buffer.getInt() : 0;
// Extract extension length as described by https://datatracker.ietf.org/doc/html/rfc3550#section-5.3.1
if (this.hasExtension)
{
buffer.position(buffer.position() + 2);
this.extension = buffer.getShort();
}
else
{
this.extension = 0;
}

this.headerLength = buffer.position();
this.encodedAudio = buffer;
@@ -145,12 +154,14 @@ public static AudioPacket decryptAudioPacket(CryptoAdapter crypto, DatagramPacke
return null;

byte[] decryptedPayload = crypto.decrypt(encryptedPacket.encodedAudio);
int offset = 4 * encryptedPacket.extension;

return new AudioPacket(
null,
encryptedPacket.seq,
encryptedPacket.timestamp,
encryptedPacket.ssrc,
ByteBuffer.wrap(decryptedPayload)
ByteBuffer.wrap(decryptedPayload, offset, decryptedPayload.length - offset).slice()
);
}