mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-07-30 22:57:11 +02:00
safely close audio on game exit
This commit is contained in:
parent
2999275ed2
commit
fb562c8077
4 changed files with 117 additions and 91 deletions
|
@ -62,11 +62,6 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
return session;
|
||||
}
|
||||
|
||||
internal bool Unregister(OboeHardwareDeviceSession session)
|
||||
{
|
||||
return _sessions.TryRemove(session, out _);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
|
@ -82,6 +77,8 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
}
|
||||
|
||||
_pauseEvent.Dispose();
|
||||
|
||||
_sessions.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
internal class OboeHardwareDeviceSession : HardwareDeviceSessionOutputBase
|
||||
{
|
||||
private OboeHardwareDeviceDriver _driver;
|
||||
private bool _isClosed;
|
||||
private bool _isWorkerActive;
|
||||
private Queue<OboeAudioBuffer> _queuedBuffers;
|
||||
private bool _isActive;
|
||||
|
@ -59,6 +60,9 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
{
|
||||
StartIfNotPlaying();
|
||||
|
||||
if (_isClosed)
|
||||
break;
|
||||
|
||||
fixed(byte* ptr = buffer.Data)
|
||||
OboeInterop.WriteToSession(_session, (ulong)ptr, buffer.SampleCount);
|
||||
|
||||
|
@ -90,18 +94,31 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_session == 0)
|
||||
return;
|
||||
|
||||
PrepareToClose();
|
||||
|
||||
OboeInterop.CloseSession(_session);
|
||||
|
||||
_session = 0;
|
||||
}
|
||||
|
||||
public override void PrepareToClose()
|
||||
{
|
||||
_isClosed = true;
|
||||
_isWorkerActive = false;
|
||||
_workerThread.Join();
|
||||
_workerThread?.Join();
|
||||
Stop();
|
||||
}
|
||||
|
||||
private void StartIfNotPlaying()
|
||||
{
|
||||
lock (_trackLock)
|
||||
{
|
||||
if (_isClosed)
|
||||
return;
|
||||
|
||||
if (OboeInterop.IsPlaying(_session) == 0)
|
||||
{
|
||||
Start();
|
||||
|
@ -145,6 +162,9 @@ namespace LibRyujinx.Shared.Audio.Oboe
|
|||
|
||||
public override void Start()
|
||||
{
|
||||
if (_isClosed)
|
||||
return;
|
||||
|
||||
OboeInterop.StartSession(_session);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,6 @@ namespace LibRyujinx
|
|||
|
||||
var init = Initialize(path, enableDebugLogs);
|
||||
|
||||
// AudioDriver = new OboeHardwareDeviceDriver();
|
||||
|
||||
_surfaceEvent?.Set();
|
||||
|
||||
_surfaceEvent = new ManualResetEvent(false);
|
||||
|
@ -104,6 +102,7 @@ namespace LibRyujinx
|
|||
JStringLocalRef timeZone,
|
||||
JBoolean ignoreMissingServices)
|
||||
{
|
||||
AudioDriver = new OboeHardwareDeviceDriver();
|
||||
return InitializeDevice(isHostMapped,
|
||||
useNce,
|
||||
(SystemLanguage)(int)systemLanguage,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue