media: s5p-mfc: DPB Count Independent of VIDIOC_REQBUF
authorAakarsh Jain <aakarsh.jain@samsung.com>
Wed, 13 Dec 2023 08:11:05 +0000 (13:41 +0530)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Wed, 13 Dec 2023 13:33:49 +0000 (14:33 +0100)
Add allocation of DPB buffers based on MFC requirement so,
codec buffers allocations has been moved after state
MFCINST_HEAD_PRODUCED. It is taken care that codec buffer allocation
is performed in process context from userspace IOCTL call.

Cc: linux-fsd@tesla.com
Signed-off-by: Smitha T Murthy <smithatmurthy@gmail.com>
Signed-off-by: Aakarsh Jain <aakarsh.jain@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_enc.c
drivers/media/platform/samsung/s5p-mfc/s5p_mfc_opr_v6.c

index ae3764969473d566a2c8a0bc4ce5a0a6a39a3af1..ef8bb40b9712e4cd39eb489a4fc83472d53a2a26 100644 (file)
@@ -1164,7 +1164,6 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
        struct s5p_mfc_dev *dev = ctx->dev;
        struct s5p_mfc_enc_params *p = &ctx->enc_params;
        struct s5p_mfc_buf *dst_mb;
-       unsigned int enc_pb_count;
 
        if (p->seq_hdr_mode == V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE) {
                if (!list_empty(&ctx->dst_queue)) {
@@ -1186,10 +1185,7 @@ static int enc_post_seq_start(struct s5p_mfc_ctx *ctx)
                        set_work_bit_irqsave(ctx);
                s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
        } else {
-               enc_pb_count = s5p_mfc_hw_call(dev->mfc_ops,
-                               get_enc_dpb_count, dev);
-               if (ctx->pb_count < enc_pb_count)
-                       ctx->pb_count = enc_pb_count;
+               ctx->pb_count = s5p_mfc_hw_call(dev->mfc_ops, get_enc_dpb_count, dev);
                if (FW_HAS_E_MIN_SCRATCH_BUF(dev)) {
                        ctx->scratch_buf_size = s5p_mfc_hw_call(dev->mfc_ops,
                                        get_e_min_scratch_buf_size, dev);
@@ -1564,14 +1560,6 @@ static int vidioc_reqbufs(struct file *file, void *priv,
                }
                ctx->capture_state = QUEUE_BUFS_REQUESTED;
 
-               ret = s5p_mfc_hw_call(ctx->dev->mfc_ops,
-                               alloc_codec_buffers, ctx);
-               if (ret) {
-                       mfc_err("Failed to allocate encoding buffers\n");
-                       reqbufs->count = 0;
-                       ret = vb2_reqbufs(&ctx->vq_dst, reqbufs);
-                       return -ENOMEM;
-               }
        } else if (reqbufs->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                if (reqbufs->count == 0) {
                        mfc_debug(2, "Freeing buffers\n");
@@ -1587,15 +1575,13 @@ static int vidioc_reqbufs(struct file *file, void *priv,
                        return -EINVAL;
                }
 
-               if (IS_MFCV6_PLUS(dev)) {
+               if (IS_MFCV6_PLUS(dev) && (!IS_MFCV12(dev))) {
                        /* Check for min encoder buffers */
                        if (ctx->pb_count &&
                                (reqbufs->count < ctx->pb_count)) {
                                reqbufs->count = ctx->pb_count;
                                mfc_debug(2, "Minimum %d output buffers needed\n",
                                                ctx->pb_count);
-                       } else {
-                               ctx->pb_count = reqbufs->count;
                        }
                }
 
index 572293f3b1903d178c1114ef2a570b6fc0d4efc1..fd945211d28e7793176a06a6c400e476aad2b30f 100644 (file)
@@ -2110,6 +2110,13 @@ static inline int s5p_mfc_run_init_enc_buffers(struct s5p_mfc_ctx *ctx)
        struct s5p_mfc_dev *dev = ctx->dev;
        int ret;
 
+       ret = s5p_mfc_hw_call(ctx->dev->mfc_ops, alloc_codec_buffers, ctx);
+       if (ret) {
+               mfc_err("Failed to allocate encoding buffers\n");
+               return -ENOMEM;
+       }
+       mfc_debug(2, "Allocated Internal Encoding Buffers\n");
+
        dev->curr_ctx = ctx->num;
        ret = s5p_mfc_set_enc_ref_buffer_v6(ctx);
        if (ret) {