Skip to content

Commit f562341

Browse files
committed
Merge branch 'step-2' into develop
2 parents aefe73e + 3cb4ac9 commit f562341

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

FlashCap.Core/Devices/AVFoundationDevice.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,36 @@ public AVFoundationDevice(string uniqueID, string modelID) :
4242
}
4343

4444
protected override async Task OnDisposeAsync()
45-
{
46-
if (this.session != null)
47-
{
48-
this.session.StopRunning();
49-
this.session.Dispose();
45+
{
46+
// Ensure that we stop the session if it's running
47+
if (this.session is not null && IsRunning)
48+
{
49+
this.session.StopRunning();
50+
IsRunning = false;
5051
}
51-
52-
this.device?.Dispose();
52+
53+
this.session?.Dispose();
5354
this.deviceInput?.Dispose();
5455
this.deviceOutput?.Dispose();
56+
this.device?.Dispose();
5557
this.queue?.Dispose();
5658

57-
Marshal.FreeHGlobal(this.bitmapHeader);
59+
this.session = null;
60+
this.deviceInput = null;
61+
this.deviceOutput = null;
62+
this.device = null;
63+
this.queue = null;
64+
65+
if (this.bitmapHeader != IntPtr.Zero)
66+
{
67+
Marshal.FreeHGlobal(this.bitmapHeader);
68+
this.bitmapHeader = IntPtr.Zero;
69+
}
5870

59-
if (frameProcessor is not null)
71+
if (this.frameProcessor is not null)
6072
{
61-
await frameProcessor.DisposeAsync().ConfigureAwait(false);
73+
await this.frameProcessor.DisposeAsync().ConfigureAwait(false);
74+
this.frameProcessor = null;
6275
}
6376

6477
await base.OnDisposeAsync().ConfigureAwait(false);

FlashCap.Core/Internal/AVFoundation/AVCaptureVideoDataOutput.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void SetPixelFormatType(int format)
7373
IntPtr pixelFormatTypeKeyPtr = Dlfcn.dlsym(LibCoreVideo.Handle, "kCVPixelBufferPixelFormatTypeKey");
7474
if (pixelFormatTypeKeyPtr == IntPtr.Zero)
7575
{
76-
throw new Exception("Error comunicating with the AVCaptureVideoDataOutput");
76+
throw new Exception("Error communicating with the AVCaptureVideoDataOutput");
7777
}
7878

7979
// Get NSString value
@@ -107,7 +107,7 @@ public void SetSampleBufferDelegate(AVFoundationDevice.VideoBufferHandler sample
107107

108108
IntPtr impCallback = Marshal.GetFunctionPointerForDelegate(callbackDelegate);
109109

110-
// "v@:@@@" this means the methood returns void and receives (self, _cmd, output, sampleBuffer, connection).
110+
// "v@:@@@" this means the method returns void and receives (self, _cmd, output, sampleBuffer, connection).
111111
string types = "v@:@@@";
112112
bool added = LibObjC.class_addMethod(delegateClass, selDidOutput, impCallback, types);
113113
if (!added)

0 commit comments

Comments
 (0)