xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3109508555
##########
drivers/video/v4l2_cap.c:
##########
@@ -540,7 +540,8 @@ static const capture_parameter_name_t
g_capture_parameter_name[] =
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;
Review Comment:
move the common change to new patch
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -315,12 +317,28 @@ int sim_bringup(void)
#ifdef CONFIG_SIM_CAMERA
/* Initialize and register the simulated video driver */
- sim_camera_initialize();
-
- ret = capture_initialize(CONFIG_SIM_CAMERA_DEV_PATH);
+ ret = sim_camera_initialize();
if (ret < 0)
{
- syslog(LOG_ERR, "ERROR: capture_initialize() failed: %d\n", ret);
+ syslog(LOG_ERR, "ERROR: sim_camera_initialize() failed: %d\n", ret);
+ }
+ else
+ {
+ int count = host_video_get_device_count();
+
+ for (int i = 0; i < count; i++)
+ {
+ char devpath[32];
+
+ snprintf(devpath, sizeof(devpath), "%s%d",
+ CONFIG_SIM_CAMERA_DEV_PATH, i);
+ ret = capture_initialize(devpath);
Review Comment:
it's betterr to call capture_register if you want to support multiple camera
##########
arch/sim/src/sim/posix/sim_host_avfoundation.c:
##########
@@ -0,0 +1,150 @@
+/****************************************************************************
+ * arch/sim/src/sim/posix/sim_host_avfoundation.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef IMGDATA_PIX_FMT_NV12
+# define IMGDATA_PIX_FMT_NV12 8
+#endif
+
+#include "sim_hostvideo.h"
+#include "../macos/sim_avfoundation_backend.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct host_video_dev_s
+{
+ struct avf_dev_s *backend;
+ int open_error;
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int host_video_get_device_count(void)
+{
+ return avf_get_device_count();
+}
+
+bool host_video_is_available(const char *host_video_dev_path)
+{
+ return avf_is_available(host_video_dev_path);
+}
+
+struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
+{
+ struct host_video_dev_s *vdev;
+
+ vdev = calloc(1, sizeof(*vdev));
+ if (vdev == NULL)
+ {
+ return NULL;
+ }
+
+ vdev->backend = avf_open(host_video_dev_path);
+ if (vdev->backend == NULL)
+ {
+ vdev->open_error = errno > 0 ? -errno : -ENODEV;
+ fprintf(stderr, "host_video_init failed: %d\n", vdev->open_error);
+ free(vdev);
+ return NULL;
+ }
+
+ return vdev;
+}
+
+int host_video_uninit(struct host_video_dev_s *vdev)
+{
+ if (vdev == NULL)
+ {
+ return -EINVAL;
+ }
+
+ avf_close(vdev->backend);
+ free(vdev);
+ return 0;
+}
+
+int host_video_start_capture(struct host_video_dev_s *vdev)
+{
+ if (vdev == NULL || vdev->backend == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return avf_start(vdev->backend);
+}
+
+int host_video_stop_capture(struct host_video_dev_s *vdev)
+{
+ if (vdev == NULL || vdev->backend == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return avf_stop(vdev->backend);
+}
+
+int host_video_dqbuf(struct host_video_dev_s *vdev, uint8_t *addr,
+ uint32_t size)
+{
+ if (vdev == NULL || vdev->backend == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return avf_read_frame(vdev->backend, addr, size);
+}
+
+int host_video_set_fmt(struct host_video_dev_s *vdev,
+ uint16_t width, uint16_t height, uint32_t fmt,
+ uint32_t denom, uint32_t numer)
+{
+ if (vdev == NULL || vdev->backend == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return avf_set_format(vdev->backend, width, height, fmt, denom, numer);
+}
+
+int host_video_try_fmt(struct host_video_dev_s *vdev,
+ uint16_t width, uint16_t height, uint32_t fmt,
+ uint32_t denom, uint32_t numer)
+{
+ if (vdev == NULL || vdev->backend == NULL)
+ {
+ return -EINVAL;
+ }
+
+ return avf_try_format(vdev->backend, width, height, fmt, denom, numer);
Review Comment:
why not let arch/sim/src/sim/macos/sim_host_avfoundation_backend.m implement
host_video_xxx and remove avf_xxx directly
##########
video/Makefile:
##########
@@ -21,8 +21,15 @@
############################################################################
include $(TOPDIR)/Make.defs
+
include videomode/Make.defs
+# 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)),)
Review Comment:
move to new patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]