From 99049a6ace16343f39936574655ca1b897353ffa Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Mon, 3 Jul 2017 12:46:51 +0200 Subject: [PATCH] Prebuffering time drastically decreased --- src/NadekoBot/DataStructures/PoopyRingBuffer.cs | 5 +++++ src/NadekoBot/Services/Music/SongBuffer.cs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs index 28b391e6..a09af647 100644 --- a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs +++ b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs @@ -38,6 +38,11 @@ namespace NadekoBot.DataStructures } } + public int LightLength => + _readPos <= _writePos? + _writePos - _readPos : + Capacity - (_readPos - _writePos); + public int RemainingCapacity { get { lock (posLock) return Capacity - Length - 1; } diff --git a/src/NadekoBot/Services/Music/SongBuffer.cs b/src/NadekoBot/Services/Music/SongBuffer.cs index 9f26671d..08737c49 100644 --- a/src/NadekoBot/Services/Music/SongBuffer.cs +++ b/src/NadekoBot/Services/Music/SongBuffer.cs @@ -54,7 +54,7 @@ namespace NadekoBot.Services.Music bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, readSize, cancelToken).ConfigureAwait(false); await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken); - if (_outStream.RemainingCapacity < _outStream.Capacity * 0.5f || bytesRead == 0) + if (_outStream.LightLength > 200_000 || bytesRead == 0) if (toReturn.TrySetResult(true)) _log.Info("Prebuffering finished"); }