Skip to content

Commit

Permalink
Disable FEC (#2670)
Browse files Browse the repository at this point in the history
* Remove incorrect usage of FEC

* Return instead of await
  • Loading branch information
KubaZ2 authored Apr 18, 2023
1 parent d5ba7d2 commit 2be9b00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/Discord.Net.WebSocket/Audio/Opus/OpusCtl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ internal enum OpusCtl : int
{
SetBitrate = 4002,
SetBandwidth = 4008,
SetInbandFEC = 4012,
SetPacketLossPercent = 4014,
SetSignal = 4024
}
Expand Down
1 change: 0 additions & 1 deletion src/Discord.Net.WebSocket/Audio/Opus/OpusEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public OpusEncoder(int bitrate, AudioApplication application, int packetLoss)
CheckError(error);
CheckError(EncoderCtl(_ptr, OpusCtl.SetSignal, (int)opusSignal));
CheckError(EncoderCtl(_ptr, OpusCtl.SetPacketLossPercent, packetLoss)); //%
CheckError(EncoderCtl(_ptr, OpusCtl.SetInbandFEC, 1)); //True
CheckError(EncoderCtl(_ptr, OpusCtl.SetBitrate, bitrate));
}

Expand Down
22 changes: 6 additions & 16 deletions src/Discord.Net.WebSocket/Audio/Streams/OpusDecodeStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,17 @@ public override void WriteHeader(ushort seq, uint timestamp, bool missed)
}

/// <exception cref="InvalidOperationException">Received payload without an RTP header.</exception>
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
{
if (!_hasHeader)
throw new InvalidOperationException("Received payload without an RTP header.");
_hasHeader = false;

if (!_nextMissed)
{
count = _decoder.DecodeFrame(buffer, offset, count, _buffer, 0, false);
await _next.WriteAsync(_buffer, 0, count, cancelToken).ConfigureAwait(false);
}
else if (count > 0)
{
count = _decoder.DecodeFrame(buffer, offset, count, _buffer, 0, true);
await _next.WriteAsync(_buffer, 0, count, cancelToken).ConfigureAwait(false);
}
else
{
count = _decoder.DecodeFrame(null, 0, 0, _buffer, 0, true);
await _next.WriteAsync(_buffer, 0, count, cancelToken).ConfigureAwait(false);
}
count = !_nextMissed || count > 0
? _decoder.DecodeFrame(buffer, offset, count, _buffer, 0, false)
: _decoder.DecodeFrame(null, 0, 0, _buffer, 0, false);

return _next.WriteAsync(_buffer, 0, count, cancelToken);
}

public override async Task FlushAsync(CancellationToken cancelToken)
Expand Down

0 comments on commit 2be9b00

Please sign in to comment.