music debug stuff

This commit is contained in:
Master Kwoth 2017-07-02 09:55:26 +02:00
parent 9bb72d9976
commit 42658355b1
4 changed files with 27 additions and 7 deletions

View File

@ -48,7 +48,7 @@ namespace NadekoBot.DataStructures
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1); private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
public PoopyRingBuffer(int capacity = 3640 * 200) public PoopyRingBuffer(int capacity = 3840 * 300)
{ {
this.Capacity = capacity + 1; this.Capacity = capacity + 1;
this.buffer = new byte[this.Capacity]; this.buffer = new byte[this.Capacity];
@ -59,7 +59,6 @@ namespace NadekoBot.DataStructures
await _locker.WaitAsync(cancelToken); await _locker.WaitAsync(cancelToken);
try try
{ {
Console.WriteLine("Reading {0}", toRead);
if (WritePos == ReadPos) if (WritePos == ReadPos)
return 0; return 0;
@ -129,7 +128,7 @@ namespace NadekoBot.DataStructures
WritePos = 0; WritePos = 0;
} }
} }
Console.WriteLine("Readpos: {0} WritePos: {1}", ReadPos, WritePos); Console.WriteLine("Readpos: {0} WritePos: {1} ({2})", ReadPos, WritePos, ReadPos - WritePos);
return toWrite; return toWrite;
} }
finally finally

View File

@ -165,6 +165,7 @@ namespace NadekoBot.Modules.Music
} }
} }
//todo, page should default to the page the current song is on
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ListQueue(int page = 1) public async Task ListQueue(int page = 1)

View File

@ -117,6 +117,7 @@ namespace NadekoBot.Services.Music
await (pauseTaskSource?.Task ?? Task.CompletedTask); await (pauseTaskSource?.Task ?? Task.CompletedTask);
} }
_log.Info(">>>>>>>>>READ 0<<<<<<<<<<");
} }
catch (OperationCanceledException) catch (OperationCanceledException)
{ {

View File

@ -42,17 +42,36 @@ namespace NadekoBot.Services.Music
byte[] buffer = new byte[3840]; byte[] buffer = new byte[3840];
while (!this.p.HasExited || cancelToken.IsCancellationRequested) while (!this.p.HasExited || cancelToken.IsCancellationRequested)
{ {
int bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, buffer.Length, cancelToken).ConfigureAwait(false); var toRead = buffer.Length;
var remCap = _outStream.RemainingCapacity;
if (remCap < 3840)
{
if (_outStream.RemainingCapacity == 0)
{
Console.WriteLine("Buffer full, not gonnna read from ffmpeg");
await Task.Delay(10);
continue;
}
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(50);
}
await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken); await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken);
if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f) if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f)
toReturn.TrySetResult(true); if(toReturn.TrySetResult(true))
Console.WriteLine("Prebuffering finished");
} }
Console.WriteLine("FFMPEG killed or song canceled");
} }
catch catch
{ {
toReturn.TrySetResult(false); if(toReturn.TrySetResult(false))
Console.WriteLine("Prebuffering failed");
//ignored //ignored
} }
}, cancelToken); }, cancelToken);