Skip to content

Commit c4c5321

Browse files
author
Aytackydln
committed
remove instance synchronizations from AudioDeviceProxy and add error handling for NAudio thread
1 parent 922bb1e commit c4c5321

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Project-Aurora/Project-Aurora/Modules/AudioCapture/AudioDeviceProxy.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Runtime.CompilerServices;
65
using System.Threading;
76
using System.Threading.Tasks;
87
using NAudio.CoreAudioApi;
@@ -36,6 +35,10 @@ public sealed class AudioDeviceProxy : IDisposable, IMMNotificationClient
3635
{
3736
return;
3837
}
38+
catch (Exception e)
39+
{
40+
Global.logger.Error(e, "Unexpected error in NAudio thread");
41+
}
3942
}
4043
})
4144
{
@@ -306,7 +309,6 @@ private void DisposeCurrentDeviceOnThread()
306309
DeviceChanged?.Invoke(this, EventArgs.Empty);
307310
}
308311

309-
[MethodImpl(MethodImplOptions.Synchronized)]
310312
public void OnDeviceStateChanged(string deviceId, DeviceState newState)
311313
{
312314
if (DeviceId != deviceId)
@@ -339,15 +341,13 @@ public void OnDeviceStateChanged(string deviceId, DeviceState newState)
339341
}
340342
}
341343

342-
[MethodImpl(MethodImplOptions.Synchronized)]
343344
public void OnDeviceAdded(string pwstrDeviceId)
344345
{
345346
if (pwstrDeviceId != DeviceId) return;
346347
var mmDevice = _deviceEnumerator.GetDevice(pwstrDeviceId);
347348
SetDevice(mmDevice);
348349
}
349350

350-
[MethodImpl(MethodImplOptions.Synchronized)]
351351
public void OnDeviceRemoved(string deviceId)
352352
{
353353
if (Device?.ID == deviceId && Device?.State != DeviceState.Active)
@@ -359,7 +359,6 @@ public void OnDeviceRemoved(string deviceId)
359359
/// <summary>
360360
/// Update the device when changed by the system.
361361
/// </summary>
362-
[MethodImpl(MethodImplOptions.Synchronized)]
363362
public void OnDefaultDeviceChanged(DataFlow flow, Role role, string? defaultDeviceId)
364363
{
365364
if (Flow != flow || !AudioDevices.DefaultDeviceId.Equals(DeviceId)) return;

0 commit comments

Comments
 (0)