free ffmpeg process

This commit is contained in:
Master Kwoth 2016-02-28 18:59:50 +01:00
parent 6e23aa2d67
commit 57e6cd2e49

View File

@ -135,13 +135,14 @@ namespace NadekoBot.Classes.Music {
private Task BufferSong(CancellationToken cancelToken) => private Task BufferSong(CancellationToken cancelToken) =>
Task.Run(async () => { Task.Run(async () => {
var p = Process.Start(new ProcessStartInfo { Process p = null;
try {
p = Process.Start(new ProcessStartInfo {
FileName = "ffmpeg", FileName = "ffmpeg",
Arguments = $"-i {SongInfo.Uri} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet", Arguments = $"-i {SongInfo.Uri} -f s16le -ar 48000 -ac 2 pipe:1 -loglevel quiet",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = true, RedirectStandardOutput = true,
}); });
int blockSize = 3840; int blockSize = 3840;
byte[] buffer = new byte[blockSize]; byte[] buffer = new byte[blockSize];
int attempt = 0; int attempt = 0;
@ -158,6 +159,14 @@ namespace NadekoBot.Classes.Music {
if (songBuffer.ContentLength > 2.MB()) if (songBuffer.ContentLength > 2.MB())
prebufferingComplete = true; prebufferingComplete = true;
} }
}
finally {
if (p != null) {
p.CancelOutputRead();
p.Close();
p.Dispose();
}
}
Console.WriteLine($"Buffering done. [{songBuffer.ContentLength}]"); Console.WriteLine($"Buffering done. [{songBuffer.ContentLength}]");
}); });
@ -169,6 +178,7 @@ namespace NadekoBot.Classes.Music {
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) { while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
await Task.Delay(waitPerAttempt); await Task.Delay(waitPerAttempt);
} }
Console.WriteLine($"Prebuffering done? in {waitPerAttempt*bufferAttempts}");
int blockSize = 3840; int blockSize = 3840;
byte[] buffer = new byte[blockSize]; byte[] buffer = new byte[blockSize];
int attempt = 0; int attempt = 0;