77//
88////////////////////////////////////////////////////////////////////////////
99
10+ using System ;
1011using System . Collections . Generic ;
1112using System . Linq ;
1213using System . Threading . Tasks ;
@@ -18,7 +19,6 @@ namespace FlashCap.Devices;
1819
1920public 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