Skip to content

examples/uvc_cam: add UVC camera streaming app#3438

Open
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:examples_uvc_cam
Open

examples/uvc_cam: add UVC camera streaming app#3438
JianyuWang0623 wants to merge 1 commit intoapache:masterfrom
JianyuWang0623:examples_uvc_cam

Conversation

@JianyuWang0623
Copy link
Copy Markdown
Contributor

Summary

Add a UVC camera streaming example application (examples/uvc_cam) that captures frames from a V4L2 camera sensor and streams them to a USB host via the UVC gadget driver.

The application:

  • Queries the sensor's native pixel format, resolution, and frame rate dynamically via VIDIOC_ENUM_FMT, VIDIOC_ENUM_FRAMESIZES, and VIDIOC_ENUM_FRAMEINTERVALS — no hardcoded video parameters.
  • Initializes/deinitializes the UVC gadget through boardctl(BOARDIOC_USBDEV_CONTROL).
  • Uses poll() with POLLOUT to wait for the USB host to start streaming, and to detect host disconnect/reconnect.
  • Supports optional positional arguments: uvc_cam [nframes] [video_dev] [uvc_dev].
  • Supports configurable frame count via Kconfig (CONFIG_EXAMPLES_UVC_CAM_NFRAMES, 0 = infinite).

Depends on the nuttx UVC gadget class driver (apache/nuttx#18609).

Impact

New example application only. No impact on existing code or build.

Adds Kconfig symbol CONFIG_EXAMPLES_UVC_CAM (depends on USBUVC), with sub-options for program name, priority, stack size, and frame count.

Testing

  • Host: Ubuntu 22.04 x86_64, GCC 13.2.0 (Xtensa esp32s3 cross-compiler)
  • Target: xtensa lckfb-szpi-esp32s3:uvc
  • Build: make distclean && ./tools/configure.sh lckfb-szpi-esp32s3:uvc && make -j$(nproc) — clean build, zero warnings.
  • Runtime: Flashed to ESP32-S3 board with GC0308 camera sensor. Verified 320×240 YUYV streaming to Linux host — frames displayed correctly via ffplay -f v4l2 -video_size 320x240 -i /dev/video1. Verified host disconnect/reconnect recovery.

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Mar 26, 2026

Awesome! @JianyuWang0623 could you also please add Documentation on how to use this application as part of documentation in apache/nuttx#18609 bundle? :-)

Usage: uvc_cam [nframes] [video_dev] [uvc_dev]

V4L2 capture -> write UVC gadget device.
Uses boardctl to initialize/deinitialize UVC gadget.
Queries sensor pixel format, resolution and frame rate via V4L2.
Uses poll() to wait for USB host streaming state.
Supports optional device path arguments (default /dev/video0, /dev/uvc0).
Supports configurable frame count (0=infinite).

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
@JianyuWang0623
Copy link
Copy Markdown
Contributor Author

Awesome! @JianyuWang0623 could you also please add Documentation on how to use this application as part of documentation in apache/nuttx#18609 bundle? :-)

@cederom Will do! I’ve just added the usage documentation here: https://github.com/apache/nuttx/compare/9d2ec9642d7bf0c41699f104c06948febeac64b4..e4babac55082a02feef90ad9ed128a5c5ad84648

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Mar 27, 2026

Awesome! @JianyuWang0623 could you also please add Documentation on how to use this application as part of documentation in apache/nuttx#18609 bundle? :-)

@cederom Will do! I’ve just added the usage documentation here: https://github.com/apache/nuttx/compare/9d2ec9642d7bf0c41699f104c06948febeac64b4..e4babac55082a02feef90ad9ed128a5c5ad84648

TANK U SIR! =)

@simbit18
Copy link
Copy Markdown
Contributor

@JianyuWang0623 This error is not related to this PR

You will need to wait for this PR #3440 to be merged, after which you will need to rebase

====================================================================================
Configuration/Tool: sim/citest
2026-03-27 02:48:55
------------------------------------------------------------------------------------
  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  % 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
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 1646k  100 1646k    0     0  3078k      0 --:--:-- --:--:-- --:--:-- 5899k

100  143k    0  143k    0     0   286k      0 --:--:-- --:--:-- --:--:--  286k
  Running NuttX...
++ pwd
+ olddir=/github/workspace/sources/nuttx
+ nuttdir=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/../../../../../../
+ cd /github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/../../../../../../
+ confpath=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/config.yaml
+ jsonconf=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/session.json
+ testpath=/github/workspace/nuttx-ntfc/external/nuttx-testing
+ ntfc test --testpath=/github/workspace/nuttx-ntfc/external/nuttx-testing --confpath=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/config.yaml --jsonconf=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/session.json
/github/workspace/sources/nuttx/../nuttx/boards/sim/sim/sim/configs/citest/run.sh: line 35: ntfc: command not found
+ ret=127
+ echo 127
+ artifacts=/github/workspace/buildartifacts/sim/citest//ntfc
+ mkdir -p /github/workspace/buildartifacts/sim/citest//ntfc
127
+ rm -f pytest.debug.log
+ mv result /github/workspace/buildartifacts/sim/citest//ntfc
mv: cannot stat 'result': No such file or directory
+ cd /github/workspace/sources/nuttx
+ exit 127
  [1/1] Normalize sim/citest
====================================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants