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 *compose = s->r; in vivid_vid_out_s_selection()
799 return -EINVAL; in vivid_vid_out_s_selection()
811 return -EINVAL; in vivid_vid_out_g_pixelaspect()
815 f->numerator = 11; in vivid_vid_out_g_pixelaspect()
816 f->denominator = 10; in vivid_vid_out_g_pixelaspect()
819 f->numerator = 54; in vivid_vid_out_g_pixelaspect()
820 f->denominator = 59; in vivid_vid_out_g_pixelaspect()
832 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_g_fmt_vid_out_overlay()
833 struct v4l2_window *win = &f->fmt.win; in vidioc_g_fmt_vid_out_overlay()
835 if (!dev->has_fb) in vidioc_g_fmt_vid_out_overlay()
836 return -EINVAL; in vidioc_g_fmt_vid_out_overlay()
837 win->w.top = dev->overlay_out_top; in vidioc_g_fmt_vid_out_overlay()
838 win->w.left = dev->overlay_out_left; in vidioc_g_fmt_vid_out_overlay()
839 win->w.width = compose->width; in vidioc_g_fmt_vid_out_overlay()
840 win->w.height = compose->height; in vidioc_g_fmt_vid_out_overlay()
841 win->field = V4L2_FIELD_ANY; in vidioc_g_fmt_vid_out_overlay()
842 win->chromakey = dev->chromakey_out; in vidioc_g_fmt_vid_out_overlay()
843 win->global_alpha = dev->global_alpha_out; in vidioc_g_fmt_vid_out_overlay()
851 const struct v4l2_rect *compose = &dev->compose_out; in vidioc_try_fmt_vid_out_overlay()
852 struct v4l2_window *win = &f->fmt.win; in vidioc_try_fmt_vid_out_overlay()
854 if (!dev->has_fb) in vidioc_try_fmt_vid_out_overlay()
855 return -EINVAL; in vidioc_try_fmt_vid_out_overlay()
856 win->w.left = clamp_t(int, win->w.left, in vidioc_try_fmt_vid_out_overlay()
857 -dev->display_width, dev->display_width); in vidioc_try_fmt_vid_out_overlay()
858 win->w.top = clamp_t(int, win->w.top, in vidioc_try_fmt_vid_out_overlay()
859 -dev->display_height, dev->display_height); in vidioc_try_fmt_vid_out_overlay()
860 win->w.width = compose->width; in vidioc_try_fmt_vid_out_overlay()
861 win->w.height = compose->height; in vidioc_try_fmt_vid_out_overlay()
866 win->field = V4L2_FIELD_ANY; in vidioc_try_fmt_vid_out_overlay()
874 struct v4l2_window *win = &f->fmt.win; in vidioc_s_fmt_vid_out_overlay()
880 dev->overlay_out_top = win->w.top; in vidioc_s_fmt_vid_out_overlay()
881 dev->overlay_out_left = win->w.left; in vidioc_s_fmt_vid_out_overlay()
882 dev->chromakey_out = win->chromakey; in vidioc_s_fmt_vid_out_overlay()
883 dev->global_alpha_out = win->global_alpha; in vidioc_s_fmt_vid_out_overlay()
891 if (i && !dev->fmt_out->can_do_overlay) { in vivid_vid_out_overlay()
892 dprintk(dev, 1, "unsupported output format for output overlay\n"); in vivid_vid_out_overlay()
893 return -EINVAL; in vivid_vid_out_overlay()
896 dev->overlay_out_enabled = i; in vivid_vid_out_overlay()
905 a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | in vivid_vid_out_g_fbuf()
911 a->flags = V4L2_FBUF_FLAG_OVERLAY | dev->fbuf_out_flags; in vivid_vid_out_g_fbuf()
912 a->base = (void *)dev->video_pbase; in vivid_vid_out_g_fbuf()
913 a->fmt.width = dev->display_width; in vivid_vid_out_g_fbuf()
914 a->fmt.height = dev->display_height; in vivid_vid_out_g_fbuf()
915 if (dev->fb_defined.green.length == 5) in vivid_vid_out_g_fbuf()
916 a->fmt.pixelformat = V4L2_PIX_FMT_ARGB555; in vivid_vid_out_g_fbuf()
918 a->fmt.pixelformat = V4L2_PIX_FMT_RGB565; in vivid_vid_out_g_fbuf()
919 a->fmt.bytesperline = dev->display_byte_stride; in vivid_vid_out_g_fbuf()
920 a->fmt.sizeimage = a->fmt.height * a->fmt.bytesperline; in vivid_vid_out_g_fbuf()
921 a->fmt.field = V4L2_FIELD_NONE; in vivid_vid_out_g_fbuf()
922 a->fmt.colorspace = V4L2_COLORSPACE_SRGB; in vivid_vid_out_g_fbuf()
923 a->fmt.priv = 0; in vivid_vid_out_g_fbuf()
938 if ((a->flags & chroma_flags) == chroma_flags) in vivid_vid_out_s_fbuf()
939 return -EINVAL; in vivid_vid_out_s_fbuf()
940 switch (a->flags & alpha_flags) { in vivid_vid_out_s_fbuf()
947 return -EINVAL; in vivid_vid_out_s_fbuf()
949 dev->fbuf_out_flags &= ~(chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
950 dev->fbuf_out_flags |= a->flags & (chroma_flags | alpha_flags); in vivid_vid_out_s_fbuf()
955 { 0, "Line-Out 1" },
956 { 1, "Line-Out 2" },
964 if (out->index >= dev->num_outputs) in vidioc_enum_output()
965 return -EINVAL; in vidioc_enum_output()
967 out->type = V4L2_OUTPUT_TYPE_ANALOG; in vidioc_enum_output()
968 switch (dev->output_type[out->index]) { in vidioc_enum_output()
970 snprintf(out->name, sizeof(out->name), "S-Video %u", in vidioc_enum_output()
971 dev->output_name_counter[out->index]); in vidioc_enum_output()
972 out->std = V4L2_STD_ALL; in vidioc_enum_output()
973 if (dev->has_audio_outputs) in vidioc_enum_output()
974 out->audioset = (1 << ARRAY_SIZE(vivid_audio_outputs)) - 1; in vidioc_enum_output()
975 out->capabilities = V4L2_OUT_CAP_STD; in vidioc_enum_output()
978 snprintf(out->name, sizeof(out->name), "HDMI %u", in vidioc_enum_output()
979 dev->output_name_counter[out->index]); in vidioc_enum_output()
980 out->capabilities = V4L2_OUT_CAP_DV_TIMINGS; in vidioc_enum_output()
990 *o = dev->output; in vidioc_g_output()
998 if (o >= dev->num_outputs) in vidioc_s_output()
999 return -EINVAL; in vidioc_s_output()
1001 if (o == dev->output) in vidioc_s_output()
1004 if (vb2_is_busy(&dev->vb_vid_out_q) || in vidioc_s_output()
1005 vb2_is_busy(&dev->vb_vbi_out_q) || in vidioc_s_output()
1006 vb2_is_busy(&dev->vb_meta_out_q)) in vidioc_s_output()
1007 return -EBUSY; in vidioc_s_output()
1009 dev->output = o; in vidioc_s_output()
1010 dev->tv_audio_output = 0; in vidioc_s_output()
1011 if (dev->output_type[o] == SVID) in vidioc_s_output()
1012 dev->vid_out_dev.tvnorms = V4L2_STD_ALL; in vidioc_s_output()
1014 dev->vid_out_dev.tvnorms = 0; in vidioc_s_output()
1016 dev->vbi_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1017 dev->meta_out_dev.tvnorms = dev->vid_out_dev.tvnorms; in vidioc_s_output()
1020 v4l2_ctrl_activate(dev->ctrl_display_present, vivid_is_hdmi_out(dev)); in vidioc_s_output()
1022 v4l2_ctrl_s_ctrl(dev->ctrl_display_present, in vidioc_s_output()
1023 dev->display_present[dev->output]); in vidioc_s_output()
1030 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_enumaudout()
1031 return -EINVAL; in vidioc_enumaudout()
1032 *vout = vivid_audio_outputs[vout->index]; in vidioc_enumaudout()
1041 return -EINVAL; in vidioc_g_audout()
1042 *vout = vivid_audio_outputs[dev->tv_audio_output]; in vidioc_g_audout()
1051 return -EINVAL; in vidioc_s_audout()
1052 if (vout->index >= ARRAY_SIZE(vivid_audio_outputs)) in vidioc_s_audout()
1053 return -EINVAL; in vidioc_s_audout()
1054 dev->tv_audio_output = vout->index; in vidioc_s_audout()
1063 return -ENODATA; in vivid_vid_out_s_std()
1064 if (dev->std_out == id) in vivid_vid_out_s_std()
1066 if (vb2_is_busy(&dev->vb_vid_out_q) || vb2_is_busy(&dev->vb_vbi_out_q)) in vivid_vid_out_s_std()
1067 return -EBUSY; in vivid_vid_out_s_std()
1068 dev->std_out = id; in vivid_vid_out_s_std()
1075 struct v4l2_bt_timings *bt = &timings->bt; in valid_cvt_gtf_timings()
1077 if ((bt->standards & (V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF)) && in valid_cvt_gtf_timings()
1089 return -ENODATA; in vivid_vid_out_s_dv_timings()
1093 return -EINVAL; in vivid_vid_out_s_dv_timings()
1094 if (v4l2_match_dv_timings(timings, &dev->dv_timings_out, 0, true)) in vivid_vid_out_s_dv_timings()
1096 if (vb2_is_busy(&dev->vb_vid_out_q)) in vivid_vid_out_s_dv_timings()
1097 return -EBUSY; in vivid_vid_out_s_dv_timings()
1098 dev->dv_timings_out = *timings; in vivid_vid_out_s_dv_timings()
1108 if (parm->type != (dev->multiplanar ? in vivid_vid_out_g_parm()
1111 return -EINVAL; in vivid_vid_out_g_parm()
1113 parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME; in vivid_vid_out_g_parm()
1114 parm->parm.output.timeperframe = dev->timeperframe_vid_out; in vivid_vid_out_g_parm()
1115 parm->parm.output.writebuffers = 1; in vivid_vid_out_g_parm()
1123 switch (sub->type) { in vidioc_subscribe_event()
1125 if (fh->vdev->vfl_dir == VFL_DIR_RX) in vidioc_subscribe_event()
1131 return -EINVAL; in vidioc_subscribe_event()