7
7
//
8
8
////////////////////////////////////////////////////////////////////////////
9
9
10
+ using System ;
10
11
using System . Collections . Generic ;
11
12
using System . Linq ;
12
13
using System . Threading . Tasks ;
@@ -18,7 +19,6 @@ namespace FlashCap.Devices;
18
19
19
20
public sealed class AVFoundationDevices : CaptureDevices
20
21
{
21
-
22
22
public AVFoundationDevices ( ) :
23
23
this ( new DefaultBufferPool ( ) )
24
24
{
@@ -42,16 +42,21 @@ protected override IEnumerable<CaptureDeviceDescriptor> OnEnumerateDescriptors()
42
42
using var discovery = AVCaptureDeviceDiscoverySession . DiscoverySessionWithVideoDevices ( ) ;
43
43
foreach ( var device in discovery . Devices )
44
44
{
45
-
46
45
using var deviceOutput = new AVCaptureVideoDataOutput ( ) ;
47
46
48
47
var characteristics = new List < VideoCharacteristics > ( ) ;
49
48
50
49
foreach ( var format in device . Formats )
51
50
{
52
51
device . LockForConfiguration ( ) ;
53
- device . ActiveFormat = format ;
54
- device . UnlockForConfiguration ( ) ;
52
+ try
53
+ {
54
+ device . ActiveFormat = format ;
55
+ }
56
+ finally
57
+ {
58
+ device . UnlockForConfiguration ( ) ;
59
+ }
55
60
56
61
var pixelFormatsNative = deviceOutput . AvailableVideoCVPixelFormatTypes ;
57
62
var pixelFormatsMapped = NativeMethods_AVFoundation . PixelFormatMap
@@ -88,11 +93,9 @@ protected override IEnumerable<CaptureDeviceDescriptor> OnEnumerateDescriptors()
88
93
}
89
94
}
90
95
}
91
-
92
- // session.Dispose();
93
96
94
97
yield return new AVFoundationDeviceDescriptor (
95
- device . UniqueID . ToString ( ) ,
98
+ device . UniqueID ,
96
99
device . ModelID ,
97
100
device . LocalizedName ,
98
101
characteristics . ToArray ( ) ,
0 commit comments