Skip to content

sim/camera: add AVFoundation backend and multi-cam support#18745

Open
PeterBee97 wants to merge 6 commits intoapache:masterfrom
PeterBee97:avfoundation
Open

sim/camera: add AVFoundation backend and multi-cam support#18745
PeterBee97 wants to merge 6 commits intoapache:masterfrom
PeterBee97:avfoundation

Conversation

@PeterBee97
Copy link
Copy Markdown
Contributor

Summary

Add AVFoundation backend and multi-cam support, enabling macOS users as well as Linux users to use multiple cameras on Simulator.

Impact

  • Impact on users: Backward compatible
  • Affected platforms:
    • SIM on macOS
    • SIM on Linux
  • Scope:
    • Enhances the SIM camera framework for multi-instance support
    • Adds a new macOS AVFoundation camera backend
    • Fixes mkallsyms host-tool behavior for Objective-C symbols on macOS
  • Non-affected platforms:
    • No impact on other boards or non-SIM targets
    • Existing Linux SIM camera behavior remains supported

Testing

Tested on:

  • Host OS: macOS Tahoe on Apple Silicon, Ubuntu x86_64
  • Target configurations: sim:nxcamera
image

@github-actions github-actions bot added Area: Build system Arch: simulator Issues related to the SIMulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: simulator labels Apr 15, 2026
anchao
anchao previously approved these changes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

@PeterBee97 WOW! Amazing! Please update the nxcamera Documentation/ to include this new parameter: https://nuttx.apache.org/docs/latest/applications/system/nxcamera/index.html

@acassis
Copy link
Copy Markdown
Contributor

acassis commented Apr 15, 2026

@PeterBee97 please include this picture in the Documentation page, it is funny :-)

simbit18
simbit18 previously approved these changes Apr 15, 2026
@PeterBee97 PeterBee97 dismissed stale reviews from simbit18 and anchao via 1131750 April 16, 2026 04:21
@PeterBee97
Copy link
Copy Markdown
Contributor Author

@PeterBee97 WOW! Amazing! Please update the nxcamera Documentation/ to include this new parameter: https://nuttx.apache.org/docs/latest/applications/system/nxcamera/index.html

As u wish :)

simbit18
simbit18 previously approved these changes Apr 16, 2026
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c Outdated
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c Outdated
char resolved_path[PATH_MAX];
int ret;

ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not call host_video_is_capture_device directly

Copy link
Copy Markdown
Contributor Author

@PeterBee97 PeterBee97 Apr 17, 2026

Choose a reason for hiding this comment

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

Because I wanted to filter-out non-capture video device. For now I have two cameras connected, but 4 video devices under /dev in host. I intentionally mapped /dev/video0 and /dev/video2 on host to /dev/video0 and /dev/video1 in NuttX. Is this behavior desired or do you prefer mapping directly without changing numbers?


fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
if (fd < 0)
ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not call open with host_video_dev_path directly

Copy link
Copy Markdown
Contributor Author

@PeterBee97 PeterBee97 Apr 17, 2026

Choose a reason for hiding this comment

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

Same reason as above. I wanted to map dev numbers without "holes".

Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c Outdated
Comment thread arch/sim/src/sim/sim_camera.c Outdated
acassis
acassis previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

@PeterBee97 Amazing! Thank you very much!

@PeterBee97 PeterBee97 dismissed stale reviews from acassis and simbit18 via c2ea6da April 17, 2026 09:16
@simbit18
Copy link
Copy Markdown
Contributor

Hi @PeterBee97 please fix

====================================================================================
Configuration/Tool: sim/nxcamera
2026-04-17 09:51:22
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100  485k  100  485k    0     0  1893k      0 --:--:-- --:--:-- --:--:-- 1893k
sim/posix/sim_host_v4l2.c: In function 'host_video_get_device_path_by_index':
Error: sim/posix/sim_host_v4l2.c:147:15: error: implicit declaration of function 'strlcpy'; did you mean 'strncpy'? [-Werror=implicit-function-declaration]
  147 |           if (strlcpy(devpath, path, devpathlen) >= devpathlen)
      |               ^~~~~~~
      |               strncpy
cc1: all warnings being treated as errors
make[1]: *** [Makefile:408: sim_host_v4l2.o] Error 1
make[1]: Target 'nuttx' not remade because of errors.
make: *** [tools/Unix.mk:568: nuttx] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 386: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory
  [1/1] Normalize sim/nxcamera
Removing libs/libbuiltin/bin/
Removing libs/libbuiltin/kbin/
Removing libs/libc/kbin/
Removing libs/libnx/bin/
Removing libs/libnx/kbin/
Removing mm/kbin/
/github/workspace/sources/nuttx /github/workspace/sources/nuttx
HEAD detached at pull/18745/merge
nothing to commit, working tree clean
/github/workspace/sources/nuttx
/github/workspace/sources/apps /github/workspace/sources/nuttx
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
/github/workspace/sources/nuttx
Build Attempt 1 of 1
===================================================================================

Comment thread tools/mkallsyms.sh
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c Outdated
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c Outdated
@PeterBee97 PeterBee97 force-pushed the avfoundation branch 2 times, most recently from 6b24b6b to 6ae23c9 Compare April 20, 2026 02:50
Comment thread drivers/video/v4l2_cap.c
static FAR struct imgsensor_s **g_capture_registered_sensor = NULL;
static size_t g_capture_registered_sensor_num;
static FAR struct imgdata_s *g_capture_data = NULL;
static FAR struct imgdata_s **g_capture_registered_data = NULL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move the common change to new patch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread video/Makefile

# Add dummy.c to ensure that we have at least one object.
# On some platforms like macOS, we can't create an empty archive.
ifeq ($(strip $(ASRCS) $(CSRCS)),)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move to new patch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread boards/sim/sim/sim/src/sim_bringup.c Outdated

snprintf(devpath, sizeof(devpath), "%s%d",
CONFIG_SIM_CAMERA_DEV_PATH, i);
ret = capture_initialize(devpath);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's betterr to call capture_register if you want to support multiple camera

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

return -EINVAL;
}

return avf_try_format(vdev->backend, width, height, fmt, denom, numer);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not let arch/sim/src/sim/macos/sim_host_avfoundation_backend.m implement host_video_xxx and remove avf_xxx directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

true

Peter Bee added 6 commits April 20, 2026 21:13
Add dummy.c so video can build an archive even when there are no other objects (e.g. on macOS).

Signed-off-by: bijunda <bijunda@bytedance.com>
Move common v4l2 capture framework changes to a standalone commit.

Signed-off-by: bijunda <bijunda@bytedance.com>
Allow the SIM camera/V4L2 capture framework to manage multiple
imgdata instances with dynamic mounting. This avoids cross-talk
between camera streams when multiple devices are used.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
Adapt the macOS AVFoundation backend for multi-device discovery,
camera index mapping and capture startup compatibility. This enables
reliable use of multiple cameras through the SIM camera framework.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
/Library/Developer/CommandLineTools/usr/bin/c++filt: error: unknown argument '-['

Signed-off-by: Peter Bee <bijunda@bytedance.com>
Document the nxcamera command usage, including device selection,
resolution, and pixel format options. Also mention recent support
for multi-instance camera mounting and the macOS AVFoundation
backend on the SIM platform.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: Build system Board: simulator Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants