Lines Matching +full:top +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2020-2021 NXP
17 #include <media/v4l2-device.h>
18 #include <media/v4l2-event.h>
19 #include <media/v4l2-mem2mem.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/videobuf2-v4l2.h>
22 #include <media/videobuf2-dma-contig.h>
23 #include <media/videobuf2-vmalloc.h>
85 strscpy(cap->driver, "amphion-vpu", sizeof(cap->driver)); in venc_querycap()
86 strscpy(cap->card, "amphion vpu encoder", sizeof(cap->card)); in venc_querycap()
87 strscpy(cap->bus_info, "platform: amphion-vpu", sizeof(cap->bus_info)); in venc_querycap()
97 memset(f->reserved, 0, sizeof(f->reserved)); in venc_enum_fmt()
98 fmt = vpu_helper_enum_format(inst, f->type, f->index); in venc_enum_fmt()
100 return -EINVAL; in venc_enum_fmt()
102 f->pixelformat = fmt->pixfmt; in venc_enum_fmt()
103 f->flags = fmt->flags; in venc_enum_fmt()
113 if (!fsize || fsize->index) in venc_enum_framesizes()
114 return -EINVAL; in venc_enum_framesizes()
116 if (!vpu_helper_find_format(inst, 0, fsize->pixel_format)) in venc_enum_framesizes()
117 return -EINVAL; in venc_enum_framesizes()
121 return -EINVAL; in venc_enum_framesizes()
122 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; in venc_enum_framesizes()
123 fsize->stepwise.max_width = res->max_width; in venc_enum_framesizes()
124 fsize->stepwise.max_height = res->max_height; in venc_enum_framesizes()
125 fsize->stepwise.min_width = res->min_width; in venc_enum_framesizes()
126 fsize->stepwise.min_height = res->min_height; in venc_enum_framesizes()
127 fsize->stepwise.step_width = res->step_width; in venc_enum_framesizes()
128 fsize->stepwise.step_height = res->step_height; in venc_enum_framesizes()
138 if (!fival || fival->index) in venc_enum_frameintervals()
139 return -EINVAL; in venc_enum_frameintervals()
141 if (!vpu_helper_find_format(inst, 0, fival->pixel_format)) in venc_enum_frameintervals()
142 return -EINVAL; in venc_enum_frameintervals()
144 if (!fival->width || !fival->height) in venc_enum_frameintervals()
145 return -EINVAL; in venc_enum_frameintervals()
149 return -EINVAL; in venc_enum_frameintervals()
150 if (fival->width < res->min_width || fival->width > res->max_width || in venc_enum_frameintervals()
151 fival->height < res->min_height || fival->height > res->max_height) in venc_enum_frameintervals()
152 return -EINVAL; in venc_enum_frameintervals()
154 fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS; in venc_enum_frameintervals()
155 fival->stepwise.min.numerator = 1; in venc_enum_frameintervals()
156 fival->stepwise.min.denominator = USHRT_MAX; in venc_enum_frameintervals()
157 fival->stepwise.max.numerator = USHRT_MAX; in venc_enum_frameintervals()
158 fival->stepwise.max.denominator = 1; in venc_enum_frameintervals()
159 fival->stepwise.step.numerator = 1; in venc_enum_frameintervals()
160 fival->stepwise.step.denominator = 1; in venc_enum_frameintervals()
168 struct venc_t *venc = inst->priv; in venc_g_fmt()
169 struct v4l2_pix_format_mplane *pixmp = &f->fmt.pix_mp; in venc_g_fmt()
173 cur_fmt = vpu_get_format(inst, f->type); in venc_g_fmt()
175 pixmp->pixelformat = cur_fmt->pixfmt; in venc_g_fmt()
176 pixmp->num_planes = cur_fmt->num_planes; in venc_g_fmt()
177 pixmp->width = cur_fmt->width; in venc_g_fmt()
178 pixmp->height = cur_fmt->height; in venc_g_fmt()
179 pixmp->field = cur_fmt->field; in venc_g_fmt()
180 pixmp->flags = cur_fmt->flags; in venc_g_fmt()
181 for (i = 0; i < pixmp->num_planes; i++) { in venc_g_fmt()
182 pixmp->plane_fmt[i].bytesperline = cur_fmt->bytesperline[i]; in venc_g_fmt()
183 pixmp->plane_fmt[i].sizeimage = cur_fmt->sizeimage[i]; in venc_g_fmt()
186 f->fmt.pix_mp.colorspace = venc->params.color.primaries; in venc_g_fmt()
187 f->fmt.pix_mp.xfer_func = venc->params.color.transfer; in venc_g_fmt()
188 f->fmt.pix_mp.ycbcr_enc = venc->params.color.matrix; in venc_g_fmt()
189 f->fmt.pix_mp.quantization = venc->params.color.full_range; in venc_g_fmt()
209 struct venc_t *venc = inst->priv; in venc_s_fmt()
210 struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; in venc_s_fmt()
213 q = v4l2_m2m_get_vq(inst->fh.m2m_ctx, f->type); in venc_s_fmt()
215 return -EINVAL; in venc_s_fmt()
217 return -EBUSY; in venc_s_fmt()
221 return -EINVAL; in venc_s_fmt()
223 cur_fmt = vpu_get_format(inst, f->type); in venc_s_fmt()
225 cur_fmt->pixfmt = fmt->pixfmt; in venc_s_fmt()
226 cur_fmt->num_planes = fmt->num_planes; in venc_s_fmt()
227 cur_fmt->flags = fmt->flags; in venc_s_fmt()
228 cur_fmt->width = pix_mp->width; in venc_s_fmt()
229 cur_fmt->height = pix_mp->height; in venc_s_fmt()
230 for (i = 0; i < fmt->num_planes; i++) { in venc_s_fmt()
231 cur_fmt->sizeimage[i] = pix_mp->plane_fmt[i].sizeimage; in venc_s_fmt()
232 cur_fmt->bytesperline[i] = pix_mp->plane_fmt[i].bytesperline; in venc_s_fmt()
235 if (pix_mp->field != V4L2_FIELD_ANY) in venc_s_fmt()
236 cur_fmt->field = pix_mp->field; in venc_s_fmt()
238 if (V4L2_TYPE_IS_OUTPUT(f->type)) { in venc_s_fmt()
239 venc->params.input_format = cur_fmt->pixfmt; in venc_s_fmt()
240 venc->params.src_stride = cur_fmt->bytesperline[0]; in venc_s_fmt()
241 venc->params.src_width = cur_fmt->width; in venc_s_fmt()
242 venc->params.src_height = cur_fmt->height; in venc_s_fmt()
243 venc->params.crop.left = 0; in venc_s_fmt()
244 venc->params.crop.top = 0; in venc_s_fmt()
245 venc->params.crop.width = cur_fmt->width; in venc_s_fmt()
246 venc->params.crop.height = cur_fmt->height; in venc_s_fmt()
248 venc->params.codec_format = cur_fmt->pixfmt; in venc_s_fmt()
249 venc->params.out_width = cur_fmt->width; in venc_s_fmt()
250 venc->params.out_height = cur_fmt->height; in venc_s_fmt()
253 if (V4L2_TYPE_IS_OUTPUT(f->type)) { in venc_s_fmt()
254 if (!vpu_color_check_primaries(pix_mp->colorspace)) { in venc_s_fmt()
255 venc->params.color.primaries = pix_mp->colorspace; in venc_s_fmt()
256 vpu_color_get_default(venc->params.color.primaries, in venc_s_fmt()
257 &venc->params.color.transfer, in venc_s_fmt()
258 &venc->params.color.matrix, in venc_s_fmt()
259 &venc->params.color.full_range); in venc_s_fmt()
261 if (!vpu_color_check_transfers(pix_mp->xfer_func)) in venc_s_fmt()
262 venc->params.color.transfer = pix_mp->xfer_func; in venc_s_fmt()
263 if (!vpu_color_check_matrix(pix_mp->ycbcr_enc)) in venc_s_fmt()
264 venc->params.color.matrix = pix_mp->ycbcr_enc; in venc_s_fmt()
265 if (!vpu_color_check_full_range(pix_mp->quantization)) in venc_s_fmt()
266 venc->params.color.full_range = pix_mp->quantization; in venc_s_fmt()
269 pix_mp->colorspace = venc->params.color.primaries; in venc_s_fmt()
270 pix_mp->xfer_func = venc->params.color.transfer; in venc_s_fmt()
271 pix_mp->ycbcr_enc = venc->params.color.matrix; in venc_s_fmt()
272 pix_mp->quantization = venc->params.color.full_range; in venc_s_fmt()
280 struct venc_t *venc = inst->priv; in venc_g_parm()
281 struct v4l2_fract *timeperframe = &parm->parm.capture.timeperframe; in venc_g_parm()
284 return -EINVAL; in venc_g_parm()
286 if (!V4L2_TYPE_IS_OUTPUT(parm->type)) in venc_g_parm()
287 return -EINVAL; in venc_g_parm()
289 if (!vpu_helper_check_type(inst, parm->type)) in venc_g_parm()
290 return -EINVAL; in venc_g_parm()
292 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in venc_g_parm()
293 parm->parm.capture.readbuffers = 0; in venc_g_parm()
294 timeperframe->numerator = venc->params.frame_rate.numerator; in venc_g_parm()
295 timeperframe->denominator = venc->params.frame_rate.denominator; in venc_g_parm()
303 struct venc_t *venc = inst->priv; in venc_s_parm()
304 struct v4l2_fract *timeperframe = &parm->parm.capture.timeperframe; in venc_s_parm()
308 return -EINVAL; in venc_s_parm()
310 if (!V4L2_TYPE_IS_OUTPUT(parm->type)) in venc_s_parm()
311 return -EINVAL; in venc_s_parm()
313 if (!vpu_helper_check_type(inst, parm->type)) in venc_s_parm()
314 return -EINVAL; in venc_s_parm()
316 if (!timeperframe->numerator) in venc_s_parm()
317 timeperframe->numerator = venc->params.frame_rate.numerator; in venc_s_parm()
318 if (!timeperframe->denominator) in venc_s_parm()
319 timeperframe->denominator = venc->params.frame_rate.denominator; in venc_s_parm()
321 venc->params.frame_rate.numerator = timeperframe->numerator; in venc_s_parm()
322 venc->params.frame_rate.denominator = timeperframe->denominator; in venc_s_parm()
324 rational_best_approximation(venc->params.frame_rate.numerator, in venc_s_parm()
325 venc->params.frame_rate.denominator, in venc_s_parm()
326 venc->params.frame_rate.numerator, in venc_s_parm()
327 venc->params.frame_rate.denominator, in venc_s_parm()
329 venc->params.frame_rate.numerator = n; in venc_s_parm()
330 venc->params.frame_rate.denominator = d; in venc_s_parm()
332 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in venc_s_parm()
333 memset(parm->parm.capture.reserved, 0, sizeof(parm->parm.capture.reserved)); in venc_s_parm()
341 struct venc_t *venc = inst->priv; in venc_g_selection()
343 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_g_selection()
344 return -EINVAL; in venc_g_selection()
346 switch (s->target) { in venc_g_selection()
349 s->r.left = 0; in venc_g_selection()
350 s->r.top = 0; in venc_g_selection()
351 s->r.width = inst->out_format.width; in venc_g_selection()
352 s->r.height = inst->out_format.height; in venc_g_selection()
355 s->r = venc->params.crop; in venc_g_selection()
358 return -EINVAL; in venc_g_selection()
372 rect = &venc->params.crop; in venc_valid_crop()
373 min_width = res->min_width; in venc_valid_crop()
374 min_height = res->min_height; in venc_valid_crop()
375 src_width = venc->params.src_width; in venc_valid_crop()
376 src_height = venc->params.src_height; in venc_valid_crop()
378 if (rect->width == 0 || rect->height == 0) in venc_valid_crop()
379 return -EINVAL; in venc_valid_crop()
380 if (rect->left > src_width - min_width || rect->top > src_height - min_height) in venc_valid_crop()
381 return -EINVAL; in venc_valid_crop()
383 rect->width = min(rect->width, src_width - rect->left); in venc_valid_crop()
384 rect->width = max_t(u32, rect->width, min_width); in venc_valid_crop()
386 rect->height = min(rect->height, src_height - rect->top); in venc_valid_crop()
387 rect->height = max_t(u32, rect->height, min_height); in venc_valid_crop()
396 struct venc_t *venc = inst->priv; in venc_s_selection()
400 return -EINVAL; in venc_s_selection()
402 if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) in venc_s_selection()
403 return -EINVAL; in venc_s_selection()
404 if (s->target != V4L2_SEL_TGT_CROP) in venc_s_selection()
405 return -EINVAL; in venc_s_selection()
407 venc->params.crop.left = ALIGN(s->r.left, res->step_width); in venc_s_selection()
408 venc->params.crop.top = ALIGN(s->r.top, res->step_height); in venc_s_selection()
409 venc->params.crop.width = ALIGN(s->r.width, res->step_width); in venc_s_selection()
410 venc->params.crop.height = ALIGN(s->r.height, res->step_height); in venc_s_selection()
412 venc->params.crop.left = 0; in venc_s_selection()
413 venc->params.crop.top = 0; in venc_s_selection()
414 venc->params.crop.width = venc->params.src_width; in venc_s_selection()
415 venc->params.crop.height = venc->params.src_height; in venc_s_selection()
418 inst->crop = venc->params.crop; in venc_s_selection()
425 struct venc_t *venc = inst->priv; in venc_drain()
428 if (!inst->fh.m2m_ctx) in venc_drain()
431 if (inst->state != VPU_CODEC_STATE_DRAIN) in venc_drain()
437 if (!venc->input_ready) in venc_drain()
440 venc->input_ready = false; in venc_drain()
441 vpu_trace(inst->dev, "[%d]\n", inst->id); in venc_drain()
445 inst->state = VPU_CODEC_STATE_STOP; in venc_drain()
446 wake_up_all(&venc->wq); in venc_drain()
453 inst->state = VPU_CODEC_STATE_DRAIN; in venc_request_eos()
469 if (cmd->cmd == V4L2_ENC_CMD_STOP) { in venc_encoder_cmd()
470 if (inst->state == VPU_CODEC_STATE_DEINIT) in venc_encoder_cmd()
482 switch (sub->type) { in venc_subscribe_event()
488 return -EINVAL; in venc_subscribe_event()
523 static int venc_op_s_ctrl(struct v4l2_ctrl *ctrl) in venc_op_s_ctrl() argument
525 struct vpu_inst *inst = ctrl_to_inst(ctrl); in venc_op_s_ctrl()
526 struct venc_t *venc = inst->priv; in venc_op_s_ctrl()
530 switch (ctrl->id) { in venc_op_s_ctrl()
532 venc->params.profile = ctrl->val; in venc_op_s_ctrl()
535 venc->params.level = ctrl->val; in venc_op_s_ctrl()
538 venc->params.rc_enable = ctrl->val; in venc_op_s_ctrl()
541 venc->params.rc_mode = ctrl->val; in venc_op_s_ctrl()
544 if (ctrl->val != venc->params.bitrate) in venc_op_s_ctrl()
545 venc->bitrate_change = true; in venc_op_s_ctrl()
546 venc->params.bitrate = ctrl->val; in venc_op_s_ctrl()
549 venc->params.bitrate_max = ctrl->val; in venc_op_s_ctrl()
552 venc->params.gop_length = ctrl->val; in venc_op_s_ctrl()
555 venc->params.bframes = ctrl->val; in venc_op_s_ctrl()
558 venc->params.i_frame_qp = ctrl->val; in venc_op_s_ctrl()
561 venc->params.p_frame_qp = ctrl->val; in venc_op_s_ctrl()
564 venc->params.b_frame_qp = ctrl->val; in venc_op_s_ctrl()
567 venc->request_key_frame = 1; in venc_op_s_ctrl()
570 venc->cpb_size = ctrl->val * 1024; in venc_op_s_ctrl()
573 venc->params.sar.enable = ctrl->val; in venc_op_s_ctrl()
576 venc->params.sar.idc = ctrl->val; in venc_op_s_ctrl()
579 venc->params.sar.width = ctrl->val; in venc_op_s_ctrl()
582 venc->params.sar.height = ctrl->val; in venc_op_s_ctrl()
587 ret = -EINVAL; in venc_op_s_ctrl()
602 struct v4l2_ctrl *ctrl; in venc_ctrl_init() local
605 ret = v4l2_ctrl_handler_init(&inst->ctrl_handler, 20); in venc_ctrl_init()
609 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
617 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
623 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
626 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
633 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
640 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
646 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
649 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
652 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
654 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
656 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
658 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
660 ctrl = v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
662 if (ctrl) in venc_ctrl_init()
663 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in venc_ctrl_init()
664 ctrl = v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
666 if (ctrl) in venc_ctrl_init()
667 ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; in venc_ctrl_init()
669 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
672 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
674 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
679 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
682 v4l2_ctrl_new_std(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
685 v4l2_ctrl_new_std_menu(&inst->ctrl_handler, &venc_ctrl_ops, in venc_ctrl_init()
691 if (inst->ctrl_handler.error) { in venc_ctrl_init()
692 ret = inst->ctrl_handler.error; in venc_ctrl_init()
693 v4l2_ctrl_handler_free(&inst->ctrl_handler); in venc_ctrl_init()
697 ret = v4l2_ctrl_handler_setup(&inst->ctrl_handler); in venc_ctrl_init()
699 dev_err(inst->dev, "[%d] setup ctrls fail, ret = %d\n", inst->id, ret); in venc_ctrl_init()
700 v4l2_ctrl_handler_free(&inst->ctrl_handler); in venc_ctrl_init()
709 struct venc_t *venc = inst->priv; in venc_check_ready()
712 if (vpu_helper_get_free_space(inst) < venc->cpb_size) in venc_check_ready()
714 return venc->input_ready; in venc_check_ready()
717 if (list_empty(&venc->frames)) in venc_check_ready()
735 venc->enable |= mask; in venc_set_enable()
737 venc->enable &= ~mask; in venc_set_enable()
742 return venc->enable & venc_get_enable_mask(type); in venc_get_enable()
747 struct venc_t *venc = inst->priv; in venc_input_done()
750 venc->input_ready = true; in venc_input_done()
752 if (inst->state == VPU_CODEC_STATE_DRAIN) in venc_input_done()
768 if (!frame || !frame->bytesused) in venc_precheck_encoded_frame()
769 return -EINVAL; in venc_precheck_encoded_frame()
771 venc = inst->priv; in venc_precheck_encoded_frame()
772 skipped = vpu_helper_find_startcode(&inst->stream_buffer, in venc_precheck_encoded_frame()
773 inst->cap_format.pixfmt, in venc_precheck_encoded_frame()
774 frame->info.wptr - inst->stream_buffer.phys, in venc_precheck_encoded_frame()
775 frame->bytesused); in venc_precheck_encoded_frame()
777 frame->bytesused -= skipped; in venc_precheck_encoded_frame()
778 frame->info.wptr = vpu_helper_step_walk(&inst->stream_buffer, in venc_precheck_encoded_frame()
779 frame->info.wptr, skipped); in venc_precheck_encoded_frame()
780 venc->skipped_bytes += skipped; in venc_precheck_encoded_frame()
781 venc->skipped_count++; in venc_precheck_encoded_frame()
791 struct venc_t *venc = inst->priv; in venc_get_one_encoded_frame()
795 return -EAGAIN; in venc_get_one_encoded_frame()
797 src_buf = vpu_find_buf_by_sequence(inst, inst->out_format.type, frame->info.frame_id); in venc_get_one_encoded_frame()
801 v4l2_m2m_src_buf_remove_by_buf(inst->fh.m2m_ctx, src_buf); in venc_get_one_encoded_frame()
804 vbuf->vb2_buf.timestamp = frame->info.timestamp; in venc_get_one_encoded_frame()
806 if (!venc_get_enable(inst->priv, vbuf->vb2_buf.type)) { in venc_get_one_encoded_frame()
810 if (frame->bytesused > vbuf->vb2_buf.planes[0].length) { in venc_get_one_encoded_frame()
812 return -ENOMEM; in venc_get_one_encoded_frame()
817 if (frame->bytesused) { in venc_get_one_encoded_frame()
818 u32 rptr = frame->info.wptr; in venc_get_one_encoded_frame()
819 void *dst = vb2_plane_vaddr(&vbuf->vb2_buf, 0); in venc_get_one_encoded_frame()
821 vpu_helper_copy_from_stream_buffer(&inst->stream_buffer, in venc_get_one_encoded_frame()
822 &rptr, frame->bytesused, dst); in venc_get_one_encoded_frame()
825 vb2_set_plane_payload(&vbuf->vb2_buf, 0, frame->bytesused); in venc_get_one_encoded_frame()
826 vbuf->sequence = frame->info.frame_id; in venc_get_one_encoded_frame()
827 vbuf->field = inst->cap_format.field; in venc_get_one_encoded_frame()
828 vbuf->flags |= frame->info.pic_type; in venc_get_one_encoded_frame()
830 dev_dbg(inst->dev, "[%d][OUTPUT TS]%32lld\n", inst->id, vbuf->vb2_buf.timestamp); in venc_get_one_encoded_frame()
832 venc->ready_count++; in venc_get_one_encoded_frame()
834 if (vbuf->flags & V4L2_BUF_FLAG_KEYFRAME) in venc_get_one_encoded_frame()
835 dev_dbg(inst->dev, "[%d][%d]key frame\n", inst->id, frame->info.frame_id); in venc_get_one_encoded_frame()
846 if (!inst->fh.m2m_ctx) in venc_get_encoded_frames()
848 venc = inst->priv; in venc_get_encoded_frames()
849 list_for_each_entry_safe(frame, tmp, &venc->frames, list) { in venc_get_encoded_frames()
851 v4l2_m2m_dst_buf_remove(inst->fh.m2m_ctx))) in venc_get_encoded_frames()
853 list_del_init(&frame->list); in venc_get_encoded_frames()
868 return -EINVAL; in venc_frame_encoded()
869 venc = inst->priv; in venc_frame_encoded()
872 return -ENOMEM; in venc_frame_encoded()
874 memcpy(&frame->info, info, sizeof(frame->info)); in venc_frame_encoded()
875 frame->bytesused = info->frame_size; in venc_frame_encoded()
878 list_add_tail(&frame->list, &venc->frames); in venc_frame_encoded()
879 venc->encode_count++; in venc_frame_encoded()
888 struct venc_t *venc = inst->priv; in venc_set_last_buffer_dequeued()
890 if (venc->stopped && list_empty(&venc->frames)) in venc_set_last_buffer_dequeued()
896 struct venc_t *venc = inst->priv; in venc_stop_done()
899 venc->stopped = true; in venc_stop_done()
903 wake_up_all(&venc->wq); in venc_stop_done()
921 venc = inst->priv; in venc_cleanup()
923 inst->priv = NULL; in venc_cleanup()
929 struct venc_t *venc = inst->priv; in venc_start_session()
934 if ((venc->enable & VENC_ENABLE_MASK) != VENC_ENABLE_MASK) in venc_start_session()
938 stream_buffer_size = vpu_iface_get_stream_buffer_size(inst->core); in venc_start_session()
940 inst->stream_buffer.length = max_t(u32, stream_buffer_size, venc->cpb_size * 3); in venc_start_session()
941 ret = vpu_alloc_dma(inst->core, &inst->stream_buffer); in venc_start_session()
945 inst->use_stream_buffer = true; in venc_start_session()
946 vpu_iface_config_stream_buffer(inst, &inst->stream_buffer); in venc_start_session()
949 ret = vpu_iface_set_encode_params(inst, &venc->params, 0); in venc_start_session()
956 inst->state = VPU_CODEC_STATE_CONFIGURED; in venc_start_session()
960 ret = vpu_iface_set_encode_params(inst, &venc->params, 1); in venc_start_session()
967 inst->state = VPU_CODEC_STATE_STARTED; in venc_start_session()
969 venc->bitrate_change = false; in venc_start_session()
970 venc->input_ready = true; in venc_start_session()
971 venc->frame_count = 0; in venc_start_session()
972 venc->encode_count = 0; in venc_start_session()
973 venc->ready_count = 0; in venc_start_session()
974 venc->stopped = false; in venc_start_session()
976 if (venc->frame_count == 0) in venc_start_session()
977 dev_err(inst->dev, "[%d] there is no input when starting\n", inst->id); in venc_start_session()
982 inst->state = VPU_CODEC_STATE_DEINIT; in venc_start_session()
984 vpu_free_dma(&inst->stream_buffer); in venc_start_session()
993 venc = inst->priv; in venc_cleanup_mem_resource()
995 for (i = 0; i < ARRAY_SIZE(venc->enc); i++) in venc_cleanup_mem_resource()
996 vpu_free_dma(&venc->enc[i]); in venc_cleanup_mem_resource()
997 for (i = 0; i < ARRAY_SIZE(venc->ref); i++) in venc_cleanup_mem_resource()
998 vpu_free_dma(&venc->ref[i]); in venc_cleanup_mem_resource()
1013 venc = inst->priv; in venc_request_mem_resource()
1014 if (enc_frame_num > ARRAY_SIZE(venc->enc)) { in venc_request_mem_resource()
1015 dev_err(inst->dev, "[%d] enc num(%d) is out of range\n", inst->id, enc_frame_num); in venc_request_mem_resource()
1018 if (ref_frame_num > ARRAY_SIZE(venc->ref)) { in venc_request_mem_resource()
1019 dev_err(inst->dev, "[%d] ref num(%d) is out of range\n", inst->id, ref_frame_num); in venc_request_mem_resource()
1022 if (act_frame_num > ARRAY_SIZE(venc->act)) { in venc_request_mem_resource()
1023 dev_err(inst->dev, "[%d] act num(%d) is out of range\n", inst->id, act_frame_num); in venc_request_mem_resource()
1028 venc->enc[i].length = enc_frame_size; in venc_request_mem_resource()
1029 ret = vpu_alloc_dma(inst->core, &venc->enc[i]); in venc_request_mem_resource()
1036 venc->ref[i].length = ref_frame_size; in venc_request_mem_resource()
1037 ret = vpu_alloc_dma(inst->core, &venc->ref[i]); in venc_request_mem_resource()
1043 if (act_frame_num != 1 || act_frame_size > inst->act.length) { in venc_request_mem_resource()
1047 venc->act[0].length = act_frame_size; in venc_request_mem_resource()
1048 venc->act[0].phys = inst->act.phys; in venc_request_mem_resource()
1049 venc->act[0].virt = inst->act.virt; in venc_request_mem_resource()
1052 vpu_iface_config_memory_resource(inst, MEM_RES_ENC, i, &venc->enc[i]); in venc_request_mem_resource()
1054 vpu_iface_config_memory_resource(inst, MEM_RES_REF, i, &venc->ref[i]); in venc_request_mem_resource()
1056 vpu_iface_config_memory_resource(inst, MEM_RES_ACT, i, &venc->act[i]); in venc_request_mem_resource()
1064 list_for_each_entry_safe(frame, tmp, &venc->frames, list) { in venc_cleanup_frames()
1065 list_del_init(&frame->list); in venc_cleanup_frames()
1072 struct venc_t *venc = inst->priv; in venc_stop_session()
1075 if (venc->enable & VENC_ENABLE_MASK) in venc_stop_session()
1078 if (inst->state == VPU_CODEC_STATE_DEINIT) in venc_stop_session()
1081 if (inst->state != VPU_CODEC_STATE_STOP) in venc_stop_session()
1085 if (!wait_event_timeout(venc->wq, venc->stopped, VPU_TIMEOUT)) { in venc_stop_session()
1086 set_bit(inst->id, &inst->core->hang_mask); in venc_stop_session()
1091 inst->state = VPU_CODEC_STATE_DEINIT; in venc_stop_session()
1092 venc_cleanup_frames(inst->priv); in venc_stop_session()
1093 vpu_free_dma(&inst->stream_buffer); in venc_stop_session()
1101 struct venc_t *venc = inst->priv; in venc_process_output()
1105 if (inst->state == VPU_CODEC_STATE_DEINIT) in venc_process_output()
1106 return -EINVAL; in venc_process_output()
1109 if (inst->state == VPU_CODEC_STATE_STARTED) in venc_process_output()
1110 inst->state = VPU_CODEC_STATE_ACTIVE; in venc_process_output()
1112 flags = vbuf->flags; in venc_process_output()
1113 if (venc->request_key_frame) { in venc_process_output()
1114 vbuf->flags |= V4L2_BUF_FLAG_KEYFRAME; in venc_process_output()
1115 venc->request_key_frame = 0; in venc_process_output()
1117 if (venc->bitrate_change) { in venc_process_output()
1118 vpu_session_update_parameters(inst, &venc->params); in venc_process_output()
1119 venc->bitrate_change = false; in venc_process_output()
1121 dev_dbg(inst->dev, "[%d][INPUT TS]%32lld\n", inst->id, vb->timestamp); in venc_process_output()
1123 vbuf->flags = flags; in venc_process_output()
1124 venc->input_ready = false; in venc_process_output()
1125 venc->frame_count++; in venc_process_output()
1138 venc = inst->priv; in venc_process_capture()
1139 if (list_empty(&venc->frames)) in venc_process_capture()
1140 return -EINVAL; in venc_process_capture()
1142 frame = list_first_entry(&venc->frames, struct venc_frame_t, list); in venc_process_capture()
1144 v4l2_m2m_dst_buf_remove_by_buf(inst->fh.m2m_ctx, vbuf); in venc_process_capture()
1149 list_del_init(&frame->list); in venc_process_capture()
1156 struct venc_t *venc = inst->priv; in venc_on_queue_empty()
1161 if (venc->stopped) in venc_on_queue_empty()
1167 struct venc_t *venc = inst->priv; in venc_get_debug_info()
1168 int num = -1; in venc_get_debug_info()
1172 num = scnprintf(str, size, "profile = %d\n", venc->params.profile); in venc_get_debug_info()
1175 num = scnprintf(str, size, "level = %d\n", venc->params.level); in venc_get_debug_info()
1179 venc->params.frame_rate.numerator, in venc_get_debug_info()
1180 venc->params.frame_rate.denominator); in venc_get_debug_info()
1183 num = scnprintf(str, size, "%d x %d -> %d x %d\n", in venc_get_debug_info()
1184 venc->params.src_width, in venc_get_debug_info()
1185 venc->params.src_height, in venc_get_debug_info()
1186 venc->params.out_width, in venc_get_debug_info()
1187 venc->params.out_height); in venc_get_debug_info()
1191 venc->params.crop.left, in venc_get_debug_info()
1192 venc->params.crop.top, in venc_get_debug_info()
1193 venc->params.crop.width, in venc_get_debug_info()
1194 venc->params.crop.height); in venc_get_debug_info()
1199 venc->enable, in venc_get_debug_info()
1200 venc->frame_count, venc->encode_count, in venc_get_debug_info()
1201 venc->ready_count, in venc_get_debug_info()
1202 venc->stopped); in venc_get_debug_info()
1205 num = scnprintf(str, size, "gop = %d\n", venc->params.gop_length); in venc_get_debug_info()
1208 num = scnprintf(str, size, "bframes = %d\n", venc->params.bframes); in venc_get_debug_info()
1212 venc->params.rc_enable ? "enable" : "disable", in venc_get_debug_info()
1213 venc->params.rc_mode, in venc_get_debug_info()
1214 venc->params.bitrate, in venc_get_debug_info()
1215 venc->params.bitrate_max, in venc_get_debug_info()
1216 venc->params.i_frame_qp); in venc_get_debug_info()
1220 venc->params.sar.enable, in venc_get_debug_info()
1221 venc->params.sar.idc, in venc_get_debug_info()
1222 venc->params.sar.width, in venc_get_debug_info()
1223 venc->params.sar.height); in venc_get_debug_info()
1229 venc->params.color.primaries, in venc_get_debug_info()
1230 venc->params.color.transfer, in venc_get_debug_info()
1231 venc->params.color.matrix, in venc_get_debug_info()
1232 venc->params.color.full_range); in venc_get_debug_info()
1236 venc->skipped_count, venc->skipped_bytes); in venc_get_debug_info()
1272 venc = inst->priv; in venc_init()
1273 venc->params.qp_min = 1; in venc_init()
1274 venc->params.qp_max = 51; in venc_init()
1275 venc->params.qp_min_i = 1; in venc_init()
1276 venc->params.qp_max_i = 51; in venc_init()
1277 venc->params.bitrate_min = BITRATE_MIN; in venc_init()
1286 venc_s_fmt(file, &inst->fh, &f); in venc_init()
1294 venc_s_fmt(file, &inst->fh, &f); in venc_init()
1300 venc_s_parm(file, &inst->fh, &parm); in venc_init()
1311 return -ENOMEM; in venc_open()
1316 return -ENOMEM; in venc_open()
1319 inst->ops = &venc_inst_ops; in venc_open()
1320 inst->formats = venc_formats; in venc_open()
1321 inst->type = VPU_CORE_TYPE_ENC; in venc_open()
1322 inst->priv = venc; in venc_open()
1323 INIT_LIST_HEAD(&venc->frames); in venc_open()
1324 init_waitqueue_head(&venc->wq); in venc_open()
1330 inst->min_buffer_out = VENC_MIN_BUFFER_OUT; in venc_open()
1331 inst->min_buffer_cap = VENC_MIN_BUFFER_CAP; in venc_open()