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
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c
Comment thread arch/sim/src/sim/posix/sim_host_v4l2.c
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 Outdated
Comment thread video/Makefile
Comment thread boards/sim/sim/sim/src/sim_bringup.c Outdated
Comment thread arch/sim/src/sim/posix/sim_host_avfoundation.c Outdated
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>
Comment thread drivers/video/v4l2_cap.c Outdated
Comment thread drivers/video/v4l2_cap.c Outdated
Comment thread boards/sim/sim/sim/src/sim_bringup.c Outdated
Comment thread boards/sim/sim/sim/src/sim_bringup.c Outdated
Comment thread boards/sim/sim/sim/src/sim_bringup.c Outdated
Comment thread arch/sim/src/sim/sim_camera.c Outdated
Comment thread arch/sim/src/sim/sim_camera.c Outdated
Comment thread arch/sim/src/sim/sim_camera.c Outdated
Comment thread arch/sim/src/Makefile Outdated
Comment thread arch/sim/src/Makefile
Peter Bee added 5 commits April 27, 2026 20:40
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>
Comment thread drivers/video/v4l2_cap.c
FAR struct imgdata_s *imgdata;
FAR struct imgsensor_s *imgsensor;
enum v4l2_scene_mode capture_scene_mode;
uint8_t open_num;
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 change

Comment thread drivers/video/v4l2_cap.c
get_connected_imgsensor(FAR struct imgsensor_s **sensors,
size_t sensor_num)
{
FAR struct imgsensor_s *sensor = 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.

why change

Comment thread drivers/video/v4l2_cap.c
return ret;
}

g_capture_registered_data[index].devpath = registered_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.

why do you need save devpath

priv->sensor.ops = &g_sim_camera_ops;
priv->sensor.frmsizes_num = 1;
priv->sensor.frmsizes = g_frmsizes;
priv->sensors[0] = sensor;
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 do you need add sensors field


wd_start(&priv->wdog, 0, sim_camera_interrupt, (wdparm_t)priv);
return 0;
g_sim_camera_privs = kmm_zalloc(sizeof(sim_camera_priv_t) * (size_t)count);
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.

delete cast

static void sim_camera_interrupt(wdparm_t arg)
{
sim_camera_priv_t *priv = (sim_camera_priv_t *)arg;
struct timespec ts;
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 change? don't add the unnecessary change into pr, which just make your change review

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.

6 participants