media: coda: add RC enable controls
authorPhilipp Zabel <p.zabel@pengutronix.de>
Wed, 18 Mar 2020 18:36:49 +0000 (19:36 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 21 Apr 2020 15:21:31 +0000 (17:21 +0200)
Currently the encoder enables the rate control algorithms if the bitrate
control is non-zero. Implement the V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE
and V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE controls to allow userspace to
choose frame-level or macroblock-level rate control updates, or to
explicitly disable rate control. Both controls are initially enabled to
keep the current behavior.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/coda/coda-bit.c
drivers/media/platform/coda/coda-common.c
drivers/media/platform/coda/coda.h

index 3443396..b021604 100644 (file)
@@ -1215,7 +1215,8 @@ static int coda_start_encoding(struct coda_ctx *ctx)
                coda_write(dev, value, CODA_CMD_ENC_SEQ_GOP_SIZE);
        }
 
-       if (ctx->params.bitrate) {
+       if (ctx->params.bitrate && (ctx->params.frame_rc_enable ||
+                                   ctx->params.mb_rc_enable)) {
                ctx->params.bitrate_changed = false;
                ctx->params.h264_intra_qp_changed = false;
 
@@ -1276,7 +1277,11 @@ static int coda_start_encoding(struct coda_ctx *ctx)
        }
        coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION);
 
-       coda_write(dev, 0, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
+       if (ctx->params.frame_rc_enable && !ctx->params.mb_rc_enable)
+               value = 1;
+       else
+               value = 0;
+       coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_INTERVAL_MODE);
 
        coda_setup_iram(ctx);
 
index 80ad2db..6f41f74 100644 (file)
@@ -2223,6 +2223,12 @@ static int coda_s_ctrl(struct v4l2_ctrl *ctrl)
        case V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION:
                ctx->params.h264_constrained_intra_pred_flag = ctrl->val;
                break;
+       case V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE:
+               ctx->params.frame_rc_enable = ctrl->val;
+               break;
+       case V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE:
+               ctx->params.mb_rc_enable = ctrl->val;
+               break;
        case V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET:
                ctx->params.h264_chroma_qp_index_offset = ctrl->val;
                break;
@@ -2322,6 +2328,10 @@ static void coda_encode_ctrls(struct coda_ctx *ctx)
                V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION, 0, 1, 1,
                0);
        v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
+               V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, 0, 1, 1, 1);
+       v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
+               V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE, 0, 1, 1, 1);
+       v4l2_ctrl_new_std(&ctx->ctrls, &coda_ctrl_ops,
                V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET, -12, 12, 1, 0);
        v4l2_ctrl_new_std_menu(&ctx->ctrls, &coda_ctrl_ops,
                V4L2_CID_MPEG_VIDEO_H264_PROFILE,
index af0f825..b81f3ac 100644 (file)
@@ -148,6 +148,8 @@ struct coda_params {
        bool                    h264_intra_qp_changed;
        bool                    intra_refresh_changed;
        bool                    slice_mode_changed;
+       bool                    frame_rc_enable;
+       bool                    mb_rc_enable;
 };
 
 struct coda_buffer_meta {