1
1
/********************************************************************
2
- * Copyright (C) 2015-2017 Antoine Aflalo
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version 2
7
- * of the License, or (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- ********************************************************************/
2
+ * Copyright (C) 2015-2017 Antoine Aflalo
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License
6
+ * as published by the Free Software Foundation; either version 2
7
+ * of the License, or (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ ********************************************************************/
14
14
15
15
using System ;
16
16
using System . Collections . Generic ;
@@ -32,10 +32,10 @@ namespace SoundSwitch.Framework.Audio.Lister
32
32
public class CachedAudioDeviceLister : IAudioDeviceLister
33
33
{
34
34
/// <inheritdoc />
35
- private DeviceReadOnlyCollection < DeviceFullInfo > PlaybackDevices { get ; set ; } = new ( Enumerable . Empty < DeviceFullInfo > ( ) , DataFlow . Render ) ;
35
+ private DeviceReadOnlyCollection < DeviceFullInfo > PlaybackDevices { get ; set ; } = new ( Enumerable . Empty < DeviceFullInfo > ( ) , DataFlow . Render ) ;
36
36
37
37
/// <inheritdoc />
38
- private DeviceReadOnlyCollection < DeviceFullInfo > RecordingDevices { get ; set ; } = new ( Enumerable . Empty < DeviceFullInfo > ( ) , DataFlow . Capture ) ;
38
+ private DeviceReadOnlyCollection < DeviceFullInfo > RecordingDevices { get ; set ; } = new ( Enumerable . Empty < DeviceFullInfo > ( ) , DataFlow . Capture ) ;
39
39
40
40
/// <summary>
41
41
/// Get devices per type and state
@@ -58,6 +58,7 @@ public DeviceReadOnlyCollection<DeviceFullInfo> GetDevices(DataFlow type, Device
58
58
private readonly ILogger _context ;
59
59
private uint _threadSafeRefreshing ;
60
60
private DateTime _lastRefresh = DateTime . UtcNow ;
61
+
61
62
public bool Refreshing
62
63
{
63
64
get => Interlocked . CompareExchange ( ref _threadSafeRefreshing , 1 , 1 ) == 1 ;
@@ -94,8 +95,10 @@ public void Refresh(CancellationToken cancellationToken = default)
94
95
_context . Warning ( "Can't refresh, already refreshing since {LastRefresh}" , _lastRefresh ) ;
95
96
//We want to be sure we get the latest refresh, it's not because we are refreshing that we'll get the latest info
96
97
JobScheduler . Instance . ScheduleJob ( new DebounceRefreshJob ( _state , this , _context ) ) ;
98
+
97
99
return ;
98
100
}
101
+
99
102
var stopWatch = Stopwatch . StartNew ( ) ;
100
103
try
101
104
{
@@ -151,7 +154,7 @@ public void Refresh(CancellationToken cancellationToken = default)
151
154
RecordingDevices = new DeviceReadOnlyCollection < DeviceFullInfo > ( recordingDevices . Values , DataFlow . Capture ) ;
152
155
153
156
154
- _context . Information ( "Refreshed all devices in {@StopTime}. {@Recording}/rec, {@Playback}/play" , stopWatch . Elapsed , recordingDevices . Count , playbackDevices . Count ) ;
157
+ _context . Information ( "Refreshed all devices in {@StopTime}. {@Recording}/rec, {@Playback}/play" , stopWatch . Elapsed , recordingDevices . Count , playbackDevices . Count ) ;
155
158
}
156
159
//If cancellation token is cancelled, its expected to throw null since the device enumerator has been disposed
157
160
catch ( NullReferenceException e ) when ( ! cancellationToken . IsCancellationRequested )
@@ -169,7 +172,7 @@ public void Refresh(CancellationToken cancellationToken = default)
169
172
public void Dispose ( )
170
173
{
171
174
MMNotificationClient . Instance . DevicesChanged -= DeviceChanged ;
172
-
175
+
173
176
foreach ( var device in PlaybackDevices . Union ( RecordingDevices ) )
174
177
{
175
178
device . Dispose ( ) ;
0 commit comments