Skip to content

Commit

Permalink
fix: Audio stream dispose (#1667)
Browse files Browse the repository at this point in the history
* Fix audio dispose

* Missed a few
  • Loading branch information
SubZero0 committed Nov 7, 2020
1 parent 2592264 commit a2af985
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@ internal BufferedWriteStream(AudioStream next, AudioClient client, int bufferMil

_task = Run();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
_disposeTokenSource?.Cancel();
_disposeTokenSource?.Dispose();
_cancelTokenSource?.Cancel();
_cancelTokenSource?.Dispose();
_queueLock?.Dispose();
_next.Dispose();
}
base.Dispose(disposing);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ public override async Task ClearAsync(CancellationToken cancelToken)

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
_decoder.Dispose();
_next.Dispose();
}
base.Dispose(disposing);
}
}
}
8 changes: 5 additions & 3 deletions src/Discord.Net.WebSocket/Audio/Streams/OpusEncodeStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -89,10 +89,12 @@ public override async Task ClearAsync(CancellationToken cancelToken)

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
_encoder.Dispose();
_next.Dispose();
}
base.Dispose(disposing);
}
}
}
7 changes: 7 additions & 0 deletions src/Discord.Net.WebSocket/Audio/Streams/RTPReadStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ public static int GetHeaderSize(byte[] buffer, int offset)
(buffer[extensionOffset + 3]);
return extensionOffset + 4 + (extensionLength * 4);
}

protected override void Dispose(bool disposing)
{
if (disposing)
_next.Dispose();
base.Dispose(disposing);
}
}
}
9 changes: 8 additions & 1 deletion src/Discord.Net.WebSocket/Audio/Streams/RTPWriteStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -69,5 +69,12 @@ public override async Task ClearAsync(CancellationToken cancelToken)
{
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
}

protected override void Dispose(bool disposing)
{
if (disposing)
_next.Dispose();
base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@ public override async Task ClearAsync(CancellationToken cancelToken)
{
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
}

protected override void Dispose(bool disposing)
{
if (disposing)
_next.Dispose();
base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,12 @@ public override async Task ClearAsync(CancellationToken cancelToken)
{
await _next.ClearAsync(cancelToken).ConfigureAwait(false);
}

protected override void Dispose(bool disposing)
{
if (disposing)
_next.Dispose();
base.Dispose(disposing);
}
}
}

0 comments on commit a2af985

Please sign in to comment.