Cleanup, improvements
This commit is contained in:
parent
f826fb97f6
commit
eba804b5ce
@ -35,7 +35,7 @@ namespace NadekoBot.DataStructures
|
|||||||
|
|
||||||
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
||||||
|
|
||||||
public PoopyRingBuffer(int capacity = 50_000_000)
|
public PoopyRingBuffer(int capacity = 81920 * 100)
|
||||||
{
|
{
|
||||||
this.Capacity = capacity + 1;
|
this.Capacity = capacity + 1;
|
||||||
this.buffer = new byte[this.Capacity];
|
this.buffer = new byte[this.Capacity];
|
||||||
|
@ -21,7 +21,10 @@ namespace NadekoBot.Services.Administration
|
|||||||
TimeZoneInfo tz;
|
TimeZoneInfo tz;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tz = TimeZoneInfo.FindSystemTimeZoneById(x.TimeZoneId);
|
if (x.TimeZoneId == null)
|
||||||
|
tz = null;
|
||||||
|
else
|
||||||
|
tz = TimeZoneInfo.FindSystemTimeZoneById(x.TimeZoneId);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -321,10 +321,10 @@ namespace NadekoBot.Services.Music
|
|||||||
}
|
}
|
||||||
newVoiceChannel = false;
|
newVoiceChannel = false;
|
||||||
var curUser = await VoiceChannel.Guild.GetCurrentUserAsync();
|
var curUser = await VoiceChannel.Guild.GetCurrentUserAsync();
|
||||||
_audioClient = await VoiceChannel.ConnectAsync();
|
|
||||||
if (curUser.VoiceChannel != null)
|
if (curUser.VoiceChannel != null)
|
||||||
{
|
{
|
||||||
await _audioClient.StopAsync();
|
var ac = await VoiceChannel.ConnectAsync();
|
||||||
|
await ac.StopAsync();
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
_audioClient = await VoiceChannel.ConnectAsync();
|
_audioClient = await VoiceChannel.ConnectAsync();
|
||||||
|
@ -10,7 +10,7 @@ namespace NadekoBot.Services.Music
|
|||||||
{
|
{
|
||||||
public class SongBuffer : IDisposable
|
public class SongBuffer : IDisposable
|
||||||
{
|
{
|
||||||
const int readSize = 38400;
|
const int readSize = 81920;
|
||||||
private Process p;
|
private Process p;
|
||||||
private PoopyRingBuffer _outStream = new PoopyRingBuffer();
|
private PoopyRingBuffer _outStream = new PoopyRingBuffer();
|
||||||
|
|
||||||
@ -52,8 +52,13 @@ namespace NadekoBot.Services.Music
|
|||||||
var toReturn = new TaskCompletionSource<bool>();
|
var toReturn = new TaskCompletionSource<bool>();
|
||||||
var _ = Task.Run(async () =>
|
var _ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
int maxLoopsPerSec = 25;
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
var delay = 1000 / maxLoopsPerSec;
|
||||||
|
int currentLoops = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
++currentLoops;
|
||||||
byte[] buffer = new byte[readSize];
|
byte[] buffer = new byte[readSize];
|
||||||
int bytesRead = 1;
|
int bytesRead = 1;
|
||||||
while (!cancelToken.IsCancellationRequested && !this.p.HasExited)
|
while (!cancelToken.IsCancellationRequested && !this.p.HasExited)
|
||||||
@ -67,7 +72,7 @@ namespace NadekoBot.Services.Music
|
|||||||
lock (locker)
|
lock (locker)
|
||||||
written = _outStream.Write(buffer, 0, bytesRead);
|
written = _outStream.Write(buffer, 0, bytesRead);
|
||||||
if (!written)
|
if (!written)
|
||||||
await Task.Delay(32, cancelToken);
|
await Task.Delay(2000, cancelToken);
|
||||||
}
|
}
|
||||||
while (!written);
|
while (!written);
|
||||||
lock (locker)
|
lock (locker)
|
||||||
@ -75,9 +80,15 @@ namespace NadekoBot.Services.Music
|
|||||||
if (toReturn.TrySetResult(true))
|
if (toReturn.TrySetResult(true))
|
||||||
_log.Info("Prebuffering finished");
|
_log.Info("Prebuffering finished");
|
||||||
|
|
||||||
await Task.Delay(5); // @.@
|
_log.Info(_outStream.Length);
|
||||||
|
await Task.Delay(10);
|
||||||
}
|
}
|
||||||
_log.Info("FFMPEG killed, song canceled, or song fully downloaded");
|
if (cancelToken.IsCancellationRequested)
|
||||||
|
_log.Info("Song canceled");
|
||||||
|
else if (p.HasExited)
|
||||||
|
_log.Info("Song buffered completely (FFmpeg exited)");
|
||||||
|
else if (bytesRead == 0)
|
||||||
|
_log.Info("Nothing read");
|
||||||
}
|
}
|
||||||
catch (System.ComponentModel.Win32Exception)
|
catch (System.ComponentModel.Win32Exception)
|
||||||
{
|
{
|
||||||
@ -119,8 +130,14 @@ Check the guides for your platform on how to setup ffmpeg correctly:
|
|||||||
{
|
{
|
||||||
_log.Error(ex);
|
_log.Error(ex);
|
||||||
}
|
}
|
||||||
try { this.p.Kill(); }
|
try
|
||||||
catch { }
|
{
|
||||||
|
if(!this.p.HasExited)
|
||||||
|
this.p.Kill();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
_outStream.Dispose();
|
_outStream.Dispose();
|
||||||
this.p.Dispose();
|
this.p.Dispose();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user