Skip to content

Commit 33d4e2d

Browse files
committed
Fixed tfm compatibility in AVFoundation related fragments.
Made build completion in linux environment.
1 parent 6ee4d4d commit 33d4e2d

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<LangVersion>latest</LangVersion>
55
<Nullable>enable</Nullable>
66
<PlatformTarget>AnyCPU</PlatformTarget>
7-
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
87

98
<DebugSymbols>true</DebugSymbols>
109
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -19,7 +18,7 @@
1918
<RootNamespace>FlashCap</RootNamespace>
2019
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
2120
<GenerateDocumentationFile>true</GenerateDocumentationFile>
22-
<NoWarn>$(NoWarn);CS1570;CS1591;CA1416;CS8981</NoWarn>
21+
<NoWarn>$(NoWarn);CS1570;CS1591;CA1416;CS8981;NETSDK1215</NoWarn>
2322

2423
<Product>FlashCap</Product>
2524
<Trademark>FlashCap</Trademark>

FlashCap.Core/Devices/AVFoundationDevice.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ protected override Task OnInitializeAsync(VideoCharacteristics characteristics,
6363
$"FlashCap: Couldn't set video format: UniqueID={this.uniqueID}");
6464
}
6565

66-
this.bitmapHeader = NativeMethods.AllocateMemory(new IntPtr(Marshal.SizeOf<BITMAPINFOHEADER>()));
66+
this.bitmapHeader = NativeMethods.AllocateMemory(new IntPtr(MarshalEx.SizeOf<BITMAPINFOHEADER>()));
6767

6868
try
6969
{
7070
unsafe
7171
{
7272
var pBih = (BITMAPINFOHEADER*)this.bitmapHeader.ToPointer();
7373

74-
pBih->biSize = sizeof(NativeMethods.BITMAPINFOHEADER);
74+
pBih->biSize = MarshalEx.SizeOf<BITMAPINFOHEADER>();
7575
pBih->biCompression = compression;
7676
pBih->biPlanes = 1;
7777
pBih->biBitCount = bitCount;
@@ -135,19 +135,19 @@ format.FormatDescription.Dimensions is var dimensions &&
135135
throw new Exception("Can't add video output");
136136
}
137137

138-
return Task.CompletedTask;
138+
return TaskCompat.CompletedTask;
139139
}
140140

141141
protected override Task OnStartAsync(CancellationToken ct)
142142
{
143143
this.session?.StartRunning();
144-
return Task.CompletedTask;
144+
return TaskCompat.CompletedTask;
145145
}
146146

147147
protected override Task OnStopAsync(CancellationToken ct)
148148
{
149149
this.session?.StopRunning();
150-
return Task.CompletedTask;
150+
return TaskCompat.CompletedTask;
151151
}
152152

153153
protected override void OnCapture(IntPtr pData, int size, long timestampMicroseconds, long frameIndex, PixelBuffer buffer)
@@ -201,8 +201,6 @@ public void CaptureOutputCallback(IntPtr self, IntPtr _cmd, IntPtr output, IntPt
201201
CVPixelBufferUnlockBaseAddress(pixelBuffer, PixelBufferLockFlags.ReadOnly);
202202
}
203203
}
204-
205204
}
206-
207205
}
208206
}

FlashCap.Core/Internal/BackwardCompat.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Generic;
1212
using System.Diagnostics;
1313
using System.Runtime.CompilerServices;
14+
using System.Runtime.InteropServices;
1415

1516
#if NET35 || NET40 || NET45
1617
namespace System
@@ -28,6 +29,29 @@ private static class EmptyArray<T>
2829
public static T[] Empty<T>() =>
2930
EmptyArray<T>.Empty;
3031
}
32+
33+
namespace Text
34+
{
35+
internal static class EncodingEx
36+
{
37+
public static unsafe string GetString(
38+
this Encoding encoding, byte* bytes, int byteCount)
39+
{
40+
var stringData = new byte[byteCount];
41+
Marshal.Copy((IntPtr)bytes, stringData, 0, stringData.Length);
42+
return Encoding.UTF8.GetString(stringData);
43+
}
44+
}
45+
}
46+
47+
namespace Runtime.InteropServices
48+
{
49+
internal static class MarshalEx
50+
{
51+
public static int SizeOf<T>() =>
52+
Marshal.SizeOf(typeof(T));
53+
}
54+
}
3155
}
3256
#else
3357
namespace System
@@ -40,6 +64,15 @@ internal static class ArrayEx
4064
public static T[] Empty<T>() =>
4165
Array.Empty<T>();
4266
}
67+
68+
namespace Runtime.InteropServices
69+
{
70+
internal static class MarshalEx
71+
{
72+
public static int SizeOf<T>() =>
73+
Marshal.SizeOf<T>();
74+
}
75+
}
4376
}
4477
#endif
4578

FlashCap.Core/Internal/NativeMethods_AVFoundation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ public struct BlockDescriptor
241241
public static IntPtr Create(string signature, Delegate target, BlockLiteralCopy copy, BlockLiteralDispose dispose)
242242
{
243243
var signatureBytes = Encoding.UTF8.GetBytes(signature);
244-
var descriptorSize = Marshal.SizeOf<BlockDescriptor>();
244+
var descriptorSize = MarshalEx.SizeOf<BlockDescriptor>();
245245

246-
var memory = Marshal.AllocHGlobal(descriptorSize + signatureBytes.Length);
246+
nint memory = Marshal.AllocHGlobal(descriptorSize + signatureBytes.Length);
247247
var memoryToSignature = memory + descriptorSize;
248248

249249
Marshal.Copy(signatureBytes, startIndex: 0, memoryToSignature, length: 0);
@@ -252,7 +252,7 @@ public static IntPtr Create(string signature, Delegate target, BlockLiteralCopy
252252
{
253253
var descriptor = (BlockDescriptor*)memory;
254254

255-
descriptor->Size = new IntPtr(Marshal.SizeOf<BlockLiteral>());
255+
descriptor->Size = new IntPtr(MarshalEx.SizeOf<BlockLiteral>());
256256
descriptor->Copy = Marshal.GetFunctionPointerForDelegate(copy);
257257
descriptor->Dispose = Marshal.GetFunctionPointerForDelegate(dispose);
258258
descriptor->Signature = memoryToSignature;
@@ -514,7 +514,7 @@ public static unsafe T[] ToArray<T>(IntPtr handle, Func<IntPtr, T> constructor)
514514
{
515515
var count = CFArrayGetCount(handle).ToInt32();
516516
if (count == 0)
517-
return Array.Empty<T>();
517+
return ArrayEx.Empty<T>();
518518

519519
var buffer = new IntPtr[count];
520520

FlashCap/FlashCap.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<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</TargetFrameworks>
45
<NoWarn>$(NoWarn);CS0649</NoWarn>
56
<IsPackable>true</IsPackable>
67
</PropertyGroup>

0 commit comments

Comments
 (0)