You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "PeterBee97 (via GitHub)" <gi...@apache.org> on 2026/04/15 14:00:07 UTC
[PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
PeterBee97 opened a new pull request, #18745:
URL: https://github.com/apache/nuttx/pull/18745
## 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`
<img width="1830" height="1196" alt="image" src="https://github.com/user-attachments/assets/710ab5c0-14d4-4f26-bf70-2122f09a14ed" />
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3093039527
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
+ sizeof(resolved_path));
+ if (ret < 0)
+ {
+ return false;
+ }
+
+ return host_video_is_capture_device(resolved_path);
}
struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
{
int fd;
+ int ret;
+ char resolved_path[PATH_MAX];
struct host_video_dev_s *vdev;
- fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
- if (fd < 0)
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
why not call open with host_video_dev_path directly
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
Review Comment:
remove format to devpath directly
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
Review Comment:
call host_video_get_device_path_by_index unitl fail to get the count
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
why not call host_video_is_capture_device directly
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -38,24 +44,40 @@
* Pre-processor Definitions
****************************************************************************/
-#define SIM_CAMERA_PERIOD MSEC2TICK(CONFIG_SIM_LOOP_INTERVAL)
+#define SIM_CAMERA_PERIOD USEC2TICK(1000000 / 30)
Review Comment:
why change
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -114,6 +330,7 @@ struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
}
vdev->fd = fd;
+ (void)snprintf(vdev->path, sizeof(vdev->path), "%s", resolved_path);
Review Comment:
strlcpy
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3206138456
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +86,246 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static int host_video_parse_device_index(const char *name, int *index)
+{
+ long value;
+ char *endptr;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ return -EINVAL;
+ }
+
+ name += 5;
+ if (*name == '\0')
+ {
+ return -EINVAL;
+ }
+
+ value = strtol(name, &endptr, 10);
+ if (*endptr != '\0' || value < 0 || value > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ *index = value;
+ return 0;
+}
+
+static int host_video_get_next_device_path(int current_index,
+ char *devpath,
+ size_t devpathlen,
+ int *next_index)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int candidate;
+ int found = INT_MAX;
+
+ dir = opendir("/dev");
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (host_video_parse_device_index(entry->d_name, &candidate) < 0 ||
+ candidate <= current_index || candidate >= found)
+ {
+ continue;
+ }
+
+ found = candidate;
+ }
+
+ closedir(dir);
+
+ if (found == INT_MAX)
+ {
+ return -ENODEV;
+ }
+
+ if (snprintf(devpath, devpathlen, "/dev/video%d", found) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ *next_index = found;
+ return 0;
+}
+
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ int count = 0;
+ int current_index = -1;
+ int ret;
+ char path[PATH_MAX];
+
+ while ((ret = host_video_get_next_device_path(current_index, path,
+ sizeof(path),
+ ¤t_index)) == 0)
+ {
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ count++;
+ }
+
+ return ret;
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #18745:
URL: https://github.com/apache/nuttx/pull/18745
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3159908246
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +429,63 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
- 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);
+ if (g_sim_camera_privs == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ for (int i = 0; i < count; i++)
+ {
+ sim_camera_priv_t *priv = &g_sim_camera_privs[i];
+ FAR struct imgsensor_s *sensor = &priv->sensor;
+ int ret;
+
+ priv->data.ops = &g_sim_camera_data_ops;
+ priv->sensor.ops = &g_sim_camera_ops;
+ priv->sensor.frmsizes_num = 1;
+ priv->sensor.frmsizes = g_frmsizes;
+ priv->sensors[0] = sensor;
Review Comment:
removed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147366790
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,10 +3776,30 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ static size_t g_capture_initialize_index;
+ FAR struct imgdata_s *data;
+ FAR struct imgsensor_s *sensor;
Review Comment:
fixed
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,10 +3776,30 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ static size_t g_capture_initialize_index;
Review Comment:
fixed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3108021465
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -120,37 +120,24 @@ static bool host_video_is_capture_device(const char *host_video_dev_path)
return available;
}
-static int host_video_get_device_path_by_index(const char *dirpath,
- int index,
+static int host_video_get_device_path_by_index(int index,
char *devpath,
size_t devpathlen)
{
- DIR *dir;
- struct dirent *entry;
int count = 0;
+ int i;
- dir = opendir(dirpath);
- if (dir == NULL)
- {
- return -errno;
- }
-
- while ((entry = readdir(dir)) != NULL)
+ for (i = 0; i < HOST_MAX_VIDEO_DEVICES; i++)
{
- char path[PATH_MAX];
-
- if (strncmp(entry->d_name, "video", 5) != 0)
- {
- continue;
- }
+ char path[32];
- if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ if (snprintf(path, sizeof(path), "/dev/video%d", i) >=
Review Comment:
changed to dynamic discovery of paths
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3159925050
##########
drivers/video/v4l2_cap.c:
##########
@@ -2092,20 +2151,17 @@ static FAR struct imgsensor_s *
get_connected_imgsensor(FAR struct imgsensor_s **sensors,
size_t sensor_num)
{
- FAR struct imgsensor_s *sensor = NULL;
Review Comment:
fixed
##########
drivers/video/v4l2_cap.c:
##########
@@ -170,16 +171,18 @@ typedef struct capture_parameter_name_s capture_parameter_name_t;
struct capture_mng_s
{
- struct v4l2_s v4l2;
+ struct v4l2_s v4l2;
/* Parameter of capture_initialize() */
- uint8_t open_num;
- capture_type_inf_t capture_inf;
- capture_type_inf_t still_inf;
- FAR struct imgdata_s *imgdata;
- FAR struct imgsensor_s *imgsensor;
- enum v4l2_scene_mode capture_scene_mode;
+ uint8_t open_num;
Review Comment:
fixed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#issuecomment-4344229642
@acassis @jerpelea this patch change the common code, before I approve the change, please don't merge the pr.
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3110907483
##########
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:
true
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#issuecomment-4257372644
> @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 :)
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3098456445
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
Because I wanted to filter-out non-capture video device. For now I have two cameras connected, but 4 video devices under /dev in host. I intentionally mapped /dev/video0 and /dev/video2 on host to /dev/video0 and /dev/video1 in NuttX. Is this behavior desired or do you prefer mapping directly?
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147368630
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -76,6 +77,7 @@
#include "sim_internal.h"
#include "sim.h"
+#include "sim_hostvideo.h"
Review Comment:
done
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -33,6 +33,7 @@
#include <nuttx/board.h>
#include <nuttx/clock.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/lib/lib.h>
Review Comment:
removed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147369934
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -315,12 +317,20 @@ 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
+ {
+ ret = sim_camera_register_capture_devices();
Review Comment:
done
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +476,91 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
+
+ g_sim_camera_privs = kmm_zalloc(sizeof(sim_camera_priv_t) * (size_t)count);
+ if (g_sim_camera_privs == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ g_sim_camera_priv_count = count;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ for (int i = 0; i < count; i++)
+ {
+ sim_camera_priv_t *priv = &g_sim_camera_privs[i];
+
+ memcpy(priv, &g_sim_camera_priv, sizeof(*priv));
+
+ priv->data.priv = priv;
+ priv->sensor.priv = priv;
+ priv->index = i;
+ snprintf(priv->devpath, sizeof(priv->devpath), "%s%d",
+ CONFIG_SIM_CAMERA_DEV_PATH, i);
+
+ imgdata_register(&priv->data.data);
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3097904270
##########
tools/mkallsyms.sh:
##########
@@ -64,7 +64,8 @@ if [ -f "${1}" ];then
${nm} -n ${1} | grep -E " [T|t] " | uniq | \
while read addr type name
do
- echo " { \"$(${filt} $name | sed -e "s/(.*)$//")\", (FAR ${CONST} void *)0x$addr },"
+ demangled=$(printf '%s\n' "$name" | ${filt} | sed -e "s/(.*)$//")
Review Comment:
move to new patch
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -120,37 +120,24 @@ static bool host_video_is_capture_device(const char *host_video_dev_path)
return available;
}
-static int host_video_get_device_path_by_index(const char *dirpath,
- int index,
+static int host_video_get_device_path_by_index(int index,
char *devpath,
size_t devpathlen)
{
- DIR *dir;
- struct dirent *entry;
int count = 0;
+ int i;
- dir = opendir(dirpath);
Review Comment:
merge to previous patch
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -120,37 +120,24 @@ static bool host_video_is_capture_device(const char *host_video_dev_path)
return available;
}
-static int host_video_get_device_path_by_index(const char *dirpath,
- int index,
+static int host_video_get_device_path_by_index(int index,
char *devpath,
size_t devpathlen)
{
- DIR *dir;
- struct dirent *entry;
int count = 0;
+ int i;
- dir = opendir(dirpath);
- if (dir == NULL)
- {
- return -errno;
- }
-
- while ((entry = readdir(dir)) != NULL)
+ for (i = 0; i < HOST_MAX_VIDEO_DEVICES; i++)
{
- char path[PATH_MAX];
-
- if (strncmp(entry->d_name, "video", 5) != 0)
- {
- continue;
- }
+ char path[32];
- if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ if (snprintf(path, sizeof(path), "/dev/video%d", i) >=
Review Comment:
why not format to devpath directly
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3098456445
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
Because I wanted to filter-out non-capture video device. For now I have two cameras connected, but 4 video devices under /dev in host. I intentionally mapped /dev/video0 and /dev/video2 on host to /dev/video0 and /dev/video1 in NuttX. Is this behavior desired or do you prefer mapping directly without changing numbers?
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3098490083
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -38,24 +44,40 @@
* Pre-processor Definitions
****************************************************************************/
-#define SIM_CAMERA_PERIOD MSEC2TICK(CONFIG_SIM_LOOP_INTERVAL)
+#define SIM_CAMERA_PERIOD USEC2TICK(1000000 / 30)
Review Comment:
my bad :<
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3206137648
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -138,29 +150,7 @@ static const struct v4l2_frmsizeenum g_frmsizes[] =
}
};
-static struct v4l2_fmtdesc g_fmts[] =
-{
- {
- .pixelformat = V4L2_PIX_FMT_YUV420,
- .description = "YUV420",
- }
-};
-
-static sim_camera_priv_t g_sim_camera_priv =
-{
- .data =
- {
- &g_sim_camera_data_ops
- },
- .sensor =
- {
- .ops = &g_sim_camera_ops,
- .frmsizes_num = 1,
- .frmsizes = g_frmsizes,
- .fmtdescs_num = 1,
- .fmtdescs = g_fmts,
- }
-};
+static sim_camera_priv_t *g_sim_camera_privs;
Review Comment:
done (`privs` is now implicitly persistent allocated with no clear owner, is that ok?)
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +433,42 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
Review Comment:
fixed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3099129308
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
+ sizeof(resolved_path));
+ if (ret < 0)
+ {
+ return false;
+ }
+
+ return host_video_is_capture_device(resolved_path);
}
struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
{
int fd;
+ int ret;
+ char resolved_path[PATH_MAX];
struct host_video_dev_s *vdev;
- fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
- if (fd < 0)
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
Same reason as above. I wanted to map dev numbers without "holes".
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3165566396
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -138,29 +150,7 @@ static const struct v4l2_frmsizeenum g_frmsizes[] =
}
};
-static struct v4l2_fmtdesc g_fmts[] =
-{
- {
- .pixelformat = V4L2_PIX_FMT_YUV420,
- .description = "YUV420",
- }
-};
-
-static sim_camera_priv_t g_sim_camera_priv =
-{
- .data =
- {
- &g_sim_camera_data_ops
- },
- .sensor =
- {
- .ops = &g_sim_camera_ops,
- .frmsizes_num = 1,
- .frmsizes = g_frmsizes,
- .fmtdescs_num = 1,
- .fmtdescs = g_fmts,
- }
-};
+static sim_camera_priv_t *g_sim_camera_privs;
Review Comment:
delete, don't need
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +86,246 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static int host_video_parse_device_index(const char *name, int *index)
+{
+ long value;
+ char *endptr;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ return -EINVAL;
+ }
+
+ name += 5;
+ if (*name == '\0')
+ {
+ return -EINVAL;
+ }
+
+ value = strtol(name, &endptr, 10);
+ if (*endptr != '\0' || value < 0 || value > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ *index = value;
+ return 0;
+}
+
+static int host_video_get_next_device_path(int current_index,
+ char *devpath,
+ size_t devpathlen,
+ int *next_index)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int candidate;
+ int found = INT_MAX;
+
+ dir = opendir("/dev");
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (host_video_parse_device_index(entry->d_name, &candidate) < 0 ||
+ candidate <= current_index || candidate >= found)
+ {
+ continue;
+ }
+
+ found = candidate;
+ }
+
+ closedir(dir);
+
+ if (found == INT_MAX)
+ {
+ return -ENODEV;
+ }
+
+ if (snprintf(devpath, devpathlen, "/dev/video%d", found) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ *next_index = found;
+ return 0;
+}
+
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ int count = 0;
+ int current_index = -1;
+ int ret;
+ char path[PATH_MAX];
+
+ while ((ret = host_video_get_next_device_path(current_index, path,
+ sizeof(path),
+ ¤t_index)) == 0)
+ {
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ count++;
+ }
+
+ return ret;
+}
+
+static int host_video_count_devices(void)
Review Comment:
merge to host_video_get_device_count
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +433,42 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
Review Comment:
why not fail
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +86,246 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static int host_video_parse_device_index(const char *name, int *index)
+{
+ long value;
+ char *endptr;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ return -EINVAL;
+ }
+
+ name += 5;
+ if (*name == '\0')
+ {
+ return -EINVAL;
+ }
+
+ value = strtol(name, &endptr, 10);
+ if (*endptr != '\0' || value < 0 || value > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ *index = value;
+ return 0;
+}
+
+static int host_video_get_next_device_path(int current_index,
+ char *devpath,
+ size_t devpathlen,
+ int *next_index)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int candidate;
+ int found = INT_MAX;
+
+ dir = opendir("/dev");
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (host_video_parse_device_index(entry->d_name, &candidate) < 0 ||
+ candidate <= current_index || candidate >= found)
+ {
+ continue;
+ }
+
+ found = candidate;
+ }
+
+ closedir(dir);
+
+ if (found == INT_MAX)
+ {
+ return -ENODEV;
+ }
+
+ if (snprintf(devpath, devpathlen, "/dev/video%d", found) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ *next_index = found;
+ return 0;
+}
+
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ int count = 0;
+ int current_index = -1;
+ int ret;
+ char path[PATH_MAX];
+
+ while ((ret = host_video_get_next_device_path(current_index, path,
+ sizeof(path),
+ ¤t_index)) == 0)
+ {
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ count++;
+ }
+
+ return ret;
Review Comment:
-ENODEV and delete ret
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3108021832
##########
tools/mkallsyms.sh:
##########
@@ -64,7 +64,8 @@ if [ -f "${1}" ];then
${nm} -n ${1} | grep -E " [T|t] " | uniq | \
while read addr type name
do
- echo " { \"$(${filt} $name | sed -e "s/(.*)$//")\", (FAR ${CONST} void *)0x$addr },"
+ demangled=$(printf '%s\n' "$name" | ${filt} | sed -e "s/(.*)$//")
Review Comment:
done
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -120,37 +120,24 @@ static bool host_video_is_capture_device(const char *host_video_dev_path)
return available;
}
-static int host_video_get_device_path_by_index(const char *dirpath,
- int index,
+static int host_video_get_device_path_by_index(int index,
char *devpath,
size_t devpathlen)
{
- DIR *dir;
- struct dirent *entry;
int count = 0;
+ int i;
- dir = opendir(dirpath);
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3206138340
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +86,246 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static int host_video_parse_device_index(const char *name, int *index)
+{
+ long value;
+ char *endptr;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ return -EINVAL;
+ }
+
+ name += 5;
+ if (*name == '\0')
+ {
+ return -EINVAL;
+ }
+
+ value = strtol(name, &endptr, 10);
+ if (*endptr != '\0' || value < 0 || value > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ *index = value;
+ return 0;
+}
+
+static int host_video_get_next_device_path(int current_index,
+ char *devpath,
+ size_t devpathlen,
+ int *next_index)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int candidate;
+ int found = INT_MAX;
+
+ dir = opendir("/dev");
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (host_video_parse_device_index(entry->d_name, &candidate) < 0 ||
+ candidate <= current_index || candidate >= found)
+ {
+ continue;
+ }
+
+ found = candidate;
+ }
+
+ closedir(dir);
+
+ if (found == INT_MAX)
+ {
+ return -ENODEV;
+ }
+
+ if (snprintf(devpath, devpathlen, "/dev/video%d", found) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ *next_index = found;
+ return 0;
+}
+
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ int count = 0;
+ int current_index = -1;
+ int ret;
+ char path[PATH_MAX];
+
+ while ((ret = host_video_get_next_device_path(current_index, path,
+ sizeof(path),
+ ¤t_index)) == 0)
+ {
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ count++;
+ }
+
+ return ret;
+}
+
+static int host_video_count_devices(void)
Review Comment:
done
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +86,246 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static int host_video_parse_device_index(const char *name, int *index)
+{
+ long value;
+ char *endptr;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ return -EINVAL;
+ }
+
+ name += 5;
+ if (*name == '\0')
+ {
+ return -EINVAL;
+ }
+
+ value = strtol(name, &endptr, 10);
+ if (*endptr != '\0' || value < 0 || value > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ *index = value;
+ return 0;
+}
+
+static int host_video_get_next_device_path(int current_index,
+ char *devpath,
+ size_t devpathlen,
+ int *next_index)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int candidate;
+ int found = INT_MAX;
+
+ dir = opendir("/dev");
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ if (host_video_parse_device_index(entry->d_name, &candidate) < 0 ||
+ candidate <= current_index || candidate >= found)
+ {
+ continue;
+ }
+
+ found = candidate;
+ }
+
+ closedir(dir);
+
+ if (found == INT_MAX)
+ {
+ return -ENODEV;
+ }
+
+ if (snprintf(devpath, devpathlen, "/dev/video%d", found) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ *next_index = found;
+ return 0;
+}
+
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ int count = 0;
+ int current_index = -1;
+ int ret;
+ char path[PATH_MAX];
+
+ while ((ret = host_video_get_next_device_path(current_index, path,
+ sizeof(path),
+ ¤t_index)) == 0)
+ {
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >=
+ (int)devpathlen)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ count++;
+ }
+
+ return ret;
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#issuecomment-4405050036
Looks like CI breaks on unrelated paths. The previous build succeeded on all except Linux sim-02, which was fixed by the latest change.
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3156071129
##########
drivers/video/v4l2_cap.c:
##########
@@ -170,16 +171,18 @@ typedef struct capture_parameter_name_s capture_parameter_name_t;
struct capture_mng_s
{
- struct v4l2_s v4l2;
+ struct v4l2_s v4l2;
/* Parameter of capture_initialize() */
- uint8_t open_num;
- capture_type_inf_t capture_inf;
- capture_type_inf_t still_inf;
- FAR struct imgdata_s *imgdata;
- FAR struct imgsensor_s *imgsensor;
- enum v4l2_scene_mode capture_scene_mode;
+ uint8_t open_num;
Review Comment:
why change
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3831,67 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ size_t index;
+ FAR char *registered_devpath;
+ size_t devpath_len;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (get_registered_data_index(devpath, &index))
+ {
+ return -EEXIST;
+ }
+
+ if (!get_available_registered_data_index(&index))
+ {
+ return -EINVAL;
+ }
+
+ devpath_len = strlen(devpath) + 1;
+ registered_devpath = kmm_malloc(devpath_len);
+ if (registered_devpath == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ strlcpy(registered_devpath, devpath, devpath_len);
+
+ ret = capture_register(devpath, g_capture_registered_data[index].data,
+ g_capture_registered_sensor,
+ g_capture_registered_sensor_num);
+ if (ret < 0)
+ {
+ kmm_free(registered_devpath);
+ return ret;
+ }
+
+ g_capture_registered_data[index].devpath = registered_devpath;
Review Comment:
why do you need save devpath
##########
drivers/video/v4l2_cap.c:
##########
@@ -2092,20 +2151,17 @@ static FAR struct imgsensor_s *
get_connected_imgsensor(FAR struct imgsensor_s **sensors,
size_t sensor_num)
{
- FAR struct imgsensor_s *sensor = NULL;
Review Comment:
why change
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3161344393
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3806,69 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ FAR capture_mng_t *cmng;
+ size_t index;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (find_driver(devpath) != NULL)
Review Comment:
let's capture_register check dup for you
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3806,69 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ FAR capture_mng_t *cmng;
+ size_t index;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (find_driver(devpath) != NULL)
+ {
+ return -EEXIST;
+ }
+
+ if (!get_available_registered_data_index(&index))
Review Comment:
if you don't want data register twice, why not zero out g_capture_data
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3806,69 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ FAR capture_mng_t *cmng;
+ size_t index;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (find_driver(devpath) != NULL)
+ {
+ return -EEXIST;
+ }
+
+ if (!get_available_registered_data_index(&index))
Review Comment:
it's hard to support mulitple camera instances in the old capture_initialize/imgdata_register/imgsensor_register, that's why capture_register is added. I would suggest you move the related change to new pr to avoid blocking your other change.
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3806,69 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ FAR capture_mng_t *cmng;
+ size_t index;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (find_driver(devpath) != NULL)
+ {
+ return -EEXIST;
+ }
+
+ if (!get_available_registered_data_index(&index))
+ {
+ return -EINVAL;
+ }
+
+ ret = capture_register(devpath, g_capture_registered_data[index].data,
+ g_capture_registered_sensor,
+ g_capture_registered_sensor_num);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ cmng = find_driver(devpath);
Review Comment:
why
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3108023175
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
Review Comment:
ok
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#issuecomment-4267951811
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
===================================================================================
```
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3099129308
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -84,27 +88,239 @@ static int host_video_ioctl(int fd, int request, void *arg)
return r;
}
+static bool host_video_is_capture_device(const char *host_video_dev_path)
+{
+ struct v4l2_capability cap;
+ int fd;
+ bool available = false;
+
+ fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
+ if (fd < 0)
+ {
+ fd = open(host_video_dev_path, O_RDONLY | O_NONBLOCK);
+ if (fd < 0)
+ {
+ return false;
+ }
+ }
+
+ memset(&cap, 0, sizeof(cap));
+ if (host_video_ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
+ {
+ uint32_t capabilities = cap.device_caps != 0 ? cap.device_caps :
+ cap.capabilities;
+
+ if ((capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0)
+ {
+ available = true;
+ }
+ }
+
+ close(fd);
+ return available;
+}
+
+static int host_video_get_device_path_by_index(const char *dirpath,
+ int index,
+ char *devpath,
+ size_t devpathlen)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char path[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(path, sizeof(path), "/dev/%s", entry->d_name) >=
+ (int)sizeof(path))
+ {
+ continue;
+ }
+
+ if (!host_video_is_capture_device(path))
+ {
+ continue;
+ }
+
+ if (count == index)
+ {
+ if (snprintf(devpath, devpathlen, "%s", path) >= devpathlen)
+ {
+ closedir(dir);
+ return -ENAMETOOLONG;
+ }
+
+ closedir(dir);
+ return 0;
+ }
+
+ count++;
+ }
+
+ closedir(dir);
+ return -ENODEV;
+}
+
+static int host_video_count_devices_in_dir(const char *dirpath)
+{
+ DIR *dir;
+ struct dirent *entry;
+ int count = 0;
+
+ dir = opendir(dirpath);
+ if (dir == NULL)
+ {
+ return -errno;
+ }
+
+ while ((entry = readdir(dir)) != NULL)
+ {
+ char devpath[PATH_MAX];
+
+ if (strncmp(entry->d_name, "video", 5) != 0)
+ {
+ continue;
+ }
+
+ if (snprintf(devpath, sizeof(devpath), "/dev/%s", entry->d_name) >=
+ (int)sizeof(devpath))
+ {
+ continue;
+ }
+
+ if (host_video_is_capture_device(devpath))
+ {
+ count++;
+ }
+ }
+
+ closedir(dir);
+ return count;
+}
+
+static int host_video_resolve_device_path(const char *host_video_dev_path,
+ char *resolved_path,
+ size_t resolved_path_len)
+{
+ const char *name;
+ char *endptr;
+ long index;
+ int ret;
+
+ name = strrchr(host_video_dev_path, '/');
+ name = name != NULL ? name + 1 : host_video_dev_path;
+
+ if (strncmp(name, "video", 5) != 0)
+ {
+ if (snprintf(resolved_path, resolved_path_len, "%s",
+ host_video_dev_path) >= (int)resolved_path_len)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ return 0;
+ }
+
+ index = strtol(name + 5, &endptr, 10);
+ if (endptr == name + 5 || *endptr != '\0' || index < 0 ||
+ index > INT_MAX)
+ {
+ return -EINVAL;
+ }
+
+ ret = host_video_get_device_path_by_index("/sys/class/video4linux", index,
+ resolved_path,
+ resolved_path_len);
+ if (ret == -ENOENT || ret == -ENODEV || ret == -EINVAL)
+ {
+ ret = host_video_get_device_path_by_index("/dev", index,
+ resolved_path,
+ resolved_path_len);
+ }
+
+ if (ret < 0)
+ {
+ WARN("failed to resolve %s to host capture device: %d",
+ host_video_dev_path, ret);
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Public Functions
****************************************************************************/
+int host_video_get_device_count(void)
+{
+ int count;
+
+ count = host_video_count_devices_in_dir("/sys/class/video4linux");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ count = host_video_count_devices_in_dir("/dev");
+ if (count >= 0)
+ {
+ return count;
+ }
+
+ return 0;
+}
+
bool host_video_is_available(const char *host_video_dev_path)
{
- return access(host_video_dev_path, F_OK) == 0;
+ char resolved_path[PATH_MAX];
+ int ret;
+
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
+ sizeof(resolved_path));
+ if (ret < 0)
+ {
+ return false;
+ }
+
+ return host_video_is_capture_device(resolved_path);
}
struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
{
int fd;
+ int ret;
+ char resolved_path[PATH_MAX];
struct host_video_dev_s *vdev;
- fd = open(host_video_dev_path, O_RDWR | O_NONBLOCK);
- if (fd < 0)
+ ret = host_video_resolve_device_path(host_video_dev_path, resolved_path,
Review Comment:
same reason as above
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3110917606
##########
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:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147373553
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -348,36 +428,46 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
priv->capture_cb = callback;
priv->capture_arg = arg;
- return host_video_start_capture(priv->vdev);
+
+ ret = host_video_start_capture(priv->vdev);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ wd_start(&g_camera_wdog, SIM_CAMERA_PERIOD, sim_camera_interrupt, 0);
Review Comment:
fixed
##########
arch/sim/src/Makefile:
##########
@@ -115,12 +115,17 @@ 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)
HOSTCFLAGS += -D_FILE_OFFSET_BITS=64
endif
+HOST_OBJCFLAGS := $(filter-out -I$(TOPDIR)/include,$(HOSTCFLAGS))
Review Comment:
removed
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147379653
##########
arch/sim/src/Makefile:
##########
@@ -145,6 +150,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
Review Comment:
it is macOS-specific section
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3110916258
##########
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:
done
##########
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:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3122954362
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,10 +3776,30 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ static size_t g_capture_initialize_index;
+ FAR struct imgdata_s *data;
+ FAR struct imgsensor_s *sensor;
Review Comment:
do you need support the origin mode(one data with multiple sensor
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -76,6 +77,7 @@
#include "sim_internal.h"
#include "sim.h"
+#include "sim_hostvideo.h"
Review Comment:
remove, don't need
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,10 +3776,30 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ static size_t g_capture_initialize_index;
Review Comment:
move to the private data section
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +476,91 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
+
+ g_sim_camera_privs = kmm_zalloc(sizeof(sim_camera_priv_t) * (size_t)count);
+ if (g_sim_camera_privs == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ g_sim_camera_priv_count = count;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ for (int i = 0; i < count; i++)
+ {
+ sim_camera_priv_t *priv = &g_sim_camera_privs[i];
+
+ memcpy(priv, &g_sim_camera_priv, sizeof(*priv));
+
+ priv->data.priv = priv;
+ priv->sensor.priv = priv;
+ priv->index = i;
+ snprintf(priv->devpath, sizeof(priv->devpath), "%s%d",
+ CONFIG_SIM_CAMERA_DEV_PATH, i);
+
+ imgdata_register(&priv->data.data);
Review Comment:
you don't need call imgdata_register/imgsensor_register anymore, call capture_register directly
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -33,6 +33,7 @@
#include <nuttx/board.h>
#include <nuttx/clock.h>
#include <nuttx/kmalloc.h>
+#include <nuttx/lib/lib.h>
Review Comment:
why need
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -138,30 +162,30 @@ static const struct v4l2_frmsizeenum g_frmsizes[] =
}
};
-static struct v4l2_fmtdesc g_fmts[] =
-{
- {
- .pixelformat = V4L2_PIX_FMT_YUV420,
- .description = "YUV420",
- }
-};
-
static sim_camera_priv_t g_sim_camera_priv =
{
.data =
{
- &g_sim_camera_data_ops
+ .data =
+ {
+ .ops = &g_sim_camera_data_ops,
+ },
},
.sensor =
{
- .ops = &g_sim_camera_ops,
- .frmsizes_num = 1,
- .frmsizes = g_frmsizes,
- .fmtdescs_num = 1,
- .fmtdescs = g_fmts,
+ .sensor =
+ {
+ .ops = &g_sim_camera_ops,
+ .frmsizes_num = 1,
+ .frmsizes = g_frmsizes,
+ },
}
};
+static sim_camera_priv_t *g_sim_camera_privs;
+static int g_sim_camera_priv_count;
+static struct wdog_s g_camera_wdog;
Review Comment:
remove, all global variables.
##########
boards/sim/sim/sim/src/sim_bringup.c:
##########
@@ -315,12 +317,20 @@ 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
+ {
+ ret = sim_camera_register_capture_devices();
Review Comment:
merge the code in sim_camera_register_capture_devices into sim_camera_initialize
##########
arch/sim/src/Makefile:
##########
@@ -115,12 +115,17 @@ 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)
HOSTCFLAGS += -D_FILE_OFFSET_BITS=64
endif
+HOST_OBJCFLAGS := $(filter-out -I$(TOPDIR)/include,$(HOSTCFLAGS))
Review Comment:
why need? HOSTCFLAGS shouldn't include nuttx/include at all.
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -44,18 +51,33 @@
* Private Types
****************************************************************************/
-typedef struct
+typedef struct sim_camera_priv_s sim_camera_priv_t;
+
+struct sim_camera_imgdata_s
{
struct imgdata_s data;
+ sim_camera_priv_t *priv;
+};
+
+struct sim_camera_sensor_s
+{
struct imgsensor_s sensor;
+ sim_camera_priv_t *priv;
+};
+
+struct sim_camera_priv_s
Review Comment:
why need add sim_camera_priv_s? the support of mulitple instance don't need this change
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -348,36 +428,46 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
priv->capture_cb = callback;
priv->capture_arg = arg;
- return host_video_start_capture(priv->vdev);
+
+ ret = host_video_start_capture(priv->vdev);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ wd_start(&g_camera_wdog, SIM_CAMERA_PERIOD, sim_camera_interrupt, 0);
Review Comment:
don't share one wdog around multiple instances, it make the code quality far poor than before.
the major in sim_camera.c should be just call capture_register in a loop.
##########
arch/sim/src/Makefile:
##########
@@ -145,6 +150,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
Review Comment:
do you need move macOS specific section
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3147372143
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -44,18 +51,33 @@
* Private Types
****************************************************************************/
-typedef struct
+typedef struct sim_camera_priv_s sim_camera_priv_t;
+
+struct sim_camera_imgdata_s
{
struct imgdata_s data;
+ sim_camera_priv_t *priv;
+};
+
+struct sim_camera_sensor_s
+{
struct imgsensor_s sensor;
+ sim_camera_priv_t *priv;
+};
+
+struct sim_camera_priv_s
Review Comment:
using container_of instead
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -138,30 +162,30 @@ static const struct v4l2_frmsizeenum g_frmsizes[] =
}
};
-static struct v4l2_fmtdesc g_fmts[] =
-{
- {
- .pixelformat = V4L2_PIX_FMT_YUV420,
- .description = "YUV420",
- }
-};
-
static sim_camera_priv_t g_sim_camera_priv =
{
.data =
{
- &g_sim_camera_data_ops
+ .data =
+ {
+ .ops = &g_sim_camera_data_ops,
+ },
},
.sensor =
{
- .ops = &g_sim_camera_ops,
- .frmsizes_num = 1,
- .frmsizes = g_frmsizes,
- .fmtdescs_num = 1,
- .fmtdescs = g_fmts,
+ .sensor =
+ {
+ .ops = &g_sim_camera_ops,
+ .frmsizes_num = 1,
+ .frmsizes = g_frmsizes,
+ },
}
};
+static sim_camera_priv_t *g_sim_camera_privs;
+static int g_sim_camera_priv_count;
+static struct wdog_s g_camera_wdog;
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#issuecomment-4252918399
@PeterBee97 please include this picture in the Documentation page, it is funny :-)
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3097663334
##########
arch/sim/src/sim/posix/sim_host_v4l2.c:
##########
@@ -114,6 +330,7 @@ struct host_video_dev_s *host_video_init(const char *host_video_dev_path)
}
vdev->fd = fd;
+ (void)snprintf(vdev->path, sizeof(vdev->path), "%s", resolved_path);
Review Comment:
Just changed from strlcpy because the Linux sim-02 CI complained about it...
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3156139262
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +429,63 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
- 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);
Review Comment:
delete cast
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -348,36 +382,45 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
priv->capture_cb = callback;
priv->capture_arg = arg;
- return host_video_start_capture(priv->vdev);
+
+ ret = host_video_start_capture(priv->vdev);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ priv->capture_started = true;
+ wd_start(&priv->wdog, SIM_CAMERA_PERIOD, sim_camera_interrupt,
+ (wdparm_t)priv);
+ return 0;
}
static int sim_camera_data_stop_capture(struct imgdata_s *data)
{
- sim_camera_priv_t *priv = (sim_camera_priv_t *)data;
+ sim_camera_priv_t *priv = container_of(data, sim_camera_priv_t, data);
priv->next_buf = NULL;
+ priv->capture_started = false;
+ wd_cancel(&priv->wdog);
return host_video_stop_capture(priv->vdev);
}
static void sim_camera_interrupt(wdparm_t arg)
{
sim_camera_priv_t *priv = (sim_camera_priv_t *)arg;
- struct timespec ts;
Review Comment:
why change? don't add the unnecessary change into pr, which just make your change review
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +429,63 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
- 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);
+ if (g_sim_camera_privs == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ for (int i = 0; i < count; i++)
+ {
+ sim_camera_priv_t *priv = &g_sim_camera_privs[i];
+ FAR struct imgsensor_s *sensor = &priv->sensor;
+ int ret;
+
+ priv->data.ops = &g_sim_camera_data_ops;
+ priv->sensor.ops = &g_sim_camera_ops;
+ priv->sensor.frmsizes_num = 1;
+ priv->sensor.frmsizes = g_frmsizes;
+ priv->sensors[0] = sensor;
Review Comment:
why do you need add sensors field
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3159910725
##########
drivers/video/v4l2_cap.c:
##########
@@ -3775,15 +3831,67 @@ static int capture_unlink(FAR struct inode *inode)
int capture_initialize(FAR const char *devpath)
{
- return capture_register(devpath,
- g_capture_data,
- g_capture_registered_sensor,
- g_capture_registered_sensor_num);
+ size_t index;
+ FAR char *registered_devpath;
+ size_t devpath_len;
+ int ret;
+
+ if (devpath == NULL || g_capture_registered_sensor == NULL ||
+ g_capture_registered_sensor_num == 0)
+ {
+ return -EINVAL;
+ }
+
+ if (get_registered_data_index(devpath, &index))
+ {
+ return -EEXIST;
+ }
+
+ if (!get_available_registered_data_index(&index))
+ {
+ return -EINVAL;
+ }
+
+ devpath_len = strlen(devpath) + 1;
+ registered_devpath = kmm_malloc(devpath_len);
+ if (registered_devpath == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ strlcpy(registered_devpath, devpath, devpath_len);
+
+ ret = capture_register(devpath, g_capture_registered_data[index].data,
+ g_capture_registered_sensor,
+ g_capture_registered_sensor_num);
+ if (ret < 0)
+ {
+ kmm_free(registered_devpath);
+ return ret;
+ }
+
+ g_capture_registered_data[index].devpath = registered_devpath;
Review Comment:
changed to save index for reference instead
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] sim/camera: add AVFoundation backend and multi-cam support [nuttx]
Posted by "PeterBee97 (via GitHub)" <gi...@apache.org>.
PeterBee97 commented on code in PR #18745:
URL: https://github.com/apache/nuttx/pull/18745#discussion_r3159906625
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -348,36 +382,45 @@ static int sim_camera_data_start_capture(struct imgdata_s *data,
priv->capture_cb = callback;
priv->capture_arg = arg;
- return host_video_start_capture(priv->vdev);
+
+ ret = host_video_start_capture(priv->vdev);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ priv->capture_started = true;
+ wd_start(&priv->wdog, SIM_CAMERA_PERIOD, sim_camera_interrupt,
+ (wdparm_t)priv);
+ return 0;
}
static int sim_camera_data_stop_capture(struct imgdata_s *data)
{
- sim_camera_priv_t *priv = (sim_camera_priv_t *)data;
+ sim_camera_priv_t *priv = container_of(data, sim_camera_priv_t, data);
priv->next_buf = NULL;
+ priv->capture_started = false;
+ wd_cancel(&priv->wdog);
return host_video_stop_capture(priv->vdev);
}
static void sim_camera_interrupt(wdparm_t arg)
{
sim_camera_priv_t *priv = (sim_camera_priv_t *)arg;
- struct timespec ts;
Review Comment:
restored
##########
arch/sim/src/sim/sim_camera.c:
##########
@@ -386,11 +429,63 @@ static void sim_camera_interrupt(wdparm_t arg)
int sim_camera_initialize(void)
{
- sim_camera_priv_t *priv = &g_sim_camera_priv;
+ int count;
+ int first_error = 0;
- imgsensor_register(&priv->sensor);
- imgdata_register(&priv->data);
+ count = host_video_get_device_count();
+ if (count <= 0)
+ {
+ count = 1;
+ }
- 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);
Review Comment:
done
--
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: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org