diff mbox series

[v4,17/17] media: mtk-vcodec: venc: fix invalid time per frame in S_PARM

Message ID 20200821103608.2310097-18-acourbot@chromium.org (mailing list archive)
State New, archived
Headers show
Series media: mtk-vcodec: venc: support for MT8183 | expand

Commit Message

Alexandre Courbot Aug. 21, 2020, 10:36 a.m. UTC
v4l2-compliance expects the driver to adjust the time per frame if it is
invalid (numerator or denominator set to 0). Adjust it to the default
value in these cases.

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

tiffany.lin Aug. 25, 2020, 5:49 a.m. UTC | #1
On Fri, 2020-08-21 at 19:36 +0900, Alexandre Courbot wrote:
> v4l2-compliance expects the driver to adjust the time per frame if it is
> invalid (numerator or denominator set to 0). Adjust it to the default
> value in these cases.
> 

Acked-by: Tiffany Lin <tiffany.lin@mediatek.com>

> Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
> ---
>  drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> index 09baac2dbc36..82b04714f750 100644
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
> @@ -200,14 +200,18 @@ static int vidioc_venc_s_parm(struct file *file, void *priv,
>  			      struct v4l2_streamparm *a)
>  {
>  	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
> +	struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;
>  
>  	if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
>  		return -EINVAL;
>  
> -	ctx->enc_params.framerate_num =
> -			a->parm.output.timeperframe.denominator;
> -	ctx->enc_params.framerate_denom =
> -			a->parm.output.timeperframe.numerator;
> +	if (timeperframe->numerator == 0 || timeperframe->denominator == 0) {
> +		timeperframe->numerator = MTK_DEFAULT_FRAMERATE_NUM;
> +		timeperframe->denominator = MTK_DEFAULT_FRAMERATE_DENOM;
> +	}
> +
> +	ctx->enc_params.framerate_num = timeperframe->denominator;
> +	ctx->enc_params.framerate_denom = timeperframe->numerator;
>  	ctx->param_change |= MTK_ENCODE_PARAM_FRAMERATE;
>  
>  	a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
diff mbox series

Patch

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
index 09baac2dbc36..82b04714f750 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
@@ -200,14 +200,18 @@  static int vidioc_venc_s_parm(struct file *file, void *priv,
 			      struct v4l2_streamparm *a)
 {
 	struct mtk_vcodec_ctx *ctx = fh_to_ctx(priv);
+	struct v4l2_fract *timeperframe = &a->parm.output.timeperframe;
 
 	if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
 		return -EINVAL;
 
-	ctx->enc_params.framerate_num =
-			a->parm.output.timeperframe.denominator;
-	ctx->enc_params.framerate_denom =
-			a->parm.output.timeperframe.numerator;
+	if (timeperframe->numerator == 0 || timeperframe->denominator == 0) {
+		timeperframe->numerator = MTK_DEFAULT_FRAMERATE_NUM;
+		timeperframe->denominator = MTK_DEFAULT_FRAMERATE_DENOM;
+	}
+
+	ctx->enc_params.framerate_num = timeperframe->denominator;
+	ctx->enc_params.framerate_denom = timeperframe->numerator;
 	ctx->param_change |= MTK_ENCODE_PARAM_FRAMERATE;
 
 	a->parm.output.capability = V4L2_CAP_TIMEPERFRAME;