media: amphion: reinit vpu if reqbufs output 0
authorMing Qian <ming.qian@nxp.com>
Tue, 13 Jun 2023 07:48:46 +0000 (15:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:50 +0000 (09:42 +0200)
[ Upstream commit 73e3f09292a0492a3fe0f87a8170a74f12624c5e ]

according to v4l2 stateful decoder document 4.5.1.3. State Machine,
the state should change from seek to initialization
if call VIDIOC_REQBUFS(OUTPUT, 0).

so reinit the vpu decoder if reqbufs output 0

Fixes: 6de8d628df6e ("media: amphion: add v4l2 m2m vpu decoder stateful driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Tested-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/amphion/vdec.c
drivers/media/platform/amphion/vpu_v4l2.c

index c08b5a2bfc1df4721724526cfc8f5bde959ef317..8edb313cd6358b4d080bd6f9f322b7124ec8d96c 100644 (file)
@@ -1407,9 +1407,7 @@ static void vdec_release(struct vpu_inst *inst)
 {
        if (inst->id != VPU_INST_NULL_ID)
                vpu_trace(inst->dev, "[%d]\n", inst->id);
-       vpu_inst_lock(inst);
        vdec_stop(inst, true);
-       vpu_inst_unlock(inst);
 }
 
 static void vdec_cleanup(struct vpu_inst *inst)
index a74953191c22106b2bb9da930bbf32dff42ef0f1..e5c8e1a753ccd7220b8caf5fbc3671b6ff571e95 100644 (file)
@@ -404,6 +404,11 @@ static int vpu_vb2_queue_setup(struct vb2_queue *vq,
        for (i = 0; i < cur_fmt->num_planes; i++)
                psize[i] = cur_fmt->sizeimage[i];
 
+       if (V4L2_TYPE_IS_OUTPUT(vq->type) && inst->state == VPU_CODEC_STATE_SEEK) {
+               vpu_trace(inst->dev, "reinit when VIDIOC_REQBUFS(OUTPUT, 0)\n");
+               call_void_vop(inst, release);
+       }
+
        return 0;
 }
 
@@ -688,9 +693,9 @@ int vpu_v4l2_close(struct file *file)
                v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
                inst->fh.m2m_ctx = NULL;
        }
+       call_void_vop(inst, release);
        vpu_inst_unlock(inst);
 
-       call_void_vop(inst, release);
        vpu_inst_unregister(inst);
        vpu_inst_put(inst);