Skip to content

Commit

Permalink
fix incorrect incoming audio packet handling
Browse files Browse the repository at this point in the history
advancing the buffer past the initial header byte was missing
  • Loading branch information
Tim Cooper committed Jul 11, 2016
1 parent cdce542 commit f0a4a29
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions gumble/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func (c *Client) handleUDPTunnel(buffer []byte) error {
}

// Session
buffer = buffer[1:]
session, n := varint.Decode(buffer)
if n <= 0 {
return errInvalidProtobuf
}
buff := buffer[n:]
buffer = buffer[n:]
user := c.Users[uint32(session)]
if user == nil {
return errInvalidProtobuf
Expand All @@ -117,25 +118,25 @@ func (c *Client) handleUDPTunnel(buffer []byte) error {

// Sequence
// TODO: use in jitter buffer
_, n = varint.Decode(buff)
_, n = varint.Decode(buffer)
if n <= 0 {
return errInvalidProtobuf
}
buff = buff[n:]
buffer = buffer[n:]

// Length
length, n := varint.Decode(buff)
length, n := varint.Decode(buffer)
if n <= 0 {
return errInvalidProtobuf
}
buff = buff[n:]
buffer = buffer[n:]
// Opus audio packets set the 13th bit in the size field as the terminator.
audioLength := int(length) &^ 0x2000
if audioLength > len(buff) {
if audioLength > len(buffer) {
return errInvalidProtobuf
}

pcm, err := decoder.Decode(buff[:audioLength], AudioMaximumFrameSize)
pcm, err := decoder.Decode(buffer[:audioLength], AudioMaximumFrameSize)
if err != nil {
return err
}
Expand All @@ -149,13 +150,13 @@ func (c *Client) handleUDPTunnel(buffer []byte) error {
AudioBuffer: AudioBuffer(pcm),
}

if len(buff)-audioLength == 3*4 {
if len(buffer)-audioLength == 3*4 {
// the packet has positional audio data; 3x float32
buff = buff[audioLength:]
buffer = buffer[audioLength:]

event.X = math.Float32frombits(binary.LittleEndian.Uint32(buff))
event.Y = math.Float32frombits(binary.LittleEndian.Uint32(buff[4:]))
event.Z = math.Float32frombits(binary.LittleEndian.Uint32(buff[8:]))
event.X = math.Float32frombits(binary.LittleEndian.Uint32(buffer))
event.Y = math.Float32frombits(binary.LittleEndian.Uint32(buffer[4:]))
event.Z = math.Float32frombits(binary.LittleEndian.Uint32(buffer[8:]))
event.HasPosition = true
}

Expand Down

0 comments on commit f0a4a29

Please sign in to comment.