Skip to content

Commit

Permalink
Remove extension from received audio packets (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidffa authored Aug 22, 2024
1 parent 03aab5c commit 18c9508
Showing 1 changed file with 13 additions and 2 deletions.
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
);
}

Expand Down

0 comments on commit 18c9508

Please sign in to comment.