Skip to content

Commit 0bb51c8

Browse files
ribaldahverkuil
authored andcommitted
media: uvcvideo: Introduce dev->meta_formats
Right now, there driver supports devices with one or two metadata formats. Prepare it to support more than two metadata formats. This is achieved with the introduction of a new field `meta_formats`, that contains the array of metadata formats supported by the device, in the order expected by userspace. Suggested-by: Hans de Goede <[email protected]> Signed-off-by: Ricardo Ribalda <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent e1ad270 commit 0bb51c8

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

drivers/media/usb/uvc/uvc_driver.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,8 @@ static int uvc_probe(struct usb_interface *intf,
22932293
goto error;
22942294
}
22952295

2296+
uvc_meta_init(dev);
2297+
22962298
if (dev->quirks & UVC_QUIRK_NO_RESET_RESUME)
22972299
udev->quirks &= ~USB_QUIRK_RESET_RESUME;
22982300

drivers/media/usb/uvc/uvc_metadata.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,20 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
6464
struct uvc_device *dev = stream->dev;
6565
struct v4l2_meta_format *fmt = &format->fmt.meta;
6666
u32 fmeta = fmt->dataformat;
67+
u32 i;
6768

6869
if (format->type != vfh->vdev->queue->type)
6970
return -EINVAL;
7071

72+
for (i = 0; (fmeta != dev->meta_formats[i]) && dev->meta_formats[i];
73+
i++)
74+
;
75+
if (!dev->meta_formats[i])
76+
fmeta = V4L2_META_FMT_UVC;
77+
7178
memset(fmt, 0, sizeof(*fmt));
7279

73-
fmt->dataformat = fmeta == dev->info->meta_format
74-
? fmeta : V4L2_META_FMT_UVC;
80+
fmt->dataformat = fmeta;
7581
fmt->buffersize = UVC_METADATA_BUF_SIZE;
7682

7783
return 0;
@@ -112,17 +118,21 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
112118
struct v4l2_fh *vfh = file->private_data;
113119
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
114120
struct uvc_device *dev = stream->dev;
115-
u32 index = fdesc->index;
121+
u32 i;
122+
123+
if (fdesc->type != vfh->vdev->queue->type)
124+
return -EINVAL;
116125

117-
if (fdesc->type != vfh->vdev->queue->type ||
118-
index > 1U || (index && !dev->info->meta_format))
126+
for (i = 0; (i < fdesc->index) && dev->meta_formats[i]; i++)
127+
;
128+
if (!dev->meta_formats[i])
119129
return -EINVAL;
120130

121131
memset(fdesc, 0, sizeof(*fdesc));
122132

123133
fdesc->type = vfh->vdev->queue->type;
124-
fdesc->index = index;
125-
fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC;
134+
fdesc->index = i;
135+
fdesc->pixelformat = dev->meta_formats[i];
126136

127137
return 0;
128138
}
@@ -168,3 +178,17 @@ int uvc_meta_register(struct uvc_streaming *stream)
168178
V4L2_BUF_TYPE_META_CAPTURE,
169179
&uvc_meta_fops, &uvc_meta_ioctl_ops);
170180
}
181+
182+
void uvc_meta_init(struct uvc_device *dev)
183+
{
184+
unsigned int i = 0;
185+
186+
dev->meta_formats[i++] = V4L2_META_FMT_UVC;
187+
188+
if (dev->info->meta_format &&
189+
!WARN_ON(dev->info->meta_format == V4L2_META_FMT_UVC))
190+
dev->meta_formats[i++] = dev->info->meta_format;
191+
192+
/* IMPORTANT: for new meta-formats update UVC_MAX_META_DATA_FORMATS. */
193+
dev->meta_formats[i++] = 0;
194+
}

drivers/media/usb/uvc/uvcvideo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ struct uvc_status {
575575
};
576576
} __packed;
577577

578+
#define UVC_MAX_META_DATA_FORMATS 3
579+
578580
struct uvc_device {
579581
struct usb_device *udev;
580582
struct usb_interface *intf;
@@ -585,6 +587,9 @@ struct uvc_device {
585587

586588
const struct uvc_device_info *info;
587589

590+
/* Zero-ended list of meta formats */
591+
u32 meta_formats[UVC_MAX_META_DATA_FORMATS + 1];
592+
588593
atomic_t nmappings;
589594

590595
/* Video control interface */
@@ -722,6 +727,7 @@ int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
722727
void uvc_video_clock_update(struct uvc_streaming *stream,
723728
struct vb2_v4l2_buffer *vbuf,
724729
struct uvc_buffer *buf);
730+
void uvc_meta_init(struct uvc_device *dev);
725731
int uvc_meta_register(struct uvc_streaming *stream);
726732

727733
int uvc_register_video_device(struct uvc_device *dev,

0 commit comments

Comments
 (0)