Skip to content
Draft
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
28 changes: 28 additions & 0 deletions bindings/csharp/src/CNativeAPI/generated/CaptureSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace CNativeAPI;

public static partial class Interop
{
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr native_capture_source_get_name(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern int native_capture_source_get_type(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong native_capture_source_from_display(ulong display);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong native_capture_source_from_window(ulong window);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_capture_source_free(ulong handle);
}

59 changes: 59 additions & 0 deletions bindings/csharp/src/CNativeAPI/generated/ScreenCapturer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace CNativeAPI;

[StructLayout(LayoutKind.Sequential)]
public struct native_capture_source_selection_options_t
{
public byte allow_displays;
public byte allow_windows;
public ulong parent_window;
}

[StructLayout(LayoutKind.Sequential)]
public struct native_screen_capture_options_t
{
public byte include_cursor;
public byte crop_enabled;
public native_rectangle_t crop;
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ScreenCapturerCaptureCallbackNativeCallback([MarshalAs(UnmanagedType.I1)] bool arg0, ulong arg1, ulong delivery, IntPtr userData);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ScreenCapturerSelectSourceCallbackNativeCallback([MarshalAs(UnmanagedType.I1)] bool arg0, ulong arg1, ulong delivery, IntPtr userData);

public static partial class Interop
{
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_capturer_is_direct_capture_supported(int type);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_capturer_is_source_selection_supported();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_capturer_is_supported();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_capture_source_selection_options_free(ref native_capture_source_selection_options_t value);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_screen_capture_options_free(ref native_screen_capture_options_t value);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_screen_capturer_capture(ulong source, native_screen_capture_options_t options, ScreenCapturerCaptureCallbackNativeCallback callback, IntPtr callback_user_data, ReleaseUserDataNativeCallback callback_release_user_data);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_screen_capturer_select_source(native_capture_source_selection_options_t options, ScreenCapturerSelectSourceCallbackNativeCallback callback, IntPtr callback_user_data, ReleaseUserDataNativeCallback callback_release_user_data);
}

96 changes: 96 additions & 0 deletions bindings/csharp/src/CNativeAPI/generated/ScreenRecorder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace CNativeAPI;

[StructLayout(LayoutKind.Sequential)]
public struct native_screen_recording_options_t
{
public native_screen_capture_options_t capture;
public double frame_rate;
public CULong video_bitrate;
}

[StructLayout(LayoutKind.Sequential)]
public struct native_screen_recording_event_t
{
public int type;
public DataUnion data;

[StructLayout(LayoutKind.Explicit)]
public struct DataUnion
{
[FieldOffset(0)] public CompletedData completed;
[FieldOffset(0)] public FailedData failed;
}

[StructLayout(LayoutKind.Sequential)]
public struct CompletedData
{
public IntPtr file_path;
public double duration;
}

[StructLayout(LayoutKind.Sequential)]
public struct FailedData
{
public IntPtr message;
}
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ScreenRecordingEventNativeCallback(IntPtr evt, IntPtr userData);

public static partial class Interop
{
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_cancel(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_is_active(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_is_supported();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_remove_listener(ulong self, ulong listenerId);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_start(ulong self, ulong source, [MarshalAs(UnmanagedType.LPUTF8Str)] string? filePath, native_screen_recording_options_t options);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool native_screen_recorder_stop(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr native_screen_recorder_get_file_path(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern double native_screen_recorder_get_duration(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern int native_screen_recorder_get_state(ulong self);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong native_screen_recorder_add_listener(ulong self, ScreenRecordingEventNativeCallback callback, IntPtr userData, ReleaseUserDataNativeCallback releaseUserData);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern ulong native_screen_recorder_create();

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_screen_recorder_free(ulong handle);

[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
public static extern void native_screen_recording_options_free(ref native_screen_recording_options_t value);
}

80 changes: 80 additions & 0 deletions bindings/csharp/src/NativeAPI/CaptureSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CNativeAPI;

namespace NativeAPI;

public enum CaptureSourceType
{
None = 0,
Display = 1,
Window = 2,
Unknown = 3,
}

/// <summary>Owned handle to a native CaptureSource.</summary>
public sealed partial class CaptureSource : IDisposable
{
public ulong NativeHandle { get; private set; }
private readonly bool _ownsHandle;

public CaptureSource(ulong nativeHandle, bool ownsHandle = true)
{
NativeHandle = nativeHandle;
_ownsHandle = ownsHandle;
}

~CaptureSource() => ReleaseHandle();

public void Dispose()
{
ReleaseHandle();
GC.SuppressFinalize(this);
}

private void ReleaseHandle()
{
if (_ownsHandle && NativeHandle != 0)
{
Interop.native_capture_source_free(NativeHandle);
NativeHandle = 0;
}
}

public static CaptureSource? FromDisplay(Display? display)
{
var rawResult = Interop.native_capture_source_from_display(display?.NativeHandle ?? 0);
return rawResult == 0 ? null : new CaptureSource(rawResult);
}

public static CaptureSource? FromWindow(Window? window)
{
var rawResult = Interop.native_capture_source_from_window(window?.NativeHandle ?? 0);
return rawResult == 0 ? null : new CaptureSource(rawResult);
}

public CaptureSourceType Type
{
get
{
var rawResult = Interop.native_capture_source_get_type(NativeHandle);
return (CaptureSourceType)rawResult;
}
}

public string? Name
{
get
{
var rawResult = Interop.native_capture_source_get_name(NativeHandle);
return Interop.ConsumeString(rawResult);
}
}

}

113 changes: 113 additions & 0 deletions bindings/csharp/src/NativeAPI/ScreenCapturer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
#nullable enable

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CNativeAPI;

namespace NativeAPI;

public struct CaptureSourceSelectionOptions
{
public bool AllowDisplays;
public bool AllowWindows;
public Window? ParentWindow;

public CaptureSourceSelectionOptions(bool allowDisplays, bool allowWindows, Window? parentWindow)
{
AllowDisplays = allowDisplays;
AllowWindows = allowWindows;
ParentWindow = parentWindow;
}

internal static CaptureSourceSelectionOptions FromRaw(in native_capture_source_selection_options_t raw)
{
return new CaptureSourceSelectionOptions(raw.allow_displays != 0, raw.allow_windows != 0, raw.parent_window == 0 ? null : new Window(Interop.native_handle_retain(raw.parent_window)));
}

internal native_capture_source_selection_options_t ToRaw()
{
var raw = new native_capture_source_selection_options_t();
raw.allow_displays = (byte)(AllowDisplays ? 1 : 0);
raw.allow_windows = (byte)(AllowWindows ? 1 : 0);
raw.parent_window = ParentWindow?.NativeHandle ?? 0;
return raw;
}

internal static void ReleaseRaw(ref native_capture_source_selection_options_t raw)
{
}
}

public struct ScreenCaptureOptions
{
public bool IncludeCursor;
public bool CropEnabled;
public Rectangle Crop;

public ScreenCaptureOptions(bool includeCursor, bool cropEnabled, Rectangle crop)
{
IncludeCursor = includeCursor;
CropEnabled = cropEnabled;
Crop = crop;
}

internal static ScreenCaptureOptions FromRaw(in native_screen_capture_options_t raw)
{
return new ScreenCaptureOptions(raw.include_cursor != 0, raw.crop_enabled != 0, Rectangle.FromRaw(in raw.crop));
}

internal native_screen_capture_options_t ToRaw()
{
var raw = new native_screen_capture_options_t();
raw.include_cursor = (byte)(IncludeCursor ? 1 : 0);
raw.crop_enabled = (byte)(CropEnabled ? 1 : 0);
raw.crop = Crop.ToRaw();
return raw;
}

internal static void ReleaseRaw(ref native_screen_capture_options_t raw)
{
}
}

public static partial class ScreenCapturer
{
public static bool IsSupported()
{
var rawResult = Interop.native_screen_capturer_is_supported();
return rawResult;
}

public static bool IsSourceSelectionSupported()
{
var rawResult = Interop.native_screen_capturer_is_source_selection_supported();
return rawResult;
}

public static bool IsDirectCaptureSupported(CaptureSourceType type)
{
var rawResult = Interop.native_screen_capturer_is_direct_capture_supported((int)type);
return rawResult;
}

public static void SelectSource(CaptureSourceSelectionOptions options, Action<bool, CaptureSource?> callback)
{
var rawOptions = options.ToRaw();
ScreenCapturerSelectSourceCallbackNativeCallback nativeCallback = (arg0, arg1, delivery, userData) => { try { if (!Interop.native_event_delivery_is_active(delivery)) return; callback(arg0, arg1 == 0 ? null : new CaptureSource(Interop.native_handle_retain(arg1))); } catch (Exception) { } finally { Interop.native_event_delivery_complete(delivery, true); } };
Interop.native_screen_capturer_select_source(rawOptions, nativeCallback, CallbackKeeper.Hold(nativeCallback), CallbackKeeper.Release);
CaptureSourceSelectionOptions.ReleaseRaw(ref rawOptions);
}

public static void Capture(CaptureSource? source, ScreenCaptureOptions options, Action<bool, Image?> callback)
{
var rawOptions = options.ToRaw();
ScreenCapturerCaptureCallbackNativeCallback nativeCallback = (arg0, arg1, delivery, userData) => { try { if (!Interop.native_event_delivery_is_active(delivery)) return; callback(arg0, arg1 == 0 ? null : new Image(Interop.native_handle_retain(arg1))); } catch (Exception) { } finally { Interop.native_event_delivery_complete(delivery, true); } };
Interop.native_screen_capturer_capture(source?.NativeHandle ?? 0, rawOptions, nativeCallback, CallbackKeeper.Hold(nativeCallback), CallbackKeeper.Release);
ScreenCaptureOptions.ReleaseRaw(ref rawOptions);
}

}

Loading
Loading