Skip to content

Commit a113175

Browse files
committed
fix(Device::Cache): Devices not being refreshed
Fixes #1323
1 parent 3c12b3f commit a113175

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/********************************************************************
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+
********************************************************************/
1414

1515
using System;
1616
using System.Collections.Generic;
@@ -32,10 +32,10 @@ namespace SoundSwitch.Framework.Audio.Lister
3232
public class CachedAudioDeviceLister : IAudioDeviceLister
3333
{
3434
/// <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);
3636

3737
/// <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);
3939

4040
/// <summary>
4141
/// Get devices per type and state
@@ -58,6 +58,7 @@ public DeviceReadOnlyCollection<DeviceFullInfo> GetDevices(DataFlow type, Device
5858
private readonly ILogger _context;
5959
private uint _threadSafeRefreshing;
6060
private DateTime _lastRefresh = DateTime.UtcNow;
61+
6162
public bool Refreshing
6263
{
6364
get => Interlocked.CompareExchange(ref _threadSafeRefreshing, 1, 1) == 1;
@@ -94,8 +95,10 @@ public void Refresh(CancellationToken cancellationToken = default)
9495
_context.Warning("Can't refresh, already refreshing since {LastRefresh}", _lastRefresh);
9596
//We want to be sure we get the latest refresh, it's not because we are refreshing that we'll get the latest info
9697
JobScheduler.Instance.ScheduleJob(new DebounceRefreshJob(_state, this, _context));
98+
9799
return;
98100
}
101+
99102
var stopWatch = Stopwatch.StartNew();
100103
try
101104
{
@@ -151,7 +154,7 @@ public void Refresh(CancellationToken cancellationToken = default)
151154
RecordingDevices = new DeviceReadOnlyCollection<DeviceFullInfo>(recordingDevices.Values, DataFlow.Capture);
152155

153156

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);
155158
}
156159
//If cancellation token is cancelled, its expected to throw null since the device enumerator has been disposed
157160
catch (NullReferenceException e) when (!cancellationToken.IsCancellationRequested)
@@ -169,7 +172,7 @@ public void Refresh(CancellationToken cancellationToken = default)
169172
public void Dispose()
170173
{
171174
MMNotificationClient.Instance.DevicesChanged -= DeviceChanged;
172-
175+
173176
foreach (var device in PlaybackDevices.Union(RecordingDevices))
174177
{
175178
device.Dispose();

0 commit comments

Comments
 (0)