drivers/media/platform/verisilicon/hantro_v4l2.c

Source file repositories/reference/linux-study-clean/drivers/media/platform/verisilicon/hantro_v4l2.c

File Facts

System
Linux kernel
Corpus path
drivers/media/platform/verisilicon/hantro_v4l2.c
Extension
.c
Size
27650 bytes
Lines
1032
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 (j == index) {
			f->pixelformat = fmt->fourcc;
			return 0;
		}
		++j;
	}

	/*
	 * Enumerate post-processed formats. As per the specification,
	 * we enumerated these formats after natively decoded formats
	 * as a hint for applications on what's the preferred fomat.
	 */
	if (!capture)
		return -EINVAL;
	formats = hantro_get_postproc_formats(ctx, &num_fmts);
	for (i = 0; i < num_fmts; i++) {
		fmt = &formats[i];

		if (!hantro_check_depth_match(fmt, ctx->bit_depth) && !enum_all_formats)
			continue;
		if (j == index) {
			f->pixelformat = fmt->fourcc;
			return 0;
		}
		++j;
	}

	return -EINVAL;
}

static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
				   struct v4l2_fmtdesc *f)
{
	return vidioc_enum_fmt(file, priv, f, true);
}

static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
				   struct v4l2_fmtdesc *f)
{
	return vidioc_enum_fmt(file, priv, f, false);
}

static int vidioc_g_fmt_out_mplane(struct file *file, void *priv,
				   struct v4l2_format *f)
{
	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
	struct hantro_ctx *ctx = file_to_ctx(file);

	vpu_debug(4, "f->type = %d\n", f->type);

	*pix_mp = ctx->src_fmt;

	return 0;
}

static int vidioc_g_fmt_cap_mplane(struct file *file, void *priv,
				   struct v4l2_format *f)
{
	struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp;
	struct hantro_ctx *ctx = file_to_ctx(file);

	vpu_debug(4, "f->type = %d\n", f->type);

	*pix_mp = ctx->dst_fmt;

	return 0;
}

static int hantro_try_fmt(const struct hantro_ctx *ctx,
			  struct v4l2_pix_format_mplane *pix_mp,
			  enum v4l2_buf_type type)
{
	const struct hantro_fmt *fmt;
	const struct hantro_fmt *vpu_fmt;
	bool capture = V4L2_TYPE_IS_CAPTURE(type);
	bool coded;

	coded = capture == ctx->is_encoder;

	vpu_debug(4, "trying format %p4cc\n", &pix_mp->pixelformat);

	fmt = hantro_find_format(ctx, pix_mp->pixelformat);
	if (!fmt) {
		fmt = hantro_get_default_fmt(ctx, coded, HANTRO_DEFAULT_BIT_DEPTH, HANTRO_AUTO_POSTPROC);
		pix_mp->pixelformat = fmt->fourcc;
	}

	if (coded) {
		pix_mp->num_planes = 1;
		vpu_fmt = fmt;

Annotation

Implementation Notes