Re: [PATCH 7/9] media: mtk-vcodec: Add frame racing mode encode process
From: Tzung-Bi Shih
Date: Tue Aug 24 2021 - 15:20:50 EST
On Mon, Aug 16, 2021 at 06:59:32PM +0800, Irui Wang wrote:
> The frame_racing mode encoding is try to use the two venc cores:
s/is try/tries/
> frame#0 use core#0, frame#1 use core#1, frame#2 use core#0...,
s/use/uses/g
> Lock the device and enabe the clock by used core, for sequence
s/enabe/enable/
> header encoding, it always used core#0.
s/used/uses/
> --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h
> @@ -273,6 +273,7 @@ struct vdec_pic_info {
> * @decoded_frame_cnt: number of decoded frames
> * @lock: protect variables accessed by V4L2 threads and worker thread such as
> * mtk_video_dec_buf.
> + * @enc_idx: used to record encoded frame count
> */
> struct mtk_vcodec_ctx {
> enum mtk_instance_type type;
> @@ -313,6 +314,8 @@ struct mtk_vcodec_ctx {
> int decoded_frame_cnt;
> struct mutex lock;
>
> + int hw_id;
> + int enc_idx;
hw_id lacks of kerneldoc which could introduce smatch warning.
> --- a/drivers/media/platform/mtk-vcodec/venc_drv_if.c
> +++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.c
> @@ -15,6 +15,7 @@
>
> #include "mtk_vcodec_enc.h"
> #include "mtk_vcodec_enc_pm.h"
> +#include "mtk_vcodec_enc_hw.h"
Please try to maintain the order.
> @@ -34,9 +35,9 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc)
> return -EINVAL;
> }
>
> - mtk_venc_lock(ctx);
> + mtk_venc_lock(ctx, 0);
Does it make more sense to use ctx->hw_id instead 0 (even if it is always 0 in the path)?
> ret = ctx->enc_if->init(ctx);
> - mtk_venc_unlock(ctx);
> + mtk_venc_unlock(ctx, 0);
Same.
> @@ -46,9 +47,9 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx,
> {
> int ret = 0;
>
> - mtk_venc_lock(ctx);
> + mtk_venc_lock(ctx, 0);
Same.
> ret = ctx->enc_if->set_param(ctx->drv_handle, type, in);
> - mtk_venc_unlock(ctx);
> + mtk_venc_unlock(ctx, 0);
Same.
> @@ -87,11 +76,67 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx)
> if (!ctx->drv_handle)
> return 0;
>
> - mtk_venc_lock(ctx);
> + mtk_venc_lock(ctx, 0);
Same.
> ret = ctx->enc_if->deinit(ctx->drv_handle);
> - mtk_venc_unlock(ctx);
> + mtk_venc_unlock(ctx, 0);
Same.
> +void venc_encode_unprepare(struct mtk_vcodec_ctx *ctx,
> + enum venc_start_opt opt)
> +{
> + unsigned long flags;
> + struct mtk_venc_comp_dev *venc;
> +
> + /*clock off and unlock after irq done*/
> + if (ctx->dev->venc_pdata->hw_mode == VENC_FRAME_RACING_MODE) {
> + if (opt == VENC_START_OPT_ENCODE_SEQUENCE_HEADER) {
> + mtk_vcodec_enc_clock_off(ctx->dev, ctx->hw_id);
> + spin_lock_irqsave(&ctx->dev->irqlock, flags);
> + venc = ctx->dev->enc_comp_dev[ctx->hw_id];
> + venc->curr_ctx = NULL;
> + spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
> + mtk_venc_unlock(ctx, ctx->hw_id);
> + }
> + } else {
> + mtk_vcodec_enc_clock_off(ctx->dev, ctx->hw_id);
> + spin_lock_irqsave(&ctx->dev->irqlock, flags);
> + ctx->dev->curr_ctx = NULL;
> + spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
> + mtk_venc_unlock(ctx, ctx->hw_id);
The few statements are identical. Should try to reuse them.