buffer is now 50MB

This commit is contained in:
Master Kwoth 2017-07-02 13:19:05 +02:00
parent 7de15bf444
commit 0e73372c23
2 changed files with 18 additions and 15 deletions

View File

@ -1,5 +1,7 @@
using System;
using NadekoBot.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
@ -48,7 +50,7 @@ namespace NadekoBot.DataStructures
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
public PoopyRingBuffer(int capacity = 3840 * 300)
public PoopyRingBuffer(int capacity = 50_000_000)
{
this.Capacity = capacity + 1;
this.buffer = new byte[this.Capacity];
@ -97,7 +99,7 @@ namespace NadekoBot.DataStructures
public Task WriteAsync(byte[] b, int offset, int toWrite, CancellationToken cancelToken) => Task.Run(async () =>
{
while (toWrite > RemainingCapacity)
await Task.Delay(100, cancelToken);
await Task.Delay(50, cancelToken);
await _locker.WaitAsync(cancelToken);
try

View File

@ -24,12 +24,17 @@ namespace NadekoBot.Services.Music
this.p = Process.Start(new ProcessStartInfo
{
FileName = "ffmpeg",
Arguments = $"-i {songUri} -f s16le -ar 48000 -vn -ac 2 pipe:1 -loglevel quiet -nostdin",
Arguments = $"-ss 0 -i {songUri} -f s16le -ar 48000 -vn -ac 2 pipe:1 -loglevel quiet",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = false,
RedirectStandardError = true,
CreateNoWindow = true,
});
var t = Task.Run(() =>
{
this.p.BeginErrorReadLine();
this.p.WaitForExit();
});
}
public Task<bool> StartBuffering(CancellationToken cancelToken)
@ -40,7 +45,8 @@ namespace NadekoBot.Services.Music
try
{
byte[] buffer = new byte[readSize];
while (!cancelToken.IsCancellationRequested)
int bytesRead = -1;
while (!cancelToken.IsCancellationRequested && bytesRead != 0)
{
var toRead = buffer.Length;
//var remCap = _outStream.RemainingCapacity;
@ -54,14 +60,8 @@ namespace NadekoBot.Services.Music
// }
// toRead = remCap;
//}
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, toRead, cancelToken).ConfigureAwait(false);
if (bytesRead == 0)
{
Console.WriteLine("I'm not reading anything from ffmpeg");
await Task.Delay(20);
continue;
}
bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, toRead, cancelToken).ConfigureAwait(false);
await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken);
if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f)
@ -70,8 +70,9 @@ namespace NadekoBot.Services.Music
}
Console.WriteLine("FFMPEG killed or song canceled");
}
catch
catch (Exception ex)
{
Console.WriteLine(ex);
if(toReturn.TrySetResult(false))
Console.WriteLine("Prebuffering failed");
//ignored