Commit acf8a57d authored by Stanimir Varbanov's avatar Stanimir Varbanov Committed by Mauro Carvalho Chehab

media: venus: vdec: Fix non reliable setting of LAST flag

In real use of dynamic-resolution-change it is observed that the
LAST buffer flag (which marks the last decoded buffer with the
resolution before the resolution-change event) is not reliably set.

Fix this by set the LAST buffer flag on next queued capture buffer
after the resolution-change event.
Signed-off-by: default avatarStanimir Varbanov <stanimir.varbanov@linaro.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent cc82fd69
...@@ -285,7 +285,6 @@ enum venus_dec_state { ...@@ -285,7 +285,6 @@ enum venus_dec_state {
VENUS_DEC_STATE_DRAIN = 5, VENUS_DEC_STATE_DRAIN = 5,
VENUS_DEC_STATE_DECODING = 6, VENUS_DEC_STATE_DECODING = 6,
VENUS_DEC_STATE_DRC = 7, VENUS_DEC_STATE_DRC = 7,
VENUS_DEC_STATE_DRC_FLUSH_DONE = 8,
}; };
struct venus_ts_metadata { struct venus_ts_metadata {
...@@ -350,7 +349,7 @@ struct venus_ts_metadata { ...@@ -350,7 +349,7 @@ struct venus_ts_metadata {
* @priv: a private for HFI operations callbacks * @priv: a private for HFI operations callbacks
* @session_type: the type of the session (decoder or encoder) * @session_type: the type of the session (decoder or encoder)
* @hprop: a union used as a holder by get property * @hprop: a union used as a holder by get property
* @last_buf: last capture buffer for dynamic-resoluton-change * @next_buf_last: a flag to mark next queued capture buffer as last
*/ */
struct venus_inst { struct venus_inst {
struct list_head list; struct list_head list;
...@@ -413,7 +412,7 @@ struct venus_inst { ...@@ -413,7 +412,7 @@ struct venus_inst {
union hfi_get_property hprop; union hfi_get_property hprop;
unsigned int core_acquired: 1; unsigned int core_acquired: 1;
unsigned int bit_depth; unsigned int bit_depth;
struct vb2_buffer *last_buf; bool next_buf_last;
}; };
#define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX) #define IS_V1(core) ((core)->res->hfi_version == HFI_VERSION_1XX)
......
...@@ -1342,6 +1342,12 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb) ...@@ -1342,6 +1342,12 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb)
v4l2_m2m_buf_queue(m2m_ctx, vbuf); v4l2_m2m_buf_queue(m2m_ctx, vbuf);
/* Skip processing queued capture buffers after LAST flag */
if (inst->session_type == VIDC_SESSION_TYPE_DEC &&
V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) &&
inst->codec_state == VENUS_DEC_STATE_DRC)
goto unlock;
cache_payload(inst, vb); cache_payload(inst, vb);
if (inst->session_type == VIDC_SESSION_TYPE_ENC && if (inst->session_type == VIDC_SESSION_TYPE_ENC &&
......
...@@ -917,10 +917,6 @@ static int vdec_start_capture(struct venus_inst *inst) ...@@ -917,10 +917,6 @@ static int vdec_start_capture(struct venus_inst *inst)
return 0; return 0;
reconfigure: reconfigure:
ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true);
if (ret)
return ret;
ret = vdec_output_conf(inst); ret = vdec_output_conf(inst);
if (ret) if (ret)
return ret; return ret;
...@@ -948,6 +944,8 @@ static int vdec_start_capture(struct venus_inst *inst) ...@@ -948,6 +944,8 @@ static int vdec_start_capture(struct venus_inst *inst)
venus_pm_load_scale(inst); venus_pm_load_scale(inst);
inst->next_buf_last = false;
ret = hfi_session_continue(inst); ret = hfi_session_continue(inst);
if (ret) if (ret)
goto free_dpb_bufs; goto free_dpb_bufs;
...@@ -988,6 +986,7 @@ static int vdec_start_output(struct venus_inst *inst) ...@@ -988,6 +986,7 @@ static int vdec_start_output(struct venus_inst *inst)
venus_helper_init_instance(inst); venus_helper_init_instance(inst);
inst->sequence_out = 0; inst->sequence_out = 0;
inst->reconfig = false; inst->reconfig = false;
inst->next_buf_last = false;
ret = vdec_set_properties(inst); ret = vdec_set_properties(inst);
if (ret) if (ret)
...@@ -1081,9 +1080,7 @@ static int vdec_stop_capture(struct venus_inst *inst) ...@@ -1081,9 +1080,7 @@ static int vdec_stop_capture(struct venus_inst *inst)
inst->codec_state = VENUS_DEC_STATE_STOPPED; inst->codec_state = VENUS_DEC_STATE_STOPPED;
break; break;
case VENUS_DEC_STATE_DRC: case VENUS_DEC_STATE_DRC:
WARN_ON(1); ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, true);
fallthrough;
case VENUS_DEC_STATE_DRC_FLUSH_DONE:
inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP; inst->codec_state = VENUS_DEC_STATE_CAPTURE_SETUP;
venus_helper_free_dpb_bufs(inst); venus_helper_free_dpb_bufs(inst);
break; break;
...@@ -1207,9 +1204,28 @@ static void vdec_buf_cleanup(struct vb2_buffer *vb) ...@@ -1207,9 +1204,28 @@ static void vdec_buf_cleanup(struct vb2_buffer *vb)
static void vdec_vb2_buf_queue(struct vb2_buffer *vb) static void vdec_vb2_buf_queue(struct vb2_buffer *vb)
{ {
struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue); struct venus_inst *inst = vb2_get_drv_priv(vb->vb2_queue);
struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
static const struct v4l2_event eos = { .type = V4L2_EVENT_EOS };
vdec_pm_get_put(inst); vdec_pm_get_put(inst);
mutex_lock(&inst->lock);
if (inst->next_buf_last && V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) &&
inst->codec_state == VENUS_DEC_STATE_DRC) {
vbuf->flags |= V4L2_BUF_FLAG_LAST;
vbuf->sequence = inst->sequence_cap++;
vbuf->field = V4L2_FIELD_NONE;
vb2_set_plane_payload(vb, 0, 0);
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE);
v4l2_event_queue_fh(&inst->fh, &eos);
inst->next_buf_last = false;
mutex_unlock(&inst->lock);
return;
}
mutex_unlock(&inst->lock);
venus_helper_vb2_buf_queue(vb); venus_helper_vb2_buf_queue(vb);
} }
...@@ -1253,13 +1269,6 @@ static void vdec_buf_done(struct venus_inst *inst, unsigned int buf_type, ...@@ -1253,13 +1269,6 @@ static void vdec_buf_done(struct venus_inst *inst, unsigned int buf_type,
vb->timestamp = timestamp_us * NSEC_PER_USEC; vb->timestamp = timestamp_us * NSEC_PER_USEC;
vbuf->sequence = inst->sequence_cap++; vbuf->sequence = inst->sequence_cap++;
if (inst->last_buf == vb) {
inst->last_buf = NULL;
vbuf->flags |= V4L2_BUF_FLAG_LAST;
vb2_set_plane_payload(vb, 0, 0);
vb->timestamp = 0;
}
if (vbuf->flags & V4L2_BUF_FLAG_LAST) { if (vbuf->flags & V4L2_BUF_FLAG_LAST) {
const struct v4l2_event ev = { .type = V4L2_EVENT_EOS }; const struct v4l2_event ev = { .type = V4L2_EVENT_EOS };
...@@ -1359,12 +1368,9 @@ static void vdec_event_change(struct venus_inst *inst, ...@@ -1359,12 +1368,9 @@ static void vdec_event_change(struct venus_inst *inst,
*/ */
if (!sufficient && inst->codec_state == VENUS_DEC_STATE_DRC) { if (!sufficient && inst->codec_state == VENUS_DEC_STATE_DRC) {
struct vb2_v4l2_buffer *last;
int ret; int ret;
last = v4l2_m2m_last_dst_buf(inst->m2m_ctx); inst->next_buf_last = true;
if (last)
inst->last_buf = &last->vb2_buf;
ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false); ret = hfi_session_flush(inst, HFI_FLUSH_OUTPUT, false);
if (ret) if (ret)
...@@ -1413,8 +1419,7 @@ static void vdec_event_notify(struct venus_inst *inst, u32 event, ...@@ -1413,8 +1419,7 @@ static void vdec_event_notify(struct venus_inst *inst, u32 event,
static void vdec_flush_done(struct venus_inst *inst) static void vdec_flush_done(struct venus_inst *inst)
{ {
if (inst->codec_state == VENUS_DEC_STATE_DRC) dev_dbg(inst->core->dev_dec, VDBGH "flush done\n");
inst->codec_state = VENUS_DEC_STATE_DRC_FLUSH_DONE;
} }
static const struct hfi_inst_ops vdec_hfi_ops = { static const struct hfi_inst_ops vdec_hfi_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment