sim: adapt macos avfoundation backend for camera indexing and capture

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>
This commit is contained in:
Peter Bee
2026-04-20 10:39:39 +08:00
committed by Xiang Xiao
parent ea05918799
commit 2a353fcc0c
4 changed files with 988 additions and 4 deletions
+6 -1
View File
@@ -416,12 +416,17 @@ 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
config SIM_CAMERA_AVFOUNDATION
bool "AVFoundation camera support on sim"
depends on HOST_MACOS
endchoice
config SIM_CAMERA_DEV_PATH
+34 -3
View File
@@ -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)
@@ -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
else
STDLIBS += -lrt
endif
@@ -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
@@ -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))), \
@@ -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)
@@ -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 $< $@
+35
View File
@@ -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>)
File diff suppressed because it is too large Load Diff