drivers/media/usb/uvc/uvc_metadata.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/uvc/uvc_metadata.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/uvc/uvc_metadata.c
Extension
.c
Size
7290 bytes
Lines
267
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (dev->meta_formats[i] == fmt->dataformat) {
			fmeta = fmt->dataformat;
			break;
		}
	}

	buffersize = max(UVC_METADATA_BUF_MIN_SIZE, fmt->buffersize);

	memset(fmt, 0, sizeof(*fmt));

	fmt->dataformat = fmeta;
	fmt->buffersize = buffersize;

	return 0;
}

static int uvc_meta_v4l2_set_format(struct file *file, void *priv,
				    struct v4l2_format *format)
{
	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
	struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
	struct v4l2_meta_format *fmt = &format->fmt.meta;
	int ret;

	ret = uvc_meta_v4l2_try_format(file, priv, format);
	if (ret < 0)
		return ret;

	/*
	 * We could in principle switch at any time, also during streaming.
	 * Metadata buffers would still be perfectly parseable, but it's more
	 * consistent and cleaner to disallow that.
	 */
	if (vb2_is_busy(&stream->meta.queue.queue))
		return -EBUSY;

	stream->meta.format = fmt->dataformat;
	stream->meta.buffersize = fmt->buffersize;

	return 0;
}

static int uvc_meta_v4l2_enum_formats(struct file *file, void *priv,
				      struct v4l2_fmtdesc *fdesc)
{
	struct v4l2_fh *vfh = file_to_v4l2_fh(file);
	struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
	struct uvc_device *dev = stream->dev;

	if (fdesc->type != vfh->vdev->queue->type)
		return -EINVAL;

	if (fdesc->index >= dev->nmeta_formats)
		return -EINVAL;

	fdesc->pixelformat = dev->meta_formats[fdesc->index];

	return 0;
}

static const struct v4l2_ioctl_ops uvc_meta_ioctl_ops = {
	.vidioc_querycap		= uvc_meta_v4l2_querycap,
	.vidioc_g_fmt_meta_cap		= uvc_meta_v4l2_get_format,
	.vidioc_s_fmt_meta_cap		= uvc_meta_v4l2_set_format,
	.vidioc_try_fmt_meta_cap	= uvc_meta_v4l2_try_format,
	.vidioc_enum_fmt_meta_cap	= uvc_meta_v4l2_enum_formats,
	.vidioc_reqbufs			= vb2_ioctl_reqbufs,
	.vidioc_querybuf		= vb2_ioctl_querybuf,
	.vidioc_qbuf			= vb2_ioctl_qbuf,
	.vidioc_dqbuf			= vb2_ioctl_dqbuf,
	.vidioc_create_bufs		= vb2_ioctl_create_bufs,
	.vidioc_prepare_buf		= vb2_ioctl_prepare_buf,
	.vidioc_streamon		= vb2_ioctl_streamon,
	.vidioc_streamoff		= vb2_ioctl_streamoff,
};

/* -----------------------------------------------------------------------------
 * V4L2 File Operations
 */

static const struct v4l2_file_operations uvc_meta_fops = {
	.owner = THIS_MODULE,
	.unlocked_ioctl = video_ioctl2,
	.open = v4l2_fh_open,
	.release = vb2_fop_release,
	.poll = vb2_fop_poll,
	.mmap = vb2_fop_mmap,
};

static struct uvc_entity *uvc_meta_find_msxu(struct uvc_device *dev)

Annotation

Implementation Notes