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->data_offset[p]) in vid_out_queue_setup()
68 return -EINVAL; in vid_out_queue_setup()
72 sizes[p] = p ? dev->bytesperline_out[p] * h + in vid_out_queue_setup()
73 vfmt->data_offset[p] : size; in vid_out_queue_setup()
76 if (vq->num_buffers + *nbuffers < 2) in vid_out_queue_setup()
77 *nbuffers = 2 - vq->num_buffers; in vid_out_queue_setup()
81 dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); in vid_out_queue_setup()
83 dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); in vid_out_queue_setup()
90 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_out_validate()
92 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_out_validate()
94 if (dev->field_out != V4L2_FIELD_ALTERNATE) in vid_out_buf_out_validate()
95 vbuf->field = dev->field_out; in vid_out_buf_out_validate()
96 else if (vbuf->field != V4L2_FIELD_TOP && in vid_out_buf_out_validate()
97 vbuf->field != V4L2_FIELD_BOTTOM) in vid_out_buf_out_validate()
98 return -EINVAL; in vid_out_buf_out_validate()
104 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_prepare()
105 const struct vivid_fmt *vfmt = dev->fmt_out; in vid_out_buf_prepare()
106 unsigned int planes = vfmt->buffers; in vid_out_buf_prepare()
107 unsigned int h = dev->fmt_out_rect.height; in vid_out_buf_prepare()
108 unsigned int size = dev->bytesperline_out[0] * h; in vid_out_buf_prepare()
111 for (p = vfmt->buffers; p < vfmt->planes; p++) in vid_out_buf_prepare()
112 size += dev->bytesperline_out[p] * h / vfmt->vdownsampling[p]; in vid_out_buf_prepare()
114 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_prepare()
116 if (WARN_ON(NULL == dev->fmt_out)) in vid_out_buf_prepare()
117 return -EINVAL; in vid_out_buf_prepare()
119 if (dev->buf_prepare_error) { in vid_out_buf_prepare()
124 dev->buf_prepare_error = false; in vid_out_buf_prepare()
125 return -EINVAL; in vid_out_buf_prepare()
130 size = dev->bytesperline_out[p] * h; in vid_out_buf_prepare()
131 size += vb->planes[p].data_offset; in vid_out_buf_prepare()
134 dprintk(dev, 1, "%s the payload is too small for plane %u (%lu < %u)\n", in vid_out_buf_prepare()
136 return -EINVAL; in vid_out_buf_prepare()
146 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_queue()
149 dprintk(dev, 1, "%s\n", __func__); in vid_out_buf_queue()
151 spin_lock(&dev->slock); in vid_out_buf_queue()
152 list_add_tail(&buf->list, &dev->vid_out_active); in vid_out_buf_queue()
153 spin_unlock(&dev->slock); in vid_out_buf_queue()
161 if (vb2_is_streaming(&dev->vb_vid_cap_q)) in vid_out_start_streaming()
162 dev->can_loop_video = vivid_vid_can_loop(dev); in vid_out_start_streaming()
164 dev->vid_out_seq_count = 0; in vid_out_start_streaming()
165 dprintk(dev, 1, "%s\n", __func__); in vid_out_start_streaming()
166 if (dev->start_streaming_error) { in vid_out_start_streaming()
167 dev->start_streaming_error = false; in vid_out_start_streaming()
168 err = -EINVAL; in vid_out_start_streaming()
170 err = vivid_start_generating_vid_out(dev, &dev->vid_out_streaming); in vid_out_start_streaming()
175 list_for_each_entry_safe(buf, tmp, &dev->vid_out_active, list) { in vid_out_start_streaming()
176 list_del(&buf->list); in vid_out_start_streaming()
177 vb2_buffer_done(&buf->vb.vb2_buf, in vid_out_start_streaming()
189 dprintk(dev, 1, "%s\n", __func__); in vid_out_stop_streaming()
190 vivid_stop_generating_vid_out(dev, &dev->vid_out_streaming); in vid_out_stop_streaming()
191 dev->can_loop_video = false; in vid_out_stop_streaming()
196 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in vid_out_buf_request_complete()
198 v4l2_ctrl_request_complete(vb->req_obj.req, &dev->ctrl_hdl_vid_out); in vid_out_buf_request_complete()
219 struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt; in vivid_update_format_out()
223 switch (dev->output_type[dev->output]) { in vivid_update_format_out()
226 dev->field_out = dev->tv_field_out; in vivid_update_format_out()
227 dev->sink_rect.width = 720; in vivid_update_format_out()
228 if (dev->std_out & V4L2_STD_525_60) { in vivid_update_format_out()
229 dev->sink_rect.height = 480; in vivid_update_format_out()
230 dev->timeperframe_vid_out = (struct v4l2_fract) { 1001, 30000 }; in vivid_update_format_out()
231 dev->service_set_out = V4L2_SLICED_CAPTION_525; in vivid_update_format_out()
233 dev->sink_rect.height = 576; in vivid_update_format_out()
234 dev->timeperframe_vid_out = (struct v4l2_fract) { 1000, 25000 }; in vivid_update_format_out()
235 dev->service_set_out = V4L2_SLICED_WSS_625 | V4L2_SLICED_TELETEXT_B; in vivid_update_format_out()
237 dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M; in vivid_update_format_out()
240 dev->sink_rect.width = bt->width; in vivid_update_format_out()
241 dev->sink_rect.height = bt->height; in vivid_update_format_out()
244 if (can_reduce_fps(bt) && (bt->flags & V4L2_DV_FL_REDUCED_FPS)) in vivid_update_format_out()
245 pixelclock = div_u64(bt->pixelclock * 1000, 1001); in vivid_update_format_out()
247 pixelclock = bt->pixelclock; in vivid_update_format_out()
249 dev->timeperframe_vid_out = (struct v4l2_fract) { in vivid_update_format_out()
252 if (bt->interlaced) in vivid_update_format_out()
253 dev->field_out = V4L2_FIELD_ALTERNATE; in vivid_update_format_out()
255 dev->field_out = V4L2_FIELD_NONE; in vivid_update_format_out()
256 if (!dev->dvi_d_out && (bt->flags & V4L2_DV_FL_IS_CE_VIDEO)) { in vivid_update_format_out()
257 if (bt->width == 720 && bt->height <= 576) in vivid_update_format_out()
258 dev->colorspace_out = V4L2_COLORSPACE_SMPTE170M; in vivid_update_format_out()
260 dev->colorspace_out = V4L2_COLORSPACE_REC709; in vivid_update_format_out()
262 dev->colorspace_out = V4L2_COLORSPACE_SRGB; in vivid_update_format_out()
266 dev->xfer_func_out = V4L2_XFER_FUNC_DEFAULT; in vivid_update_format_out()
267 dev->ycbcr_enc_out = V4L2_YCBCR_ENC_DEFAULT; in vivid_update_format_out()
268 dev->hsv_enc_out = V4L2_HSV_ENC_180; in vivid_update_format_out()
269 dev->quantization_out = V4L2_QUANTIZATION_DEFAULT; in vivid_update_format_out()
270 dev->compose_out = dev->sink_rect; in vivid_update_format_out()
271 dev->compose_bounds_out = dev->sink_rect; in vivid_update_format_out()
272 dev->crop_out = dev->compose_out; in vivid_update_format_out()
273 if (V4L2_FIELD_HAS_T_OR_B(dev->field_out)) in vivid_update_format_out()
274 dev->crop_out.height /= 2; in vivid_update_format_out()
275 dev->fmt_out_rect = dev->crop_out; in vivid_update_format_out()
276 for (p = 0; p < dev->fmt_out->planes; p++) in vivid_update_format_out()
277 dev->bytesperline_out[p] = in vivid_update_format_out()
278 (dev->sink_rect.width * dev->fmt_out->bit_depth[p]) / 8; in vivid_update_format_out()
298 return dev->dv_timings_out.bt.interlaced ? V4L2_FIELD_ALTERNATE : in vivid_field_out()
306 return (dev->std_out & V4L2_STD_525_60) ? in vivid_get_pixel_aspect()
310 dev->sink_rect.width == 720 && dev->sink_rect.height <= 576) in vivid_get_pixel_aspect()
311 return dev->sink_rect.height == 480 ? in vivid_get_pixel_aspect()
321 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_g_fmt_vid_out()
322 const struct vivid_fmt *fmt = dev->fmt_out; in vivid_g_fmt_vid_out()
325 mp->width = dev->fmt_out_rect.width; in vivid_g_fmt_vid_out()
326 mp->height = dev->fmt_out_rect.height; in vivid_g_fmt_vid_out()
327 mp->field = dev->field_out; in vivid_g_fmt_vid_out()
328 mp->pixelformat = fmt->fourcc; in vivid_g_fmt_vid_out()
329 mp->colorspace = dev->colorspace_out; in vivid_g_fmt_vid_out()
330 mp->xfer_func = dev->xfer_func_out; in vivid_g_fmt_vid_out()
331 mp->ycbcr_enc = dev->ycbcr_enc_out; in vivid_g_fmt_vid_out()
332 mp->quantization = dev->quantization_out; in vivid_g_fmt_vid_out()
333 mp->num_planes = fmt->buffers; in vivid_g_fmt_vid_out()
334 for (p = 0; p < mp->num_planes; p++) { in vivid_g_fmt_vid_out()
335 mp->plane_fmt[p].bytesperline = dev->bytesperline_out[p]; in vivid_g_fmt_vid_out()
336 mp->plane_fmt[p].sizeimage = in vivid_g_fmt_vid_out()
337 mp->plane_fmt[p].bytesperline * mp->height + in vivid_g_fmt_vid_out()
338 fmt->data_offset[p]; in vivid_g_fmt_vid_out()
340 for (p = fmt->buffers; p < fmt->planes; p++) { in vivid_g_fmt_vid_out()
341 unsigned stride = dev->bytesperline_out[p]; in vivid_g_fmt_vid_out()
343 mp->plane_fmt[0].sizeimage += in vivid_g_fmt_vid_out()
344 (stride * mp->height) / fmt->vdownsampling[p]; in vivid_g_fmt_vid_out()
353 struct v4l2_bt_timings *bt = &dev->dv_timings_out.bt; in vivid_try_fmt_vid_out()
354 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_try_fmt_vid_out()
355 struct v4l2_plane_pix_format *pfmt = mp->plane_fmt; in vivid_try_fmt_vid_out()
358 unsigned factor = 1; in vivid_try_fmt_vid_out() local
362 fmt = vivid_get_format(dev, mp->pixelformat); in vivid_try_fmt_vid_out()
364 dprintk(dev, 1, "Fourcc format (0x%08x) unknown.\n", in vivid_try_fmt_vid_out()
365 mp->pixelformat); in vivid_try_fmt_vid_out()
366 mp->pixelformat = V4L2_PIX_FMT_YUYV; in vivid_try_fmt_vid_out()
367 fmt = vivid_get_format(dev, mp->pixelformat); in vivid_try_fmt_vid_out()
370 mp->field = vivid_field_out(dev, mp->field); in vivid_try_fmt_vid_out()
373 h = (dev->std_out & V4L2_STD_525_60) ? 480 : 576; in vivid_try_fmt_vid_out()
375 w = dev->sink_rect.width; in vivid_try_fmt_vid_out()
376 h = dev->sink_rect.height; in vivid_try_fmt_vid_out()
378 if (V4L2_FIELD_HAS_T_OR_B(mp->field)) in vivid_try_fmt_vid_out()
379 factor = 2; in vivid_try_fmt_vid_out()
380 if (!dev->has_scaler_out && !dev->has_crop_out && !dev->has_compose_out) { in vivid_try_fmt_vid_out()
381 mp->width = w; in vivid_try_fmt_vid_out()
382 mp->height = h / factor; in vivid_try_fmt_vid_out()
384 struct v4l2_rect r = { 0, 0, mp->width, mp->height * factor }; in vivid_try_fmt_vid_out()
388 if (dev->has_scaler_out && !dev->has_crop_out) { in vivid_try_fmt_vid_out()
392 } else if (!dev->has_scaler_out && dev->has_compose_out && !dev->has_crop_out) { in vivid_try_fmt_vid_out()
393 v4l2_rect_set_max_size(&r, &dev->sink_rect); in vivid_try_fmt_vid_out()
394 } else if (!dev->has_scaler_out && !dev->has_compose_out) { in vivid_try_fmt_vid_out()
395 v4l2_rect_set_min_size(&r, &dev->sink_rect); in vivid_try_fmt_vid_out()
397 mp->width = r.width; in vivid_try_fmt_vid_out()
398 mp->height = r.height / factor; in vivid_try_fmt_vid_out()
403 mp->num_planes = fmt->buffers; in vivid_try_fmt_vid_out()
404 for (p = 0; p < fmt->buffers; p++) { in vivid_try_fmt_vid_out()
406 bytesperline = (mp->width * fmt->bit_depth[p]) >> 3; in vivid_try_fmt_vid_out()
408 max_bpl = (MAX_ZOOM * MAX_WIDTH * fmt->bit_depth[p]) >> 3; in vivid_try_fmt_vid_out()
415 pfmt[p].sizeimage = (pfmt[p].bytesperline * mp->height) / in vivid_try_fmt_vid_out()
416 fmt->vdownsampling[p] + fmt->data_offset[p]; in vivid_try_fmt_vid_out()
420 for (p = fmt->buffers; p < fmt->planes; p++) in vivid_try_fmt_vid_out()
421 pfmt[0].sizeimage += (pfmt[0].bytesperline * mp->height * in vivid_try_fmt_vid_out()
422 (fmt->bit_depth[p] / fmt->vdownsampling[p])) / in vivid_try_fmt_vid_out()
423 (fmt->bit_depth[0] / fmt->vdownsampling[0]); in vivid_try_fmt_vid_out()
425 mp->xfer_func = V4L2_XFER_FUNC_DEFAULT; in vivid_try_fmt_vid_out()
426 mp->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in vivid_try_fmt_vid_out()
427 mp->quantization = V4L2_QUANTIZATION_DEFAULT; in vivid_try_fmt_vid_out()
429 mp->colorspace = V4L2_COLORSPACE_SMPTE170M; in vivid_try_fmt_vid_out()
430 } else if (dev->dvi_d_out || !(bt->flags & V4L2_DV_FL_IS_CE_VIDEO)) { in vivid_try_fmt_vid_out()
431 mp->colorspace = V4L2_COLORSPACE_SRGB; in vivid_try_fmt_vid_out()
432 if (dev->dvi_d_out) in vivid_try_fmt_vid_out()
433 mp->quantization = V4L2_QUANTIZATION_LIM_RANGE; in vivid_try_fmt_vid_out()
434 } else if (bt->width == 720 && bt->height <= 576) { in vivid_try_fmt_vid_out()
435 mp->colorspace = V4L2_COLORSPACE_SMPTE170M; in vivid_try_fmt_vid_out()
436 } else if (mp->colorspace != V4L2_COLORSPACE_SMPTE170M && in vivid_try_fmt_vid_out()
437 mp->colorspace != V4L2_COLORSPACE_REC709 && in vivid_try_fmt_vid_out()
438 mp->colorspace != V4L2_COLORSPACE_OPRGB && in vivid_try_fmt_vid_out()
439 mp->colorspace != V4L2_COLORSPACE_BT2020 && in vivid_try_fmt_vid_out()
440 mp->colorspace != V4L2_COLORSPACE_SRGB) { in vivid_try_fmt_vid_out()
441 mp->colorspace = V4L2_COLORSPACE_REC709; in vivid_try_fmt_vid_out()
443 memset(mp->reserved, 0, sizeof(mp->reserved)); in vivid_try_fmt_vid_out()
450 struct v4l2_pix_format_mplane *mp = &f->fmt.pix_mp; in vivid_s_fmt_vid_out()
452 struct v4l2_rect *crop = &dev->crop_out; in vivid_s_fmt_vid_out()
453 struct v4l2_rect *compose = &dev->compose_out; in vivid_s_fmt_vid_out()
454 struct vb2_queue *q = &dev->vb_vid_out_q; in vivid_s_fmt_vid_out()
456 unsigned factor = 1; in vivid_s_fmt_vid_out() local
464 mp->width != dev->fmt_out_rect.width || in vivid_s_fmt_vid_out()
465 mp->height != dev->fmt_out_rect.height || in vivid_s_fmt_vid_out()
466 mp->pixelformat != dev->fmt_out->fourcc || in vivid_s_fmt_vid_out()
467 mp->field != dev->field_out)) { in vivid_s_fmt_vid_out()
468 dprintk(dev, 1, "%s device busy\n", __func__); in vivid_s_fmt_vid_out()
469 return -EBUSY; in vivid_s_fmt_vid_out()
480 dev->fmt_out = vivid_get_format(dev, mp->pixelformat); in vivid_s_fmt_vid_out()
481 if (V4L2_FIELD_HAS_T_OR_B(mp->field)) in vivid_s_fmt_vid_out()
482 factor = 2; in vivid_s_fmt_vid_out()
484 if (dev->has_scaler_out || dev->has_crop_out || dev->has_compose_out) { in vivid_s_fmt_vid_out()
485 struct v4l2_rect r = { 0, 0, mp->width, mp->height }; in vivid_s_fmt_vid_out()
487 if (dev->has_scaler_out) { in vivid_s_fmt_vid_out()
488 if (dev->has_crop_out) in vivid_s_fmt_vid_out()
492 if (dev->has_compose_out && !dev->has_crop_out) { in vivid_s_fmt_vid_out()
496 factor * r.height / MAX_ZOOM in vivid_s_fmt_vid_out()
501 factor * r.height * MAX_ZOOM in vivid_s_fmt_vid_out()
506 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
507 } else if (dev->has_compose_out) { 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()
515 crop->width * MAX_ZOOM, in vivid_s_fmt_vid_out()
516 factor * crop->height * MAX_ZOOM in vivid_s_fmt_vid_out()
521 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
523 } else if (dev->has_compose_out && !dev->has_crop_out) { in vivid_s_fmt_vid_out()
525 r.height *= factor; in vivid_s_fmt_vid_out()
527 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
528 } else if (!dev->has_compose_out) { in vivid_s_fmt_vid_out()
530 r.height /= factor; in vivid_s_fmt_vid_out()
533 r.height *= factor; in vivid_s_fmt_vid_out()
535 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_s_fmt_vid_out()
536 crop->top *= factor; in vivid_s_fmt_vid_out()
537 crop->height *= factor; in vivid_s_fmt_vid_out()
540 crop->top /= factor; in vivid_s_fmt_vid_out()
541 crop->height /= factor; in vivid_s_fmt_vid_out()
544 struct v4l2_rect r = { 0, 0, mp->width, mp->height }; in vivid_s_fmt_vid_out()
547 r.height /= factor; in vivid_s_fmt_vid_out()
551 dev->fmt_out_rect.width = mp->width; in vivid_s_fmt_vid_out()
552 dev->fmt_out_rect.height = mp->height; in vivid_s_fmt_vid_out()
553 for (p = 0; p < mp->num_planes; p++) in vivid_s_fmt_vid_out()
554 dev->bytesperline_out[p] = mp->plane_fmt[p].bytesperline; in vivid_s_fmt_vid_out()
555 for (p = dev->fmt_out->buffers; p < dev->fmt_out->planes; p++) in vivid_s_fmt_vid_out()
556 dev->bytesperline_out[p] = in vivid_s_fmt_vid_out()
557 (dev->bytesperline_out[0] * dev->fmt_out->bit_depth[p]) / in vivid_s_fmt_vid_out()
558 dev->fmt_out->bit_depth[0]; in vivid_s_fmt_vid_out()
559 dev->field_out = mp->field; in vivid_s_fmt_vid_out()
561 dev->tv_field_out = mp->field; in vivid_s_fmt_vid_out()
564 dev->colorspace_out = mp->colorspace; in vivid_s_fmt_vid_out()
565 dev->xfer_func_out = mp->xfer_func; in vivid_s_fmt_vid_out()
566 dev->ycbcr_enc_out = mp->ycbcr_enc; in vivid_s_fmt_vid_out()
567 dev->quantization_out = mp->quantization; in vivid_s_fmt_vid_out()
568 if (dev->loop_video) { in vivid_s_fmt_vid_out()
580 if (!dev->multiplanar) in vidioc_g_fmt_vid_out_mplane()
581 return -ENOTTY; in vidioc_g_fmt_vid_out_mplane()
590 if (!dev->multiplanar) in vidioc_try_fmt_vid_out_mplane()
591 return -ENOTTY; in vidioc_try_fmt_vid_out_mplane()
600 if (!dev->multiplanar) in vidioc_s_fmt_vid_out_mplane()
601 return -ENOTTY; in vidioc_s_fmt_vid_out_mplane()
610 if (dev->multiplanar) in vidioc_g_fmt_vid_out()
611 return -ENOTTY; in vidioc_g_fmt_vid_out()
620 if (dev->multiplanar) in vidioc_try_fmt_vid_out()
621 return -ENOTTY; in vidioc_try_fmt_vid_out()
630 if (dev->multiplanar) in vidioc_s_fmt_vid_out()
631 return -ENOTTY; in vidioc_s_fmt_vid_out()
640 if (!dev->has_crop_out && !dev->has_compose_out) in vivid_vid_out_g_selection()
641 return -ENOTTY; in vivid_vid_out_g_selection()
642 if (sel->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in vivid_vid_out_g_selection()
643 return -EINVAL; in vivid_vid_out_g_selection()
645 sel->r.left = sel->r.top = 0; in vivid_vid_out_g_selection()
646 switch (sel->target) { in vivid_vid_out_g_selection()
648 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
649 return -EINVAL; in vivid_vid_out_g_selection()
650 sel->r = dev->crop_out; in vivid_vid_out_g_selection()
653 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
654 return -EINVAL; in vivid_vid_out_g_selection()
655 sel->r = dev->fmt_out_rect; in vivid_vid_out_g_selection()
658 if (!dev->has_crop_out) in vivid_vid_out_g_selection()
659 return -EINVAL; in vivid_vid_out_g_selection()
660 sel->r = vivid_max_rect; in vivid_vid_out_g_selection()
663 if (!dev->has_compose_out) in vivid_vid_out_g_selection()
664 return -EINVAL; in vivid_vid_out_g_selection()
665 sel->r = dev->compose_out; in vivid_vid_out_g_selection()
669 if (!dev->has_compose_out) in vivid_vid_out_g_selection()
670 return -EINVAL; in vivid_vid_out_g_selection()
671 sel->r = dev->sink_rect; in vivid_vid_out_g_selection()
674 return -EINVAL; in vivid_vid_out_g_selection()
682 struct v4l2_rect *crop = &dev->crop_out; in vivid_vid_out_s_selection()
683 struct v4l2_rect *compose = &dev->compose_out; in vivid_vid_out_s_selection()
684 unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_out) ? 2 : 1; in vivid_vid_out_s_selection() local
687 if (!dev->has_crop_out && !dev->has_compose_out) in vivid_vid_out_s_selection()
688 return -ENOTTY; in vivid_vid_out_s_selection()
689 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) in vivid_vid_out_s_selection()
690 return -EINVAL; in vivid_vid_out_s_selection()
692 switch (s->target) { in vivid_vid_out_s_selection()
694 if (!dev->has_crop_out) in vivid_vid_out_s_selection()
695 return -EINVAL; in vivid_vid_out_s_selection()
696 ret = vivid_vid_adjust_sel(s->flags, &s->r); in vivid_vid_out_s_selection()
699 v4l2_rect_set_min_size(&s->r, &vivid_min_rect); in vivid_vid_out_s_selection()
700 v4l2_rect_set_max_size(&s->r, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
701 if (dev->has_scaler_out) { in vivid_vid_out_s_selection()
704 dev->sink_rect.width * MAX_ZOOM, in vivid_vid_out_s_selection()
705 (dev->sink_rect.height / factor) * MAX_ZOOM in vivid_vid_out_s_selection()
708 v4l2_rect_set_max_size(&s->r, &max_rect); in vivid_vid_out_s_selection()
709 if (dev->has_compose_out) { in vivid_vid_out_s_selection()
712 s->r.width / MAX_ZOOM, in vivid_vid_out_s_selection()
713 (s->r.height * factor) / MAX_ZOOM in vivid_vid_out_s_selection()
717 s->r.width * MAX_ZOOM, in vivid_vid_out_s_selection()
718 (s->r.height * factor) * MAX_ZOOM in vivid_vid_out_s_selection()
723 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
725 } else if (dev->has_compose_out) { in vivid_vid_out_s_selection()
726 s->r.top *= factor; in vivid_vid_out_s_selection()
727 s->r.height *= factor; in vivid_vid_out_s_selection()
728 v4l2_rect_set_max_size(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
729 v4l2_rect_set_size_to(compose, &s->r); in vivid_vid_out_s_selection()
730 v4l2_rect_map_inside(compose, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
731 s->r.top /= factor; in vivid_vid_out_s_selection()
732 s->r.height /= factor; in vivid_vid_out_s_selection()
734 v4l2_rect_set_size_to(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
735 s->r.height /= factor; in vivid_vid_out_s_selection()
737 v4l2_rect_map_inside(&s->r, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
738 *crop = s->r; in vivid_vid_out_s_selection()
741 if (!dev->has_compose_out) in vivid_vid_out_s_selection()
742 return -EINVAL; in vivid_vid_out_s_selection()
743 ret = vivid_vid_adjust_sel(s->flags, &s->r); in vivid_vid_out_s_selection()
746 v4l2_rect_set_min_size(&s->r, &vivid_min_rect); in vivid_vid_out_s_selection()
747 v4l2_rect_set_max_size(&s->r, &dev->sink_rect); in vivid_vid_out_s_selection()
748 v4l2_rect_map_inside(&s->r, &dev->compose_bounds_out); in vivid_vid_out_s_selection()
749 s->r.top /= factor; in vivid_vid_out_s_selection()
750 s->r.height /= factor; in vivid_vid_out_s_selection()
751 if (dev->has_scaler_out) { in vivid_vid_out_s_selection()
752 struct v4l2_rect fmt = dev->fmt_out_rect; in vivid_vid_out_s_selection()
755 s->r.width * MAX_ZOOM, in vivid_vid_out_s_selection()
756 s->r.height * MAX_ZOOM in vivid_vid_out_s_selection()
760 s->r.width / MAX_ZOOM, in vivid_vid_out_s_selection()
761 s->r.height / MAX_ZOOM in vivid_vid_out_s_selection()
765 if (!dev->has_crop_out) in vivid_vid_out_s_selection()
767 if (!v4l2_rect_same_size(&dev->fmt_out_rect, &fmt) && in vivid_vid_out_s_selection()
768 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
769 return -EBUSY; in vivid_vid_out_s_selection()
770 if (dev->has_crop_out) { in vivid_vid_out_s_selection()
774 dev->fmt_out_rect = fmt; in vivid_vid_out_s_selection()
775 } else if (dev->has_crop_out) { in vivid_vid_out_s_selection()
776 struct v4l2_rect fmt = dev->fmt_out_rect; in vivid_vid_out_s_selection()
778 v4l2_rect_set_min_size(&fmt, &s->r); in vivid_vid_out_s_selection()
779 if (!v4l2_rect_same_size(&dev->fmt_out_rect, &fmt) && in vivid_vid_out_s_selection()
780 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
781 return -EBUSY; in vivid_vid_out_s_selection()
782 dev->fmt_out_rect = fmt; in vivid_vid_out_s_selection()
783 v4l2_rect_set_size_to(crop, &s->r); in vivid_vid_out_s_selection()
784 v4l2_rect_map_inside(crop, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
786 if (!v4l2_rect_same_size(&s->r, &dev->fmt_out_rect) && in vivid_vid_out_s_selection()
787 vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_selection()
788 return -EBUSY; in vivid_vid_out_s_selection()
789 v4l2_rect_set_size_to(&dev->fmt_out_rect, &s->r); in vivid_vid_out_s_selection()
790 v4l2_rect_set_size_to(crop, &s->r); in vivid_vid_out_s_selection()
791 crop->height /= factor; in vivid_vid_out_s_selection()
792 v4l2_rect_map_inside(crop, &dev->fmt_out_rect); in vivid_vid_out_s_selection()
794 s->r.top *= factor; in vivid_vid_out_s_selection()
795 s->r.height *= factor; in vivid_vid_out_s_selection()
796 if (dev->bitmap_out && (compose->width != s->r.width || in vivid_vid_out_s_selection()
797 compose->height != s->r.height)) { in vivid_vid_out_s_selection()
798 vfree(dev->bitmap_out); in vivid_vid_out_s_selection()
799 dev->bitmap_out = NULL; in vivid_vid_out_s_selection()
801 *compose = s->r; in vivid_vid_out_s_selection()
804 return -EINVAL; in vivid_vid_out_s_selection()
816 return -EINVAL; in vivid_vid_out_g_pixelaspect()
820 f->numerator = 11; in vivid_vid_out_g_pixelaspect()
821 f->denominator = 10; in vivid_vid_out_g_pixelaspect()
824 f->numerator = 54; in vivid_vid_out_g_pixelaspect()
825 f->denominator = 59; in vivid_vid_out_g_pixelaspect()
837 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_g_fmt_vid_out_overlay()
838 struct v4l2_window *win = &f->fmt.win; in vidioc_g_fmt_vid_out_overlay()
839 unsigned clipcount = win->clipcount; in vidioc_g_fmt_vid_out_overlay()
841 if (!dev->has_fb) in vidioc_g_fmt_vid_out_overlay()
842 return -EINVAL; in vidioc_g_fmt_vid_out_overlay()
843 win->w.top = dev->overlay_out_top; in vidioc_g_fmt_vid_out_overlay()
844 win->w.left = dev->overlay_out_left; in vidioc_g_fmt_vid_out_overlay()
845 win->w.width = compose->width; in vidioc_g_fmt_vid_out_overlay()
846 win->w.height = compose->height; in vidioc_g_fmt_vid_out_overlay()
847 win->clipcount = dev->clipcount_out; in vidioc_g_fmt_vid_out_overlay()
848 win->field = V4L2_FIELD_ANY; in vidioc_g_fmt_vid_out_overlay()
849 win->chromakey = dev->chromakey_out; in vidioc_g_fmt_vid_out_overlay()
850 win->global_alpha = dev->global_alpha_out; in vidioc_g_fmt_vid_out_overlay()
851 if (clipcount > dev->clipcount_out) in vidioc_g_fmt_vid_out_overlay()
852 clipcount = dev->clipcount_out; in vidioc_g_fmt_vid_out_overlay()
853 if (dev->bitmap_out == NULL) in vidioc_g_fmt_vid_out_overlay()
854 win->bitmap = NULL; in vidioc_g_fmt_vid_out_overlay()
855 else if (win->bitmap) { in vidioc_g_fmt_vid_out_overlay()
856 if (copy_to_user(win->bitmap, dev->bitmap_out, in vidioc_g_fmt_vid_out_overlay()
857 ((dev->compose_out.width + 7) / 8) * dev->compose_out.height)) in vidioc_g_fmt_vid_out_overlay()
858 return -EFAULT; in vidioc_g_fmt_vid_out_overlay()
860 if (clipcount && win->clips) in vidioc_g_fmt_vid_out_overlay()
861 memcpy(win->clips, dev->clips_out, in vidioc_g_fmt_vid_out_overlay()
862 clipcount * sizeof(dev->clips_out[0])); in vidioc_g_fmt_vid_out_overlay()
870 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_try_fmt_vid_out_overlay()
871 struct v4l2_window *win = &f->fmt.win; in vidioc_try_fmt_vid_out_overlay()
874 if (!dev->has_fb) in vidioc_try_fmt_vid_out_overlay()
875 return -EINVAL; in vidioc_try_fmt_vid_out_overlay()
876 win->w.left = clamp_t(int, win->w.left, in vidioc_try_fmt_vid_out_overlay()
877 -dev->display_width, dev->display_width); in vidioc_try_fmt_vid_out_overlay()
878 win->w.top = clamp_t(int, win->w.top, in vidioc_try_fmt_vid_out_overlay()
879 -dev->display_height, dev->display_height); in vidioc_try_fmt_vid_out_overlay()
880 win->w.width = compose->width; in vidioc_try_fmt_vid_out_overlay()
881 win->w.height = compose->height; in vidioc_try_fmt_vid_out_overlay()
886 win->field = V4L2_FIELD_ANY; in vidioc_try_fmt_vid_out_overlay()
887 if (win->clipcount && !win->clips) in vidioc_try_fmt_vid_out_overlay()
888 win->clipcount = 0; in vidioc_try_fmt_vid_out_overlay()
889 if (win->clipcount > MAX_CLIPS) in vidioc_try_fmt_vid_out_overlay()
890 win->clipcount = MAX_CLIPS; in vidioc_try_fmt_vid_out_overlay()
891 if (win->clipcount) { in vidioc_try_fmt_vid_out_overlay()
892 memcpy(dev->try_clips_out, win->clips, in vidioc_try_fmt_vid_out_overlay()
893 win->clipcount * sizeof(dev->clips_out[0])); in vidioc_try_fmt_vid_out_overlay()
894 for (i = 0; i < win->clipcount; i++) { in vidioc_try_fmt_vid_out_overlay()
895 struct v4l2_rect *r = &dev->try_clips_out[i].c; in vidioc_try_fmt_vid_out_overlay()
897 r->top = clamp_t(s32, r->top, 0, dev->display_height - 1); in vidioc_try_fmt_vid_out_overlay()
898 r->height = clamp_t(s32, r->height, 1, dev->display_height - r->top); in vidioc_try_fmt_vid_out_overlay()
899 r->left = clamp_t(u32, r->left, 0, dev->display_width - 1); in vidioc_try_fmt_vid_out_overlay()
900 r->width = clamp_t(u32, r->width, 1, dev->display_width - r->left); in vidioc_try_fmt_vid_out_overlay()
903 * Yeah, so sue me, it's an O(n^2) algorithm. But n is a small in vidioc_try_fmt_vid_out_overlay()
904 * number and it's typically a one-time deal. in vidioc_try_fmt_vid_out_overlay()
906 for (i = 0; i < win->clipcount - 1; i++) { in vidioc_try_fmt_vid_out_overlay()
907 struct v4l2_rect *r1 = &dev->try_clips_out[i].c; in vidioc_try_fmt_vid_out_overlay()
909 for (j = i + 1; j < win->clipcount; j++) { in vidioc_try_fmt_vid_out_overlay()
910 struct v4l2_rect *r2 = &dev->try_clips_out[j].c; in vidioc_try_fmt_vid_out_overlay()
913 return -EINVAL; in vidioc_try_fmt_vid_out_overlay()
916 memcpy(win->clips, dev->try_clips_out, in vidioc_try_fmt_vid_out_overlay()
917 win->clipcount * sizeof(dev->clips_out[0])); in vidioc_try_fmt_vid_out_overlay()
926 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_s_fmt_vid_out_overlay()
927 struct v4l2_window *win = &f->fmt.win; in vidioc_s_fmt_vid_out_overlay()
929 unsigned bitmap_size = ((compose->width + 7) / 8) * compose->height; in vidioc_s_fmt_vid_out_overlay()
930 unsigned clips_size = win->clipcount * sizeof(dev->clips_out[0]); in vidioc_s_fmt_vid_out_overlay()
936 if (win->bitmap) { in vidioc_s_fmt_vid_out_overlay()
940 return -ENOMEM; in vidioc_s_fmt_vid_out_overlay()
941 if (copy_from_user(new_bitmap, win->bitmap, bitmap_size)) { in vidioc_s_fmt_vid_out_overlay()
943 return -EFAULT; in vidioc_s_fmt_vid_out_overlay()
947 dev->overlay_out_top = win->w.top; in vidioc_s_fmt_vid_out_overlay()
948 dev->overlay_out_left = win->w.left; in vidioc_s_fmt_vid_out_overlay()
949 vfree(dev->bitmap_out); in vidioc_s_fmt_vid_out_overlay()
950 dev->bitmap_out = new_bitmap; in vidioc_s_fmt_vid_out_overlay()
951 dev->clipcount_out = win->clipcount; in vidioc_s_fmt_vid_out_overlay()
952 if (dev->clipcount_out) in vidioc_s_fmt_vid_out_overlay()
953 memcpy(dev->clips_out, dev->try_clips_out, clips_size); in vidioc_s_fmt_vid_out_overlay()
954 dev->chromakey_out = win->chromakey; in vidioc_s_fmt_vid_out_overlay()
955 dev->global_alpha_out = win->global_alpha; in vidioc_s_fmt_vid_out_overlay()
963 if (i && !dev->fmt_out->can_do_overlay) { in vivid_vid_out_overlay()
964 dprintk(dev, 1, "unsupported output format for output overlay\n"); in vivid_vid_out_overlay()
965 return -EINVAL; in vivid_vid_out_overlay()
968 dev->overlay_out_enabled = i; in vivid_vid_out_overlay()
977 a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | in vivid_vid_out_g_fbuf()
985 a->flags = V4L2_FBUF_FLAG_OVERLAY | dev->fbuf_out_flags; in vivid_vid_out_g_fbuf()
986 a->base = (void *)dev->video_pbase; in vivid_vid_out_g_fbuf()
987 a->fmt.width = dev->display_width; in vivid_vid_out_g_fbuf()
988 a->fmt.height = dev->display_height; in vivid_vid_out_g_fbuf()
989 if (dev->fb_defined.green.length == 5) in vivid_vid_out_g_fbuf()
990 a->fmt.pixelformat = V4L2_PIX_FMT_ARGB555; in vivid_vid_out_g_fbuf()
992 a->fmt.pixelformat = V4L2_PIX_FMT_RGB565; in vivid_vid_out_g_fbuf()
993 a->fmt.bytesperline = dev->display_byte_stride; in vivid_vid_out_g_fbuf()
994 a->fmt.sizeimage = a->fmt.height * a->fmt.bytesperline; in vivid_vid_out_g_fbuf()
995 a->fmt.field = V4L2_FIELD_NONE; in vivid_vid_out_g_fbuf()
996 a->fmt.colorspace = V4L2_COLORSPACE_SRGB; in vivid_vid_out_g_fbuf()
997 a->fmt.priv = 0; in vivid_vid_out_g_fbuf()
1012 if ((a->flags & chroma_flags) == chroma_flags) in vivid_vid_out_s_fbuf()
1013 return -EINVAL; in vivid_vid_out_s_fbuf()
1014 switch (a->flags & alpha_flags) { in vivid_vid_out_s_fbuf()
1021 return -EINVAL; in vivid_vid_out_s_fbuf()
1023 dev->fbuf_out_flags &= ~(chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
1024 dev->fbuf_out_flags |= a->flags & (chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
1029 { 0, "Line-Out 1" },
1030 { 1, "Line-Out 2" },
1038 if (out->index >= dev->num_outputs) in vidioc_enum_output()
1039 return -EINVAL; in vidioc_enum_output()
1041 out->type = V4L2_OUTPUT_TYPE_ANALOG; in vidioc_enum_output()
1042 switch (dev->output_type[out->index]) { in vidioc_enum_output()
1044 snprintf(out->name, sizeof(out->name), "S-Video %u", in vidioc_enum_output()
1045 dev->output_name_counter[out->index]); in vidioc_enum_output()
1046 out->std = V4L2_STD_ALL; in vidioc_enum_output()
1047 if (dev->has_audio_outputs) in vidioc_enum_output()
1048 out->audioset = (1 << ARRAY_SIZE(vivid_audio_outputs)) - 1; in vidioc_enum_output()
1049 out->capabilities = V4L2_OUT_CAP_STD; in vidioc_enum_output()
1052 snprintf(out->name, sizeof(out->name), "HDMI %u", in vidioc_enum_output()
1053 dev->output_name_counter[out->index]); in vidioc_enum_output()
1054 out->capabilities = V4L2_OUT_CAP_DV_TIMINGS; in vidioc_enum_output()
1064 *o = dev->output; in vidioc_g_output()
1072 if (o >= dev->num_outputs) in vidioc_s_output()
1073 return -EINVAL; in vidioc_s_output()
1075 if (o == dev->output) in vidioc_s_output()
1078 if (vb2_is_busy(&dev->vb_vid_out_q) || in vidioc_s_output()
1079 vb2_is_busy(&dev->vb_vbi_out_q) || in vidioc_s_output()
1080 vb2_is_busy(&dev->vb_meta_out_q)) in vidioc_s_output()
1081 return -EBUSY; in vidioc_s_output()
1083 dev->output = o; in vidioc_s_output()
1084 dev->tv_audio_output = 0; in vidioc_s_output()
1085 if (dev->output_type[o] == SVID) in vidioc_s_output()
1086 dev->vid_out_dev.tvnorms = V4L2_STD_ALL; in vidioc_s_output()
1088 dev->vid_out_dev.tvnorms = 0; in vidioc_s_output()
1090 dev->vbi_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1091 dev->meta_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1094 v4l2_ctrl_activate(dev->ctrl_display_present, vivid_is_hdmi_out(dev)); in vidioc_s_output()
1096 v4l2_ctrl_s_ctrl(dev->ctrl_display_present, in vidioc_s_output()
1097 dev->display_present[dev->output]); in vidioc_s_output()
1104 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_enumaudout()
1105 return -EINVAL; in vidioc_enumaudout()
1106 *vout = vivid_audio_outputs[vout->index]; in vidioc_enumaudout()
1115 return -EINVAL; in vidioc_g_audout()
1116 *vout = vivid_audio_outputs[dev->tv_audio_output]; in vidioc_g_audout()
1125 return -EINVAL; in vidioc_s_audout()
1126 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_s_audout()
1127 return -EINVAL; in vidioc_s_audout()
1128 dev->tv_audio_output = vout->index; in vidioc_s_audout()
1137 return -ENODATA; in vivid_vid_out_s_std()
1138 if (dev->std_out == id) in vivid_vid_out_s_std()
1140 if (vb2_is_busy(&dev->vb_vid_out_q) || vb2_is_busy(&dev->vb_vbi_out_q)) in vivid_vid_out_s_std()
1141 return -EBUSY; in vivid_vid_out_s_std()
1142 dev->std_out = id; in vivid_vid_out_s_std()
1149 struct v4l2_bt_timings *bt = &timings->bt; in valid_cvt_gtf_timings()
1151 if ((bt->standards & (V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF)) && in valid_cvt_gtf_timings()
1163 return -ENODATA; in vivid_vid_out_s_dv_timings()
1167 return -EINVAL; in vivid_vid_out_s_dv_timings()
1168 if (v4l2_match_dv_timings(timings, &dev->dv_timings_out, 0, true)) in vivid_vid_out_s_dv_timings()
1170 if (vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_dv_timings()
1171 return -EBUSY; in vivid_vid_out_s_dv_timings()
1172 dev->dv_timings_out = *timings; in vivid_vid_out_s_dv_timings()
1182 if (parm->type != (dev->multiplanar ? in vivid_vid_out_g_parm()
1185 return -EINVAL; in vivid_vid_out_g_parm()
1187 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; in vivid_vid_out_g_parm()
1188 parm->parm.output.timeperframe = dev->timeperframe_vid_out; in vivid_vid_out_g_parm()
1189 parm->parm.output.writebuffers = 1; in vivid_vid_out_g_parm()
1197 switch (sub->type) { in vidioc_subscribe_event()
1199 if (fh->vdev->vfl_dir == VFL_DIR_RX) in vidioc_subscribe_event()
1205 return -EINVAL; in vidioc_subscribe_event()