forked from pothtonswer/discordmuffin
Fix RTP extended header parsing
As ext header length isn't always 1, the shift to find the beginning of the Opus packet must be adjusted dynamically.
This commit is contained in:
parent
c27ad65527
commit
b18e1d7276
1 changed files with 9 additions and 3 deletions
12
voice.go
12
voice.go
|
@ -831,9 +831,15 @@ func (v *VoiceConnection) opusReceiver(udpConn *net.UDPConn, close <-chan struct
|
||||||
copy(nonce[:], recvbuf[0:12])
|
copy(nonce[:], recvbuf[0:12])
|
||||||
p.Opus, _ = secretbox.Open(nil, recvbuf[12:rlen], &nonce, &v.op4.SecretKey)
|
p.Opus, _ = secretbox.Open(nil, recvbuf[12:rlen], &nonce, &v.op4.SecretKey)
|
||||||
|
|
||||||
if len(p.Opus) > 8 && recvbuf[0] == 0x90 {
|
// extension bit set, and not a RTCP packet
|
||||||
// Extension bit is set, first 8 bytes is the extended header
|
if ((recvbuf[0] & 0x10) == 0x10) && ((recvbuf[1] & 0x80) == 0) {
|
||||||
p.Opus = p.Opus[8:]
|
// get extended header length
|
||||||
|
extlen := binary.BigEndian.Uint16(p.Opus[2:4])
|
||||||
|
// 4 bytes (ext header header) + 4*extlen (ext header data)
|
||||||
|
shift := int(4 + 4*extlen)
|
||||||
|
if len(p.Opus) > shift {
|
||||||
|
p.Opus = p.Opus[shift:]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c != nil {
|
if c != nil {
|
||||||
|
|
Loading…
Reference in a new issue