Skip to content

Add Linux support (x64) - #6

Merged
cornpip merged 18 commits into
mainfrom
linux-support
Aug 17, 2026
Merged

Add Linux support (x64)#6
cornpip merged 18 commits into
mainfrom
linux-support

Conversation

@cornpip

@cornpip cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner

The same Dart API now runs on Linux desktop through the bundled libuvc backend.

What

  • New linux/ plugin: sysfs enumeration, fd open through the existing uvc_wrap path, FlPixelBufferTexture preview, netlink uevent deviceEvents
  • libusb 1.0.29 and libjpeg-turbo 3.2.0 vendored; libjpeg links static, libusb ships as a replaceable shared libusb1.0.so (LGPL)
  • Shared ABI additions land in both backends (uvc_get_preview_transform); H.264 modes and recording are not available on Linux yet
  • CI: arm64 example build (Debian bullseye container, runs on Raspberry Pi OS from bullseye onward), promoted to the Linux build check for PRs and main

Verified

  • Linux x64: WSL2 real-camera preview, 13 native integration tests, 19 unit tests
  • Linux arm64: Raspberry Pi 4 real-camera preview and mode switching; iso transfer cap fixes the VL805 xhci stream death
  • Windows and Android: builds pass, new ABI symbol exported, no behavior change for existing platforms

The same Dart API runs on Linux desktop through the bundled libuvc
backend. The linux/ plugin enumerates cameras via sysfs, opens the
/dev/bus/usb node, and hands the fd to the existing uvc_wrap path;
preview renders through FlPixelBufferTexture and deviceEvents comes
from a netlink uevent monitor.

libusb 1.0.29 and libjpeg-turbo 3.2.0 sources are vendored: libjpeg
links static, libusb ships as a separate shared libusb1.0.so because
it is LGPL and must remain replaceable.

ABI: add uvc_get_preview_transform (both backends), keep the frame
listener registered across preview stops, and exclude H.264 from the
mode list on non-Android builds. H.264 preview and MP4 recording are
not available on Linux yet.
Adds the Linux platform scaffold, hides the record button where
recording is not available, saves captures to ~/Pictures, and points
the native test bindings at the per-platform library name.
libuvc's install(EXPORT) rules were riding along with the app install,
shipping libuvc.a plus cmake/pkgconfig metadata in bundle/lib. Part of
the unreleased Linux support, so the changelog entry already covers it.
The Android-only 48KB iso transfer cap now applies to all Linux builds:
the Pi 4's VL805 xhci mishandles large iso URBs (Transfer event TRB DMA
ptr not part of current TD) and the stream dies at high resolutions.
FFI_UVC_MAX_ISO_BYTES overrides the cap on desktop Linux for tuning.
Part of the unreleased Linux support, so the changelog entry covers it.
@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

flutter_ffi_uvc/NOTICES

Lines 592 to 593 in 29ce4d2

bundled unmodified. On Linux, unmodified sources from upstream release
3.2.0 are bundled and built as a static library during the app build.

P1 Badge Copy the newly vendored licenses into NOTICES

The Linux attribution is added without replacing the existing Android-era license blocks: the newly added libjpeg-turbo-src/LICENSE.md, libjpeg-turbo-src/README.ijg, and libusb/COPYING differ from the copies currently embedded in NOTICES. Consequently, Flutter's license collector publishes notices from different upstream copies than the Linux sources being shipped; resync the new vendored license files verbatim as required. .agents/docs/license-notices.mdL16-L22


if (g_hash_table_lookup(self->known_video_devices, message->device_name) ==
nullptr) {

P2 Badge Clear stale devices before suppressing attach events

When listUsbDevices or an earlier attach has populated known_video_devices, canceling the event stream stops the monitor but retains that table. If the camera is unplugged while there is no listener, then the stream is subscribed again before it is replugged into the same port, its sysfs basename is still present here and the new attach event is silently discarded. Reconcile or clear remembered devices when monitoring restarts before using this lookup for deduplication.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The embedded libusb and libjpeg-turbo license copies were still the
Android-prebuilt-era variants; NOTICES now carries the texts of the
Linux-vendored sources (libusb 1.0.29, libjpeg-turbo 3.2.0) verbatim,
per the license-notices sync rule.
A device unplugged while the uevent monitor was stopped left a stale
entry in the known-device table, so its next attach on the same port
was suppressed as a duplicate-interface event. Dedupe now compares the
remembered deviceId, which changes with the replug's fresh devnum.
Part of the unreleased Linux support, so the changelog entry covers it.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

linux:
pluginClass: FlutterFfiUvcPlugin

P2 Badge Document Linux behavior in the public Dart API

When consumers target the newly registered Linux platform, the IDE-facing declarations in lib/src/uvc_camera_api.dart remain Android/Windows-only: lines 1121-1145 omit Linux permission, enumeration, event, and open semantics; lines 1308-1327 do not say recording is unsupported; line 1374 incorrectly calls debugBmControls() Android-only even though Linux uses the libuvc backend; and lines 1406-1409 omit Linux's H.264 exclusion. Update these public API comments along with the platform registration so Linux users are not given incorrect capability and lifecycle guidance. .agents/docs/scope.mdL3-L4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The dartdoc on the UvcCamera surface still described Android/Windows
only: permission, enumeration, device events, and open semantics now
cover Linux; startVideoRecording states it is unavailable on Linux;
debugBmControls is Android and Linux (the libuvc backend implements
it); supportedModes notes the Linux H.264 exclusion. README's
debugBmControls note matches.
Platform mentions in the UvcCamera dartdoc now follow one rule: name a
platform only where the caller must behave differently (capability
gaps, permission flow, thrown errors), never to describe which native
stack implements a member. Adds the missing Linux coverage under that
rule: recording unavailability, debugBmControls availability, H.264
mode exclusion, device-node access. README's debugBmControls note
matches.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20318c22d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread linux/flutter_ffi_uvc_plugin.cc
Comment thread linux/flutter_ffi_uvc_plugin.cc Outdated
Plugin dispose now stops the shared native session (uvc_close_device)
before closing the USB fd it streams on, so transfer threads cannot
touch a closed descriptor during engine teardown. Subscribing to
deviceEvents seeds the known-device table from sysfs, so detach events
also fire for cameras attached before the subscription that were never
enumerated through listUsbDevices. Part of the unreleased Linux
support, so the changelog entry covers it.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57994ddb68

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread linux/flutter_ffi_uvc_plugin.cc Outdated
Seeding first left a gap: a camera attached after the sysfs scan but
before the netlink socket bound was neither cached nor queued, so it
produced no events at all. The socket now binds first and queues
events during the scan; a device seen by both paths dedupes by
deviceId. Part of the unreleased Linux support.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 96d2aa95c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread linux/CMakeLists.txt Outdated
target_link_options needs CMake 3.13; pass the link-time rpath-link
flag through target_link_libraries instead, which accepts linker flags
on every version this file declares support for. No behavior change:
the built plugin's RUNPATH and the app link are identical.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c29a74ff71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread linux/flutter_ffi_uvc_plugin.cc Outdated
Interface removals now only gather evidence: an uncached video-class
interface removal records a placeholder (covering a device unplugged
while the seed scan was still running), and the usb_device removal
that ends the burst emits the detach using the cached identity plus
the uevent environment. Emitting once per usb_device removal also
removes the double-report risk of per-interface emission, and a device
reset (interfaces recreated, devnum unchanged) now passes without a
spurious detach/attach pair. Part of the unreleased Linux support.
@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: c573029b33

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cornpip

cornpip commented Aug 17, 2026

Copy link
Copy Markdown
Owner Author

Codex findings addressed:

@cornpip
cornpip merged commit ae3aea5 into main Aug 17, 2026
1 check passed
@cornpip
cornpip deleted the linux-support branch August 17, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant