Lines Matching refs:ctx
92 static void set_default_params(struct hva_ctx *ctx) in set_default_params() argument
94 struct hva_frameinfo *frameinfo = &ctx->frameinfo; in set_default_params()
95 struct hva_streaminfo *streaminfo = &ctx->streaminfo; in set_default_params()
112 ctx->colorspace = V4L2_COLORSPACE_REC709; in set_default_params()
113 ctx->xfer_func = V4L2_XFER_FUNC_DEFAULT; in set_default_params()
114 ctx->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; in set_default_params()
115 ctx->quantization = V4L2_QUANTIZATION_DEFAULT; in set_default_params()
117 ctx->max_stream_size = estimated_stream_size(streaminfo->width, in set_default_params()
121 static const struct hva_enc *hva_find_encoder(struct hva_ctx *ctx, in hva_find_encoder() argument
125 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_find_encoder()
190 static int hva_open_encoder(struct hva_ctx *ctx, u32 streamformat, in hva_open_encoder() argument
193 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_open_encoder()
194 struct device *dev = ctx_to_dev(ctx); in hva_open_encoder()
199 enc = (struct hva_enc *)hva_find_encoder(ctx, pixelformat, in hva_open_encoder()
203 ctx->name, (char *)&pixelformat, (char *)&streamformat); in hva_open_encoder()
208 ctx->name, (char *)&pixelformat, (char *)&streamformat); in hva_open_encoder()
211 snprintf(ctx->name, sizeof(ctx->name), "[%3d:%4.4s]", in hva_open_encoder()
215 ret = enc->open(ctx); in hva_open_encoder()
218 ctx->name, ret); in hva_open_encoder()
222 dev_dbg(dev, "%s %s encoder opened\n", ctx->name, enc->name); in hva_open_encoder()
236 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_querycap() local
237 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_querycap()
250 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_enum_fmt_stream() local
251 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_enum_fmt_stream()
264 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_enum_fmt_frame() local
265 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_enum_fmt_frame()
277 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_g_fmt_stream() local
278 struct hva_streaminfo *streaminfo = &ctx->streaminfo; in hva_g_fmt_stream()
283 f->fmt.pix.colorspace = ctx->colorspace; in hva_g_fmt_stream()
284 f->fmt.pix.xfer_func = ctx->xfer_func; in hva_g_fmt_stream()
285 f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc; in hva_g_fmt_stream()
286 f->fmt.pix.quantization = ctx->quantization; in hva_g_fmt_stream()
289 f->fmt.pix.sizeimage = ctx->max_stream_size; in hva_g_fmt_stream()
296 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_g_fmt_frame() local
297 struct hva_frameinfo *frameinfo = &ctx->frameinfo; in hva_g_fmt_frame()
302 f->fmt.pix.colorspace = ctx->colorspace; in hva_g_fmt_frame()
303 f->fmt.pix.xfer_func = ctx->xfer_func; in hva_g_fmt_frame()
304 f->fmt.pix.ycbcr_enc = ctx->ycbcr_enc; in hva_g_fmt_frame()
305 f->fmt.pix.quantization = ctx->quantization; in hva_g_fmt_frame()
317 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_try_fmt_stream() local
318 struct device *dev = ctx_to_dev(ctx); in hva_try_fmt_stream()
325 enc = hva_find_encoder(ctx, ctx->frameinfo.pixelformat, streamformat); in hva_try_fmt_stream()
329 ctx->name, (char *)&pix->pixelformat); in hva_try_fmt_stream()
335 if (ctx->flags & HVA_FLAG_FRAMEINFO) { in hva_try_fmt_stream()
340 pix->width = ctx->frameinfo.width; in hva_try_fmt_stream()
341 pix->height = ctx->frameinfo.height; in hva_try_fmt_stream()
345 ctx->name, width, height, in hva_try_fmt_stream()
360 ctx->name, width, height, in hva_try_fmt_stream()
369 pix->colorspace = ctx->colorspace; in hva_try_fmt_stream()
370 pix->xfer_func = ctx->xfer_func; in hva_try_fmt_stream()
371 pix->ycbcr_enc = ctx->ycbcr_enc; in hva_try_fmt_stream()
372 pix->quantization = ctx->quantization; in hva_try_fmt_stream()
381 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_try_fmt_frame() local
382 struct device *dev = ctx_to_dev(ctx); in hva_try_fmt_frame()
388 enc = hva_find_encoder(ctx, pixelformat, ctx->streaminfo.streamformat); in hva_try_fmt_frame()
392 ctx->name, (char *)&pixelformat); in hva_try_fmt_frame()
410 ctx->name, width, height, pix->width, pix->height); in hva_try_fmt_frame()
431 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_s_fmt_stream() local
432 struct device *dev = ctx_to_dev(ctx); in hva_s_fmt_stream()
439 ctx->name, (char *)&f->fmt.pix.pixelformat); in hva_s_fmt_stream()
443 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); in hva_s_fmt_stream()
446 ctx->name); in hva_s_fmt_stream()
450 ctx->max_stream_size = f->fmt.pix.sizeimage; in hva_s_fmt_stream()
451 ctx->streaminfo.width = f->fmt.pix.width; in hva_s_fmt_stream()
452 ctx->streaminfo.height = f->fmt.pix.height; in hva_s_fmt_stream()
453 ctx->streaminfo.streamformat = f->fmt.pix.pixelformat; in hva_s_fmt_stream()
454 ctx->flags |= HVA_FLAG_STREAMINFO; in hva_s_fmt_stream()
461 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_s_fmt_frame() local
462 struct device *dev = ctx_to_dev(ctx); in hva_s_fmt_frame()
470 ctx->name, (char *)&pix->pixelformat); in hva_s_fmt_frame()
474 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); in hva_s_fmt_frame()
476 dev_dbg(dev, "%s V4L2 S_FMT (OUTPUT): queue busy\n", ctx->name); in hva_s_fmt_frame()
480 ctx->colorspace = pix->colorspace; in hva_s_fmt_frame()
481 ctx->xfer_func = pix->xfer_func; in hva_s_fmt_frame()
482 ctx->ycbcr_enc = pix->ycbcr_enc; in hva_s_fmt_frame()
483 ctx->quantization = pix->quantization; in hva_s_fmt_frame()
485 ctx->frameinfo.aligned_width = ALIGN(pix->width, HVA_WIDTH_ALIGNMENT); in hva_s_fmt_frame()
486 ctx->frameinfo.aligned_height = ALIGN(pix->height, in hva_s_fmt_frame()
488 ctx->frameinfo.size = pix->sizeimage; in hva_s_fmt_frame()
489 ctx->frameinfo.pixelformat = pix->pixelformat; in hva_s_fmt_frame()
490 ctx->frameinfo.width = pix->width; in hva_s_fmt_frame()
491 ctx->frameinfo.height = pix->height; in hva_s_fmt_frame()
492 ctx->flags |= HVA_FLAG_FRAMEINFO; in hva_s_fmt_frame()
499 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_g_parm() local
500 struct v4l2_fract *time_per_frame = &ctx->ctrls.time_per_frame; in hva_g_parm()
515 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_s_parm() local
516 struct v4l2_fract *time_per_frame = &ctx->ctrls.time_per_frame; in hva_s_parm()
535 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_qbuf() local
536 struct device *dev = ctx_to_dev(ctx); in hva_qbuf()
549 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, buf->type); in hva_qbuf()
553 ctx->name, buf->index, vq->num_buffers); in hva_qbuf()
561 return v4l2_m2m_qbuf(file, ctx->fh.m2m_ctx, buf); in hva_qbuf()
595 struct hva_ctx *ctx = container_of(ctrl->handler, struct hva_ctx, in hva_s_ctrl() local
597 struct device *dev = ctx_to_dev(ctx); in hva_s_ctrl()
599 dev_dbg(dev, "%s S_CTRL: id = %d, val = %d\n", ctx->name, in hva_s_ctrl()
604 ctx->ctrls.bitrate_mode = ctrl->val; in hva_s_ctrl()
607 ctx->ctrls.gop_size = ctrl->val; in hva_s_ctrl()
610 ctx->ctrls.bitrate = ctrl->val; in hva_s_ctrl()
613 ctx->ctrls.aspect = ctrl->val; in hva_s_ctrl()
616 ctx->ctrls.profile = ctrl->val; in hva_s_ctrl()
617 if (ctx->flags & HVA_FLAG_STREAMINFO) in hva_s_ctrl()
618 snprintf(ctx->streaminfo.profile, in hva_s_ctrl()
619 sizeof(ctx->streaminfo.profile), in hva_s_ctrl()
624 ctx->ctrls.level = ctrl->val; in hva_s_ctrl()
625 if (ctx->flags & HVA_FLAG_STREAMINFO) in hva_s_ctrl()
626 snprintf(ctx->streaminfo.level, in hva_s_ctrl()
627 sizeof(ctx->streaminfo.level), in hva_s_ctrl()
632 ctx->ctrls.entropy_mode = ctrl->val; in hva_s_ctrl()
635 ctx->ctrls.cpb_size = ctrl->val; in hva_s_ctrl()
638 ctx->ctrls.dct8x8 = ctrl->val; in hva_s_ctrl()
641 ctx->ctrls.qpmin = ctrl->val; in hva_s_ctrl()
644 ctx->ctrls.qpmax = ctrl->val; in hva_s_ctrl()
647 ctx->ctrls.vui_sar = ctrl->val; in hva_s_ctrl()
650 ctx->ctrls.vui_sar_idc = ctrl->val; in hva_s_ctrl()
653 ctx->ctrls.sei_fp = ctrl->val; in hva_s_ctrl()
656 ctx->ctrls.sei_fp_type = ctrl->val; in hva_s_ctrl()
660 ctx->name, ctrl->id); in hva_s_ctrl()
672 static int hva_ctrls_setup(struct hva_ctx *ctx) in hva_ctrls_setup() argument
674 struct device *dev = ctx_to_dev(ctx); in hva_ctrls_setup()
679 v4l2_ctrl_handler_init(&ctx->ctrl_handler, 15); in hva_ctrls_setup()
681 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
687 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
691 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
696 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
706 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
712 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
718 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
724 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
728 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
732 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
736 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
740 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
745 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
751 v4l2_ctrl_new_std(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
756 v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &hva_ctrl_ops, in hva_ctrls_setup()
762 if (ctx->ctrl_handler.error) { in hva_ctrls_setup()
763 int err = ctx->ctrl_handler.error; in hva_ctrls_setup()
766 ctx->name, err); in hva_ctrls_setup()
767 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in hva_ctrls_setup()
771 v4l2_ctrl_handler_setup(&ctx->ctrl_handler); in hva_ctrls_setup()
774 ctx->ctrls.time_per_frame.numerator = HVA_DEFAULT_FRAME_NUM; in hva_ctrls_setup()
775 ctx->ctrls.time_per_frame.denominator = HVA_DEFAULT_FRAME_DEN; in hva_ctrls_setup()
786 struct hva_ctx *ctx = container_of(work, struct hva_ctx, run_work); in hva_run_work() local
788 const struct hva_enc *enc = ctx->enc; in hva_run_work()
794 mutex_lock(&ctx->lock); in hva_run_work()
796 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in hva_run_work()
797 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in hva_run_work()
801 frame->vbuf.sequence = ctx->frame_num++; in hva_run_work()
803 ret = enc->encode(ctx, frame, stream); in hva_run_work()
813 dst_buf->sequence = ctx->stream_num - 1; in hva_run_work()
819 mutex_unlock(&ctx->lock); in hva_run_work()
821 v4l2_m2m_job_finish(ctx->hva_dev->m2m_dev, ctx->fh.m2m_ctx); in hva_run_work()
826 struct hva_ctx *ctx = priv; in hva_device_run() local
827 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_device_run()
829 queue_work(hva->work_queue, &ctx->run_work); in hva_device_run()
834 struct hva_ctx *ctx = priv; in hva_job_abort() local
835 struct device *dev = ctx_to_dev(ctx); in hva_job_abort()
837 dev_dbg(dev, "%s aborting job\n", ctx->name); in hva_job_abort()
839 ctx->aborting = true; in hva_job_abort()
844 struct hva_ctx *ctx = priv; in hva_job_ready() local
845 struct device *dev = ctx_to_dev(ctx); in hva_job_ready()
847 if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) { in hva_job_ready()
849 ctx->name); in hva_job_ready()
853 if (!v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx)) { in hva_job_ready()
855 ctx->name); in hva_job_ready()
859 if (ctx->aborting) { in hva_job_ready()
860 dev_dbg(dev, "%s job not ready: aborting\n", ctx->name); in hva_job_ready()
882 struct hva_ctx *ctx = vb2_get_drv_priv(vq); in hva_queue_setup() local
883 struct device *dev = ctx_to_dev(ctx); in hva_queue_setup()
886 dev_dbg(dev, "%s %s queue setup: num_buffers %d\n", ctx->name, in hva_queue_setup()
890 ctx->frameinfo.size : ctx->max_stream_size; in hva_queue_setup()
904 struct hva_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in hva_buf_prepare() local
905 struct device *dev = ctx_to_dev(ctx); in hva_buf_prepare()
916 ctx->name, vb->index, vbuf->field); in hva_buf_prepare()
925 frame->info = ctx->frameinfo; in hva_buf_prepare()
930 ctx->name, vb->index, in hva_buf_prepare()
946 ctx->name, vb->index, in hva_buf_prepare()
956 struct hva_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in hva_buf_queue() local
959 if (ctx->fh.m2m_ctx) in hva_buf_queue()
960 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); in hva_buf_queue()
965 struct hva_ctx *ctx = vb2_get_drv_priv(vq); in hva_start_streaming() local
966 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_start_streaming()
967 struct device *dev = ctx_to_dev(ctx); in hva_start_streaming()
973 dev_dbg(dev, "%s %s start streaming\n", ctx->name, in hva_start_streaming()
978 if (!vb2_start_streaming_called(&ctx->fh.m2m_ctx->cap_q_ctx.q)) in hva_start_streaming()
981 if (!vb2_start_streaming_called(&ctx->fh.m2m_ctx->out_q_ctx.q)) in hva_start_streaming()
988 hva->instances[i] = ctx; in hva_start_streaming()
990 ctx->id = i; in hva_start_streaming()
997 dev_err(dev, "%s maximum instances reached\n", ctx->name); in hva_start_streaming()
1004 if (!ctx->enc) { in hva_start_streaming()
1005 ret = hva_open_encoder(ctx, in hva_start_streaming()
1006 ctx->streaminfo.streamformat, in hva_start_streaming()
1007 ctx->frameinfo.pixelformat, in hva_start_streaming()
1008 &ctx->enc); in hva_start_streaming()
1016 hva->instances[ctx->id] = NULL; in hva_start_streaming()
1021 while ((vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) in hva_start_streaming()
1025 while ((vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) in hva_start_streaming()
1034 struct hva_ctx *ctx = vb2_get_drv_priv(vq); in hva_stop_streaming() local
1035 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_stop_streaming()
1036 struct device *dev = ctx_to_dev(ctx); in hva_stop_streaming()
1037 const struct hva_enc *enc = ctx->enc; in hva_stop_streaming()
1040 dev_dbg(dev, "%s %s stop streaming\n", ctx->name, in hva_stop_streaming()
1045 ctx->frame_num = 0; in hva_stop_streaming()
1046 while ((vbuf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) in hva_stop_streaming()
1050 ctx->stream_num = 0; in hva_stop_streaming()
1051 while ((vbuf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx))) in hva_stop_streaming()
1056 vb2_is_streaming(&ctx->fh.m2m_ctx->cap_q_ctx.q)) || in hva_stop_streaming()
1058 vb2_is_streaming(&ctx->fh.m2m_ctx->out_q_ctx.q))) { in hva_stop_streaming()
1060 ctx->name, to_type_str(vq->type), in hva_stop_streaming()
1061 vb2_is_streaming(&ctx->fh.m2m_ctx->out_q_ctx.q), in hva_stop_streaming()
1062 vb2_is_streaming(&ctx->fh.m2m_ctx->cap_q_ctx.q)); in hva_stop_streaming()
1068 dev_dbg(dev, "%s %s encoder closed\n", ctx->name, enc->name); in hva_stop_streaming()
1069 enc->close(ctx); in hva_stop_streaming()
1070 ctx->enc = NULL; in hva_stop_streaming()
1073 hva->instances[ctx->id] = NULL; in hva_stop_streaming()
1077 ctx->aborting = false; in hva_stop_streaming()
1095 static int queue_init(struct hva_ctx *ctx, struct vb2_queue *vq) in queue_init() argument
1098 vq->drv_priv = ctx; in queue_init()
1102 vq->lock = &ctx->hva_dev->lock; in queue_init()
1110 struct hva_ctx *ctx = priv; in hva_queue_init() local
1116 src_vq->dev = ctx->hva_dev->dev; in hva_queue_init()
1118 ret = queue_init(ctx, src_vq); in hva_queue_init()
1125 dst_vq->dev = ctx->hva_dev->dev; in hva_queue_init()
1127 return queue_init(ctx, dst_vq); in hva_queue_init()
1134 struct hva_ctx *ctx; in hva_open() local
1137 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in hva_open()
1138 if (!ctx) { in hva_open()
1142 ctx->hva_dev = hva; in hva_open()
1144 INIT_WORK(&ctx->run_work, hva_run_work); in hva_open()
1145 v4l2_fh_init(&ctx->fh, video_devdata(file)); in hva_open()
1146 file->private_data = &ctx->fh; in hva_open()
1147 v4l2_fh_add(&ctx->fh); in hva_open()
1149 ret = hva_ctrls_setup(ctx); in hva_open()
1155 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in hva_open()
1157 mutex_init(&ctx->lock); in hva_open()
1159 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(hva->m2m_dev, ctx, in hva_open()
1161 if (IS_ERR(ctx->fh.m2m_ctx)) { in hva_open()
1162 ret = PTR_ERR(ctx->fh.m2m_ctx); in hva_open()
1171 snprintf(ctx->name, sizeof(ctx->name), "[%3d:----]", in hva_open()
1176 set_default_params(ctx); in hva_open()
1178 dev_info(dev, "%s encoder instance created\n", ctx->name); in hva_open()
1183 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in hva_open()
1185 v4l2_fh_del(&ctx->fh); in hva_open()
1186 v4l2_fh_exit(&ctx->fh); in hva_open()
1187 kfree(ctx); in hva_open()
1194 struct hva_ctx *ctx = fh_to_ctx(file->private_data); in hva_release() local
1195 struct hva_dev *hva = ctx_to_hdev(ctx); in hva_release()
1196 struct device *dev = ctx_to_dev(ctx); in hva_release()
1197 const struct hva_enc *enc = ctx->enc; in hva_release()
1200 dev_dbg(dev, "%s %s encoder closed\n", ctx->name, enc->name); in hva_release()
1201 enc->close(ctx); in hva_release()
1202 ctx->enc = NULL; in hva_release()
1205 hva->instances[ctx->id] = NULL; in hva_release()
1209 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); in hva_release()
1211 v4l2_ctrl_handler_free(&ctx->ctrl_handler); in hva_release()
1213 v4l2_fh_del(&ctx->fh); in hva_release()
1214 v4l2_fh_exit(&ctx->fh); in hva_release()
1216 dev_info(dev, "%s encoder instance released\n", ctx->name); in hva_release()
1218 kfree(ctx); in hva_release()