Skip to content

Commit 4449558

Browse files
author
Dikshita Agarwal
committed
FROMLIST: media: iris: Add support for drain sequence in encoder video device
Add support for handling start and stop commands, including the end-of-stream (drain) sequence, in the encoder video device. This enables proper signaling to the firmware and ensures that all pending frames are processed and flushed before completing the stream. Link: https://lore.kernel.org/linux-media/[email protected]/ Signed-off-by: Dikshita Agarwal <[email protected]>
1 parent cef00f3 commit 4449558

File tree

5 files changed

+123
-7
lines changed

5 files changed

+123
-7
lines changed

drivers/media/platform/qcom/iris/iris_hfi_gen1_command.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,31 @@ static int iris_hfi_gen1_session_unset_buffers(struct iris_inst *inst, struct ir
455455

456456
static int iris_hfi_gen1_session_drain(struct iris_inst *inst, u32 plane)
457457
{
458-
struct hfi_session_empty_buffer_compressed_pkt ip_pkt = {0};
458+
if (inst->domain == DECODER) {
459+
struct hfi_session_empty_buffer_compressed_pkt ip_pkt = {0};
460+
461+
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_compressed_pkt);
462+
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
463+
ip_pkt.shdr.session_id = inst->session_id;
464+
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
465+
ip_pkt.packet_buffer = 0xdeadb000;
466+
467+
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
468+
}
459469

460-
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_compressed_pkt);
461-
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
462-
ip_pkt.shdr.session_id = inst->session_id;
463-
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
464-
ip_pkt.packet_buffer = 0xdeadb000;
470+
if (inst->domain == ENCODER) {
471+
struct hfi_session_empty_buffer_uncompressed_pkt ip_pkt = {0};
472+
473+
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_uncompressed_pkt);
474+
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
475+
ip_pkt.shdr.session_id = inst->session_id;
476+
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
477+
ip_pkt.packet_buffer = 0xdeadb000;
478+
479+
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
480+
}
465481

466-
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
482+
return -EINVAL;
467483
}
468484

469485
static int

drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ static void iris_hfi_gen1_session_ftb_done(struct iris_inst *inst, void *packet)
487487
flags |= V4L2_BUF_FLAG_LAST;
488488
inst->last_buffer_dequeued = true;
489489
}
490+
} else if (inst->domain == ENCODER) {
491+
if (!inst->last_buffer_dequeued && iris_drain_pending(inst)) {
492+
flags |= V4L2_BUF_FLAG_LAST;
493+
inst->last_buffer_dequeued = true;
494+
}
490495
}
491496
}
492497
buf->timestamp = timestamp_us;

drivers/media/platform/qcom/iris/iris_venc.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,61 @@ int iris_venc_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf)
519519

520520
return iris_queue_buffer(inst, buf);
521521
}
522+
523+
int iris_venc_start_cmd(struct iris_inst *inst)
524+
{
525+
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
526+
enum iris_inst_sub_state clear_sub_state = 0;
527+
struct vb2_queue *dst_vq;
528+
int ret;
529+
530+
dst_vq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
531+
532+
if (inst->sub_state & IRIS_INST_SUB_DRAIN &&
533+
inst->sub_state & IRIS_INST_SUB_DRAIN_LAST) {
534+
vb2_clear_last_buffer_dequeued(dst_vq);
535+
clear_sub_state = IRIS_INST_SUB_DRAIN | IRIS_INST_SUB_DRAIN_LAST;
536+
if (inst->sub_state & IRIS_INST_SUB_INPUT_PAUSE) {
537+
if (hfi_ops->session_resume_drain) {
538+
ret = hfi_ops->session_resume_drain(inst,
539+
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
540+
if (ret)
541+
return ret;
542+
}
543+
clear_sub_state |= IRIS_INST_SUB_INPUT_PAUSE;
544+
}
545+
if (inst->sub_state & IRIS_INST_SUB_OUTPUT_PAUSE) {
546+
if (hfi_ops->session_resume_drain) {
547+
ret = hfi_ops->session_resume_drain(inst,
548+
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
549+
if (ret)
550+
return ret;
551+
}
552+
clear_sub_state |= IRIS_INST_SUB_OUTPUT_PAUSE;
553+
}
554+
} else {
555+
dev_err(inst->core->dev, "start called before receiving last_flag\n");
556+
iris_inst_change_state(inst, IRIS_INST_ERROR);
557+
return -EBUSY;
558+
}
559+
560+
inst->last_buffer_dequeued = false;
561+
562+
return iris_inst_change_sub_state(inst, clear_sub_state, 0);
563+
}
564+
565+
int iris_venc_stop_cmd(struct iris_inst *inst)
566+
{
567+
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
568+
int ret;
569+
570+
ret = hfi_ops->session_drain(inst, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
571+
if (ret)
572+
return ret;
573+
574+
ret = iris_inst_change_sub_state(inst, 0, IRIS_INST_SUB_DRAIN);
575+
576+
iris_scale_power(inst);
577+
578+
return ret;
579+
}

drivers/media/platform/qcom/iris/iris_venc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ int iris_venc_s_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm);
2121
int iris_venc_streamon_input(struct iris_inst *inst);
2222
int iris_venc_streamon_output(struct iris_inst *inst);
2323
int iris_venc_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf);
24+
int iris_venc_start_cmd(struct iris_inst *inst);
25+
int iris_venc_stop_cmd(struct iris_inst *inst);
2426

2527
#endif

drivers/media/platform/qcom/iris/iris_vidc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,39 @@ static int iris_dec_cmd(struct file *filp, void *fh,
598598
return ret;
599599
}
600600

601+
static int iris_enc_cmd(struct file *filp, void *fh,
602+
struct v4l2_encoder_cmd *enc)
603+
{
604+
struct iris_inst *inst = iris_get_inst(filp, NULL);
605+
int ret = 0;
606+
607+
mutex_lock(&inst->lock);
608+
609+
ret = v4l2_m2m_ioctl_encoder_cmd(filp, fh, enc);
610+
if (ret)
611+
goto unlock;
612+
613+
if (inst->state == IRIS_INST_DEINIT)
614+
goto unlock;
615+
616+
if (!iris_allow_cmd(inst, enc->cmd)) {
617+
ret = -EBUSY;
618+
goto unlock;
619+
}
620+
621+
if (enc->cmd == V4L2_ENC_CMD_START)
622+
ret = iris_venc_start_cmd(inst);
623+
else if (enc->cmd == V4L2_ENC_CMD_STOP)
624+
ret = iris_venc_stop_cmd(inst);
625+
else
626+
ret = -EINVAL;
627+
628+
unlock:
629+
mutex_unlock(&inst->lock);
630+
631+
return ret;
632+
}
633+
601634
static struct v4l2_file_operations iris_v4l2_file_ops = {
602635
.owner = THIS_MODULE,
603636
.open = iris_open,
@@ -673,6 +706,8 @@ static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops_enc = {
673706
.vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
674707
.vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
675708
.vidioc_remove_bufs = v4l2_m2m_ioctl_remove_bufs,
709+
.vidioc_try_encoder_cmd = v4l2_m2m_ioctl_try_encoder_cmd,
710+
.vidioc_encoder_cmd = iris_enc_cmd,
676711
};
677712

678713
void iris_init_ops(struct iris_core *core)

0 commit comments

Comments
 (0)