From ce439fc1ee002a05841057b23b8418830498c5f7 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Sun, 10 Apr 2022 12:01:30 +0200 Subject: [PATCH] Move `dev->subdev_fd` to `dev->v4l2.subdev_fd` --- device/device.c | 2 -- device/device.h | 5 ++++- device/v4l2/device.c | 9 +++++---- device/v4l2/device_media.c | 6 +++--- device/v4l2/device_options.c | 6 +++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/device/device.c b/device/device.c index ff4f732..7f8d181 100644 --- a/device/device.c +++ b/device/device.c @@ -10,14 +10,12 @@ device_t *device_open(const char *name, const char *path, device_hw_t *hw) { dev->path = strdup(path); dev->hw = hw; dev->fd = -1; - dev->subdev_fd = -1; dev->allow_dma = true; if (dev->hw->device_open(dev) < 0) { E_LOG_ERROR(dev, "Can't open device: %s", path); } - E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->fd); return dev; error: diff --git a/device/device.h b/device/device.h index ea35c19..ec0971c 100644 --- a/device/device.h +++ b/device/device.h @@ -33,13 +33,16 @@ typedef struct device_s { char *path; char bus_info[64]; int fd; - int subdev_fd; bool allow_dma; device_hw_t *hw; buffer_list_t *capture_list; buffer_list_t *output_list; + struct { + int subdev_fd; + } v4l2; + device_t *output_device; bool paused; bool decoder_started; diff --git a/device/v4l2/device.c b/device/v4l2/device.c index faa1e08..6fd4d8e 100644 --- a/device/v4l2/device.c +++ b/device/v4l2/device.c @@ -5,7 +5,7 @@ int v4l2_device_open(device_t *dev) { dev->fd = -1; - dev->subdev_fd = -1; + dev->v4l2.subdev_fd = -1; dev->fd = open(dev->path, O_RDWR|O_NONBLOCK); if (dev->fd < 0) { @@ -22,7 +22,8 @@ int v4l2_device_open(device_t *dev) } strcpy(dev->bus_info, v4l2_cap.bus_info); - dev->subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0); + dev->v4l2.subdev_fd = v4l2_device_open_v4l2_subdev(dev, 0); + E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->fd); return 0; @@ -32,8 +33,8 @@ error: void v4l2_device_close(device_t *dev) { - if (dev->subdev_fd >= 0) { - close(dev->subdev_fd); + if (dev->v4l2.subdev_fd >= 0) { + close(dev->v4l2.subdev_fd); } if(dev->fd >= 0) { diff --git a/device/v4l2/device_media.c b/device/v4l2/device_media.c index 8b750e7..88e14c6 100644 --- a/device/v4l2/device_media.c +++ b/device/v4l2/device_media.c @@ -111,7 +111,7 @@ int v4l2_device_set_pad_format(device_t *dev, unsigned width, unsigned height, u { struct v4l2_subdev_format fmt = {0}; - if (dev->subdev_fd < 0) { + if (dev->v4l2.subdev_fd < 0) { return -1; } @@ -123,8 +123,8 @@ int v4l2_device_set_pad_format(device_t *dev, unsigned width, unsigned height, u fmt.format.colorspace = V4L2_COLORSPACE_RAW; fmt.format.field = V4L2_FIELD_ANY; - E_LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->subdev_fd); - E_XIOCTL(dev, dev->subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->subdev_fd); + E_LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->v4l2.subdev_fd); + E_XIOCTL(dev, dev->v4l2.subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->v4l2.subdev_fd); return 0; error: diff --git a/device/v4l2/device_options.c b/device/v4l2/device_options.c index 764148d..ab1bb05 100644 --- a/device/v4l2/device_options.c +++ b/device/v4l2/device_options.c @@ -15,7 +15,7 @@ int v4l2_device_set_option_by_id(device_t *dev, const char *name, uint32_t id, i ctl.id = id; ctl.value = value; E_LOG_DEBUG(dev, "Configuring option %s (%08x) = %d", name, id, value); - E_XIOCTL(dev, dev->subdev_fd >= 0 ? dev->subdev_fd : dev->fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name); + E_XIOCTL(dev, dev->v4l2.subdev_fd >= 0 ? dev->v4l2.subdev_fd : dev->fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name); return 0; error: return -1; @@ -152,8 +152,8 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) v4l2_device_option_normalize_name(keyp); - if (dev->subdev_fd >= 0) - ret = v4l2_device_set_option_string_fd(dev, dev->subdev_fd, keyp, valuep); + if (dev->v4l2.subdev_fd >= 0) + ret = v4l2_device_set_option_string_fd(dev, dev->v4l2.subdev_fd, keyp, valuep); if (ret <= 0) ret = v4l2_device_set_option_string_fd(dev, dev->fd, keyp, valuep);