Skip to content

Commit facf837

Browse files
committed
Merge branch 'feature/132-2' into develop
2 parents a2ef892 + 08c7554 commit facf837

10 files changed

+919
-53
lines changed

FlashCap.Core/Internal/IndependentSingleApartmentContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public IndependentSingleApartmentContext()
120120
this.thread.SetApartmentState(ApartmentState.STA); // Improved compatibility
121121
this.thread.Start();
122122

123-
this.ready.Wait();
123+
this.ready!.Wait();
124124
this.ready.Dispose();
125125
this.ready = null;
126126
}

FlashCap.Core/Internal/V4L2/NativeMethods_V4L2_Interop.cs

+297-3
Large diffs are not rendered by default.

FlashCap.Core/Internal/V4L2/NativeMethods_V4L2_Interop_i686.cs

+247-3
Large diffs are not rendered by default.

FlashCap.Core/Internal/V4L2/NativeMethods_V4L2_Interop_loongarch64.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ public uint reserved2
189189
set => this.reserved2_ = (uint)value;
190190
}
191191

192+
[FieldOffset(80)] private int request_fd_;
193+
public int request_fd
194+
{
195+
get => this.request_fd_;
196+
set => this.request_fd_ = (int)value;
197+
}
198+
192199
[FieldOffset(80)] private uint reserved_;
193200
public uint reserved
194201
{
@@ -312,11 +319,18 @@ public uint pixelformat
312319
set => this.pixelformat_ = (uint)value;
313320
}
314321

315-
[FieldOffset(48)] private fixed uint reserved_[4];
322+
[FieldOffset(48)] private uint mbus_code_;
323+
public uint mbus_code
324+
{
325+
get => this.mbus_code_;
326+
set => this.mbus_code_ = (uint)value;
327+
}
328+
329+
[FieldOffset(52)] private fixed uint reserved_[3];
316330
public uint[] reserved
317331
{
318-
get { fixed (uint* p = this.reserved_) { return get(p, 4); } }
319-
set { fixed (uint* p = this.reserved_) { set(p, value, 4); } }
332+
get { fixed (uint* p = this.reserved_) { return get(p, 3); } }
333+
set { fixed (uint* p = this.reserved_) { set(p, value, 3); } }
320334
}
321335

322336
}
@@ -970,11 +984,18 @@ public uint memory
970984
set => this.memory_ = (uint)value;
971985
}
972986

973-
[FieldOffset(12)] private fixed uint reserved_[2];
987+
[FieldOffset(12)] private uint capabilities_;
988+
public uint capabilities
989+
{
990+
get => this.capabilities_;
991+
set => this.capabilities_ = (uint)value;
992+
}
993+
994+
[FieldOffset(16)] private fixed uint reserved_[1];
974995
public uint[] reserved
975996
{
976-
get { fixed (uint* p = this.reserved_) { return get(p, 2); } }
977-
set { fixed (uint* p = this.reserved_) { set(p, value, 2); } }
997+
get { fixed (uint* p = this.reserved_) { return get(p, 1); } }
998+
set { fixed (uint* p = this.reserved_) { set(p, value, 1); } }
978999
}
9791000

9801001
}

FlashCap.Core/Internal/V4L2/NativeMethods_V4L2_Interop_x86_64.cs

+302-7
Large diffs are not rendered by default.

FlashCap.V4L2Generator/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.json
2+
videodev2.dumper*
3+
*_version.txt
4+
NativeMethods_V4L2_Interop.cs
5+

FlashCap.V4L2Generator/Program.cs

+18-27
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,6 @@ public SymbolName(string name, bool withComment = false)
6464
private static readonly HashSet<string> symbolExactIncludeList =
6565
new HashSet<string>()
6666
{
67-
"V4L2_CAP_VIDEO_CAPTURE",
68-
"V4L2_PIX_FMT_ABGR32",
69-
"V4L2_PIX_FMT_ARGB32",
70-
"V4L2_PIX_FMT_JPEG",
71-
"V4L2_PIX_FMT_MJPEG",
72-
"V4L2_PIX_FMT_RGB24",
73-
"V4L2_PIX_FMT_RGB332",
74-
"V4L2_PIX_FMT_RGB565X",
75-
"V4L2_PIX_FMT_RGB565",
76-
"V4L2_PIX_FMT_UYVY",
77-
"V4L2_PIX_FMT_XRGB32",
78-
"V4L2_PIX_FMT_YUYV",
79-
"V4L2_PIX_FMT_NV12",
80-
"VIDIOC_DQBUF",
81-
"VIDIOC_ENUM_FMT",
82-
"VIDIOC_ENUM_FRAMEINTERVALS",
83-
"VIDIOC_ENUM_FRAMESIZES",
84-
"VIDIOC_QBUF",
85-
"VIDIOC_QUERYBUF",
86-
"VIDIOC_QUERYCAP",
87-
"VIDIOC_REQBUFS",
88-
"VIDIOC_S_FMT",
89-
"VIDIOC_STREAMOFF",
90-
"VIDIOC_STREAMON",
9167
"v4l2_buf_type",
9268
"v4l2_field",
9369
"v4l2_frmivaltypes",
@@ -196,7 +172,9 @@ private static void GenerateStructureDumper(
196172
string sourceHeaderFileName,
197173
string clangAstJsonFileName,
198174
string dumperFileName,
199-
string architecture)
175+
string architecture,
176+
string clangVersion,
177+
string gccVersion)
200178
{
201179
var versionLabel = LoadVersionLabel();
202180

@@ -244,6 +222,8 @@ private static void GenerateStructureDumper(
244222
{
245223
tw.WriteLine($"// This is auto generated code by FlashCap.V4L2Generator [{ThisAssembly.AssemblyVersion}]. Do not edit.");
246224
tw.WriteLine($"// {versionLabel}");
225+
tw.WriteLine($"// {clangVersion.Replace("\r", "").Replace("\n", "")}");
226+
tw.WriteLine($"// {gccVersion.Replace("\r", "").Replace("\n", "")}");
247227
tw.WriteLine($"// {DateTimeOffset.Now:R}");
248228
tw.WriteLine();
249229

@@ -261,6 +241,8 @@ private static void GenerateStructureDumper(
261241
tw.WriteLine();
262242
tw.WriteLine(" printf(\" \\\"label\\\": \\\"{0}\\\",\\n\");", versionLabel);
263243
tw.WriteLine(" printf(\" \\\"architecture\\\": \\\"{0}\\\",\\n\");", architecture);
244+
tw.WriteLine(" printf(\" \\\"clangVersion\\\": \\\"{0}\\\",\\n\");", clangVersion);
245+
tw.WriteLine(" printf(\" \\\"gccVersion\\\": \\\"{0}\\\",\\n\");", gccVersion);
264246
tw.WriteLine(" printf(\" \\\"sizeof_size_t\\\": %d,\\n\", (int)sizeof(size_t));");
265247
tw.WriteLine(" printf(\" \\\"sizeof_off_t\\\": %d,\\n\", (int)sizeof(off_t));");
266248
tw.WriteLine();
@@ -424,6 +406,8 @@ private static void GenerateInteropCode(
424406
{
425407
tw.WriteLine($"// This is auto generated code by FlashCap.V4L2Generator [{ThisAssembly.AssemblyVersion}]. Do not edit.");
426408
tw.WriteLine($"// {root.Label}");
409+
tw.WriteLine($"// {root.ClangVersion}");
410+
tw.WriteLine($"// {root.GccVersion}");
427411
tw.WriteLine($"// {DateTimeOffset.Now:R}");
428412
tw.WriteLine();
429413

@@ -448,21 +432,28 @@ private static void GenerateInteropCode(
448432
{
449433
tw.WriteLine(" public abstract string Label { get; }");
450434
tw.WriteLine(" public abstract string Architecture { get; }");
435+
tw.WriteLine(" public virtual string ClangVersion => throw new NotImplementedException();");
436+
tw.WriteLine(" public virtual string GccVersion => throw new NotImplementedException();");
451437
tw.WriteLine(" public abstract int sizeof_size_t { get; }");
452438
tw.WriteLine(" public abstract int sizeof_off_t { get; }");
453439
}
454440
else
455441
{
456442
tw.WriteLine(" public override string Label => \"{0}\";", root.Label);
457443
tw.WriteLine(" public override string Architecture => \"{0}\";", root.Architecture);
444+
tw.WriteLine(" public override string ClangVersion => \"{0}\";", root.ClangVersion);
445+
tw.WriteLine(" public override string GccVersion => \"{0}\";", root.GccVersion);
458446
tw.WriteLine(" public override int sizeof_size_t => {0};", root.sizeof_size_t);
459447
tw.WriteLine(" public override int sizeof_off_t => {0};", root.sizeof_off_t);
460448
}
461449
tw.WriteLine();
462450

463451
tw.WriteLine(" // Definitions");
464452
foreach (var definition in root.Definitions.
465-
Where(d => symbolExactIncludeList.Contains(d.Key)).
453+
Where(d => symbolExactIncludeList.Contains(d.Key) ||
454+
d.Key.StartsWith("V4L2_CAP_") ||
455+
d.Key.StartsWith("V4L2_PIX_FMT_") ||
456+
d.Key.StartsWith("VIDIOC_")).
466457
OrderBy(d => d.Key))
467458
{
468459
if (isBase)
@@ -677,7 +668,7 @@ public static void Main(string[] args)
677668
{
678669
case 1:
679670
Console.Write(" Generating dumper source code ...");
680-
GenerateStructureDumper(args[1], args[2], args[3], args[4]);
671+
GenerateStructureDumper(args[1], args[2], args[3], args[4], args[5], args[6]);
681672
Console.WriteLine(" done.");
682673
break;
683674
case 2:

FlashCap.V4L2Generator/StructureDumpedJsonSchema.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public sealed class StructureDumpedJsonRoot
4646
{
4747
public readonly string Label;
4848
public readonly string Architecture;
49+
public readonly string ClangVersion;
50+
public readonly string GccVersion;
4951
public readonly int sizeof_size_t;
5052
public readonly int sizeof_off_t;
5153
public readonly IReadOnlyDictionary<string, uint> Definitions;
@@ -54,14 +56,16 @@ public sealed class StructureDumpedJsonRoot
5456

5557
[JsonConstructor]
5658
public StructureDumpedJsonRoot(
57-
string label, string architecture,
59+
string label, string architecture, string clangVersion, string gccVersion,
5860
int sizeof_size_t, int sizeof_off_t,
5961
Dictionary<string, uint> definitions,
6062
Dictionary<string, JToken> enums,
6163
Dictionary<string, StructureType> structures)
6264
{
6365
this.Label = label;
6466
this.Architecture = architecture;
67+
this.ClangVersion = clangVersion;
68+
this.GccVersion = gccVersion;
6569
this.sizeof_size_t = sizeof_size_t;
6670
this.sizeof_off_t = sizeof_off_t;
6771
this.Definitions = definitions;

FlashCap.V4L2Generator/dumper.sh

100755100644
+16-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
#!/bin/bash
22

3-
#sudo apt install clang mono
3+
#sudo apt install clang-11 build-essential mono-devel
4+
#sudo apt install clang-10 build-essential mono-devel
5+
6+
Clang=clang-11; export Clang
7+
#Clang=clang-11; export Clang
8+
Configuration=Debug; export Configuration
9+
10+
$Clang -v |& head -n 1 > clang_version.txt
11+
gcc -v |& tail -n 1 > gcc_version.txt
412

513
echo "Step 1: Dump video2dev.h AST by Clang."
6-
clang -Xclang -ast-dump=json -fsyntax-only /usr/include/linux/videodev2.h > videodev2.h.ast.json
14+
$Clang -Xclang -ast-dump=json -fsyntax-only /usr/include/linux/videodev2.h > videodev2.h.ast.json
715

816
echo "Step 2: Generate members dumper."
9-
mono FlashCap.V4L2Generator.exe 1 /usr/include/linux/videodev2.h videodev2.h.ast.json videodev2.dumper.cpp `uname -m`
17+
mono bin/$Configuration/mono/FlashCap.V4L2Generator.exe 1 /usr/include/linux/videodev2.h videodev2.h.ast.json videodev2.dumper.cpp `uname -m` "`cat clang_version.txt`" "`cat gcc_version.txt`"
1018

1119
echo "Step 3: Execute members dumper."
1220
gcc -o videodev2.dumper videodev2.dumper.cpp
1321
./videodev2.dumper > videodev2.h.members.json
1422

1523
echo "Step 4: Generate interop code."
16-
mono FlashCap.V4L2Generator.exe 2 videodev2.h.members.json ../../../../FlashCap.Core/Internal/V4L2/
24+
mono bin/$Configuration/mono/FlashCap.V4L2Generator.exe 2 videodev2.h.members.json ../FlashCap.Core/Internal/V4L2/
1725

1826
echo "Step 5: Generate base interop code."
19-
mono FlashCap.V4L2Generator.exe 3 videodev2.h.members.json .
27+
mono bin/$Configuration/mono/FlashCap.V4L2Generator.exe 3 videodev2.h.members.json .
28+
29+
echo ""
30+
echo "Done, you have to check './NativeMethods_V4L2_Interop.cs' to merge manually some symbols into '../FlashCap.Core/Internal/V4L2/NativeMethods_V4L2_Interop.cs'."
2031

samples/FlashCap.Wpf/FlashCap.Wpf.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<EnableWindowsTargeting>true</EnableWindowsTargeting>
1010
<DebugType>portable</DebugType>
1111
<DebugSymbols>true</DebugSymbols>
12+
<EnableWindowsTargeting>true</EnableWindowsTargeting>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

0 commit comments

Comments
 (0)