Removed leftover lock, started adding Task result to SendPCMFrame.
This commit is contained in:
@@ -122,6 +122,9 @@
|
|||||||
<Compile Include="..\Discord.Net\Helpers\JsonHttpClient.Events.cs">
|
<Compile Include="..\Discord.Net\Helpers\JsonHttpClient.Events.cs">
|
||||||
<Link>Helpers\JsonHttpClient.Events.cs</Link>
|
<Link>Helpers\JsonHttpClient.Events.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\Discord.Net\Helpers\TaskHelper.cs">
|
||||||
|
<Link>Helpers\TaskHelper.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\Discord.Net\HttpException.cs">
|
<Compile Include="..\Discord.Net\HttpException.cs">
|
||||||
<Link>HttpException.cs</Link>
|
<Link>HttpException.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -645,15 +645,15 @@ namespace Discord
|
|||||||
/// <summary> Sends a PCM frame to the voice server. </summary>
|
/// <summary> Sends a PCM frame to the voice server. </summary>
|
||||||
/// <param name="data">PCM frame to send.</param>
|
/// <param name="data">PCM frame to send.</param>
|
||||||
/// <param name="count">Number of bytes in this frame. </param>
|
/// <param name="count">Number of bytes in this frame. </param>
|
||||||
public void SendVoicePCM(byte[] data, int count)
|
public Task SendVoicePCM(byte[] data, int count)
|
||||||
{
|
{
|
||||||
CheckReady();
|
CheckReady();
|
||||||
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client.");
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client.");
|
||||||
if (count == 0) return;
|
if (count == 0) return TaskHelper.CompletedTask;
|
||||||
|
|
||||||
if (_isDebugMode)
|
if (_isDebugMode)
|
||||||
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Queued {count} bytes for voice output.");
|
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Queued {count} bytes for voice output.");
|
||||||
_voiceWebSocket.SendPCMFrame(data, count);
|
return _voiceWebSocket.SendPCMFrame(data, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Clears the PCM buffer. </summary>
|
/// <summary> Clears the PCM buffer. </summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Discord.API.Models;
|
using Discord.API.Models;
|
||||||
|
using Discord.Helpers;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
@@ -81,11 +82,7 @@ namespace Discord
|
|||||||
RaiseOnDebugMessage(DebugMessageType.WebSocketUnknownOpCode, "Unknown Opcode: " + msg.Operation);
|
RaiseOnDebugMessage(DebugMessageType.WebSocketUnknownOpCode, "Unknown Opcode: " + msg.Operation);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if DNXCORE
|
return TaskHelper.CompletedTask;
|
||||||
return Task.CompletedTask
|
|
||||||
#else
|
|
||||||
return Task.Delay(0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override object GetKeepAlive()
|
protected override object GetKeepAlive()
|
||||||
|
|||||||
@@ -369,25 +369,27 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendPCMFrame(byte[] data, int count)
|
public Task SendPCMFrame(byte[] data, int count)
|
||||||
{
|
{
|
||||||
if (count != _encoder.FrameSize)
|
if (count != _encoder.FrameSize)
|
||||||
throw new InvalidOperationException($"Invalid frame size. Got {count}, expected {_encoder.FrameSize}.");
|
throw new InvalidOperationException($"Invalid frame size. Got {count}, expected {_encoder.FrameSize}.");
|
||||||
|
|
||||||
lock (_encoder)
|
byte[] payload;
|
||||||
|
int encodedLength;
|
||||||
|
lock (_encoder)
|
||||||
{
|
{
|
||||||
byte[] payload = new byte[4000];
|
payload = new byte[4000];
|
||||||
int encodedLength = _encoder.EncodeFrame(data, payload);
|
encodedLength = _encoder.EncodeFrame(data, payload);
|
||||||
|
|
||||||
if (_mode == "xsalsa20_poly1305")
|
if (_mode == "xsalsa20_poly1305")
|
||||||
{
|
{
|
||||||
//TODO: Encode
|
//TODO: Encode
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (_sendQueue)
|
|
||||||
_sendQueue.Enqueue(new Packet(payload, encodedLength));
|
|
||||||
}
|
}
|
||||||
}
|
_sendQueue.Enqueue(new Packet(payload, encodedLength));
|
||||||
|
|
||||||
|
return Task.Delay(0);
|
||||||
|
}
|
||||||
public void ClearPCMFrames()
|
public void ClearPCMFrames()
|
||||||
{
|
{
|
||||||
_isClearing = true;
|
_isClearing = true;
|
||||||
|
|||||||
17
src/Discord.Net/Helpers/TaskHelper.cs
Normal file
17
src/Discord.Net/Helpers/TaskHelper.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Discord.Helpers
|
||||||
|
{
|
||||||
|
internal static class TaskHelper
|
||||||
|
{
|
||||||
|
public static Task CompletedTask { get; }
|
||||||
|
static TaskHelper()
|
||||||
|
{
|
||||||
|
#if DNXCORE50
|
||||||
|
CompletedTask = Task.CompletedTask;
|
||||||
|
#else
|
||||||
|
CompletedTask = Task.Delay(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user