Repository navigation
Expand file tree
/
Copy pathCaptureSource.cs
More file actions
80 lines (66 loc) · 1.9 KB
/
Copy pathCaptureSource.cs
File metadata and controls
80 lines (66 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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);
}
}
}