Lines Matching +full:n +full:- +full:factor
1 // SPDX-License-Identifier: GPL-2.0-only
3 * vivid-vid-out.c - video output support functions.
12 #include <linux/v4l2-dv-timings.h>
13 #include <media/v4l2-common.h>
14 #include <media/v4l2-event.h>
15 #include <media/v4l2-dv-timings.h>
16 #include <media/v4l2-rect.h>
18 #include "vivid-core.h"
19 #include "vivid-vid-common.h"
20 #include "vivid-kthread-out.h"
21 #include "vivid-vid-out.h"
28 const struct vivid_fmt *vfmt = dev->fmt_out; in vid_out_queue_setup()
29 unsigned planes = vfmt->buffers; in vid_out_queue_setup()
30 unsigned h = dev->fmt_out_rect.height; in vid_out_queue_setup()
31 unsigned int size = dev->bytesperline_out[0] * h + vfmt->data_offset[0]; in vid_out_queue_setup()
34 for (p = vfmt->buffers; p < vfmt->planes; p++) in vid_out_queue_setup()
35 size += dev->bytesperline_out[p] * h / vfmt->vdownsampling[p] + in vid_out_queue_setup()
36 vfmt->data_offset[p]; in vid_out_queue_setup()
38 if (dev->field_out == V4L2_FIELD_ALTERNATE) { in vid_out_queue_setup()
44 return -EINVAL; in vid_out_queue_setup()
47 if (dev->queue_setup_error) { in vid_out_queue_setup()
52 dev->queue_setup_error = false; in vid_out_queue_setup()
53 return -EINVAL; in vid_out_queue_setup()
62 return -EINVAL; in vid_out_queue_setup()
64 return -EINVAL; in vid_out_queue_setup()
66 if (sizes[p] < dev->bytesperline_out[p] * h / in vid_out_queue_setup()
67 vfmt->vdownsampling[p] + in vid_out_queue_setup()
68 vfmt->data_offset[p]) in vid_out_queue_setup()
69 return -EINVAL; in vid_out_queue_setup()
73 sizes[p] = p ? dev->bytesperline_out[p] * h / in vid_out_queue_setup()
74 vfmt->vdownsampling[p] + in vid_out_queue_setup()
75 vfmt->data_offset[p] : size; in vid_out_queue_setup()
80 dprintk(dev, 1, "%s: count=%u\n", __func__, *nbuffers); in vid_out_queue_setup()
82 dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); in vid_out_queue_setup()
89 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_out_validate()
91 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_out_validate()
93 if (dev->field_out != V4L2_FIELD_ALTERNATE) in vid_out_buf_out_validate()
94 vbuf->field = dev->field_out; in vid_out_buf_out_validate()
95 else if (vbuf->field != V4L2_FIELD_TOP && in vid_out_buf_out_validate()
96 vbuf->field != V4L2_FIELD_BOTTOM) in vid_out_buf_out_validate()
97 return -EINVAL; in vid_out_buf_out_validate()
103 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_prepare()
104 const struct vivid_fmt *vfmt = dev->fmt_out; in vid_out_buf_prepare()
105 unsigned int planes = vfmt->buffers; in vid_out_buf_prepare()
106 unsigned int h = dev->fmt_out_rect.height; in vid_out_buf_prepare()
107 unsigned int size = dev->bytesperline_out[0] * h; in vid_out_buf_prepare()
110 for (p = vfmt->buffers; p < vfmt->planes; p++) in vid_out_buf_prepare()
111 size += dev->bytesperline_out[p] * h / vfmt->vdownsampling[p]; in vid_out_buf_prepare()
113 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_prepare()
115 if (WARN_ON(NULL == dev->fmt_out)) in vid_out_buf_prepare()
116 return -EINVAL; in vid_out_buf_prepare()
118 if (dev->buf_prepare_error) { in vid_out_buf_prepare()
123 dev->buf_prepare_error = false; in vid_out_buf_prepare()
124 return -EINVAL; in vid_out_buf_prepare()
129 size = dev->bytesperline_out[p] * h / vfmt->vdownsampling[p]; in vid_out_buf_prepare()
130 size += vb->planes[p].data_offset; in vid_out_buf_prepare()
133 dprintk(dev, 1, "%s the payload is too small for plane %u (%lu < %u)\n", in vid_out_buf_prepare()
135 return -EINVAL; in vid_out_buf_prepare()
145 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_queue()
148 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_queue()
150 spin_lock(&dev->slock); in vid_out_buf_queue()
151 list_add_tail(&buf->list, &dev->vid_out_active); in vid_out_buf_queue()
152 spin_unlock(&dev->slock); in vid_out_buf_queue()
160 dev->vid_out_seq_count = 0; in vid_out_start_streaming()
161 dprintk(dev, 1, "%s\n", __func__); in vid_out_start_streaming()
162 if (dev->start_streaming_error) { in vid_out_start_streaming()
163 dev->start_streaming_error = false; in vid_out_start_streaming()
164 err = -EINVAL; in vid_out_start_streaming()
166 err = vivid_start_generating_vid_out(dev, &dev->vid_out_streaming); in vid_out_start_streaming()
171 list_for_each_entry_safe(buf, tmp, &dev->vid_out_active, list) { in vid_out_start_streaming()
172 list_del(&buf->list); in vid_out_start_streaming()
173 vb2_buffer_done(&buf->vb.vb2_buf, in vid_out_start_streaming()
185 dprintk(dev, 1, "%s\n", __func__); in vid_out_stop_streaming()
186 vivid_stop_generating_vid_out(dev, &dev->vid_out_streaming); in vid_out_stop_streaming()
191 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_request_complete()
193 v4l2_ctrl_request_complete(vb->req_obj.req, &dev->ctrl_hdl_vid_out); in vid_out_buf_request_complete()
214 struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt; in vivid_update_format_out()
218 switch (dev->output_type[dev->output]) { in vivid_update_format_out()
221 dev->field_out = dev->tv_field_out; in vivid_update_format_out()
222 dev->sink_rect.width = 720; in vivid_update_format_out()
223 if (dev->std_out & V4L2_STD_525_60) { in vivid_update_format_out()
224 dev->sink_rect.height = 480; in vivid_update_format_out()
225 dev->timeperframe_vid_out = (struct v4l2_fract) { 1001, 30000 }; in vivid_update_format_out()
226 dev->service_set_out = V4L2_SLICED_CAPTION_525; in vivid_update_format_out()
228 dev->sink_rect.height = 576; in vivid_update_format_out()
229 dev->timeperframe_vid_out = (struct v4l2_fract) { 1000, 25000 }; in vivid_update_format_out()
230 dev->service_set_out = V4L2_SLICED_WSS_625 | V4L2_SLICED_TELETEXT_B; in vivid_update_format_out()
232 dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M; in vivid_update_format_out()
235 dev->sink_rect.width = bt->width; in vivid_update_format_out()
236 dev->sink_rect.height = bt->height; in vivid_update_format_out()
239 if (can_reduce_fps(bt) && (bt->flags & V4L2_DV_FL_REDUCED_FPS)) in vivid_update_format_out()
240 pixelclock = div_u64(bt->pixelclock * 1000, 1001); in vivid_update_format_out()
242 pixelclock = bt->pixelclock; in vivid_update_format_out()
244 dev->timeperframe_vid_out = (struct v4l2_fract) { in vivid_update_format_out()
247 if (bt->interlaced) in vivid_update_format_out()
248 dev->field_out = V4L2_FIELD_ALTERNATE; in vivid_update_format_out()
250 dev->field_out = V4L2_FIELD_NONE; in vivid_update_format_out()
251 if (!dev->dvi_d_out && (bt->flags & V4L2_DV_FL_IS_CE_VIDEO)) { in vivid_update_format_out()
252 if (bt->width == 720 && bt->height <= 576) in vivid_update_format_out()
253 dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M; in vivid_update_format_out()
255 dev->colorspace_out = V4L2_COLORSPACE_REC709; in vivid_update_format_out()
257 dev->colorspace_out = V4L2_COLORSPACE_SRGB; in vivid_update_format_out()
261 dev->xfer_func_out = V4L2_XFER_FUNC_DEFAULT; in vivid_update_format_out()
262 dev->ycbcr_enc_out = V4L2_YCBCR_ENC_DEFAULT; in vivid_update_format_out()
263 dev->hsv_enc_out = V4L2_HSV_ENC_180; in vivid_update_format_out()
264 dev->quantization_out = V4L2_QUANTIZATION_DEFAULT; in vivid_update_format_out()
265 dev->compose_out = dev->sink_rect; in vivid_update_format_out()
266 dev->compose_bounds_out = dev->sink_rect; in vivid_update_format_out()
267 dev->crop_out = dev->compose_out; in vivid_update_format_out()
268 if (V4L2_FIELD_HAS_T_OR_B(dev->field_out)) in vivid_update_format_out()
269 dev->crop_out.height /= 2; in vivid_update_format_out()
270 dev->fmt_out_rect = dev->crop_out; in vivid_update_format_out()
271 for (p = 0; p < dev->fmt_out->planes; p++) in vivid_update_format_out()
272 dev->bytesperline_out[p] = in vivid_update_format_out()
273 (dev->sink_rect.width * dev->fmt_out->bit_depth[p]) / 8; in vivid_update_format_out()
293 return dev->dv_timings_out.bt.interlaced ? V4L2_FIELD_ALTERNATE : in vivid_field_out()
301 return (dev->std_out & V4L2_STD_525_60) ? in vivid_get_pixel_aspect()
305 dev->sink_rect.width == 720 && dev->sink_rect.height <= 576) in vivid_get_pixel_aspect()
306 return dev->sink_rect.height == 480 ? in vivid_get_pixel_aspect()
316 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_g_fmt_vid_out()
317 const struct vivid_fmt *fmt = dev->fmt_out; in vivid_g_fmt_vid_out()
320 mp->width = dev->fmt_out_rect.width; in vivid_g_fmt_vid_out()
321 mp->height = dev->fmt_out_rect.height; in vivid_g_fmt_vid_out()
322 mp->field = dev->field_out; in vivid_g_fmt_vid_out()
323 mp->pixelformat = fmt->fourcc; in vivid_g_fmt_vid_out()
324 mp->colorspace = dev->colorspace_out; in vivid_g_fmt_vid_out()
325 mp->xfer_func = dev->xfer_func_out; in vivid_g_fmt_vid_out()
326 mp->ycbcr_enc = dev->ycbcr_enc_out; in vivid_g_fmt_vid_out()
327 mp->quantization = dev->quantization_out; in vivid_g_fmt_vid_out()
328 mp->num_planes = fmt->buffers; in vivid_g_fmt_vid_out()
329 for (p = 0; p < mp->num_planes; p++) { in vivid_g_fmt_vid_out()
330 mp->plane_fmt[p].bytesperline = dev->bytesperline_out[p]; in vivid_g_fmt_vid_out()
331 mp->plane_fmt[p].sizeimage = in vivid_g_fmt_vid_out()
332 mp->plane_fmt[p].bytesperline * mp->height / in vivid_g_fmt_vid_out()
333 fmt->vdownsampling[p] + fmt->data_offset[p]; in vivid_g_fmt_vid_out()
335 for (p = fmt->buffers; p < fmt->planes; p++) { in vivid_g_fmt_vid_out()
336 unsigned stride = dev->bytesperline_out[p]; in vivid_g_fmt_vid_out()
338 mp->plane_fmt[0].sizeimage += in vivid_g_fmt_vid_out()
339 (stride * mp->height) / fmt->vdownsampling[p]; in vivid_g_fmt_vid_out()
348 struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt; in vivid_try_fmt_vid_out()
349 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_try_fmt_vid_out()
350 struct v4l2_plane_pix_format *pfmt = mp->plane_fmt; in vivid_try_fmt_vid_out()
353 unsigned factor = 1; in vivid_try_fmt_vid_out() local
357 fmt = vivid_get_format(dev, mp->pixelformat); in vivid_try_fmt_vid_out()
359 dprintk(dev, 1, "Fourcc format (0x%08x) unknown.\n", in vivid_try_fmt_vid_out()
360 mp->pixelformat); in vivid_try_fmt_vid_out()
361 mp->pixelformat = V4L2_PIX_FMT_YUYV; in vivid_try_fmt_vid_out()
362 fmt = vivid_get_format(dev, mp->pixelformat); in vivid_try_fmt_vid_out()
365 mp->field = vivid_field_out(dev, mp->field); in vivid_try_fmt_vid_out()
368 h = (dev->std_out & V4L2_STD_525_60) ? 480 : 576; in vivid_try_fmt_vid_out()
370 w = dev->sink_rect.width; in vivid_try_fmt_vid_out()
371 h = dev->sink_rect.height; in vivid_try_fmt_vid_out()
373 if (V4L2_FIELD_HAS_T_OR_B(mp->field)) in vivid_try_fmt_vid_out()
374 factor = 2; in vivid_try_fmt_vid_out()
375 if (!dev->has_scaler_out && !dev->has_crop_out && !dev->has_compose_out) { in vivid_try_fmt_vid_out()
376 mp->width = w; in vivid_try_fmt_vid_out()
377 mp->height = h / factor; in vivid_try_fmt_vid_out()
379 struct v4l2_rect r = { 0, 0, mp->width, mp->height * factor }; in vivid_try_fmt_vid_out()
383 if (dev->has_scaler_out && !dev->has_crop_out) { in vivid_try_fmt_vid_out()
387 } else if (!dev->has_scaler_out && dev->has_compose_out && !dev->has_crop_out) { in vivid_try_fmt_vid_out()
388 v4l2_rect_set_max_size(&r, &dev->sink_rect); in vivid_try_fmt_vid_out()
389 } else if (!dev->has_scaler_out && !dev->has_compose_out) { in vivid_try_fmt_vid_out()
390 v4l2_rect_set_min_size(&r, &dev->sink_rect); in vivid_try_fmt_vid_out()
392 mp->width = r.width; in vivid_try_fmt_vid_out()
393 mp->height = r.height / factor; in vivid_try_fmt_vid_out()
398 mp->num_planes = fmt->buffers; in vivid_try_fmt_vid_out()
399 for (p = 0; p < fmt->buffers; p++) { in vivid_try_fmt_vid_out()
401 bytesperline = (mp->width * fmt->bit_depth[p]) >> 3; in vivid_try_fmt_vid_out()
403 max_bpl = (MAX_ZOOM * MAX_WIDTH * fmt->bit_depth[p]) >> 3; in vivid_try_fmt_vid_out()
410 pfmt[p].sizeimage = (pfmt[p].bytesperline * mp->height) / in vivid_try_fmt_vid_out()
411 fmt->vdownsampling[p] + fmt->data_offset[p]; in vivid_try_fmt_vid_out()
415 for (p = fmt->buffers; p < fmt->planes; p++) in vivid_try_fmt_vid_out()
416 pfmt[0].sizeimage += (pfmt[0].bytesperline * mp->height * in vivid_try_fmt_vid_out()
417 (fmt->bit_depth[p] / fmt->vdownsampling[p])) / in vivid_try_fmt_vid_out()
418 (fmt->bit_depth[0] / fmt->vdownsampling[0]); in vivid_try_fmt_vid_out()
420 mp->xfer_func = V4L2_XFER_FUNC_DEFAULT; in vivid_try_fmt_vid_out()
421 mp->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in vivid_try_fmt_vid_out()
422 mp->quantization = V4L2_QUANTIZATION_DEFAULT; in vivid_try_fmt_vid_out()
424 mp->colorspace = V4L2_COLORSPACE_SMPTE170M; in vivid_try_fmt_vid_out()
425 } else if (dev->dvi_d_out || !(bt->flags & V4L2_DV_FL_IS_CE_VIDEO)) { in vivid_try_fmt_vid_out()
426 mp->colorspace = V4L2_COLORSPACE_SRGB; in vivid_try_fmt_vid_out()
427 if (dev->dvi_d_out) in vivid_try_fmt_vid_out()
428 mp->quantization = V4L2_QUANTIZATION_LIM_RANGE; in vivid_try_fmt_vid_out()
429 } else if (bt->width == 720 && bt->height <= 576) { in vivid_try_fmt_vid_out()
430 mp->colorspace = V4L2_COLORSPACE_SMPTE170M; in vivid_try_fmt_vid_out()
431 } else if (mp->colorspace != V4L2_COLORSPACE_SMPTE170M && in vivid_try_fmt_vid_out()
432 mp->colorspace != V4L2_COLORSPACE_REC709 && in vivid_try_fmt_vid_out()
433 mp->colorspace != V4L2_COLORSPACE_OPRGB && in vivid_try_fmt_vid_out()
434 mp->colorspace != V4L2_COLORSPACE_BT2020 && in vivid_try_fmt_vid_out()
435 mp->colorspace != V4L2_COLORSPACE_SRGB) { in vivid_try_fmt_vid_out()
436 mp->colorspace = V4L2_COLORSPACE_REC709; in vivid_try_fmt_vid_out()
438 memset(mp->reserved, 0, sizeof(mp->reserved)); in vivid_try_fmt_vid_out()
445 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_s_fmt_vid_out()
447 struct v4l2_rect *crop = &dev->crop_out; in vivid_s_fmt_vid_out()
448 struct v4l2_rect *compose = &dev->compose_out; in vivid_s_fmt_vid_out()
449 struct vb2_queue *q = &dev->vb_vid_out_q; in vivid_s_fmt_vid_out()
451 unsigned factor = 1; in vivid_s_fmt_vid_out() local
459 mp->width != dev->fmt_out_rect.width || in vivid_s_fmt_vid_out()
460 mp->height != dev->fmt_out_rect.height || in vivid_s_fmt_vid_out()
461 mp->pixelformat != dev->fmt_out->fourcc || in vivid_s_fmt_vid_out()
462 mp->field != dev->field_out)) { in vivid_s_fmt_vid_out()
463 dprintk(dev, 1, "%s device busy\n", __func__); in vivid_s_fmt_vid_out()
464 return -EBUSY; in vivid_s_fmt_vid_out()
475 dev->fmt_out = vivid_get_format(dev, mp->pixelformat); in vivid_s_fmt_vid_out()
476 if (V4L2_FIELD_HAS_T_OR_B(mp->field)) in vivid_s_fmt_vid_out()
477 factor = 2; in vivid_s_fmt_vid_out()
479 if (dev->has_scaler_out || dev->has_crop_out || dev->has_compose_out) { in vivid_s_fmt_vid_out()
480 struct v4l2_rect r = { 0, 0, mp->width, mp->height }; in vivid_s_fmt_vid_out()
482 if (dev->has_scaler_out) { in vivid_s_fmt_vid_out()
483 if (dev->has_crop_out) in vivid_s_fmt_vid_out()
487 if (dev->has_compose_out && !dev->has_crop_out) { in vivid_s_fmt_vid_out()
491 factor * r.height / MAX_ZOOM in vivid_s_fmt_vid_out()
496 factor * r.height * MAX_ZOOM in vivid_s_fmt_vid_out()
501 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
502 } else if (dev->has_compose_out) { in vivid_s_fmt_vid_out()
505 crop->width / MAX_ZOOM, in vivid_s_fmt_vid_out()
506 factor * crop->height / MAX_ZOOM in vivid_s_fmt_vid_out()
510 crop->width * MAX_ZOOM, in vivid_s_fmt_vid_out()
511 factor * crop->height * MAX_ZOOM in vivid_s_fmt_vid_out()
516 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
518 } else if (dev->has_compose_out && !dev->has_crop_out) { in vivid_s_fmt_vid_out()
520 r.height *= factor; in vivid_s_fmt_vid_out()
522 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
523 } else if (!dev->has_compose_out) { in vivid_s_fmt_vid_out()
525 r.height /= factor; in vivid_s_fmt_vid_out()
528 r.height *= factor; in vivid_s_fmt_vid_out()
530 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
531 crop->top *= factor; in vivid_s_fmt_vid_out()
532 crop->height *= factor; in vivid_s_fmt_vid_out()
535 crop->top /= factor; in vivid_s_fmt_vid_out()
536 crop->height /= factor; in vivid_s_fmt_vid_out()
539 struct v4l2_rect r = { 0, 0, mp->width, mp->height }; in vivid_s_fmt_vid_out()
542 r.height /= factor; in vivid_s_fmt_vid_out()
546 dev->fmt_out_rect.width = mp->width; in vivid_s_fmt_vid_out()
547 dev->fmt_out_rect.height = mp->height; in vivid_s_fmt_vid_out()
548 for (p = 0; p < mp->num_planes; p++) in vivid_s_fmt_vid_out()
549 dev->bytesperline_out[p] = mp->plane_fmt[p].bytesperline; in vivid_s_fmt_vid_out()
550 for (p = dev->fmt_out->buffers; p < dev->fmt_out->planes; p++) in vivid_s_fmt_vid_out()
551 dev->bytesperline_out[p] = in vivid_s_fmt_vid_out()
552 (dev->bytesperline_out[0] * dev->fmt_out->bit_depth[p]) / in vivid_s_fmt_vid_out()
553 dev->fmt_out->bit_depth[0]; in vivid_s_fmt_vid_out()
554 dev->field_out = mp->field; in vivid_s_fmt_vid_out()
556 dev->tv_field_out = mp->field; in vivid_s_fmt_vid_out()
559 dev->colorspace_out = mp->colorspace; in vivid_s_fmt_vid_out()
560 dev->xfer_func_out = mp->xfer_func; in vivid_s_fmt_vid_out()
561 dev->ycbcr_enc_out = mp->ycbcr_enc; in vivid_s_fmt_vid_out()
562 dev->quantization_out = mp->quantization; in vivid_s_fmt_vid_out()
577 if (!dev->multiplanar) in vidioc_g_fmt_vid_out_mplane()
578 return -ENOTTY; in vidioc_g_fmt_vid_out_mplane()
587 if (!dev->multiplanar) in vidioc_try_fmt_vid_out_mplane()
588 return -ENOTTY; in vidioc_try_fmt_vid_out_mplane()
597 if (!dev->multiplanar) in vidioc_s_fmt_vid_out_mplane()
598 return -ENOTTY; in vidioc_s_fmt_vid_out_mplane()
607 if (dev->multiplanar) in vidioc_g_fmt_vid_out()
608 return -ENOTTY; in vidioc_g_fmt_vid_out()
617 if (dev->multiplanar) in vidioc_try_fmt_vid_out()
618 return -ENOTTY; in vidioc_try_fmt_vid_out()
627 if (dev->multiplanar) in vidioc_s_fmt_vid_out()
628 return -ENOTTY; in vidioc_s_fmt_vid_out()
637 if (!dev->has_crop_out && !dev->has_compose_out) in vivid_vid_out_g_selection()
638 return -ENOTTY; in vivid_vid_out_g_selection()
639 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in vivid_vid_out_g_selection()
640 return -EINVAL; in vivid_vid_out_g_selection()
642 sel->r.left = sel->r.top = 0; in vivid_vid_out_g_selection()
643 switch (sel->target) { in vivid_vid_out_g_selection()
645 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
646 return -EINVAL; in vivid_vid_out_g_selection()
647 sel->r = dev->crop_out; in vivid_vid_out_g_selection()
650 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
651 return -EINVAL; in vivid_vid_out_g_selection()
652 sel->r = dev->fmt_out_rect; in vivid_vid_out_g_selection()
655 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
656 return -EINVAL; in vivid_vid_out_g_selection()
657 sel->r = vivid_max_rect; in vivid_vid_out_g_selection()
660 if (!dev->has_compose_out) in vivid_vid_out_g_selection()
661 return -EINVAL; in vivid_vid_out_g_selection()
662 sel->r = dev->compose_out; in vivid_vid_out_g_selection()
666 if (!dev->has_compose_out) in vivid_vid_out_g_selection()
667 return -EINVAL; in vivid_vid_out_g_selection()
668 sel->r = dev->sink_rect; in vivid_vid_out_g_selection()
671 return -EINVAL; in vivid_vid_out_g_selection()
679 struct v4l2_rect *crop = &dev->crop_out; in vivid_vid_out_s_selection()
680 struct v4l2_rect *compose = &dev->compose_out; in vivid_vid_out_s_selection()
681 unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_out) ? 2 : 1; in vivid_vid_out_s_selection() local
684 if (!dev->has_crop_out && !dev->has_compose_out) in vivid_vid_out_s_selection()
685 return -ENOTTY; in vivid_vid_out_s_selection()
686 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in vivid_vid_out_s_selection()
687 return -EINVAL; in vivid_vid_out_s_selection()
689 switch (s->target) { in vivid_vid_out_s_selection()
691 if (!dev->has_crop_out) in vivid_vid_out_s_selection()
692 return -EINVAL; in vivid_vid_out_s_selection()
693 ret = vivid_vid_adjust_sel(s->flags, &s->r); in vivid_vid_out_s_selection()
696 v4l2_rect_set_min_size(&s->r, &vivid_min_rect); in vivid_vid_out_s_selection()
697 v4l2_rect_set_max_size(&s->r, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
698 if (dev->has_scaler_out) { in vivid_vid_out_s_selection()
701 dev->sink_rect.width * MAX_ZOOM, in vivid_vid_out_s_selection()
702 (dev->sink_rect.height / factor) * MAX_ZOOM in vivid_vid_out_s_selection()
705 v4l2_rect_set_max_size(&s->r, &max_rect); in vivid_vid_out_s_selection()
706 if (dev->has_compose_out) { in vivid_vid_out_s_selection()
709 s->r.width / MAX_ZOOM, in vivid_vid_out_s_selection()
710 (s->r.height * factor) / MAX_ZOOM in vivid_vid_out_s_selection()
714 s->r.width * MAX_ZOOM, in vivid_vid_out_s_selection()
715 (s->r.height * factor) * MAX_ZOOM in vivid_vid_out_s_selection()
720 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
722 } else if (dev->has_compose_out) { in vivid_vid_out_s_selection()
723 s->r.top *= factor; in vivid_vid_out_s_selection()
724 s->r.height *= factor; in vivid_vid_out_s_selection()
725 v4l2_rect_set_max_size(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
726 v4l2_rect_set_size_to(compose, &s->r); in vivid_vid_out_s_selection()
727 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
728 s->r.top /= factor; in vivid_vid_out_s_selection()
729 s->r.height /= factor; in vivid_vid_out_s_selection()
731 v4l2_rect_set_size_to(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
732 s->r.height /= factor; in vivid_vid_out_s_selection()
734 v4l2_rect_map_inside(&s->r, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
735 *crop = s->r; in vivid_vid_out_s_selection()
738 if (!dev->has_compose_out) in vivid_vid_out_s_selection()
739 return -EINVAL; in vivid_vid_out_s_selection()
740 ret = vivid_vid_adjust_sel(s->flags, &s->r); in vivid_vid_out_s_selection()
743 v4l2_rect_set_min_size(&s->r, &vivid_min_rect); in vivid_vid_out_s_selection()
744 v4l2_rect_set_max_size(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
745 v4l2_rect_map_inside(&s->r, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
746 s->r.top /= factor; in vivid_vid_out_s_selection()
747 s->r.height /= factor; in vivid_vid_out_s_selection()
748 if (dev->has_scaler_out) { in vivid_vid_out_s_selection()
749 struct v4l2_rect fmt = dev->fmt_out_rect; in vivid_vid_out_s_selection()
752 s->r.width * MAX_ZOOM, in vivid_vid_out_s_selection()
753 s->r.height * MAX_ZOOM in vivid_vid_out_s_selection()
757 s->r.width / MAX_ZOOM, in vivid_vid_out_s_selection()
758 s->r.height / MAX_ZOOM in vivid_vid_out_s_selection()
762 if (!dev->has_crop_out) in vivid_vid_out_s_selection()
764 if (!v4l2_rect_same_size(&dev->fmt_out_rect, &fmt) && in vivid_vid_out_s_selection()
765 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
766 return -EBUSY; in vivid_vid_out_s_selection()
767 if (dev->has_crop_out) { in vivid_vid_out_s_selection()
771 dev->fmt_out_rect = fmt; in vivid_vid_out_s_selection()
772 } else if (dev->has_crop_out) { in vivid_vid_out_s_selection()
773 struct v4l2_rect fmt = dev->fmt_out_rect; in vivid_vid_out_s_selection()
775 v4l2_rect_set_min_size(&fmt, &s->r); in vivid_vid_out_s_selection()
776 if (!v4l2_rect_same_size(&dev->fmt_out_rect, &fmt) && in vivid_vid_out_s_selection()
777 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
778 return -EBUSY; in vivid_vid_out_s_selection()
779 dev->fmt_out_rect = fmt; in vivid_vid_out_s_selection()
780 v4l2_rect_set_size_to(crop, &s->r); in vivid_vid_out_s_selection()
781 v4l2_rect_map_inside(crop, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
783 if (!v4l2_rect_same_size(&s->r, &dev->fmt_out_rect) && in vivid_vid_out_s_selection()
784 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
785 return -EBUSY; in vivid_vid_out_s_selection()
786 v4l2_rect_set_size_to(&dev->fmt_out_rect, &s->r); in vivid_vid_out_s_selection()
787 v4l2_rect_set_size_to(crop, &s->r); in vivid_vid_out_s_selection()
788 crop->height /= factor; in vivid_vid_out_s_selection()
789 v4l2_rect_map_inside(crop, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
791 s->r.top *= factor; in vivid_vid_out_s_selection()
792 s->r.height *= factor; in vivid_vid_out_s_selection()
793 *compose = s->r; in vivid_vid_out_s_selection()
796 return -EINVAL; in vivid_vid_out_s_selection()
808 return -EINVAL; in vivid_vid_out_g_pixelaspect()
812 f->numerator = 11; in vivid_vid_out_g_pixelaspect()
813 f->denominator = 10; in vivid_vid_out_g_pixelaspect()
816 f->numerator = 54; in vivid_vid_out_g_pixelaspect()
817 f->denominator = 59; in vivid_vid_out_g_pixelaspect()
829 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_g_fmt_vid_out_overlay()
830 struct v4l2_window *win = &f->fmt.win; in vidioc_g_fmt_vid_out_overlay()
832 if (!dev->has_fb) in vidioc_g_fmt_vid_out_overlay()
833 return -EINVAL; in vidioc_g_fmt_vid_out_overlay()
834 win->w.top = dev->overlay_out_top; in vidioc_g_fmt_vid_out_overlay()
835 win->w.left = dev->overlay_out_left; in vidioc_g_fmt_vid_out_overlay()
836 win->w.width = compose->width; in vidioc_g_fmt_vid_out_overlay()
837 win->w.height = compose->height; in vidioc_g_fmt_vid_out_overlay()
838 win->field = V4L2_FIELD_ANY; in vidioc_g_fmt_vid_out_overlay()
839 win->chromakey = dev->chromakey_out; in vidioc_g_fmt_vid_out_overlay()
840 win->global_alpha = dev->global_alpha_out; in vidioc_g_fmt_vid_out_overlay()
848 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_try_fmt_vid_out_overlay()
849 struct v4l2_window *win = &f->fmt.win; in vidioc_try_fmt_vid_out_overlay()
851 if (!dev->has_fb) in vidioc_try_fmt_vid_out_overlay()
852 return -EINVAL; in vidioc_try_fmt_vid_out_overlay()
853 win->w.left = clamp_t(int, win->w.left, in vidioc_try_fmt_vid_out_overlay()
854 -dev->display_width, dev->display_width); in vidioc_try_fmt_vid_out_overlay()
855 win->w.top = clamp_t(int, win->w.top, in vidioc_try_fmt_vid_out_overlay()
856 -dev->display_height, dev->display_height); in vidioc_try_fmt_vid_out_overlay()
857 win->w.width = compose->width; in vidioc_try_fmt_vid_out_overlay()
858 win->w.height = compose->height; in vidioc_try_fmt_vid_out_overlay()
863 win->field = V4L2_FIELD_ANY; in vidioc_try_fmt_vid_out_overlay()
871 struct v4l2_window *win = &f->fmt.win; in vidioc_s_fmt_vid_out_overlay()
877 dev->overlay_out_top = win->w.top; in vidioc_s_fmt_vid_out_overlay()
878 dev->overlay_out_left = win->w.left; in vidioc_s_fmt_vid_out_overlay()
879 dev->chromakey_out = win->chromakey; in vidioc_s_fmt_vid_out_overlay()
880 dev->global_alpha_out = win->global_alpha; in vidioc_s_fmt_vid_out_overlay()
888 if (i && !dev->fmt_out->can_do_overlay) { in vivid_vid_out_overlay()
889 dprintk(dev, 1, "unsupported output format for output overlay\n"); in vivid_vid_out_overlay()
890 return -EINVAL; in vivid_vid_out_overlay()
893 dev->overlay_out_enabled = i; in vivid_vid_out_overlay()
902 a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | in vivid_vid_out_g_fbuf()
908 a->flags = V4L2_FBUF_FLAG_OVERLAY | dev->fbuf_out_flags; in vivid_vid_out_g_fbuf()
909 a->base = (void *)dev->video_pbase; in vivid_vid_out_g_fbuf()
910 a->fmt.width = dev->display_width; in vivid_vid_out_g_fbuf()
911 a->fmt.height = dev->display_height; in vivid_vid_out_g_fbuf()
912 if (dev->fb_defined.green.length == 5) in vivid_vid_out_g_fbuf()
913 a->fmt.pixelformat = V4L2_PIX_FMT_ARGB555; in vivid_vid_out_g_fbuf()
915 a->fmt.pixelformat = V4L2_PIX_FMT_RGB565; in vivid_vid_out_g_fbuf()
916 a->fmt.bytesperline = dev->display_byte_stride; in vivid_vid_out_g_fbuf()
917 a->fmt.sizeimage = a->fmt.height * a->fmt.bytesperline; in vivid_vid_out_g_fbuf()
918 a->fmt.field = V4L2_FIELD_NONE; in vivid_vid_out_g_fbuf()
919 a->fmt.colorspace = V4L2_COLORSPACE_SRGB; in vivid_vid_out_g_fbuf()
920 a->fmt.priv = 0; in vivid_vid_out_g_fbuf()
935 if ((a->flags & chroma_flags) == chroma_flags) in vivid_vid_out_s_fbuf()
936 return -EINVAL; in vivid_vid_out_s_fbuf()
937 switch (a->flags & alpha_flags) { in vivid_vid_out_s_fbuf()
944 return -EINVAL; in vivid_vid_out_s_fbuf()
946 dev->fbuf_out_flags &= ~(chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
947 dev->fbuf_out_flags |= a->flags & (chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
952 { 0, "Line-Out 1" },
953 { 1, "Line-Out 2" },
961 if (out->index >= dev->num_outputs) in vidioc_enum_output()
962 return -EINVAL; in vidioc_enum_output()
964 out->type = V4L2_OUTPUT_TYPE_ANALOG; in vidioc_enum_output()
965 switch (dev->output_type[out->index]) { in vidioc_enum_output()
967 snprintf(out->name, sizeof(out->name), "S-Video %03u-%u", in vidioc_enum_output()
968 dev->inst, dev->output_name_counter[out->index]); in vidioc_enum_output()
969 out->std = V4L2_STD_ALL; in vidioc_enum_output()
970 if (dev->has_audio_outputs) in vidioc_enum_output()
971 out->audioset = (1 << ARRAY_SIZE(vivid_audio_outputs)) - 1; in vidioc_enum_output()
972 out->capabilities = V4L2_OUT_CAP_STD; in vidioc_enum_output()
975 snprintf(out->name, sizeof(out->name), "HDMI %03u-%u", in vidioc_enum_output()
976 dev->inst, dev->output_name_counter[out->index]); in vidioc_enum_output()
977 out->capabilities = V4L2_OUT_CAP_DV_TIMINGS; in vidioc_enum_output()
987 *o = dev->output; in vidioc_g_output()
995 if (o >= dev->num_outputs) in vidioc_s_output()
996 return -EINVAL; in vidioc_s_output()
998 if (o == dev->output) in vidioc_s_output()
1001 if (vb2_is_busy(&dev->vb_vid_out_q) || in vidioc_s_output()
1002 vb2_is_busy(&dev->vb_vbi_out_q) || in vidioc_s_output()
1003 vb2_is_busy(&dev->vb_meta_out_q)) in vidioc_s_output()
1004 return -EBUSY; in vidioc_s_output()
1006 dev->output = o; in vidioc_s_output()
1007 dev->tv_audio_output = 0; in vidioc_s_output()
1008 if (dev->output_type[o] == SVID) in vidioc_s_output()
1009 dev->vid_out_dev.tvnorms = V4L2_STD_ALL; in vidioc_s_output()
1011 dev->vid_out_dev.tvnorms = 0; in vidioc_s_output()
1013 dev->vbi_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1014 dev->meta_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1022 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_enumaudout()
1023 return -EINVAL; in vidioc_enumaudout()
1024 *vout = vivid_audio_outputs[vout->index]; in vidioc_enumaudout()
1033 return -EINVAL; in vidioc_g_audout()
1034 *vout = vivid_audio_outputs[dev->tv_audio_output]; in vidioc_g_audout()
1043 return -EINVAL; in vidioc_s_audout()
1044 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_s_audout()
1045 return -EINVAL; in vidioc_s_audout()
1046 dev->tv_audio_output = vout->index; in vidioc_s_audout()
1055 return -ENODATA; in vivid_vid_out_s_std()
1056 if (dev->std_out == id) in vivid_vid_out_s_std()
1058 if (vb2_is_busy(&dev->vb_vid_out_q) || vb2_is_busy(&dev->vb_vbi_out_q)) in vivid_vid_out_s_std()
1059 return -EBUSY; in vivid_vid_out_s_std()
1060 dev->std_out = id; in vivid_vid_out_s_std()
1067 struct v4l2_bt_timings *bt = &timings->bt; in valid_cvt_gtf_timings()
1069 if ((bt->standards & (V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF)) && in valid_cvt_gtf_timings()
1081 return -ENODATA; in vivid_vid_out_s_dv_timings()
1085 return -EINVAL; in vivid_vid_out_s_dv_timings()
1086 if (v4l2_match_dv_timings(timings, &dev->dv_timings_out, 0, true)) in vivid_vid_out_s_dv_timings()
1088 if (vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_dv_timings()
1089 return -EBUSY; in vivid_vid_out_s_dv_timings()
1090 dev->dv_timings_out = *timings; in vivid_vid_out_s_dv_timings()
1100 if (parm->type != (dev->multiplanar ? in vivid_vid_out_g_parm()
1103 return -EINVAL; in vivid_vid_out_g_parm()
1105 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; in vivid_vid_out_g_parm()
1106 parm->parm.output.timeperframe = dev->timeperframe_vid_out; in vivid_vid_out_g_parm()
1107 parm->parm.output.writebuffers = 1; in vivid_vid_out_g_parm()
1115 switch (sub->type) { in vidioc_subscribe_event()
1117 if (fh->vdev->vfl_dir == VFL_DIR_RX) in vidioc_subscribe_event()
1123 return -EINVAL; in vidioc_subscribe_event()