Try reading more from ffmpeg
This commit is contained in:
parent
4d52566250
commit
bbe3ac66e3
@ -9,7 +9,7 @@ namespace NadekoBot.Services.Music
|
|||||||
{
|
{
|
||||||
public class SongBuffer : IDisposable
|
public class SongBuffer : IDisposable
|
||||||
{
|
{
|
||||||
const int maxReadSize = 3840;
|
const int readSize = 38400;
|
||||||
private Process p;
|
private Process p;
|
||||||
private PoopyRingBuffer _outStream = new PoopyRingBuffer();
|
private PoopyRingBuffer _outStream = new PoopyRingBuffer();
|
||||||
|
|
||||||
@ -39,38 +39,33 @@ namespace NadekoBot.Services.Music
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[3840];
|
byte[] buffer = new byte[readSize];
|
||||||
while (!cancelToken.IsCancellationRequested)
|
while (!cancelToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var toRead = buffer.Length;
|
var toRead = buffer.Length;
|
||||||
var remCap = _outStream.RemainingCapacity;
|
var remCap = _outStream.RemainingCapacity;
|
||||||
if (remCap < 3840)
|
if (remCap < readSize)
|
||||||
{
|
{
|
||||||
if (_outStream.RemainingCapacity == 0)
|
if (_outStream.RemainingCapacity == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Buffer full, not gonnna read from ffmpeg");
|
Console.WriteLine("Buffer full, not gonnna read from ffmpeg");
|
||||||
await Task.Delay(10);
|
await Task.Delay(20);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
toRead = remCap;
|
toRead = remCap;
|
||||||
}
|
}
|
||||||
do
|
|
||||||
|
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, toRead, cancelToken).ConfigureAwait(false);
|
||||||
|
if (bytesRead == 0)
|
||||||
{
|
{
|
||||||
if(p.HasExited)
|
Console.WriteLine("I'm not reading anything from ffmpeg");
|
||||||
Console.WriteLine("FFMPEG has exited, I'm in the read/write loop");
|
await Task.Delay(20);
|
||||||
|
continue;
|
||||||
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, toRead, cancelToken).ConfigureAwait(false);
|
}
|
||||||
if (bytesRead == 0)
|
await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken);
|
||||||
{
|
|
||||||
Console.WriteLine("I'm not reading anything from ffmpeg");
|
|
||||||
await Task.Delay(20);
|
|
||||||
}
|
|
||||||
await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken);
|
|
||||||
|
|
||||||
} while (p.HasExited && !cancelToken.IsCancellationRequested);
|
|
||||||
|
|
||||||
if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f)
|
if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f)
|
||||||
if(toReturn.TrySetResult(true))
|
if (toReturn.TrySetResult(true))
|
||||||
Console.WriteLine("Prebuffering finished");
|
Console.WriteLine("Prebuffering finished");
|
||||||
}
|
}
|
||||||
Console.WriteLine("FFMPEG killed or song canceled");
|
Console.WriteLine("FFMPEG killed or song canceled");
|
||||||
|
Loading…
Reference in New Issue
Block a user