drivers/media/pci/cx18/cx18-ioctl.c

Source file repositories/reference/linux-study-clean/drivers/media/pci/cx18/cx18-ioctl.c

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/cx18/cx18-ioctl.c
Extension
.c
Size
29065 bytes
Lines
1058
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 (pixfmt->pixelformat == V4L2_PIX_FMT_NV12_16L16) {
			pixfmt->sizeimage = h * 720 * 3 / 2;
			pixfmt->bytesperline = 720; /* First plane */
		} else {
			pixfmt->sizeimage = h * 720 * 2;
			pixfmt->bytesperline = 1440; /* Packed */
		}
	} else {
		pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
		pixfmt->sizeimage = 128 * 1024;
		pixfmt->bytesperline = 0;
	}

	pixfmt->width = w;
	pixfmt->height = h;
	pixfmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
	pixfmt->field = V4L2_FIELD_INTERLACED;
	return 0;
}

static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
			      struct v4l2_format *fmt)
{
	struct cx18_open_id *id = file2id(file);
	struct cx18 *cx = id->cx;
	struct v4l2_subdev_format format = {
		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
	};
	struct cx18_stream *s = &cx->streams[id->type];
	int ret;
	int w, h;

	ret = cx18_try_fmt_vid_cap(file, fh, fmt);
	if (ret)
		return ret;
	w = fmt->fmt.pix.width;
	h = fmt->fmt.pix.height;

	if (cx->cxhdl.width == w && cx->cxhdl.height == h &&
	    s->pixelformat == fmt->fmt.pix.pixelformat)
		return 0;

	if (atomic_read(&cx->ana_capturing) > 0)
		return -EBUSY;

	s->pixelformat = fmt->fmt.pix.pixelformat;
	s->vb_bytes_per_frame = fmt->fmt.pix.sizeimage;
	s->vb_bytes_per_line = fmt->fmt.pix.bytesperline;

	format.format.width = cx->cxhdl.width = w;
	format.format.height = cx->cxhdl.height = h;
	format.format.code = MEDIA_BUS_FMT_FIXED;
	v4l2_subdev_call(cx->sd_av, pad, set_fmt, NULL, &format);
	return cx18_g_fmt_vid_cap(file, fh, fmt);
}

u16 cx18_service2vbi(int type)
{
	switch (type) {
	case V4L2_SLICED_TELETEXT_B:
		return CX18_SLICED_TYPE_TELETEXT_B;
	case V4L2_SLICED_CAPTION_525:
		return CX18_SLICED_TYPE_CAPTION_525;
	case V4L2_SLICED_WSS_625:
		return CX18_SLICED_TYPE_WSS_625;
	case V4L2_SLICED_VPS:
		return CX18_SLICED_TYPE_VPS;
	default:
		return 0;
	}
}

/* Check if VBI services are allowed on the (field, line) for the video std */
static int valid_service_line(int field, int line, int is_pal)
{
	return (is_pal && line >= 6 &&
		((field == 0 && line <= 23) || (field == 1 && line <= 22))) ||
	       (!is_pal && line >= 10 && line < 22);
}

/*
 * For a (field, line, std) and inbound potential set of services for that line,
 * return the first valid service of those passed in the incoming set for that
 * line in priority order:
 * CC, VPS, or WSS over TELETEXT for well known lines
 * TELETEXT, before VPS, before CC, before WSS, for other lines
 */
static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
{
	u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);

Annotation

Implementation Notes