Browse Source

Internalize VoiceBuffer, expose it via interface

tags/docs-0.9
RogueException 9 years ago
parent
commit
558fa86dea
2 changed files with 19 additions and 6 deletions
  1. +13
    -0
      src/Discord.Net/DiscordSimpleClient.Voice.cs
  2. +6
    -6
      src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs

+ 13
- 0
src/Discord.Net/DiscordSimpleClient.Voice.cs View File

@@ -1,13 +1,24 @@
using Discord.Helpers; using Discord.Helpers;
using Discord.WebSockets; using Discord.WebSockets;
using Discord.WebSockets.Voice;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;


namespace Discord namespace Discord
{ {
public interface IDiscordVoiceBuffer
{
int FrameSize { get; }
int FrameCount { get; }
ushort ReadPos { get; }
ushort WritePos { get; }
}

public interface IDiscordVoiceClient public interface IDiscordVoiceClient
{ {
IDiscordVoiceBuffer OutputBuffer { get; }

Task JoinChannel(string channelId); Task JoinChannel(string channelId);


void SendVoicePCM(byte[] data, int count); void SendVoicePCM(byte[] data, int count);
@@ -18,6 +29,8 @@ namespace Discord


public partial class DiscordSimpleClient : IDiscordVoiceClient public partial class DiscordSimpleClient : IDiscordVoiceClient
{ {
IDiscordVoiceBuffer IDiscordVoiceClient.OutputBuffer => _voiceSocket.OutputBuffer;

async Task IDiscordVoiceClient.JoinChannel(string channelId) async Task IDiscordVoiceClient.JoinChannel(string channelId)
{ {
CheckReady(checkVoice: true); CheckReady(checkVoice: true);


+ 6
- 6
src/Discord.Net/WebSockets/Voice/VoiceBuffer.cs View File

@@ -3,7 +3,7 @@ using System.Threading;


namespace Discord.WebSockets.Voice namespace Discord.WebSockets.Voice
{ {
public class VoiceBuffer
internal class VoiceBuffer : IDiscordVoiceBuffer
{ {
public int FrameSize => _frameSize; public int FrameSize => _frameSize;
public int FrameCount => _frameCount; public int FrameCount => _frameCount;
@@ -17,7 +17,7 @@ namespace Discord.WebSockets.Voice
private ManualResetEventSlim _underflowEvent, _notOverflowEvent; private ManualResetEventSlim _underflowEvent, _notOverflowEvent;
private bool _isClearing; private bool _isClearing;


internal VoiceBuffer(int frameCount, int frameSize)
public VoiceBuffer(int frameCount, int frameSize)
{ {
_frameSize = frameSize; _frameSize = frameSize;
_frameCount = frameCount; _frameCount = frameCount;
@@ -30,7 +30,7 @@ namespace Discord.WebSockets.Voice
_notOverflowEvent = new ManualResetEventSlim(); //Notifies when an overflow is solved _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 wholeFrames = bytes / _frameSize;
int expectedBytes = wholeFrames * _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) if (_writeCursor == _readCursor)
{ {
@@ -93,7 +93,7 @@ namespace Discord.WebSockets.Voice
return !isClearing; return !isClearing;
} }


internal void Clear(CancellationToken cancelToken)
public void Clear(CancellationToken cancelToken)
{ {
lock (this) lock (this)
{ {
@@ -107,7 +107,7 @@ namespace Discord.WebSockets.Voice
} }
} }


internal void Wait(CancellationToken cancelToken)
public void Wait(CancellationToken cancelToken)
{ {
_underflowEvent.Wait(cancelToken); _underflowEvent.Wait(cancelToken);
} }


Loading…
Cancel
Save