aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs
diff options
context:
space:
mode:
authorMary <mary@mary.zone>2023-03-27 20:56:36 +0200
committerGitHub <noreply@github.com>2023-03-27 20:56:36 +0200
commit7ca779a26d76a3ad1edd94ba6c1cfd7466d73314 (patch)
treeca38a3f6013a79fd6e1a2b7f920c6f9e3b6c61f0 /Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs
parentb5032b3c91e9af6a1afb87b4bd8346922084ae75 (diff)
audout: Fix a possible crash with SDL2 when the SDL2 audio backend is dummy (#4605)1.1.686
This change makes audio device error not fatal. In case of error, the SDL2 audio backend will behave like the dummy backend.
Diffstat (limited to 'Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs')
-rw-r--r--Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs27
1 files changed, 17 insertions, 10 deletions
diff --git a/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs b/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs
index 38e2b133..14310b93 100644
--- a/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs
+++ b/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceSession.cs
@@ -18,6 +18,7 @@ namespace Ryujinx.Audio.Backends.SDL2
private ulong _playedSampleCount;
private ManualResetEvent _updateRequiredEvent;
private uint _outputStream;
+ private bool _hasSetupError;
private SDL_AudioCallback _callbackDelegate;
private int _bytesPerFrame;
private uint _sampleCount;
@@ -42,7 +43,7 @@ namespace Ryujinx.Audio.Backends.SDL2
private void EnsureAudioStreamSetup(AudioBuffer buffer)
{
uint bufferSampleCount = (uint)GetSampleCount(buffer);
- bool needAudioSetup = _outputStream == 0 ||
+ bool needAudioSetup = (_outputStream == 0 && !_hasSetupError) ||
(bufferSampleCount >= Constants.TargetSampleCount && bufferSampleCount < _sampleCount);
if (needAudioSetup)
@@ -51,12 +52,9 @@ namespace Ryujinx.Audio.Backends.SDL2
uint newOutputStream = SDL2HardwareDeviceDriver.OpenStream(RequestedSampleFormat, RequestedSampleRate, RequestedChannelCount, _sampleCount, _callbackDelegate);
- if (newOutputStream == 0)
- {
- // No stream in place, this is unexpected.
- throw new InvalidOperationException($"OpenStream failed with error: \"{SDL_GetError()}\"");
- }
- else
+ _hasSetupError = newOutputStream == 0;
+
+ if (!_hasSetupError)
{
if (_outputStream != 0)
{
@@ -151,11 +149,20 @@ namespace Ryujinx.Audio.Backends.SDL2
{
EnsureAudioStreamSetup(buffer);
- SDL2AudioBuffer driverBuffer = new SDL2AudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
+ if (_outputStream != 0)
+ {
+ SDL2AudioBuffer driverBuffer = new SDL2AudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
- _ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
+ _ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
- _queuedBuffers.Enqueue(driverBuffer);
+ _queuedBuffers.Enqueue(driverBuffer);
+ }
+ else
+ {
+ Interlocked.Add(ref _playedSampleCount, GetSampleCount(buffer));
+
+ _updateRequiredEvent.Set();
+ }
}
public override void SetVolume(float volume)