Internalize VoiceBuffer, expose it via interface
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
using Discord.Helpers;
|
||||
using Discord.WebSockets;
|
||||
using Discord.WebSockets.Voice;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public interface IDiscordVoiceBuffer
|
||||
{
|
||||
int FrameSize { get; }
|
||||
int FrameCount { get; }
|
||||
ushort ReadPos { get; }
|
||||
ushort WritePos { get; }
|
||||
}
|
||||
|
||||
public interface IDiscordVoiceClient
|
||||
{
|
||||
IDiscordVoiceBuffer OutputBuffer { get; }
|
||||
|
||||
Task JoinChannel(string channelId);
|
||||
|
||||
void SendVoicePCM(byte[] data, int count);
|
||||
@@ -18,6 +29,8 @@ namespace Discord
|
||||
|
||||
public partial class DiscordSimpleClient : IDiscordVoiceClient
|
||||
{
|
||||
IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer;
|
||||
|
||||
async Task IDiscordVoiceClient.JoinChannel(string channelId)
|
||||
{
|
||||
CheckReady(checkVoice: true);
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading;
|
||||
|
||||
namespace Discord.WebSockets.Voice
|
||||
{
|
||||
public class VoiceBuffer
|
||||
internal class VoiceBuffer : IDiscordVoiceBuffer
|
||||
{
|
||||
public int FrameSize => _frameSize;
|
||||
public int FrameCount => _frameCount;
|
||||
@@ -17,7 +17,7 @@ namespace Discord.WebSockets.Voice
|
||||
private ManualResetEventSlim _underflowEvent, _notOverflowEvent;
|
||||
private bool _isClearing;
|
||||
|
||||
internal VoiceBuffer(int frameCount, int frameSize)
|
||||
public VoiceBuffer(int frameCount, int frameSize)
|
||||
{
|
||||
_frameSize = frameSize;
|
||||
_frameCount = frameCount;
|
||||
@@ -30,7 +30,7 @@ namespace Discord.WebSockets.Voice
|
||||
_notOverflowEvent = new ManualResetEventSlim(); //Notifies when an overflow is solved
|
||||
}
|
||||
|
||||
internal void Push(byte[] buffer, int bytes, CancellationToken cancelToken)
|
||||
public void Push(byte[] buffer, int bytes, CancellationToken cancelToken)
|
||||
{
|
||||
int wholeFrames = bytes / _frameSize;
|
||||
int expectedBytes = wholeFrames * _frameSize;
|
||||
@@ -74,7 +74,7 @@ namespace Discord.WebSockets.Voice
|
||||
}
|
||||
}
|
||||
|
||||
internal bool Pop(byte[] buffer)
|
||||
public bool Pop(byte[] buffer)
|
||||
{
|
||||
if (_writeCursor == _readCursor)
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace Discord.WebSockets.Voice
|
||||
return !isClearing;
|
||||
}
|
||||
|
||||
internal void Clear(CancellationToken cancelToken)
|
||||
public void Clear(CancellationToken cancelToken)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
@@ -107,7 +107,7 @@ namespace Discord.WebSockets.Voice
|
||||
}
|
||||
}
|
||||
|
||||
internal void Wait(CancellationToken cancelToken)
|
||||
public void Wait(CancellationToken cancelToken)
|
||||
{
|
||||
_underflowEvent.Wait(cancelToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user