From 42658355b1f122c09889f83af936d16b2cc3ce7c Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 2 Jul 2017 09:55:26 +0200 Subject: [PATCH] music debug stuff --- .../DataStructures/PoopyRingBuffer.cs | 5 ++-- src/NadekoBot/Modules/Music/Music.cs | 1 + src/NadekoBot/Services/Music/MusicPlayer.cs | 1 + src/NadekoBot/Services/Music/SongBuffer.cs | 27 ++++++++++++++++--- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs index 4c8764db..0a2ca39f 100644 --- a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs +++ b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs @@ -48,7 +48,7 @@ namespace NadekoBot.DataStructures 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.buffer = new byte[this.Capacity]; @@ -59,7 +59,6 @@ namespace NadekoBot.DataStructures await _locker.WaitAsync(cancelToken); try { - Console.WriteLine("Reading {0}", toRead); if (WritePos == ReadPos) return 0; @@ -129,7 +128,7 @@ namespace NadekoBot.DataStructures WritePos = 0; } } - Console.WriteLine("Readpos: {0} WritePos: {1}", ReadPos, WritePos); + Console.WriteLine("Readpos: {0} WritePos: {1} ({2})", ReadPos, WritePos, ReadPos - WritePos); return toWrite; } finally diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 11448b60..a8906e62 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -165,6 +165,7 @@ namespace NadekoBot.Modules.Music } } + //todo, page should default to the page the current song is on [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task ListQueue(int page = 1) diff --git a/src/NadekoBot/Services/Music/MusicPlayer.cs b/src/NadekoBot/Services/Music/MusicPlayer.cs index 24da1242..535cfe34 100644 --- a/src/NadekoBot/Services/Music/MusicPlayer.cs +++ b/src/NadekoBot/Services/Music/MusicPlayer.cs @@ -117,6 +117,7 @@ namespace NadekoBot.Services.Music await (pauseTaskSource?.Task ?? Task.CompletedTask); } + _log.Info(">>>>>>>>>READ 0<<<<<<<<<<"); } catch (OperationCanceledException) { diff --git a/src/NadekoBot/Services/Music/SongBuffer.cs b/src/NadekoBot/Services/Music/SongBuffer.cs index 5f4c8c91..1c73da10 100644 --- a/src/NadekoBot/Services/Music/SongBuffer.cs +++ b/src/NadekoBot/Services/Music/SongBuffer.cs @@ -42,17 +42,36 @@ namespace NadekoBot.Services.Music byte[] buffer = new byte[3840]; 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); 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 { - toReturn.TrySetResult(false); + if(toReturn.TrySetResult(false)) + Console.WriteLine("Prebuffering failed"); //ignored } }, cancelToken);