Lines Matching +full:scaled +full:- +full:output +full:- +full:hz
1 // SPDX-License-Identifier: GPL-2.0-only
3 * vivid-kthread-cap.h - video/vbi capture thread support functions.
20 #include <linux/v4l2-dv-timings.h>
23 #include <media/videobuf2-vmalloc.h>
24 #include <media/v4l2-dv-timings.h>
25 #include <media/v4l2-ioctl.h>
26 #include <media/v4l2-fh.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-rect.h>
30 #include "vivid-core.h"
31 #include "vivid-vid-common.h"
32 #include "vivid-vid-cap.h"
33 #include "vivid-vid-out.h"
34 #include "vivid-radio-common.h"
35 #include "vivid-radio-rx.h"
36 #include "vivid-radio-tx.h"
37 #include "vivid-sdr-cap.h"
38 #include "vivid-vbi-cap.h"
39 #include "vivid-vbi-out.h"
40 #include "vivid-osd.h"
41 #include "vivid-ctrls.h"
42 #include "vivid-kthread-cap.h"
43 #include "vivid-meta-cap.h"
48 return dev->std_cap[dev->input]; in vivid_get_std_cap()
60 if ((dev->fbuf_out_flags & V4L2_FBUF_FLAG_CHROMAKEY) && in copy_pix()
61 *osd != dev->chromakey_out) in copy_pix()
63 if ((dev->fbuf_out_flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY) && in copy_pix()
64 out == dev->chromakey_out) in copy_pix()
66 if (dev->fmt_cap->alpha_mask) { in copy_pix()
67 if ((dev->fbuf_out_flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) && in copy_pix()
68 dev->global_alpha_out) in copy_pix()
70 if ((dev->fbuf_out_flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) && in copy_pix()
71 *cap & dev->fmt_cap->alpha_mask) in copy_pix()
73 if ((dev->fbuf_out_flags & V4L2_FBUF_FLAG_LOCAL_INV_ALPHA) && in copy_pix()
74 !(*cap & dev->fmt_cap->alpha_mask)) in copy_pix()
114 error -= dstw; in scale_line()
123 * The nominal pipeline is that the video output buffer is cropped by
124 * crop_out, scaled to compose_out, overlaid with the output overlay,
125 * cropped on the capture side by crop_cap and scaled again to the video
131 * video output buffer that is and which part of the video capture buffer
132 * so we can scale the video straight from the output buffer to the capture
135 * If we need to deal with an output overlay, then there is no choice and
136 * that intermediate step still has to be taken. For the output overlay
149 0, 0, dev->display_width, dev->display_height in vivid_precalc_copy_rects()
153 out_dev->overlay_out_left, out_dev->overlay_out_top, in vivid_precalc_copy_rects()
154 out_dev->compose_out.width, out_dev->compose_out.height in vivid_precalc_copy_rects()
157 v4l2_rect_intersect(&dev->loop_vid_copy, &dev->crop_cap, &out_dev->compose_out); in vivid_precalc_copy_rects()
159 dev->loop_vid_out = dev->loop_vid_copy; in vivid_precalc_copy_rects()
160 v4l2_rect_scale(&dev->loop_vid_out, &out_dev->compose_out, &out_dev->crop_out); in vivid_precalc_copy_rects()
161 dev->loop_vid_out.left += out_dev->crop_out.left; in vivid_precalc_copy_rects()
162 dev->loop_vid_out.top += out_dev->crop_out.top; in vivid_precalc_copy_rects()
164 dev->loop_vid_cap = dev->loop_vid_copy; in vivid_precalc_copy_rects()
165 v4l2_rect_scale(&dev->loop_vid_cap, &dev->crop_cap, &dev->compose_cap); in vivid_precalc_copy_rects()
169 dev->loop_vid_copy.width, dev->loop_vid_copy.height, in vivid_precalc_copy_rects()
170 dev->loop_vid_copy.left, dev->loop_vid_copy.top, in vivid_precalc_copy_rects()
171 dev->loop_vid_out.width, dev->loop_vid_out.height, in vivid_precalc_copy_rects()
172 dev->loop_vid_out.left, dev->loop_vid_out.top, in vivid_precalc_copy_rects()
173 dev->loop_vid_cap.width, dev->loop_vid_cap.height, in vivid_precalc_copy_rects()
174 dev->loop_vid_cap.left, dev->loop_vid_cap.top); in vivid_precalc_copy_rects()
179 r_overlay.left += out_dev->compose_out.left - out_dev->overlay_out_left; in vivid_precalc_copy_rects()
180 r_overlay.top += out_dev->compose_out.top - out_dev->overlay_out_top; in vivid_precalc_copy_rects()
182 v4l2_rect_intersect(&dev->loop_vid_overlay, &r_overlay, &dev->loop_vid_copy); in vivid_precalc_copy_rects()
183 dev->loop_fb_copy = dev->loop_vid_overlay; in vivid_precalc_copy_rects()
185 /* shift dev->loop_fb_copy back again to the fb origin */ in vivid_precalc_copy_rects()
186 dev->loop_fb_copy.left -= out_dev->compose_out.left - out_dev->overlay_out_left; in vivid_precalc_copy_rects()
187 dev->loop_fb_copy.top -= out_dev->compose_out.top - out_dev->overlay_out_top; in vivid_precalc_copy_rects()
189 dev->loop_vid_overlay_cap = dev->loop_vid_overlay; in vivid_precalc_copy_rects()
190 v4l2_rect_scale(&dev->loop_vid_overlay_cap, &dev->crop_cap, &dev->compose_cap); in vivid_precalc_copy_rects()
194 dev->loop_fb_copy.width, dev->loop_fb_copy.height, in vivid_precalc_copy_rects()
195 dev->loop_fb_copy.left, dev->loop_fb_copy.top, in vivid_precalc_copy_rects()
196 dev->loop_vid_overlay.width, dev->loop_vid_overlay.height, in vivid_precalc_copy_rects()
197 dev->loop_vid_overlay.left, dev->loop_vid_overlay.top, in vivid_precalc_copy_rects()
198 dev->loop_vid_overlay_cap.width, dev->loop_vid_overlay_cap.height, in vivid_precalc_copy_rects()
199 dev->loop_vid_overlay_cap.left, dev->loop_vid_overlay_cap.top); in vivid_precalc_copy_rects()
209 return vb2_plane_vaddr(&buf->vb.vb2_buf, p); in plane_vaddr()
210 vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in plane_vaddr()
212 vbuf += bpl[i] * h / tpg->vdownsampling[i]; in plane_vaddr()
220 bool blank = dev->must_blank[vid_cap_buf->vb.vb2_buf.index]; in vivid_copy_buffer()
221 struct tpg_data *tpg = &dev->tpg; in vivid_copy_buffer()
223 unsigned vdiv = out_dev->fmt_out->vdownsampling[p]; in vivid_copy_buffer()
225 unsigned img_width = tpg_hdiv(tpg, p, dev->compose_cap.width); in vivid_copy_buffer()
226 unsigned img_height = dev->compose_cap.height; in vivid_copy_buffer()
227 unsigned stride_cap = tpg->bytesperline[p]; in vivid_copy_buffer()
228 unsigned stride_out = out_dev->bytesperline_out[p]; in vivid_copy_buffer()
229 unsigned stride_osd = dev->display_byte_stride; in vivid_copy_buffer()
230 unsigned hmax = (img_height * tpg->perc_fill) / 100; in vivid_copy_buffer()
234 bool blend = out_dev->fbuf_out_flags; in vivid_copy_buffer()
244 unsigned vid_cap_left = tpg_hdiv(tpg, p, dev->loop_vid_cap.left); in vivid_copy_buffer()
248 vid_out_int_part = dev->loop_vid_out.height / dev->loop_vid_cap.height; in vivid_copy_buffer()
249 vid_out_fract_part = dev->loop_vid_out.height % dev->loop_vid_cap.height; in vivid_copy_buffer()
251 if (!list_empty(&out_dev->vid_out_active)) in vivid_copy_buffer()
252 vid_out_buf = list_entry(out_dev->vid_out_active.next, in vivid_copy_buffer()
255 return -ENODATA; in vivid_copy_buffer()
257 vid_cap_buf->vb.field = vid_out_buf->vb.field; in vivid_copy_buffer()
260 out_dev->bytesperline_out, out_dev->fmt_out_rect.height); in vivid_copy_buffer()
261 if (p < out_dev->fmt_out->buffers) in vivid_copy_buffer()
262 voutbuf += vid_out_buf->vb.vb2_buf.planes[p].data_offset; in vivid_copy_buffer()
263 voutbuf += tpg_hdiv(tpg, p, dev->loop_vid_out.left) + in vivid_copy_buffer()
264 (dev->loop_vid_out.top / vdiv) * stride_out; in vivid_copy_buffer()
265 vcapbuf += tpg_hdiv(tpg, p, dev->compose_cap.left) + in vivid_copy_buffer()
266 (dev->compose_cap.top / vdiv) * stride_cap; in vivid_copy_buffer()
268 if (dev->loop_vid_copy.width == 0 || dev->loop_vid_copy.height == 0) { in vivid_copy_buffer()
274 memcpy(vcapbuf, tpg->black_line[p], img_width); in vivid_copy_buffer()
278 if (out_dev->overlay_out_enabled && in vivid_copy_buffer()
279 dev->loop_vid_overlay.width && dev->loop_vid_overlay.height) { in vivid_copy_buffer()
280 vosdbuf = dev->video_vbase; in vivid_copy_buffer()
281 vosdbuf += (dev->loop_fb_copy.left * twopixsize) / 2 + in vivid_copy_buffer()
282 dev->loop_fb_copy.top * stride_osd; in vivid_copy_buffer()
283 vid_overlay_int_part = dev->loop_vid_overlay.height / in vivid_copy_buffer()
284 dev->loop_vid_overlay_cap.height; in vivid_copy_buffer()
285 vid_overlay_fract_part = dev->loop_vid_overlay.height % in vivid_copy_buffer()
286 dev->loop_vid_overlay_cap.height; in vivid_copy_buffer()
289 vid_cap_right = tpg_hdiv(tpg, p, dev->loop_vid_cap.left + dev->loop_vid_cap.width); in vivid_copy_buffer()
291 quick = dev->loop_vid_out.width == dev->loop_vid_cap.width; in vivid_copy_buffer()
293 dev->cur_scaled_line = dev->loop_vid_out.height; in vivid_copy_buffer()
296 bool osdline = vosdbuf && y >= dev->loop_vid_overlay_cap.top && in vivid_copy_buffer()
297 y < dev->loop_vid_overlay_cap.top + dev->loop_vid_overlay_cap.height; in vivid_copy_buffer()
303 if (y < dev->loop_vid_cap.top || in vivid_copy_buffer()
304 y >= dev->loop_vid_cap.top + dev->loop_vid_cap.height) { in vivid_copy_buffer()
305 memcpy(vcapbuf, tpg->black_line[p], img_width); in vivid_copy_buffer()
310 if (dev->loop_vid_cap.left) in vivid_copy_buffer()
311 memcpy(vcapbuf, tpg->black_line[p], vid_cap_left); in vivid_copy_buffer()
315 memcpy(vcapbuf + vid_cap_right, tpg->black_line[p], in vivid_copy_buffer()
316 img_width - vid_cap_right); in vivid_copy_buffer()
321 tpg_hdiv(tpg, p, dev->loop_vid_cap.width)); in vivid_copy_buffer()
324 if (dev->cur_scaled_line == vid_out_y) { in vivid_copy_buffer()
325 memcpy(vcapbuf + vid_cap_left, dev->scaled_line, in vivid_copy_buffer()
326 tpg_hdiv(tpg, p, dev->loop_vid_cap.width)); in vivid_copy_buffer()
330 scale_line(voutbuf + vid_out_y * stride_out, dev->scaled_line, in vivid_copy_buffer()
331 tpg_hdiv(tpg, p, dev->loop_vid_out.width), in vivid_copy_buffer()
332 tpg_hdiv(tpg, p, dev->loop_vid_cap.width), in vivid_copy_buffer()
340 ((dev->loop_vid_overlay.left - dev->loop_vid_copy.left) * in vivid_copy_buffer()
344 scale_line(voutbuf + vid_out_y * stride_out, dev->blended_line, in vivid_copy_buffer()
345 dev->loop_vid_out.width, dev->loop_vid_copy.width, in vivid_copy_buffer()
348 blend_line(dev, vid_overlay_y + dev->loop_vid_overlay.top, in vivid_copy_buffer()
349 dev->loop_vid_overlay.left, in vivid_copy_buffer()
350 dev->blended_line + offset, osd, in vivid_copy_buffer()
351 dev->loop_vid_overlay.width, twopixsize / 2); in vivid_copy_buffer()
353 memcpy(dev->blended_line + offset, in vivid_copy_buffer()
354 osd, (dev->loop_vid_overlay.width * twopixsize) / 2); in vivid_copy_buffer()
355 scale_line(dev->blended_line, dev->scaled_line, in vivid_copy_buffer()
356 dev->loop_vid_copy.width, dev->loop_vid_cap.width, in vivid_copy_buffer()
359 dev->cur_scaled_line = vid_out_y; in vivid_copy_buffer()
360 memcpy(vcapbuf + vid_cap_left, dev->scaled_line, in vivid_copy_buffer()
361 tpg_hdiv(tpg, p, dev->loop_vid_cap.width)); in vivid_copy_buffer()
367 if (vid_overlay_error >= dev->loop_vid_overlay_cap.height) { in vivid_copy_buffer()
368 vid_overlay_error -= dev->loop_vid_overlay_cap.height; in vivid_copy_buffer()
374 if (vid_out_error >= dev->loop_vid_cap.height / vdiv) { in vivid_copy_buffer()
375 vid_out_error -= dev->loop_vid_cap.height / vdiv; in vivid_copy_buffer()
383 memcpy(vcapbuf, tpg->contrast_line[p], img_width); in vivid_copy_buffer()
390 struct tpg_data *tpg = &dev->tpg; in vivid_fillbuff()
391 unsigned factor = V4L2_FIELD_HAS_T_OR_B(dev->field_cap) ? 2 : 1; in vivid_fillbuff()
394 bool is_60hz = is_tv && (dev->std_cap[dev->input] & V4L2_STD_525_60); in vivid_fillbuff()
402 buf->vb.sequence = dev->vid_cap_seq_count; in vivid_fillbuff()
403 v4l2_ctrl_s_ctrl(dev->ro_int32, buf->vb.sequence & 0xff); in vivid_fillbuff()
404 if (dev->field_cap == V4L2_FIELD_ALTERNATE) { in vivid_fillbuff()
406 * 60 Hz standards start with the bottom field, 50 Hz standards in vivid_fillbuff()
407 * with the top field. So if the 0-based seq_count is even, in vivid_fillbuff()
408 * then the field is TOP for 50 Hz and BOTTOM for 60 Hz in vivid_fillbuff()
411 buf->vb.field = ((dev->vid_cap_seq_count & 1) ^ is_60hz) ? in vivid_fillbuff()
417 buf->vb.sequence /= 2; in vivid_fillbuff()
419 buf->vb.field = dev->field_cap; in vivid_fillbuff()
421 tpg_s_field(tpg, buf->vb.field, in vivid_fillbuff()
422 dev->field_cap == V4L2_FIELD_ALTERNATE); in vivid_fillbuff()
423 tpg_s_perc_fill_blank(tpg, dev->must_blank[buf->vb.vb2_buf.index]); in vivid_fillbuff()
427 !VIVID_INVALID_SIGNAL(dev->std_signal_mode[dev->input])) || in vivid_fillbuff()
429 !VIVID_INVALID_SIGNAL(dev->dv_timings_signal_mode[dev->input])))) { in vivid_fillbuff()
432 * If the vivid instance of the output device is different in vivid_fillbuff()
434 * must take care to properly serialize the output device to in vivid_fillbuff()
437 * If the output device is part of the same instance, then the in vivid_fillbuff()
447 if (out_dev && dev != out_dev && !mutex_trylock(&out_dev->mutex)) in vivid_fillbuff()
456 tpg->bytesperline, tpg->buf_height); in vivid_fillbuff()
459 * The first plane of a multiplanar format has a non-zero in vivid_fillbuff()
461 * correctly supports non-zero data offsets. in vivid_fillbuff()
463 if (p < tpg_g_buffers(tpg) && dev->fmt_cap->data_offset[p]) { in vivid_fillbuff()
464 memset(vbuf, dev->fmt_cap->data_offset[p] & 0xff, in vivid_fillbuff()
465 dev->fmt_cap->data_offset[p]); in vivid_fillbuff()
466 vbuf += dev->fmt_cap->data_offset[p]; in vivid_fillbuff()
474 mutex_unlock(&out_dev->mutex); in vivid_fillbuff()
476 dev->must_blank[buf->vb.vb2_buf.index] = false; in vivid_fillbuff()
479 if (dev->field_cap != V4L2_FIELD_ALTERNATE || in vivid_fillbuff()
480 (dev->vid_cap_seq_count & 1) == 0) in vivid_fillbuff()
481 dev->ms_vid_cap = in vivid_fillbuff()
482 jiffies_to_msecs(jiffies - dev->jiffies_vid_cap); in vivid_fillbuff()
484 ms = dev->ms_vid_cap; in vivid_fillbuff()
485 if (dev->osd_mode <= 1) { in vivid_fillbuff()
491 buf->vb.sequence, in vivid_fillbuff()
492 (dev->field_cap == V4L2_FIELD_ALTERNATE) ? in vivid_fillbuff()
493 (buf->vb.field == V4L2_FIELD_TOP ? in vivid_fillbuff()
497 if (dev->osd_mode == 0) { in vivid_fillbuff()
499 dev->src_rect.width, dev->src_rect.height, dev->input); in vivid_fillbuff()
502 gain = v4l2_ctrl_g_ctrl(dev->gain); in vivid_fillbuff()
503 mutex_lock(dev->ctrl_hdl_user_vid.lock); in vivid_fillbuff()
506 dev->brightness->cur.val, in vivid_fillbuff()
507 dev->contrast->cur.val, in vivid_fillbuff()
508 dev->saturation->cur.val, in vivid_fillbuff()
509 dev->hue->cur.val); in vivid_fillbuff()
513 dev->autogain->cur.val, gain, dev->alpha->cur.val); in vivid_fillbuff()
514 mutex_unlock(dev->ctrl_hdl_user_vid.lock); in vivid_fillbuff()
516 mutex_lock(dev->ctrl_hdl_user_aud.lock); in vivid_fillbuff()
519 dev->volume->cur.val, dev->mute->cur.val); in vivid_fillbuff()
520 mutex_unlock(dev->ctrl_hdl_user_aud.lock); in vivid_fillbuff()
522 mutex_lock(dev->ctrl_hdl_user_gen.lock); in vivid_fillbuff()
524 dev->int32->cur.val, in vivid_fillbuff()
525 dev->ro_int32->cur.val, in vivid_fillbuff()
526 *dev->int64->p_cur.p_s64, in vivid_fillbuff()
527 dev->bitmask->cur.val); in vivid_fillbuff()
530 dev->boolean->cur.val, in vivid_fillbuff()
531 dev->menu->qmenu[dev->menu->cur.val], in vivid_fillbuff()
532 dev->string->p_cur.p_char); in vivid_fillbuff()
535 dev->int_menu->qmenu_int[dev->int_menu->cur.val], in vivid_fillbuff()
536 dev->int_menu->cur.val); in vivid_fillbuff()
537 mutex_unlock(dev->ctrl_hdl_user_gen.lock); in vivid_fillbuff()
539 if (dev->button_pressed) { in vivid_fillbuff()
540 dev->button_pressed--; in vivid_fillbuff()
544 if (dev->osd[0]) { in vivid_fillbuff()
547 " OSD \"%s\"", dev->osd); in vivid_fillbuff()
551 if (dev->osd_jiffies && in vivid_fillbuff()
552 time_is_before_jiffies(dev->osd_jiffies + 5 * HZ)) { in vivid_fillbuff()
553 dev->osd[0] = 0; in vivid_fillbuff()
554 dev->osd_jiffies = 0; in vivid_fillbuff()
564 f_period = (u64)dev->timeperframe_vid_cap.numerator * 1000000000; in vivid_cap_update_frame_period()
565 if (WARN_ON(dev->timeperframe_vid_cap.denominator == 0)) in vivid_cap_update_frame_period()
566 dev->timeperframe_vid_cap.denominator = 1; in vivid_cap_update_frame_period()
567 do_div(f_period, dev->timeperframe_vid_cap.denominator); in vivid_cap_update_frame_period()
568 if (dev->field_cap == V4L2_FIELD_ALTERNATE) in vivid_cap_update_frame_period()
574 dev->cap_frame_eof_offset = f_period * 9; in vivid_cap_update_frame_period()
575 do_div(dev->cap_frame_eof_offset, 10); in vivid_cap_update_frame_period()
576 dev->cap_frame_period = f_period; in vivid_cap_update_frame_period()
589 while (dropped_bufs-- > 1) in vivid_thread_vid_cap_tick()
590 tpg_update_mv_count(&dev->tpg, in vivid_thread_vid_cap_tick()
591 dev->field_cap == V4L2_FIELD_NONE || in vivid_thread_vid_cap_tick()
592 dev->field_cap == V4L2_FIELD_ALTERNATE); in vivid_thread_vid_cap_tick()
595 if (dev->perc_dropped_buffers && in vivid_thread_vid_cap_tick()
596 get_random_u32_below(100) < dev->perc_dropped_buffers) in vivid_thread_vid_cap_tick()
599 spin_lock(&dev->slock); in vivid_thread_vid_cap_tick()
600 if (!list_empty(&dev->vid_cap_active)) { in vivid_thread_vid_cap_tick()
601 vid_cap_buf = list_entry(dev->vid_cap_active.next, struct vivid_buffer, list); in vivid_thread_vid_cap_tick()
602 list_del(&vid_cap_buf->list); in vivid_thread_vid_cap_tick()
604 if (!list_empty(&dev->vbi_cap_active)) { in vivid_thread_vid_cap_tick()
605 if (dev->field_cap != V4L2_FIELD_ALTERNATE || in vivid_thread_vid_cap_tick()
606 (dev->vbi_cap_seq_count & 1)) { in vivid_thread_vid_cap_tick()
607 vbi_cap_buf = list_entry(dev->vbi_cap_active.next, in vivid_thread_vid_cap_tick()
609 list_del(&vbi_cap_buf->list); in vivid_thread_vid_cap_tick()
612 if (!list_empty(&dev->meta_cap_active)) { in vivid_thread_vid_cap_tick()
613 meta_cap_buf = list_entry(dev->meta_cap_active.next, in vivid_thread_vid_cap_tick()
615 list_del(&meta_cap_buf->list); in vivid_thread_vid_cap_tick()
618 spin_unlock(&dev->slock); in vivid_thread_vid_cap_tick()
623 f_time = ktime_get_ns() + dev->time_wrap_offset; in vivid_thread_vid_cap_tick()
626 v4l2_ctrl_request_setup(vid_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
627 &dev->ctrl_hdl_vid_cap); in vivid_thread_vid_cap_tick()
631 vid_cap_buf->vb.vb2_buf.index); in vivid_thread_vid_cap_tick()
633 v4l2_ctrl_request_complete(vid_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
634 &dev->ctrl_hdl_vid_cap); in vivid_thread_vid_cap_tick()
635 vb2_buffer_done(&vid_cap_buf->vb.vb2_buf, dev->dqbuf_error ? in vivid_thread_vid_cap_tick()
638 vid_cap_buf->vb.vb2_buf.index); in vivid_thread_vid_cap_tick()
640 vid_cap_buf->vb.vb2_buf.timestamp = f_time; in vivid_thread_vid_cap_tick()
641 if (!dev->tstamp_src_is_soe) in vivid_thread_vid_cap_tick()
642 vid_cap_buf->vb.vb2_buf.timestamp += dev->cap_frame_eof_offset; in vivid_thread_vid_cap_tick()
648 v4l2_ctrl_request_setup(vbi_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
649 &dev->ctrl_hdl_vbi_cap); in vivid_thread_vid_cap_tick()
650 if (vbi_cap_buf->vb.vb2_buf.type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) in vivid_thread_vid_cap_tick()
654 v4l2_ctrl_request_complete(vbi_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
655 &dev->ctrl_hdl_vbi_cap); in vivid_thread_vid_cap_tick()
656 vb2_buffer_done(&vbi_cap_buf->vb.vb2_buf, dev->dqbuf_error ? in vivid_thread_vid_cap_tick()
659 vbi_cap_buf->vb.vb2_buf.index); in vivid_thread_vid_cap_tick()
662 vbi_period = dev->cap_frame_period * 5; in vivid_thread_vid_cap_tick()
664 vbi_cap_buf->vb.vb2_buf.timestamp = f_time + dev->cap_frame_eof_offset + vbi_period; in vivid_thread_vid_cap_tick()
668 v4l2_ctrl_request_setup(meta_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
669 &dev->ctrl_hdl_meta_cap); in vivid_thread_vid_cap_tick()
671 v4l2_ctrl_request_complete(meta_cap_buf->vb.vb2_buf.req_obj.req, in vivid_thread_vid_cap_tick()
672 &dev->ctrl_hdl_meta_cap); in vivid_thread_vid_cap_tick()
673 vb2_buffer_done(&meta_cap_buf->vb.vb2_buf, dev->dqbuf_error ? in vivid_thread_vid_cap_tick()
676 meta_cap_buf->vb.vb2_buf.index); in vivid_thread_vid_cap_tick()
677 meta_cap_buf->vb.vb2_buf.timestamp = f_time + dev->cap_frame_eof_offset; in vivid_thread_vid_cap_tick()
680 dev->dqbuf_error = false; in vivid_thread_vid_cap_tick()
684 tpg_update_mv_count(&dev->tpg, dev->field_cap == V4L2_FIELD_NONE || in vivid_thread_vid_cap_tick()
685 dev->field_cap == V4L2_FIELD_ALTERNATE); in vivid_thread_vid_cap_tick()
706 dev->cap_seq_offset = 0; in vivid_thread_vid_cap()
707 dev->cap_seq_count = 0; in vivid_thread_vid_cap()
708 dev->cap_seq_resync = false; in vivid_thread_vid_cap()
709 dev->jiffies_vid_cap = jiffies; in vivid_thread_vid_cap()
710 dev->cap_stream_start = ktime_get_ns(); in vivid_thread_vid_cap()
711 if (dev->time_wrap) in vivid_thread_vid_cap()
712 dev->time_wrap_offset = dev->time_wrap - dev->cap_stream_start; in vivid_thread_vid_cap()
714 dev->time_wrap_offset = 0; in vivid_thread_vid_cap()
722 if (!mutex_trylock(&dev->mutex)) { in vivid_thread_vid_cap()
728 if (dev->cap_seq_resync) { in vivid_thread_vid_cap()
729 dev->jiffies_vid_cap = cur_jiffies; in vivid_thread_vid_cap()
730 dev->cap_seq_offset = dev->cap_seq_count + 1; in vivid_thread_vid_cap()
731 dev->cap_seq_count = 0; in vivid_thread_vid_cap()
732 dev->cap_stream_start += dev->cap_frame_period * in vivid_thread_vid_cap()
733 dev->cap_seq_offset; in vivid_thread_vid_cap()
735 dev->cap_seq_resync = false; in vivid_thread_vid_cap()
737 numerator = dev->timeperframe_vid_cap.numerator; in vivid_thread_vid_cap()
738 denominator = dev->timeperframe_vid_cap.denominator; in vivid_thread_vid_cap()
740 if (dev->field_cap == V4L2_FIELD_ALTERNATE) in vivid_thread_vid_cap()
744 jiffies_since_start = cur_jiffies - dev->jiffies_vid_cap; in vivid_thread_vid_cap()
747 (HZ * numerator) / 2; in vivid_thread_vid_cap()
748 do_div(buffers_since_start, HZ * numerator); in vivid_thread_vid_cap()
752 * 'jiffies-per-day' to ease jiffies_to_msecs calculation) in vivid_thread_vid_cap()
757 dev->jiffies_vid_cap = cur_jiffies; in vivid_thread_vid_cap()
758 dev->cap_seq_offset = buffers_since_start; in vivid_thread_vid_cap()
761 dropped_bufs = buffers_since_start + dev->cap_seq_offset - dev->cap_seq_count; in vivid_thread_vid_cap()
762 dev->cap_seq_count = buffers_since_start + dev->cap_seq_offset; in vivid_thread_vid_cap()
763 dev->vid_cap_seq_count = dev->cap_seq_count - dev->vid_cap_seq_start; in vivid_thread_vid_cap()
764 dev->vbi_cap_seq_count = dev->cap_seq_count - dev->vbi_cap_seq_start; in vivid_thread_vid_cap()
765 dev->meta_cap_seq_count = dev->cap_seq_count - dev->meta_cap_seq_start; in vivid_thread_vid_cap()
776 jiffies_since_start = jiffies - dev->jiffies_vid_cap; in vivid_thread_vid_cap()
778 mutex_unlock(&dev->mutex); in vivid_thread_vid_cap()
784 next_jiffies_since_start = numerators_since_start * HZ + in vivid_thread_vid_cap()
791 wait_jiffies = next_jiffies_since_start - jiffies_since_start; in vivid_thread_vid_cap()
802 v4l2_ctrl_grab(dev->ctrl_has_crop_cap, grab); in vivid_grab_controls()
803 v4l2_ctrl_grab(dev->ctrl_has_compose_cap, grab); in vivid_grab_controls()
804 v4l2_ctrl_grab(dev->ctrl_has_scaler_cap, grab); in vivid_grab_controls()
811 if (dev->kthread_vid_cap) { in vivid_start_generating_vid_cap()
812 u32 seq_count = dev->cap_seq_count + dev->seq_wrap * 128; in vivid_start_generating_vid_cap()
814 if (pstreaming == &dev->vid_cap_streaming) in vivid_start_generating_vid_cap()
815 dev->vid_cap_seq_start = seq_count; in vivid_start_generating_vid_cap()
816 else if (pstreaming == &dev->vbi_cap_streaming) in vivid_start_generating_vid_cap()
817 dev->vbi_cap_seq_start = seq_count; in vivid_start_generating_vid_cap()
819 dev->meta_cap_seq_start = seq_count; in vivid_start_generating_vid_cap()
825 tpg_init_mv_count(&dev->tpg); in vivid_start_generating_vid_cap()
827 dev->vid_cap_seq_start = dev->seq_wrap * 128; in vivid_start_generating_vid_cap()
828 dev->vbi_cap_seq_start = dev->seq_wrap * 128; in vivid_start_generating_vid_cap()
829 dev->meta_cap_seq_start = dev->seq_wrap * 128; in vivid_start_generating_vid_cap()
831 dev->kthread_vid_cap = kthread_run(vivid_thread_vid_cap, dev, in vivid_start_generating_vid_cap()
832 "%s-vid-cap", dev->v4l2_dev.name); in vivid_start_generating_vid_cap()
834 if (IS_ERR(dev->kthread_vid_cap)) { in vivid_start_generating_vid_cap()
835 int err = PTR_ERR(dev->kthread_vid_cap); in vivid_start_generating_vid_cap()
837 dev->kthread_vid_cap = NULL; in vivid_start_generating_vid_cap()
838 v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n"); in vivid_start_generating_vid_cap()
852 if (dev->kthread_vid_cap == NULL) in vivid_stop_generating_vid_cap()
856 if (pstreaming == &dev->vid_cap_streaming) { in vivid_stop_generating_vid_cap()
858 while (!list_empty(&dev->vid_cap_active)) { in vivid_stop_generating_vid_cap()
861 buf = list_entry(dev->vid_cap_active.next, in vivid_stop_generating_vid_cap()
863 list_del(&buf->list); in vivid_stop_generating_vid_cap()
864 v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req, in vivid_stop_generating_vid_cap()
865 &dev->ctrl_hdl_vid_cap); in vivid_stop_generating_vid_cap()
866 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in vivid_stop_generating_vid_cap()
868 buf->vb.vb2_buf.index); in vivid_stop_generating_vid_cap()
872 if (pstreaming == &dev->vbi_cap_streaming) { in vivid_stop_generating_vid_cap()
873 while (!list_empty(&dev->vbi_cap_active)) { in vivid_stop_generating_vid_cap()
876 buf = list_entry(dev->vbi_cap_active.next, in vivid_stop_generating_vid_cap()
878 list_del(&buf->list); in vivid_stop_generating_vid_cap()
879 v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req, in vivid_stop_generating_vid_cap()
880 &dev->ctrl_hdl_vbi_cap); in vivid_stop_generating_vid_cap()
881 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in vivid_stop_generating_vid_cap()
883 buf->vb.vb2_buf.index); in vivid_stop_generating_vid_cap()
887 if (pstreaming == &dev->meta_cap_streaming) { in vivid_stop_generating_vid_cap()
888 while (!list_empty(&dev->meta_cap_active)) { in vivid_stop_generating_vid_cap()
891 buf = list_entry(dev->meta_cap_active.next, in vivid_stop_generating_vid_cap()
893 list_del(&buf->list); in vivid_stop_generating_vid_cap()
894 v4l2_ctrl_request_complete(buf->vb.vb2_buf.req_obj.req, in vivid_stop_generating_vid_cap()
895 &dev->ctrl_hdl_meta_cap); in vivid_stop_generating_vid_cap()
896 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); in vivid_stop_generating_vid_cap()
898 buf->vb.vb2_buf.index); in vivid_stop_generating_vid_cap()
902 if (dev->vid_cap_streaming || dev->vbi_cap_streaming || in vivid_stop_generating_vid_cap()
903 dev->meta_cap_streaming) in vivid_stop_generating_vid_cap()
908 kthread_stop(dev->kthread_vid_cap); in vivid_stop_generating_vid_cap()
909 dev->kthread_vid_cap = NULL; in vivid_stop_generating_vid_cap()