Skip to content

Commit 7980958

Browse files
committed
Fixed configuration locker leaks.
1 parent 6428bf5 commit 7980958

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

FlashCap.Core/Devices/AVFoundationDevices.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88
////////////////////////////////////////////////////////////////////////////
99

10+
using System;
1011
using System.Collections.Generic;
1112
using System.Linq;
1213
using System.Threading.Tasks;
@@ -18,7 +19,6 @@ namespace FlashCap.Devices;
1819

1920
public sealed class AVFoundationDevices : CaptureDevices
2021
{
21-
2222
public AVFoundationDevices() :
2323
this(new DefaultBufferPool())
2424
{
@@ -42,16 +42,21 @@ protected override IEnumerable<CaptureDeviceDescriptor> OnEnumerateDescriptors()
4242
using var discovery = AVCaptureDeviceDiscoverySession.DiscoverySessionWithVideoDevices();
4343
foreach (var device in discovery.Devices)
4444
{
45-
4645
using var deviceOutput = new AVCaptureVideoDataOutput();
4746

4847
var characteristics = new List<VideoCharacteristics>();
4948

5049
foreach (var format in device.Formats)
5150
{
5251
device.LockForConfiguration();
53-
device.ActiveFormat = format;
54-
device.UnlockForConfiguration();
52+
try
53+
{
54+
device.ActiveFormat = format;
55+
}
56+
finally
57+
{
58+
device.UnlockForConfiguration();
59+
}
5560

5661
var pixelFormatsNative = deviceOutput.AvailableVideoCVPixelFormatTypes;
5762
var pixelFormatsMapped = NativeMethods_AVFoundation.PixelFormatMap
@@ -88,11 +93,9 @@ protected override IEnumerable<CaptureDeviceDescriptor> OnEnumerateDescriptors()
8893
}
8994
}
9095
}
91-
92-
// session.Dispose();
9396

9497
yield return new AVFoundationDeviceDescriptor(
95-
device.UniqueID.ToString(),
98+
device.UniqueID,
9699
device.ModelID,
97100
device.LocalizedName,
98101
characteristics.ToArray(),

0 commit comments

Comments
 (0)