From 558fa86deaa19bbbc3f1a4c9843f4b2411378c0f Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 17 Oct 2015 19:26:30 -0300 Subject: [PATCH] Internalize VoiceBuffer, expose it via interface --- src/Discord.Net/DiscordSimpleClient.Voice.cs | 13 +++++++++++++ src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs | 12 ++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net/DiscordSimpleClient.Voice.cs b/src/Discord.Net/DiscordSimpleClient.Voice.cs index 1c66b9af8..a24f5e12e 100644 --- a/src/Discord.Net/DiscordSimpleClient.Voice.cs +++ b/src/Discord.Net/DiscordSimpleClient.Voice.cs @@ -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); diff --git a/src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs b/src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs index 4085bbb6c..4307f6516 100644 --- a/src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs +++ b/src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs @@ -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); }