From a33041f79952a01412fdc65527d4399011e53662 Mon Sep 17 00:00:00 2001 From: Govindaraj Rajagopal Date: Mon, 31 May 2021 15:49:12 +0530 Subject: [PATCH] video: driver: add scaling checks for encode session Encoder supports downscale with scaling ratio upto 1/8 of width and 1/8 of height. So added necessary scaling checks at streamon. Change-Id: I3a29b43c79cf4e693ba2c0d9f98ec24410d50fbd Signed-off-by: Govindaraj Rajagopal --- driver/platform/waipio/src/msm_vidc_waipio.c | 5 +-- .../variant/iris2/src/msm_vidc_buffer_iris2.c | 3 +- driver/vidc/inc/msm_vidc_driver.h | 6 ++++ driver/vidc/inc/msm_vidc_internal.h | 3 +- driver/vidc/src/msm_vdec.c | 4 --- driver/vidc/src/msm_venc.c | 11 ++---- driver/vidc/src/msm_vidc_driver.c | 34 ++++++++++++++++--- 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/driver/platform/waipio/src/msm_vidc_waipio.c b/driver/platform/waipio/src/msm_vidc_waipio.c index c168aeded7..b331acc744 100644 --- a/driver/platform/waipio/src/msm_vidc_waipio.c +++ b/driver/platform/waipio/src/msm_vidc_waipio.c @@ -205,10 +205,7 @@ static struct msm_platform_inst_capability instance_data_waipio[] = { {OPERATING_RATE, ENC|DEC, CODECS_ALL, 1, INT_MAX, 1, (DEFAULT_FPS << 16)}, - {SCALE_X, ENC, H264|HEVC, 8192, 65536, 1, 8192}, - {SCALE_X, DEC, H264|HEVC|VP9, 65536, 65536, 1, 65536}, - {SCALE_Y, ENC, H264|HEVC, 8192, 65536, 1, 8192}, - {SCALE_Y, DEC, H264|HEVC|VP9, 65536, 65536, 1, 65536}, + {SCALE_FACTOR, ENC, H264|HEVC, 1, 8, 1, 8}, {MB_CYCLES_VSP, ENC, CODECS_ALL, 25, 25, 1, 25}, {MB_CYCLES_VSP, DEC, CODECS_ALL, 25, 25, 1, 25}, diff --git a/driver/variant/iris2/src/msm_vidc_buffer_iris2.c b/driver/variant/iris2/src/msm_vidc_buffer_iris2.c index faff09f519..9219cc16cb 100644 --- a/driver/variant/iris2/src/msm_vidc_buffer_iris2.c +++ b/driver/variant/iris2/src/msm_vidc_buffer_iris2.c @@ -455,8 +455,7 @@ static u32 msm_vidc_encoder_vpss_size_iris2(struct msm_vidc_inst* inst) msm_vidc_v4l2_to_hfi_enum(inst, ROTATION, &rotation_val); f = &inst->fmts[OUTPUT_PORT]; - if (inst->capabilities->cap[ROTATION].value == 90 || - inst->capabilities->cap[ROTATION].value == 270) { + if (is_rotation_90_or_270(inst)) { /* * output width and height are rotated, * so unrotate them to use as arguments to diff --git a/driver/vidc/inc/msm_vidc_driver.h b/driver/vidc/inc/msm_vidc_driver.h index 5e44a77fc1..b33fc70ca7 100644 --- a/driver/vidc/inc/msm_vidc_driver.h +++ b/driver/vidc/inc/msm_vidc_driver.h @@ -73,6 +73,12 @@ static inline is_scaling_enabled(struct msm_vidc_inst *inst) inst->crop.height != inst->compose.height; } +static inline is_rotation_90_or_270(struct msm_vidc_inst *inst) +{ + return inst->capabilities->cap[ROTATION].value == 90 || + inst->capabilities->cap[ROTATION].value == 270; +} + static inline is_internal_buffer(enum msm_vidc_buffer_type buffer_type) { return buffer_type == MSM_VIDC_BUF_BIN || diff --git a/driver/vidc/inc/msm_vidc_internal.h b/driver/vidc/inc/msm_vidc_internal.h index c3402c7ef0..bc77845c1d 100644 --- a/driver/vidc/inc/msm_vidc_internal.h +++ b/driver/vidc/inc/msm_vidc_internal.h @@ -347,8 +347,7 @@ enum msm_vidc_inst_capability_type { POWER_SAVE_MBPS, FRAME_RATE, OPERATING_RATE, - SCALE_X, - SCALE_Y, + SCALE_FACTOR, MB_CYCLES_VSP, MB_CYCLES_VPP, MB_CYCLES_LP, diff --git a/driver/vidc/src/msm_vdec.c b/driver/vidc/src/msm_vdec.c index 17e42b1e66..b9f9f94381 100644 --- a/driver/vidc/src/msm_vdec.c +++ b/driver/vidc/src/msm_vdec.c @@ -1397,10 +1397,6 @@ int msm_vdec_streamon_input(struct msm_vidc_inst *inst) if (rc) goto error; - rc = msm_vidc_check_scaling_supported(inst); - if (rc) - goto error; - rc = msm_vdec_set_input_properties(inst); if (rc) goto error; diff --git a/driver/vidc/src/msm_venc.c b/driver/vidc/src/msm_venc.c index 308a0acd0f..caeb1d84f7 100644 --- a/driver/vidc/src/msm_venc.c +++ b/driver/vidc/src/msm_venc.c @@ -247,8 +247,7 @@ static int msm_venc_set_crop_offsets(struct msm_vidc_inst *inst, width = inst->compose.width; height = inst->compose.height; - if (inst->capabilities->cap[ROTATION].value == 90 || - inst->capabilities->cap[ROTATION].value == 270) { + if (is_rotation_90_or_270(inst)) { width = inst->compose.height; height = inst->compose.width; } @@ -1051,8 +1050,7 @@ int msm_venc_s_fmt_output(struct msm_vidc_inst *inst, struct v4l2_format *f) /* use rotated width height if rotation is enabled */ width = inst->compose.width; height = inst->compose.height; - if (inst->capabilities->cap[ROTATION].value == 90 || - inst->capabilities->cap[ROTATION].value == 270) { + if (is_rotation_90_or_270(inst)) { width = inst->compose.height; height = inst->compose.width; } @@ -1424,10 +1422,7 @@ int msm_venc_s_selection(struct msm_vidc_inst* inst, struct v4l2_selection* s) inst->compose.width = s->r.width; inst->compose.height= s->r.height; - if (inst->crop.left != inst->compose.left || - inst->crop.top != inst->compose.top || - inst->crop.width != inst->compose.width || - inst->crop.height != inst->compose.height) { + if (is_scaling_enabled(inst)) { i_vpr_h(inst, "%s: scaling enabled, crop: l %d t %d w %d h %d compose: l %d t %d w %d h %d\n", __func__, inst->crop.left, inst->crop.top, diff --git a/driver/vidc/src/msm_vidc_driver.c b/driver/vidc/src/msm_vidc_driver.c index 8e0dcc83c2..38a0f049a6 100644 --- a/driver/vidc/src/msm_vidc_driver.c +++ b/driver/vidc/src/msm_vidc_driver.c @@ -67,8 +67,7 @@ static const struct msm_vidc_cap_name cap_name_arr[] = { {POWER_SAVE_MBPS, "POWER_SAVE_MBPS" }, {FRAME_RATE, "FRAME_RATE" }, {OPERATING_RATE, "OPERATING_RATE" }, - {SCALE_X, "SCALE_X" }, - {SCALE_Y, "SCALE_Y" }, + {SCALE_FACTOR, "SCALE_FACTOR" }, {MB_CYCLES_VSP, "MB_CYCLES_VSP" }, {MB_CYCLES_VPP, "MB_CYCLES_VPP" }, {MB_CYCLES_LP, "MB_CYCLES_LP" }, @@ -5377,7 +5376,9 @@ exit: int msm_vidc_check_scaling_supported(struct msm_vidc_inst *inst) { - if (!inst) { + u32 iwidth, owidth, iheight, oheight, ds_factor; + + if (!inst || !inst->capabilities) { d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } @@ -5387,7 +5388,32 @@ int msm_vidc_check_scaling_supported(struct msm_vidc_inst *inst) return 0; } - /* todo: add scaling check for encode session */ + if (!is_scaling_enabled(inst)) { + i_vpr_h(inst, "%s: Scaling not enabled. skip scaling check\n", __func__); + return 0; + } + + iwidth = inst->crop.width; + iheight = inst->crop.height; + owidth = inst->compose.width; + oheight = inst->compose.height; + ds_factor = inst->capabilities->cap[SCALE_FACTOR].value; + + /* upscaling: encoder doesnot support upscaling */ + if (owidth > iwidth || oheight > iheight) { + i_vpr_e(inst, "%s: upscale not supported: input [%u x %u], output [%u x %u]\n", + __func__, iwidth, iheight, owidth, oheight); + return -EINVAL; + } + + /* downscaling: only supported upto 1/8 of width & 1/8 of height */ + if (iwidth > owidth * ds_factor || iheight > oheight * ds_factor) { + i_vpr_e(inst, + "%s: unsupported ratio: input [%u x %u], output [%u x %u], ratio %u\n", + __func__, iwidth, iheight, owidth, oheight, ds_factor); + return -EINVAL; + } + return 0; }