Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 111 additions & 3 deletions Documentation/applications/system/nxcamera/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,111 @@
============================================
``nxcamera`` NxCamera video test application
============================================
=============================================
``nxcamera`` Camera/Video Stream Test Command
=============================================

Introduction
============

``nxcamera`` is a command-line utility for testing camera devices and video
stream capture in NuttX. It is built on top of the NuttX video subsystem
(using a V4L2-style interface) and is typically used to:

- Enumerate and open video device nodes such as ``/dev/video0`` and
``/dev/video1``
- Configure capture parameters including resolution and pixel format
- Capture video frames for validation, debugging, or simple data dumping,
depending on platform support and build configuration

Usage
=====

``nxcamera`` is an interactive command-line program. Start it from NSH, then
enter commands at the ``nxcamera>`` prompt:

.. code-block:: console

nsh> nxcamera
nxcamera>

Tip: Execute NSH Commands (Hidden)
==================================

At the ``nxcamera>`` prompt you can run an NSH command by prefixing it with
``!``. This is useful for quickly checking system state or invoking other
utilities without exiting ``nxcamera``.

.. code-block:: console

nxcamera> !ls /dev
/dev:
console
fb0
gpio0
gpio1
gpio2
gpio3
loop
null
oneshot
ram0
ram1
ram2
video0
video1
zero
nxcamera> !poweroff
bash>

A typical workflow at the prompt is:

- ``input /dev/video0`` to set the input video node.
- ``output /dev/fb0`` to set the output node, for example a framebuffer.
- ``stream 640 480 30 NV12`` to start streaming with ``width height fps
format``.
- ``stop`` to stop streaming.

You may just copy-paste the commands below to get started:

.. code-block:: console

nxcamera
input /dev/video0
output /dev/fb0
stream 640 480 30 YUYV # or NV12 on macOS

Pixel Format
============

For the ``stream`` command, the pixel format depends on the platform. On the
macOS ``sim`` platform you may use ``NV12``, while on Linux systems ``YUYV``
is more commonly used.

Examples
========

1. Start ``nxcamera`` and configure a typical interactive capture session:

.. code-block:: console

nsh> nxcamera
nxcamera> input /dev/video0
nxcamera> output /dev/fb0
nxcamera> stream 640 480 30 NV12
nxcamera> stop

.. figure:: nxcamera_macos_sim.png
:alt: nxcamera running on the macOS SIM platform
:align: center

``nxcamera`` using the macOS AVFoundation backend on the SIM platform.

Features and Updates
====================

- Multiple camera instances are supported, allowing several cameras to be
exposed as different device nodes such as ``/dev/video0`` and
``/dev/video1``. This makes it easier to select and validate different
video input sources on the same system.
- On the ``sim`` platform, support has been added for the macOS
AVFoundation backend. This enables camera capture and functional
verification on macOS hosts, subject to build configuration and host
permission settings.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions arch/sim/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,21 @@ if SIM_CAMERA

choice
prompt "Simulated camera device type"
default SIM_CAMERA_V4L2
default SIM_CAMERA_V4L2 if HOST_LINUX
default SIM_CAMERA_AVFOUNDATION if HOST_MACOS

config SIM_CAMERA_V4L2
bool "V4L2 camera support on sim"
depends on HOST_LINUX

endchoice
config SIM_CAMERA_AVFOUNDATION
bool "AVFoundation camera support on sim"
depends on HOST_MACOS

config HOST_CAMERA_DEV_PATH
string "Host camera device path"
default "/dev/video0"
endchoice

config SIM_CAMERA_DEV_PATH
string "NuttX video device path"
string "NuttX video device path prefix"
default "/dev/video"

endif
Expand Down
37 changes: 34 additions & 3 deletions arch/sim/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ CFLAGS += -fvisibility=default
HOSTCFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
$(ARCHCFLAGS) $(HOSTINCLUDES) $(EXTRAFLAGS) -D__SIM__ \
-fvisibility=default
HOSTMFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
$(ARCHCFLAGS) $(HOSTINCLUDES) $(EXTRAFLAGS) -D__SIM__ \
-fvisibility=default

HOSTCFLAGS += ${INCDIR_PREFIX}$(ARCH_SRCDIR)
HOSTCFLAGS += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip

ifeq ($(CONFIG_HOST_MACOS),y)
HOSTCFLAGS += -Wno-deprecated-declarations
ifeq ($(CONFIG_SIM_X11FB),y)
HOSTCFLAGS += -I/opt/X11/include
endif
endif

ifeq ($(CONFIG_FS_LARGEFILE),y)
Expand Down Expand Up @@ -145,6 +152,11 @@ ifeq ($(CONFIG_HAVE_CXXINITIALIZE),y)
LDFLAGS += -Wl,-ld_classic,-no_fixup_chains
endif
endif

# Keep the simulator executable from exporting NuttX symbols. Otherwise dyld
# may resolve host libc references against NuttX's internal libc implementation
# during process initialization, which can crash before main() runs.
LDFLAGS += -Wl,-exported_symbol,__mh_execute_header
Comment thread
PeterBee97 marked this conversation as resolved.
else
STDLIBS += -lrt
endif
Expand Down Expand Up @@ -313,6 +325,15 @@ ifeq ($(CONFIG_SIM_CAMERA_V4L2),y)
STDLIBS += -lv4l2
endif

ifeq ($(CONFIG_SIM_CAMERA_AVFOUNDATION),y)
HOSTMSRCS += sim/macos/sim_host_avfoundation_backend.m
CSRCS += sim_camera.c
ifeq ($(CONFIG_HOST_MACOS),y)
STDLIBS += -framework AVFoundation -framework CoreMedia \
-framework CoreVideo -framework Foundation
endif
endif

ifeq ($(CONFIG_SIM_VIDEO_DECODER),y)
CSRCS += sim_decoder.c
CSRCS += sim_openh264dec.c
Expand All @@ -325,12 +346,14 @@ ifeq ($(CONFIG_SIM_VIDEO_ENCODER),y)
endif

COBJS = $(CSRCS:.c=$(OBJEXT))
HOSTCOBJS = $(HOSTSRCS:.c=$(OBJEXT))
HOSTMOBJS = $(HOSTMSRCS:.m=$(OBJEXT))

NUTTXOBJS = $(AOBJS) $(COBJS)
HOSTOBJS = $(HOSTSRCS:.c=$(OBJEXT))
HOSTOBJS = $(HOSTCOBJS) $(HOSTMOBJS)
HEADOBJ = $(HEADSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(HOSTSRCS)
SRCS = $(ASRCS) $(CSRCS) $(HOSTSRCS) $(HOSTMSRCS)
OBJS = $(AOBJS) $(COBJS) $(HOSTOBJS)

$(foreach lib,$(notdir $(wildcard $(APPDIR)$(DELIM)staging$(DELIM)*$(LIBEXT))), \
Expand Down Expand Up @@ -386,11 +409,16 @@ $(AOBJS): %$(OBJEXT): %.S
$(COBJS) $(LINKOBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)

$(HOSTOBJS) $(HEADOBJ): %$(OBJEXT): %.c
$(HOSTCOBJS) $(HEADOBJ): %$(OBJEXT): %.c
$(Q) $(ECHO_BEGIN)"CC: $<"
$(Q) "$(CC)" -c $(HOSTCFLAGS) $< -o $@
$(Q) $(ECHO_END)

$(HOSTMOBJS): %$(OBJEXT): %.m
$(Q) $(ECHO_BEGIN)"CC: $<"
$(Q) $(HOSTCC) -c $(HOSTMFLAGS) -x objective-c $< -o $@
$(Q) $(ECHO_END)

# The architecture-specific library

libarch$(LIBEXT): $(NUTTXOBJS)
Expand Down Expand Up @@ -506,6 +534,9 @@ makedepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds) $(HOSTSRCS:.c=.ddh)
$(call CATFILE, Make.dep, $^)
$(call DELFILE, $^)

$(HOSTSRCS:.c=.ddh): %.ddh: %.c
$(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(HOSTCFLAGS) -- $< > $@

config.h: $(TOPDIR)/include/nuttx/config.h
@echo "CP: $<"
$(Q) cp $< $@
Expand Down
35 changes: 35 additions & 0 deletions arch/sim/src/sim/macos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ##############################################################################
# arch/sim/src/sim/macos/CMakeLists.txt
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################

add_library(sim_avf_backend OBJECT EXCLUDE_FROM_ALL
sim_host_avfoundation_backend.m)

set_property(TARGET sim_avf_backend PROPERTY INCLUDE_DIRECTORIES "")
set_property(TARGET sim_avf_backend PROPERTY COMPILE_OPTIONS "")
set_property(TARGET sim_avf_backend PROPERTY COMPILE_DEFINITIONS "")
set_property(TARGET sim_avf_backend PROPERTY INTERFACE_INCLUDE_DIRECTORIES "")
set_property(TARGET sim_avf_backend PROPERTY INTERFACE_COMPILE_OPTIONS "")
set_property(TARGET sim_avf_backend PROPERTY INTERFACE_COMPILE_DEFINITIONS "")

target_include_directories(sim_avf_backend PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_compile_options(sim_avf_backend
PRIVATE $<$<COMPILE_LANGUAGE:OBJC>:-fobjc-arc>)
Loading
Loading