Added Flush support for audio streams

This commit is contained in:
RogueException
2016-12-30 17:02:25 -04:00
parent beb2acb40c
commit f4469a76be
6 changed files with 53 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Discord.Audio
{
@@ -33,6 +35,10 @@ namespace Discord.Audio
}
public override void Write(byte[] buffer, int offset, int count)
{
WriteAsync(buffer, offset, count, CancellationToken.None).GetAwaiter().GetResult();
}
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
unchecked
{
@@ -48,10 +54,17 @@ namespace Discord.Audio
count = SecretBox.Encrypt(buffer, offset, count, _buffer, 12, _nonce, _secretKey);
Buffer.BlockCopy(_nonce, 0, _buffer, 0, 12); //Copy the RTP header from nonce to buffer
_target.SendAsync(_buffer, count + 12).GetAwaiter().GetResult();
await _target.SendAsync(_buffer, count + 12).ConfigureAwait(false);
}
public override void Flush() { }
public override void Flush()
{
FlushAsync(CancellationToken.None).GetAwaiter().GetResult();
}
public override async Task FlushAsync(CancellationToken cancellationToken)
{
await _target.FlushAsync().ConfigureAwait(false);
}
public override long Length { get { throw new NotSupportedException(); } }
public override long Position