media: vicodec: bugfix - call v4l2_m2m_buf_copy_metadata also if decoding fails
authorDafna Hirschfeld <dafna3@gmail.com>
Wed, 6 Mar 2019 21:13:28 +0000 (16:13 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 25 Mar 2019 17:41:38 +0000 (13:41 -0400)
The function 'v4l2_m2m_buf_copy_metadata' should
be called even if decoding/encoding ends with
status VB2_BUF_STATE_ERROR, so that the metadata
is copied from the source buffer to the dest buffer.

Signed-off-by: Dafna Hirschfeld <dafna3@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/vicodec/vicodec-core.c

index 47765751eed7b1193c5d29c8c243b0699af4f9d3..11fbc44973b2ba81585a369f2d764c74e993350d 100644 (file)
@@ -158,12 +158,10 @@ static int device_process(struct vicodec_ctx *ctx,
                          struct vb2_v4l2_buffer *dst_vb)
 {
        struct vicodec_dev *dev = ctx->dev;
-       struct vicodec_q_data *q_dst;
        struct v4l2_fwht_state *state = &ctx->state;
        u8 *p_src, *p_dst;
        int ret;
 
-       q_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
        if (ctx->is_enc)
                p_src = vb2_plane_vaddr(&src_vb->vb2_buf, 0);
        else
@@ -186,8 +184,10 @@ static int device_process(struct vicodec_ctx *ctx,
                        return comp_sz_or_errcode;
                vb2_set_plane_payload(&dst_vb->vb2_buf, 0, comp_sz_or_errcode);
        } else {
+               struct vicodec_q_data *q_dst;
                unsigned int comp_frame_size = ntohl(ctx->state.header.size);
 
+               q_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
                if (comp_frame_size > ctx->comp_max_size)
                        return -EINVAL;
                state->info = q_dst->info;
@@ -196,11 +196,6 @@ static int device_process(struct vicodec_ctx *ctx,
                        return ret;
                vb2_set_plane_payload(&dst_vb->vb2_buf, 0, q_dst->sizeimage);
        }
-
-       dst_vb->sequence = q_dst->sequence++;
-       dst_vb->flags &= ~V4L2_BUF_FLAG_LAST;
-       v4l2_m2m_buf_copy_metadata(src_vb, dst_vb, !ctx->is_enc);
-
        return 0;
 }
 
@@ -274,16 +269,22 @@ static void device_run(void *priv)
        struct vicodec_ctx *ctx = priv;
        struct vicodec_dev *dev = ctx->dev;
        struct vb2_v4l2_buffer *src_buf, *dst_buf;
-       struct vicodec_q_data *q_src;
+       struct vicodec_q_data *q_src, *q_dst;
        u32 state;
 
        src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
        dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
        q_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+       q_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
 
        state = VB2_BUF_STATE_DONE;
        if (device_process(ctx, src_buf, dst_buf))
                state = VB2_BUF_STATE_ERROR;
+       else
+               dst_buf->sequence = q_dst->sequence++;
+       dst_buf->flags &= ~V4L2_BUF_FLAG_LAST;
+       v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, !ctx->is_enc);
+
        ctx->last_dst_buf = dst_buf;
 
        spin_lock(ctx->lock);