FlashCap uses V4L2 (Video4Linux2) for Linux image capture. If you wish to port FlashCap to a Linux platform not currently supported (e.g., mips64, riscv32/64, sparc64), follow these guidelines.
Core Mechanism: V4L2Generator
Because standard .NET interop defaults are optimized for Windows and may not match the target Linux ABI, FlashCap uses FlashCap.V4L2Generator. This generator uses Clang JSON AST files to automatically generate C# interop source code that strictly adheres to the correct ABI structures for the target platform.
Porting Requirements
- Clang: You must use a Clang version compatible with your target Linux ABI. Verified versions include
13, 11, and 10. - Runtime: A working
.NET or mono runtime is required on the target Linux platform. - Build Environment: It is highly recommended to use a QEMU-based virtual machine for a stable build environment. Automation scripts for this are located in the
qemu-vm-builder/ directory.
Implementation Steps
- Build the Generator: Build
FlashCap.V4L2Generator first. If the target environment lacks the .NET SDK, use build-mono.sh to compile using mcs (mono). - Generate Code: Follow the procedure outlined in the
dumper.sh script (you may need to adapt it for your specific environment). - Integrate Source: The generated code will be placed in
FlashCap.Core/Internal/V4L2/. - Update Type Initializer: Add a new platform branch to the
switch statement in NativeMethods_V4L2.cs to handle the new architecture.
// Example of adding a new platform branch in NativeMethods_V4L2.cs
switch (buf.machine)
{
// ... existing cases ...
case "loongarch64":
Interop = new NativeMethods_V4L2_Interop_loongarch64();
break;
// Add your new port here
case "your_new_arch":
Interop = new NativeMethods_V4L2_Interop_your_new_arch();
break;
default:
throw new InvalidOperationException($"FlashCap: Architecture '{buf.machine}' is not supported.");
}
Submitting a Pull Request
When submitting a port, please include the following details for documentation:
- Target physical machine model.
- Capture unit/camera model.
- Connection method (e.g., USB, PCIe, internal camera).
- Source of the hardware (if not a common retail item).
- Any known constraints or limitations (e.g., specific video characteristics that don't work).