Browse Source

Logging and one-byte headers

pull/57/head
Bottersnike 8 years ago
parent
commit
82418bf652
  1. 26
      disco/voice/client.py
  2. 6
      disco/voice/opus.py

26
disco/voice/client.py

@ -111,8 +111,27 @@ class UDPVoiceClient(LoggingClass):
nonce[:12] = header
buff = self.vc.secret_box.decrypt(bytes(buff), bytes(nonce))
# Packets starting with b'\x90' need the first 8 bytes ignored
if check == self._CHECK2:
if buff[0] == 0xBE and buff[1] == 0xDE: # RFC5285 Section 4.2: One-Byte Header
# Please note: This has been added to future-proof the code however I have been
# unable to find any voice clients that are using the one-byte headers. As such,
# this code is untested but should work.
rtp_header_extension_length = buff[2] << 8 | buff[3]
index = 4
for i in range(rtp_header_extension_length):
byte = buff[index]
index += 1
if byte == 0:
continue
l = (byte & 0b1111) + 1
index += l
while buff[index] == 0:
index += 1
buff = buff[index:]
elif check == self._CHECK2:
# Packets starting with b'\x90' need the first 8 bytes ignored BecauseDiscord(tm)
buff = buff[8:]
if ssrc not in self._decoders:
@ -126,6 +145,9 @@ class UDPVoiceClient(LoggingClass):
user_id = int(self.vc.ssrc_lookup[ssrc])
member = self.vc.channel.guild.get_member(user_id)
else:
self.log.warning('User speaking was unknown! Dropping packet.')
return
buff = self._decoders[ssrc].decode(buff)

6
disco/voice/opus.py

@ -156,7 +156,7 @@ class OpusEncoder(BaseOpus):
return array.array('b', data[:ret]).tostring()
class OpusDecoder(BaseOpus):
class OpusDecoder(BaseOpus, LoggingClass):
EXPORTED = {
'opus_decoder_get_size': ([ctypes.c_int], ctypes.c_int),
'opus_decoder_create': ([ctypes.c_int, ctypes.c_int, c_int_ptr], DecoderStructPtr),
@ -245,10 +245,10 @@ class OpusDecoder(BaseOpus):
result = self.opus_decode(self.inst, data, len(data), pcm_ptr, frame_size, decode_fec)
if result < 0:
# log.debug('error happened in decode')
self.log.debug('error happened in decode')
raise Exception('Failed to decode: {}'.format(result))
# log.debug('opus decode result: {} (total buf size: {})'.format(result, len(pcm)))
self.log.debug('opus decode result: {} (total buf size: {})'.format(result, len(pcm)))
if six.PY3:
return array.array('h', pcm).tobytes()

Loading…
Cancel
Save