Add various optimizations and cleanups (#1114)
* Change all Select(... as ...) to OfType
* Add changes according to 194a8aa427
This commit is contained in:
@@ -16,7 +16,7 @@ using System.Collections.Generic;
|
||||
namespace Discord.Audio
|
||||
{
|
||||
//TODO: Add audio reconnecting
|
||||
internal partial class AudioClient : IAudioClient, IDisposable
|
||||
internal partial class AudioClient : IAudioClient
|
||||
{
|
||||
internal struct StreamPair
|
||||
{
|
||||
@@ -65,7 +65,7 @@ namespace Discord.Audio
|
||||
|
||||
ApiClient = new DiscordVoiceAPIClient(guild.Id, Discord.WebSocketProvider, Discord.UdpSocketProvider);
|
||||
ApiClient.SentGatewayMessage += async opCode => await _audioLogger.DebugAsync($"Sent {opCode}").ConfigureAwait(false);
|
||||
ApiClient.SentDiscovery += async () => await _audioLogger.DebugAsync($"Sent Discovery").ConfigureAwait(false);
|
||||
ApiClient.SentDiscovery += async () => await _audioLogger.DebugAsync("Sent Discovery").ConfigureAwait(false);
|
||||
//ApiClient.SentData += async bytes => await _audioLogger.DebugAsync($"Sent {bytes} Bytes").ConfigureAwait(false);
|
||||
ApiClient.ReceivedEvent += ProcessMessageAsync;
|
||||
ApiClient.ReceivedPacket += ProcessPacketAsync;
|
||||
@@ -131,7 +131,7 @@ namespace Discord.Audio
|
||||
await keepaliveTask.ConfigureAwait(false);
|
||||
_keepaliveTask = null;
|
||||
|
||||
while (_heartbeatTimes.TryDequeue(out long time)) { }
|
||||
while (_heartbeatTimes.TryDequeue(out _)) { }
|
||||
_lastMessageTime = 0;
|
||||
|
||||
await ClearInputStreamsAsync().ConfigureAwait(false);
|
||||
@@ -292,7 +292,7 @@ namespace Discord.Audio
|
||||
{
|
||||
if (packet.Length != 70)
|
||||
{
|
||||
await _audioLogger.DebugAsync($"Malformed Packet").ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Malformed Packet").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
string ip;
|
||||
@@ -304,7 +304,7 @@ namespace Discord.Audio
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _audioLogger.DebugAsync($"Malformed Packet", ex).ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Malformed Packet", ex).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace Discord.Audio
|
||||
{
|
||||
if (pair.Key == value)
|
||||
{
|
||||
int latency = (int)(Environment.TickCount - pair.Value);
|
||||
int latency = Environment.TickCount - pair.Value;
|
||||
int before = UdpLatency;
|
||||
UdpLatency = latency;
|
||||
|
||||
@@ -344,7 +344,7 @@ namespace Discord.Audio
|
||||
{
|
||||
if (!RTPReadStream.TryReadSsrc(packet, 0, out var ssrc))
|
||||
{
|
||||
await _audioLogger.DebugAsync($"Malformed Frame").ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Malformed Frame").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
if (!_ssrcMap.TryGetValue(ssrc, out var userId))
|
||||
@@ -363,7 +363,7 @@ namespace Discord.Audio
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _audioLogger.DebugAsync($"Malformed Frame", ex).ConfigureAwait(false);
|
||||
await _audioLogger.DebugAsync("Malformed Frame", ex).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
//await _audioLogger.DebugAsync($"Received {packet.Length} bytes from user {userId}").ConfigureAwait(false);
|
||||
@@ -372,7 +372,7 @@ namespace Discord.Audio
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _audioLogger.WarningAsync($"Failed to process UDP packet", ex).ConfigureAwait(false);
|
||||
await _audioLogger.WarningAsync("Failed to process UDP packet", ex).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user