Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FSharp.FlashCap/FSharp.FlashCap.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net48;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion FlashCap.Core/FlashCap.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net35;net40;net45;net461;net48;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net45;net461;net48;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CS0649</NoWarn>
<IsPackable>true</IsPackable>
Expand Down
69 changes: 44 additions & 25 deletions FlashCap.Core/Internal/AVFoundation/AVCaptureSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public AVCaptureSession() : base(IntPtr.Zero, false)
Init();
}

private void ValidateHandle(string method)
{
if (Handle == IntPtr.Zero)
{
throw new NullReferenceException($"{nameof(AVCaptureSession)} handle is NULL in '{method}'.");
}
}

private void Init()
{
var sessionClass = LibObjC.SendAndGetHandle(
Expand All @@ -34,50 +42,61 @@ private void Init()
LibObjC.GetSelector("init"));

Handle = sessionObj;
ValidateHandle(nameof(Init));

LibCoreFoundation.CFRetain(this.Handle);
LibCoreFoundation.CFRetain(this.Handle);
}

public void AddInput(AVCaptureInput input) =>
LibObjC.SendNoResult(
Handle,
LibObjC.GetSelector("addInput:"),
input.Handle);

public void AddInput(AVCaptureInput input)
{
ValidateHandle(nameof(AddInput));

LibObjC.SendNoResult(
Handle,
LibObjC.GetSelector("addInput:"),
input.Handle);
}

public void AddOutput(AVCaptureOutput output)
{
IntPtr allocSel = LibObjC.GetSelector("alloc");
IntPtr initSel = LibObjC.GetSelector("init");

var videoDataOutputObj = output as AVCaptureVideoDataOutput ;

if (videoDataOutputObj == null)
{
throw new Exception("Failed to get video data output");
}

var videoDataOutput = videoDataOutputObj.Handle;

var videoDataOutputObj = output as AVCaptureVideoDataOutput
?? throw new Exception("Failed to get video data output") ;

var videoDataOutput = videoDataOutputObj.Handle;

ValidateHandle(nameof(AddOutput));
LibObjC.SendNoResult(
Handle,
LibObjC.GetSelector("addOutput:"),
videoDataOutput);
}

public bool CanAddOutput(AVCaptureOutput output) =>
LibObjC.SendAndGetBool(
public bool CanAddOutput(AVCaptureOutput output)
{
ValidateHandle(nameof(CanAddOutput));
return LibObjC.SendAndGetBool(
Handle,
LibObjC.GetSelector("canAddOutput:"),
output.Handle);

public void StartRunning() =>
output.Handle);
}

public void StartRunning()
{
ValidateHandle(nameof(StartRunning));
LibObjC.SendNoResult(
Handle,
LibObjC.GetSelector("startRunning"));

public void StopRunning() =>
LibObjC.GetSelector("startRunning"));
}

public void StopRunning()
{
ValidateHandle(nameof(StopRunning));
LibObjC.SendNoResult(
Handle,
LibObjC.GetSelector("stopRunning"));
LibObjC.GetSelector("stopRunning"));
}
}
}
13 changes: 11 additions & 2 deletions FlashCap.Core/Internal/AVFoundation/LibAVFoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
////////////////////////////////////////////////////////////////////////////

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Linq;
using static FlashCap.Internal.NativeMethods_AVFoundation;
Expand All @@ -24,6 +23,14 @@ internal static partial class LibAVFoundation

public delegate void AVRequestAccessStatus(bool accessGranted);

private static void ValidateHandle(string method)
{
if (Handle == IntPtr.Zero)
{
throw new NullReferenceException($"{nameof(LibAVFoundation)} handle is NULL in '{method}'.");
}
}

public sealed class AVFrameRateRange : LibObjC.NSObject
{
public AVFrameRateRange(IntPtr handle, bool retain) :
Expand Down Expand Up @@ -226,6 +233,7 @@ public static AVAuthorizationStatus GetAuthorizationStatus(IntPtr mediaType)

public static unsafe void RequestAccessForMediaType(IntPtr mediaType, AVRequestAccessStatus completion)
{
ValidateHandle(nameof(RequestAccessForMediaType));
RequestAccessForMediaTypeBlockFactory ??= LibObjC.BlockLiteralFactory.CreateFactory<RequestAccessForMediaTypeTrampoline>(
signature: "v@?^vC",
delegate (IntPtr block, byte accessGranted)
Expand Down Expand Up @@ -260,6 +268,7 @@ public AVCaptureDeviceDiscoverySession(IntPtr handle, bool retain) :

public static AVCaptureDeviceDiscoverySession DiscoverySessionWithVideoDevices()
{
ValidateHandle(nameof(DiscoverySessionWithVideoDevices));
var deviceTypes = new[]
{
AVCaptureDeviceType.BuiltInWideAngleCamera,
Expand Down Expand Up @@ -369,7 +378,7 @@ private static unsafe IntPtr FromDevice(AVCaptureDevice device)
public abstract class AVCaptureVideoDataOutputSampleBuffer : LibObjC.NSObject
{
private const string HandleVariableName = nameof(GCHandle);
private static IntPtr HandleVariableDescriptor;
private static readonly IntPtr HandleVariableDescriptor;

static AVCaptureVideoDataOutputSampleBuffer()
{
Expand Down
2 changes: 1 addition & 1 deletion FlashCap/FlashCap.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net35;net40;net45;net461;net48;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net35;net40;net45;net461;net48;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS0649</NoWarn>
<IsPackable>true</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<TargetFrameworks>net48;net8.0;net9.0;net10.0</TargetFrameworks>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

Expand Down