|
|
@ -22,6 +22,7 @@ MAX_SEQUENCE = 65535 |
|
|
|
|
|
|
|
RTP_HEADER_ONE_BYTE = (0xBE, 0xDE) |
|
|
|
|
|
|
|
|
|
|
|
class RTPHeader(namedtuple('RTPHeader', ['version', 'padding', 'extension', 'csrc_count', 'marker', 'payload_type', 'sequence', 'timestamp', 'ssrc'])): |
|
|
|
""" |
|
|
|
RTP Packet's Header information |
|
|
@ -46,7 +47,8 @@ class RTPHeader(namedtuple('RTPHeader', ['version', 'padding', 'extension', 'csr |
|
|
|
RTP packet's SSRC, the person talking |
|
|
|
""" |
|
|
|
|
|
|
|
class VoiceData(namedtuple('VoiceData', ['data', 'user_id', 'rtp', 'codec', 'channel'])): |
|
|
|
|
|
|
|
class VoiceData(namedtuple('VoiceData', ['data', 'user_id', 'payload_type', 'channel', 'rtp'])): |
|
|
|
""" |
|
|
|
Voice Data received from the UDP socket |
|
|
|
Attributes |
|
|
@ -55,12 +57,14 @@ class VoiceData(namedtuple('VoiceData', ['data', 'user_id', 'rtp', 'codec', 'cha |
|
|
|
the decrypted data |
|
|
|
user_id: snowflake |
|
|
|
the id of the user who sent this data |
|
|
|
payload_type : string |
|
|
|
the payload's type, currently only 'opus' supported |
|
|
|
channel : object?? |
|
|
|
rtp : RTPHeader |
|
|
|
the rtp packet's header data |
|
|
|
codec : string |
|
|
|
the codec this packet is using |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
class UDPVoiceClient(LoggingClass): |
|
|
|
def __init__(self, vc): |
|
|
|
super(UDPVoiceClient, self).__init__() |
|
|
@ -175,7 +179,7 @@ class UDPVoiceClient(LoggingClass): |
|
|
|
|
|
|
|
try: |
|
|
|
data = self._secret_box.decrypt(bytes(data[12:]), bytes(nonce)) |
|
|
|
except: |
|
|
|
except Exception: |
|
|
|
continue |
|
|
|
|
|
|
|
# RFC3550 Section 5.1 (Padding) |
|
|
@ -185,7 +189,7 @@ class UDPVoiceClient(LoggingClass): |
|
|
|
|
|
|
|
if rtp.extension: |
|
|
|
# RFC5285 Section 4.2: One-Byte Header |
|
|
|
rtp_extension_header = struct.unpack_from('>BB', data[:2]) |
|
|
|
rtp_extension_header = struct.unpack_from('>BB', data) |
|
|
|
if rtp_extension_header == RTP_HEADER_ONE_BYTE: |
|
|
|
data = data[2:] |
|
|
|
|
|
|
@ -211,7 +215,8 @@ class UDPVoiceClient(LoggingClass): |
|
|
|
offset += 1 |
|
|
|
|
|
|
|
if len(fields): |
|
|
|
data = b''.join(fields + [data[offset:]]) |
|
|
|
fields.append(data[offset:]) |
|
|
|
data = b''.join(fields) |
|
|
|
else: |
|
|
|
data = data[offset:] |
|
|
|
|
|
|
@ -221,7 +226,13 @@ class UDPVoiceClient(LoggingClass): |
|
|
|
continue |
|
|
|
|
|
|
|
user_id = self.vc.audio_ssrcs.get(rtp.ssrc, None) |
|
|
|
payload = VoiceData(data=data, user_id=user_id, rtp=rtp, codec=payload_type.name, channel=self.vc.channel) |
|
|
|
payload = VoiceData( |
|
|
|
data=data, |
|
|
|
payload_type=payload_type.name, |
|
|
|
user_id=user_id, |
|
|
|
channel=self.vc.channel, |
|
|
|
rtp=rtp |
|
|
|
) |
|
|
|
|
|
|
|
self.vc.client.gw.events.emit('VoiceData', payload) |
|
|
|
|
|
|
|