Added isDisposed checks to audio classes. Dont flush the OpusEncodeStream
This commit is contained in:
@@ -43,9 +43,9 @@ namespace Discord.Audio
|
||||
private Task _heartbeatTask;
|
||||
private long _heartbeatTime;
|
||||
private string _url;
|
||||
private bool _isDisposed;
|
||||
private uint _ssrc;
|
||||
private byte[] _secretKey;
|
||||
private bool _isDisposed;
|
||||
|
||||
public SocketGuild Guild { get; }
|
||||
public DiscordVoiceAPIClient ApiClient { get; private set; }
|
||||
@@ -165,8 +165,9 @@ namespace Discord.Audio
|
||||
|
||||
ConnectionState = ConnectionState.Disconnected;
|
||||
await _audioLogger.InfoAsync("Disconnected").ConfigureAwait(false);
|
||||
|
||||
await _disconnectedEvent.InvokeAsync(ex).ConfigureAwait(false);
|
||||
|
||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Guild.Id, null, false, false).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Stream CreateOpusStream(int samplesPerFrame)
|
||||
@@ -314,10 +315,12 @@ namespace Discord.Audio
|
||||
|
||||
internal void Dispose(bool disposing)
|
||||
{
|
||||
DisconnectInternalAsync(null).GetAwaiter().GetResult();
|
||||
if (!_isDisposed)
|
||||
if (disposing && !_isDisposed)
|
||||
{
|
||||
_isDisposed = true;
|
||||
ApiClient.Dispose();
|
||||
DisconnectInternalAsync(null).GetAwaiter().GetResult();
|
||||
ApiClient.Dispose();
|
||||
}
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public void Dispose() => Dispose(true);
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Discord.Audio
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
/*public override void Flush()
|
||||
{
|
||||
FlushAsync(CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace Discord.Audio
|
||||
catch (Exception) { } //Incomplete frame
|
||||
_partialFramePos = 0;
|
||||
await base.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}*/
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Discord.Audio
|
||||
private readonly byte[] _nonce, _secretKey;
|
||||
private int _samplesPerFrame;
|
||||
private uint _ssrc, _timestamp = 0;
|
||||
private bool _isDisposed;
|
||||
|
||||
protected readonly byte[] _buffer;
|
||||
|
||||
@@ -36,7 +37,11 @@ namespace Discord.Audio
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
Flush();
|
||||
if (disposing && !_isDisposed)
|
||||
{
|
||||
_isDisposed = true;
|
||||
Flush();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
||||
@@ -479,7 +479,6 @@ namespace Discord.WebSocket
|
||||
if (AudioClient != null)
|
||||
await AudioClient.DisconnectAsync().ConfigureAwait(false);
|
||||
AudioClient = null;
|
||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, null, false, false).ConfigureAwait(false);
|
||||
}
|
||||
internal async Task FinishConnectAudio(int id, string url, string token)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user