media: cedrus: set codec ops immediately
authorJernej Skrabec <jernej.skrabec@gmail.com>
Wed, 2 Nov 2022 18:08:05 +0000 (19:08 +0100)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 4 Nov 2022 15:56:35 +0000 (16:56 +0100)
We'll need codec ops soon after output format is set in following
commits. Let's move current codec setup to set output format callback.
While at it, let's remove one level of indirection by changing
current_codec to point to codec ops structure directly.

Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/staging/media/sunxi/cedrus/cedrus.c
drivers/staging/media/sunxi/cedrus/cedrus.h
drivers/staging/media/sunxi/cedrus/cedrus_dec.c
drivers/staging/media/sunxi/cedrus/cedrus_hw.c
drivers/staging/media/sunxi/cedrus/cedrus_video.c

index a88ca89d966da6a80addeb14e88863454b4d6489..37b1df9a9d6abdc100b12918f16a502cca2acaac 100644 (file)
@@ -456,11 +456,6 @@ static int cedrus_probe(struct platform_device *pdev)
                return ret;
        }
 
-       dev->dec_ops[CEDRUS_CODEC_MPEG2] = &cedrus_dec_ops_mpeg2;
-       dev->dec_ops[CEDRUS_CODEC_H264] = &cedrus_dec_ops_h264;
-       dev->dec_ops[CEDRUS_CODEC_H265] = &cedrus_dec_ops_h265;
-       dev->dec_ops[CEDRUS_CODEC_VP8] = &cedrus_dec_ops_vp8;
-
        mutex_init(&dev->dev_mutex);
 
        INIT_DELAYED_WORK(&dev->watchdog_work, cedrus_watchdog);
index 736d81f376f3523633432ba03b6bc84065c6af0b..bcb7f31bde5e58fc1174ee0336959f4c162642e8 100644 (file)
@@ -118,7 +118,7 @@ struct cedrus_ctx {
 
        struct v4l2_pix_format          src_fmt;
        struct v4l2_pix_format          dst_fmt;
-       enum cedrus_codec               current_codec;
+       struct cedrus_dec_ops           *current_codec;
 
        struct v4l2_ctrl_handler        hdl;
        struct v4l2_ctrl                **ctrls;
@@ -185,7 +185,6 @@ struct cedrus_dev {
        struct platform_device  *pdev;
        struct device           *dev;
        struct v4l2_m2m_dev     *m2m_dev;
-       struct cedrus_dec_ops   *dec_ops[CEDRUS_CODEC_LAST];
 
        /* Device file mutex */
        struct mutex            dev_mutex;
index e7f7602a5ab403c2ee31e4bc75de8466aacdcd1c..fbbf9e6f0f50c294e8a002945824486ccce27371 100644 (file)
@@ -94,7 +94,7 @@ void cedrus_device_run(void *priv)
 
        cedrus_dst_format_set(dev, &ctx->dst_fmt);
 
-       error = dev->dec_ops[ctx->current_codec]->setup(ctx, &run);
+       error = ctx->current_codec->setup(ctx, &run);
        if (error)
                v4l2_err(&ctx->dev->v4l2_dev,
                         "Failed to setup decoding job: %d\n", error);
@@ -110,7 +110,7 @@ void cedrus_device_run(void *priv)
                schedule_delayed_work(&dev->watchdog_work,
                                      msecs_to_jiffies(2000));
 
-               dev->dec_ops[ctx->current_codec]->trigger(ctx);
+               ctx->current_codec->trigger(ctx);
        } else {
                v4l2_m2m_buf_done_and_job_finish(ctx->dev->m2m_dev,
                                                 ctx->fh.m2m_ctx,
index a6470a89851e3d09d76a9f39df7f8537160011e0..c3387cd1e80f4a653ab59a865a8a7fce23ff2f98 100644 (file)
@@ -132,12 +132,12 @@ static irqreturn_t cedrus_irq(int irq, void *data)
                return IRQ_NONE;
        }
 
-       status = dev->dec_ops[ctx->current_codec]->irq_status(ctx);
+       status = ctx->current_codec->irq_status(ctx);
        if (status == CEDRUS_IRQ_NONE)
                return IRQ_NONE;
 
-       dev->dec_ops[ctx->current_codec]->irq_disable(ctx);
-       dev->dec_ops[ctx->current_codec]->irq_clear(ctx);
+       ctx->current_codec->irq_disable(ctx);
+       ctx->current_codec->irq_clear(ctx);
 
        if (status == CEDRUS_IRQ_ERROR)
                state = VB2_BUF_STATE_ERROR;
index 77c537e7a2dec7cc4eff5b9f6cb253b855926a83..f1d80398a4f0d062940e36cf142c7960ea6a27dd 100644 (file)
@@ -333,6 +333,21 @@ static int cedrus_s_fmt_vid_out_p(struct cedrus_ctx *ctx,
                break;
        }
 
+       switch (ctx->src_fmt.pixelformat) {
+       case V4L2_PIX_FMT_MPEG2_SLICE:
+               ctx->current_codec = &cedrus_dec_ops_mpeg2;
+               break;
+       case V4L2_PIX_FMT_H264_SLICE:
+               ctx->current_codec = &cedrus_dec_ops_h264;
+               break;
+       case V4L2_PIX_FMT_HEVC_SLICE:
+               ctx->current_codec = &cedrus_dec_ops_h265;
+               break;
+       case V4L2_PIX_FMT_VP8_FRAME:
+               ctx->current_codec = &cedrus_dec_ops_vp8;
+               break;
+       }
+
        /* Propagate format information to capture. */
        ctx->dst_fmt.colorspace = pix_fmt->colorspace;
        ctx->dst_fmt.xfer_func = pix_fmt->xfer_func;
@@ -491,34 +506,13 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
        struct cedrus_dev *dev = ctx->dev;
        int ret = 0;
 
-       switch (ctx->src_fmt.pixelformat) {
-       case V4L2_PIX_FMT_MPEG2_SLICE:
-               ctx->current_codec = CEDRUS_CODEC_MPEG2;
-               break;
-
-       case V4L2_PIX_FMT_H264_SLICE:
-               ctx->current_codec = CEDRUS_CODEC_H264;
-               break;
-
-       case V4L2_PIX_FMT_HEVC_SLICE:
-               ctx->current_codec = CEDRUS_CODEC_H265;
-               break;
-
-       case V4L2_PIX_FMT_VP8_FRAME:
-               ctx->current_codec = CEDRUS_CODEC_VP8;
-               break;
-
-       default:
-               return -EINVAL;
-       }
-
        if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
                ret = pm_runtime_resume_and_get(dev->dev);
                if (ret < 0)
                        goto err_cleanup;
 
-               if (dev->dec_ops[ctx->current_codec]->start) {
-                       ret = dev->dec_ops[ctx->current_codec]->start(ctx);
+               if (ctx->current_codec->start) {
+                       ret = ctx->current_codec->start(ctx);
                        if (ret)
                                goto err_pm;
                }
@@ -540,8 +534,8 @@ static void cedrus_stop_streaming(struct vb2_queue *vq)
        struct cedrus_dev *dev = ctx->dev;
 
        if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
-               if (dev->dec_ops[ctx->current_codec]->stop)
-                       dev->dec_ops[ctx->current_codec]->stop(ctx);
+               if (ctx->current_codec->stop)
+                       ctx->current_codec->stop(ctx);
 
                pm_runtime_put(dev->dev);
        }