mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-21 00:54:52 -04:00
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. Tested-by: Vikash Garodia <quic_vgarodia@quicinc.com> # X1E80100 Reviewed-by: Vikash Garodia <quic_vgarodia@quicinc.com> Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8550-HDK Tested-by: Neil Armstrong <neil.armstrong@linaro.org> # on SM8650-HDK Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> # x1e80100-crd Signed-off-by: Bryan O'Donoghue <bod@kernel.org> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
This commit is contained in:
committed by
Hans Verkuil
parent
8cefa0ac93
commit
75db90ae06
@@ -450,15 +450,31 @@ static int iris_hfi_gen1_session_unset_buffers(struct iris_inst *inst, struct ir
|
||||
|
||||
static int iris_hfi_gen1_session_drain(struct iris_inst *inst, u32 plane)
|
||||
{
|
||||
struct hfi_session_empty_buffer_compressed_pkt ip_pkt = {0};
|
||||
if (inst->domain == DECODER) {
|
||||
struct hfi_session_empty_buffer_compressed_pkt ip_pkt = {0};
|
||||
|
||||
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_compressed_pkt);
|
||||
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
|
||||
ip_pkt.shdr.session_id = inst->session_id;
|
||||
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
|
||||
ip_pkt.packet_buffer = 0xdeadb000;
|
||||
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_compressed_pkt);
|
||||
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
|
||||
ip_pkt.shdr.session_id = inst->session_id;
|
||||
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
|
||||
ip_pkt.packet_buffer = 0xdeadb000;
|
||||
|
||||
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
|
||||
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
|
||||
}
|
||||
|
||||
if (inst->domain == ENCODER) {
|
||||
struct hfi_session_empty_buffer_uncompressed_pkt ip_pkt = {0};
|
||||
|
||||
ip_pkt.shdr.hdr.size = sizeof(struct hfi_session_empty_buffer_uncompressed_pkt);
|
||||
ip_pkt.shdr.hdr.pkt_type = HFI_CMD_SESSION_EMPTY_BUFFER;
|
||||
ip_pkt.shdr.session_id = inst->session_id;
|
||||
ip_pkt.flags = HFI_BUFFERFLAG_EOS;
|
||||
ip_pkt.packet_buffer = 0xdeadb000;
|
||||
|
||||
return iris_hfi_queue_cmd_write(inst->core, &ip_pkt, ip_pkt.shdr.hdr.size);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -485,6 +485,11 @@ static void iris_hfi_gen1_session_ftb_done(struct iris_inst *inst, void *packet)
|
||||
flags |= V4L2_BUF_FLAG_LAST;
|
||||
inst->last_buffer_dequeued = true;
|
||||
}
|
||||
} else if (inst->domain == ENCODER) {
|
||||
if (!inst->last_buffer_dequeued && iris_drain_pending(inst)) {
|
||||
flags |= V4L2_BUF_FLAG_LAST;
|
||||
inst->last_buffer_dequeued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
buf->timestamp = timestamp_us;
|
||||
|
||||
@@ -263,11 +263,11 @@ bool iris_allow_cmd(struct iris_inst *inst, u32 cmd)
|
||||
struct vb2_queue *src_q = v4l2_m2m_get_src_vq(inst->m2m_ctx);
|
||||
struct vb2_queue *dst_q = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
|
||||
|
||||
if (cmd == V4L2_DEC_CMD_START) {
|
||||
if (cmd == V4L2_DEC_CMD_START || cmd == V4L2_ENC_CMD_START) {
|
||||
if (vb2_is_streaming(src_q) || vb2_is_streaming(dst_q))
|
||||
if (iris_drc_pending(inst) || iris_drain_pending(inst))
|
||||
return true;
|
||||
} else if (cmd == V4L2_DEC_CMD_STOP) {
|
||||
} else if (cmd == V4L2_DEC_CMD_STOP || cmd == V4L2_ENC_CMD_STOP) {
|
||||
if (vb2_is_streaming(src_q))
|
||||
if (inst->sub_state != IRIS_INST_SUB_DRAIN)
|
||||
return true;
|
||||
|
||||
@@ -519,3 +519,61 @@ int iris_venc_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf)
|
||||
|
||||
return iris_queue_buffer(inst, buf);
|
||||
}
|
||||
|
||||
int iris_venc_start_cmd(struct iris_inst *inst)
|
||||
{
|
||||
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
|
||||
enum iris_inst_sub_state clear_sub_state = 0;
|
||||
struct vb2_queue *dst_vq;
|
||||
int ret;
|
||||
|
||||
dst_vq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
|
||||
|
||||
if (inst->sub_state & IRIS_INST_SUB_DRAIN &&
|
||||
inst->sub_state & IRIS_INST_SUB_DRAIN_LAST) {
|
||||
vb2_clear_last_buffer_dequeued(dst_vq);
|
||||
clear_sub_state = IRIS_INST_SUB_DRAIN | IRIS_INST_SUB_DRAIN_LAST;
|
||||
if (inst->sub_state & IRIS_INST_SUB_INPUT_PAUSE) {
|
||||
if (hfi_ops->session_resume_drain) {
|
||||
ret = hfi_ops->session_resume_drain(inst,
|
||||
V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
clear_sub_state |= IRIS_INST_SUB_INPUT_PAUSE;
|
||||
}
|
||||
if (inst->sub_state & IRIS_INST_SUB_OUTPUT_PAUSE) {
|
||||
if (hfi_ops->session_resume_drain) {
|
||||
ret = hfi_ops->session_resume_drain(inst,
|
||||
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
clear_sub_state |= IRIS_INST_SUB_OUTPUT_PAUSE;
|
||||
}
|
||||
} else {
|
||||
dev_err(inst->core->dev, "start called before receiving last_flag\n");
|
||||
iris_inst_change_state(inst, IRIS_INST_ERROR);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
inst->last_buffer_dequeued = false;
|
||||
|
||||
return iris_inst_change_sub_state(inst, clear_sub_state, 0);
|
||||
}
|
||||
|
||||
int iris_venc_stop_cmd(struct iris_inst *inst)
|
||||
{
|
||||
const struct iris_hfi_command_ops *hfi_ops = inst->core->hfi_ops;
|
||||
int ret;
|
||||
|
||||
ret = hfi_ops->session_drain(inst, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = iris_inst_change_sub_state(inst, 0, IRIS_INST_SUB_DRAIN);
|
||||
|
||||
iris_scale_power(inst);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,7 @@ int iris_venc_s_param(struct iris_inst *inst, struct v4l2_streamparm *s_parm);
|
||||
int iris_venc_streamon_input(struct iris_inst *inst);
|
||||
int iris_venc_streamon_output(struct iris_inst *inst);
|
||||
int iris_venc_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf);
|
||||
int iris_venc_start_cmd(struct iris_inst *inst);
|
||||
int iris_venc_stop_cmd(struct iris_inst *inst);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -597,6 +597,39 @@ static int iris_dec_cmd(struct file *filp, void *fh,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int iris_enc_cmd(struct file *filp, void *fh,
|
||||
struct v4l2_encoder_cmd *enc)
|
||||
{
|
||||
struct iris_inst *inst = iris_get_inst(filp);
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&inst->lock);
|
||||
|
||||
ret = v4l2_m2m_ioctl_encoder_cmd(filp, fh, enc);
|
||||
if (ret)
|
||||
goto unlock;
|
||||
|
||||
if (inst->state == IRIS_INST_DEINIT)
|
||||
goto unlock;
|
||||
|
||||
if (!iris_allow_cmd(inst, enc->cmd)) {
|
||||
ret = -EBUSY;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
if (enc->cmd == V4L2_ENC_CMD_START)
|
||||
ret = iris_venc_start_cmd(inst);
|
||||
else if (enc->cmd == V4L2_ENC_CMD_STOP)
|
||||
ret = iris_venc_stop_cmd(inst);
|
||||
else
|
||||
ret = -EINVAL;
|
||||
|
||||
unlock:
|
||||
mutex_unlock(&inst->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct v4l2_file_operations iris_v4l2_file_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = iris_open,
|
||||
@@ -672,6 +705,8 @@ static const struct v4l2_ioctl_ops iris_v4l2_ioctl_ops_enc = {
|
||||
.vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
|
||||
.vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
|
||||
.vidioc_remove_bufs = v4l2_m2m_ioctl_remove_bufs,
|
||||
.vidioc_try_encoder_cmd = v4l2_m2m_ioctl_try_encoder_cmd,
|
||||
.vidioc_encoder_cmd = iris_enc_cmd,
|
||||
};
|
||||
|
||||
void iris_init_ops(struct iris_core *core)
|
||||
|
||||
Reference in New Issue
Block a user