video: driver: Add enc vbr min quality restrictions

Do not support vbr min quality with below configs:
- HEVC 10bit
- Bitstream fps > 60
- ROI enabled/support
- HP encoding
- External Blur
- Resolution beyond 1080P.

Change-Id: I5e4a420abdd0c6fee4342c3c097684ef69bb0597
Signed-off-by: Akshata Sahukar <asahukar@codeaurora.org>
This commit is contained in:
Akshata Sahukar
2021-06-14 13:25:26 -07:00
parent 71bb59790c
commit 36a4971392
8 changed files with 271 additions and 64 deletions

View File

@@ -139,7 +139,7 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
CAP_FLAG_ROOT,
{0},
{PROFILE, MIN_FRAME_QP, MAX_FRAME_QP, I_FRAME_QP, META_ROI_INFO,
BLUR_TYPES}},
BLUR_TYPES, MIN_QUALITY}},
{PIX_FMTS, DEC, HEVC|HEIC,
MSM_VIDC_FMT_NV12,
@@ -438,7 +438,7 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
0, 7, 1, 0,
V4L2_CID_MPEG_VIDEO_B_FRAMES,
HFI_PROP_MAX_B_FRAMES,
CAP_FLAG_OUTPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
CAP_FLAG_OUTPUT_PORT,
{ENH_LAYER_COUNT},
{0},
msm_vidc_adjust_b_frame, msm_vidc_set_u32},
@@ -447,10 +447,19 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
VIDC_BLUR_NONE, VIDC_BLUR_ADAPTIVE, 1, VIDC_BLUR_ADAPTIVE,
V4L2_CID_MPEG_VIDC_VIDEO_BLUR_TYPES,
HFI_PROP_BLUR_TYPES,
CAP_FLAG_OUTPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
CAP_FLAG_OUTPUT_PORT,
{PIX_FMTS, BITRATE_MODE, CONTENT_ADAPTIVE_CODING},
{BLUR_RESOLUTION},
msm_vidc_adjust_blur_type, msm_vidc_set_blur_type},
msm_vidc_adjust_blur_type, msm_vidc_set_u32_enum},
{BLUR_TYPES, ENC, H264|HEVC,
VIDC_BLUR_NONE, VIDC_BLUR_ADAPTIVE, 1, VIDC_BLUR_ADAPTIVE,
V4L2_CID_MPEG_VIDC_VIDEO_BLUR_TYPES,
HFI_PROP_BLUR_TYPES,
CAP_FLAG_OUTPUT_PORT,
{PIX_FMTS, BITRATE_MODE, CONTENT_ADAPTIVE_CODING, MIN_QUALITY},
{BLUR_RESOLUTION},
msm_vidc_adjust_blur_type, msm_vidc_set_u32_enum},
{BLUR_RESOLUTION, ENC, CODECS_ALL,
0, S32_MAX, 1, 0,
@@ -565,27 +574,41 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
V4L2_CID_MPEG_VIDC_CONTENT_ADAPTIVE_CODING,
HFI_PROP_CONTENT_ADAPTIVE_CODING,
CAP_FLAG_OUTPUT_PORT,
{BITRATE_MODE},
{BITRATE_MODE, MIN_QUALITY},
{BLUR_TYPES},
NULL, msm_vidc_set_vbr_related_properties},
msm_vidc_adjust_cac,
msm_vidc_set_vbr_related_properties},
{BITRATE_BOOST, ENC, H264|HEVC,
0, 50, 25, 25,
0, MAX_BITRATE_BOOST, 25, MAX_BITRATE_BOOST,
V4L2_CID_MPEG_VIDC_QUALITY_BITRATE_BOOST,
HFI_PROP_BITRATE_BOOST,
CAP_FLAG_OUTPUT_PORT,
{BITRATE_MODE},
{BITRATE_MODE, MIN_QUALITY},
{0},
NULL, msm_vidc_set_vbr_related_properties},
msm_vidc_adjust_bitrate_boost,
msm_vidc_set_vbr_related_properties},
{MIN_QUALITY, ENC, H264|HEVC,
0, 80, 80, 80,
V4L2_CID_MPEG_VIDC_MIN_QUALITY,
{MIN_QUALITY, ENC, H264,
0, MAX_SUPPORTED_MIN_QUALITY, 70, MAX_SUPPORTED_MIN_QUALITY,
0,
HFI_PROP_MAINTAIN_MIN_QUALITY,
CAP_FLAG_OUTPUT_PORT,
{BITRATE_MODE},
{0},
NULL, msm_vidc_set_vbr_related_properties},
{BITRATE_MODE, ENH_LAYER_COUNT, META_ROI_INFO},
{CONTENT_ADAPTIVE_CODING, BITRATE_BOOST, BLUR_TYPES},
msm_vidc_adjust_min_quality,
msm_vidc_set_vbr_related_properties},
{MIN_QUALITY, ENC, HEVC,
0, MAX_SUPPORTED_MIN_QUALITY, 70, MAX_SUPPORTED_MIN_QUALITY,
0,
HFI_PROP_MAINTAIN_MIN_QUALITY,
CAP_FLAG_OUTPUT_PORT,
{BITRATE_MODE, PIX_FMTS, ENH_LAYER_COUNT,
META_ROI_INFO},
{CONTENT_ADAPTIVE_CODING, BITRATE_BOOST, BLUR_TYPES},
msm_vidc_adjust_min_quality,
msm_vidc_set_vbr_related_properties},
{VBV_DELAY, ENC, H264|HEVC,
200, 300, 100, 300,
@@ -756,7 +779,7 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
CAP_FLAG_DYNAMIC_ALLOWED,
{BITRATE_MODE, META_EVA_STATS},
{GOP_SIZE, B_FRAME, BIT_RATE},
{GOP_SIZE, B_FRAME, BIT_RATE, MIN_QUALITY},
msm_vidc_adjust_layer_count, msm_vidc_set_layer_count_and_type},
{ENH_LAYER_COUNT, ENC, H264,
@@ -766,7 +789,7 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
CAP_FLAG_DYNAMIC_ALLOWED,
{BITRATE_MODE, META_EVA_STATS},
{GOP_SIZE, B_FRAME, BIT_RATE},
{GOP_SIZE, B_FRAME, BIT_RATE, MIN_QUALITY},
msm_vidc_adjust_layer_count, msm_vidc_set_layer_count_and_type},
/*
@@ -1437,6 +1460,16 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
{0},
msm_vidc_adjust_roi_info, NULL},
{META_ROI_INFO, ENC, H264|HEVC,
V4L2_MPEG_MSM_VIDC_DISABLE, V4L2_MPEG_MSM_VIDC_ENABLE,
1, V4L2_MPEG_MSM_VIDC_DISABLE,
V4L2_CID_MPEG_VIDC_METADATA_ROI_INFO,
HFI_PROP_ROI_INFO,
CAP_FLAG_INPUT_PORT,
{BITRATE_MODE, PIX_FMTS},
{MIN_QUALITY},
msm_vidc_adjust_roi_info, NULL},
{META_DEC_QP_METADATA, DEC, CODECS_ALL,
V4L2_MPEG_MSM_VIDC_DISABLE, V4L2_MPEG_MSM_VIDC_ENABLE,
1, V4L2_MPEG_MSM_VIDC_DISABLE,

View File

@@ -564,7 +564,7 @@ static int msm_vidc_input_min_count_iris2(struct msm_vidc_inst* inst)
if (is_decode_session(inst)) {
input_min_count = MIN_DEC_INPUT_BUFFERS;
} else if (is_encode_session(inst)) {
total_hb_layer = is_hierb_requested(inst) ?
total_hb_layer = is_hierb_type_requested(inst) ?
inst->capabilities->cap[ENH_LAYER_COUNT].value + 1 : 0;
if (inst->codec == MSM_VIDC_H264 &&
!inst->capabilities->cap[LAYER_ENABLE].value) {

View File

@@ -34,6 +34,9 @@ int msm_vidc_adjust_hevc_max_qp(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_hevc_frame_qp(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_blur_type(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_blur_resolution(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_cac(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_bitrate_boost(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_min_quality(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_lowlatency_mode(void *instance, struct v4l2_ctrl *ctrl);
int msm_vidc_adjust_v4l2_properties(struct msm_vidc_inst *inst);
int msm_vidc_adjust_session_priority(void *instance, struct v4l2_ctrl *ctrl);
@@ -83,8 +86,6 @@ int msm_vidc_set_flip(void *instance,
enum msm_vidc_inst_capability_type cap_id);
int msm_vidc_set_rotation(void *instance,
enum msm_vidc_inst_capability_type cap_id);
int msm_vidc_set_blur_type(void *instance,
enum msm_vidc_inst_capability_type cap_id);
int msm_vidc_set_blur_resolution(void *instance,
enum msm_vidc_inst_capability_type cap_id);
int msm_vidc_set_stage(void *instance,

View File

@@ -212,7 +212,7 @@ static inline bool is_lowlatency_session(struct msm_vidc_inst *inst)
return !!(inst->capabilities->cap[LOWLATENCY_MODE].value);
}
static inline bool is_hierb_requested(struct msm_vidc_inst *inst)
static inline bool is_hierb_type_requested(struct msm_vidc_inst *inst)
{
return (inst->codec == MSM_VIDC_H264 &&
inst->capabilities->cap[LAYER_TYPE].value ==

View File

@@ -65,6 +65,8 @@
#define MIN_HEVC_SLICE_WIDTH 384
#define MIN_AVC_SLICE_WIDTH 192
#define MIN_SLICE_HEIGHT 128
#define MAX_BITRATE_BOOST 25
#define MAX_SUPPORTED_MIN_QUALITY 70
#define DCVS_WINDOW 16
/* Superframe can have maximum of 32 frames */

View File

@@ -26,7 +26,7 @@ u32 msm_vidc_input_min_count(struct msm_vidc_inst* inst)
input_min_count = MIN_DEC_INPUT_BUFFERS;
} else if (is_encode_session(inst)) {
input_min_count = MIN_ENC_INPUT_BUFFERS;
if (is_hierb_requested(inst)) {
if (is_hierb_type_requested(inst)) {
hb_enh_layer =
inst->capabilities->cap[ENH_LAYER_COUNT].value;
if (inst->codec == MSM_VIDC_H264 &&

View File

@@ -423,11 +423,10 @@ static int msm_vidc_adjust_dynamic_property(struct msm_vidc_inst *inst,
* adjustment is allowed for its children.
*/
if (!(capability->cap[cap_id].flags & CAP_FLAG_DYNAMIC_ALLOWED)) {
i_vpr_e(inst,
i_vpr_h(inst,
"%s: dynamic setting of cap[%d] %s is not allowed\n",
__func__, cap_id, cap_name(cap_id));
msm_vidc_change_inst_state(inst, MSM_VIDC_ERROR, __func__);
return -EINVAL;
return 0;
}
/*
@@ -1445,9 +1444,6 @@ int msm_vidc_adjust_b_frame(void *instance, struct v4l2_ctrl *ctrl)
}
capability = inst->capabilities;
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
adjusted_value = ctrl ? ctrl->val : capability->cap[B_FRAME].value;
if (msm_vidc_get_parent_value(inst, B_FRAME,
@@ -1782,7 +1778,7 @@ int msm_vidc_adjust_blur_type(void *instance, struct v4l2_ctrl *ctrl)
s32 adjusted_value;
struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
s32 rc_type = -1, cac = -1;
s32 pix_fmts = -1;
s32 pix_fmts = -1, min_quality = -1;
if (!inst || !inst->capabilities) {
d_vpr_e("%s: invalid params\n", __func__);
@@ -1790,9 +1786,6 @@ int msm_vidc_adjust_blur_type(void *instance, struct v4l2_ctrl *ctrl)
}
capability = inst->capabilities;
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
adjusted_value = ctrl ? ctrl->val :
capability->cap[BLUR_TYPES].value;
@@ -1804,15 +1797,18 @@ int msm_vidc_adjust_blur_type(void *instance, struct v4l2_ctrl *ctrl)
msm_vidc_get_parent_value(inst, BLUR_TYPES,
CONTENT_ADAPTIVE_CODING, &cac, __func__) ||
msm_vidc_get_parent_value(inst, BLUR_TYPES, PIX_FMTS,
&pix_fmts, __func__))
&pix_fmts, __func__) ||
msm_vidc_get_parent_value(inst, BLUR_TYPES, MIN_QUALITY,
&min_quality, __func__))
return -EINVAL;
if (adjusted_value == VIDC_BLUR_EXTERNAL) {
if (is_scaling_enabled(inst)) {
if (is_scaling_enabled(inst) || min_quality) {
adjusted_value = VIDC_BLUR_NONE;
}
} else if (adjusted_value == VIDC_BLUR_ADAPTIVE) {
if (is_scaling_enabled(inst) || (rc_type != HFI_RC_VBR_CFR) ||
if (is_scaling_enabled(inst) || min_quality ||
(rc_type != HFI_RC_VBR_CFR) ||
!cac || is_10bit_colorformat(pix_fmts)) {
adjusted_value = VIDC_BLUR_NONE;
}
@@ -1853,6 +1849,210 @@ int msm_vidc_adjust_blur_resolution(void *instance, struct v4l2_ctrl *ctrl)
return 0;
}
int msm_vidc_adjust_cac(void *instance, struct v4l2_ctrl *ctrl)
{
struct msm_vidc_inst_capability *capability;
s32 adjusted_value;
struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
s32 min_quality = -1, rc_type = -1;
if (!inst || !inst->capabilities) {
d_vpr_e("%s: invalid params\n", __func__);
return -EINVAL;
}
capability = inst->capabilities;
adjusted_value = ctrl ? ctrl->val :
capability->cap[CONTENT_ADAPTIVE_CODING].value;
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
if (msm_vidc_get_parent_value(inst, CONTENT_ADAPTIVE_CODING,
MIN_QUALITY, &min_quality, __func__) ||
msm_vidc_get_parent_value(inst, CONTENT_ADAPTIVE_CODING,
BITRATE_MODE, &rc_type, __func__))
return -EINVAL;
/*
* CAC is supported only for VBR rc type.
* Hence, do not adjust or set to firmware for non VBR rc's
*/
if (rc_type != HFI_RC_VBR_CFR) {
adjusted_value = 0;
goto adjust;
}
if (min_quality) {
adjusted_value = 1;
goto adjust;
}
adjust:
msm_vidc_update_cap_value(inst, CONTENT_ADAPTIVE_CODING,
adjusted_value, __func__);
return 0;
}
int msm_vidc_adjust_bitrate_boost(void *instance, struct v4l2_ctrl *ctrl)
{
struct msm_vidc_inst_capability *capability;
s32 adjusted_value;
struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
s32 min_quality = -1, rc_type = -1;
if (!inst || !inst->capabilities) {
d_vpr_e("%s: invalid params\n", __func__);
return -EINVAL;
}
capability = inst->capabilities;
adjusted_value = ctrl ? ctrl->val :
capability->cap[BITRATE_BOOST].value;
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
if (msm_vidc_get_parent_value(inst, BITRATE_BOOST,
MIN_QUALITY, &min_quality, __func__) ||
msm_vidc_get_parent_value(inst, BITRATE_BOOST,
BITRATE_MODE, &rc_type, __func__))
return -EINVAL;
/*
* Bitrate Boost are supported only for VBR rc type.
* Hence, do not adjust or set to firmware for non VBR rc's
*/
if (rc_type != HFI_RC_VBR_CFR) {
adjusted_value = 0;
goto adjust;
}
if (min_quality) {
adjusted_value = MAX_BITRATE_BOOST;
goto adjust;
}
adjust:
msm_vidc_update_cap_value(inst, BITRATE_BOOST,
adjusted_value, __func__);
return 0;
}
int msm_vidc_adjust_min_quality(void *instance, struct v4l2_ctrl *ctrl)
{
struct msm_vidc_inst_capability *capability;
s32 adjusted_value;
struct msm_vidc_inst *inst = (struct msm_vidc_inst *) instance;
s32 roi_enable = -1, rc_type = -1, enh_layer_count = -1, pix_fmts = -1;
u32 width, height, frame_rate;
struct v4l2_format *f;
if (!inst || !inst->capabilities) {
d_vpr_e("%s: invalid params\n", __func__);
return -EINVAL;
}
capability = inst->capabilities;
adjusted_value = ctrl ? ctrl->val : capability->cap[MIN_QUALITY].value;
/*
* Although MIN_QUALITY is static, one of its parents,
* ENH_LAYER_COUNT is dynamic cap. Hence, dynamic call
* may be made for MIN_QUALITY via ENH_LAYER_COUNT.
* Therefore, below streaming check is required to avoid
* runtime modification of MIN_QUALITY.
*/
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
if (msm_vidc_get_parent_value(inst, MIN_QUALITY,
BITRATE_MODE, &rc_type, __func__) ||
msm_vidc_get_parent_value(inst, MIN_QUALITY,
META_ROI_INFO, &roi_enable, __func__) ||
msm_vidc_get_parent_value(inst, MIN_QUALITY,
ENH_LAYER_COUNT, &enh_layer_count, __func__))
return -EINVAL;
/*
* Min Quality is supported only for VBR rc type.
* Hence, do not adjust or set to firmware for non VBR rc's
*/
if (rc_type != HFI_RC_VBR_CFR) {
adjusted_value = 0;
goto update_and_exit;
}
frame_rate = inst->capabilities->cap[FRAME_RATE].value >> 16;
f = &inst->fmts[OUTPUT_PORT];
width = f->fmt.pix_mp.width;
height = f->fmt.pix_mp.height;
/*
* VBR Min Quality not supported for:
* - HEVC 10bit
* - ROI support
* - HP encoding
* - External Blur
* - Resolution beyond 1080P
* (It will fall back to CQCAC 25% or 0% (CAC) or CQCAC-OFF)
*/
if (inst->codec == MSM_VIDC_HEVC) {
if (msm_vidc_get_parent_value(inst, MIN_QUALITY,
PIX_FMTS, &pix_fmts, __func__))
return -EINVAL;
if (is_10bit_colorformat(pix_fmts)) {
i_vpr_h(inst,
"%s: min quality is supported only for 8 bit\n",
__func__);
adjusted_value = 0;
goto update_and_exit;
}
}
if (res_is_greater_than(width, height, 1920, 1080)) {
i_vpr_h(inst, "%s: unsupported res, wxh %ux%u\n",
__func__, width, height);
adjusted_value = 0;
goto update_and_exit;
}
if (frame_rate > 60) {
i_vpr_h(inst, "%s: unsupported fps %u\n",
__func__, frame_rate);
adjusted_value = 0;
goto update_and_exit;
}
if (roi_enable) {
i_vpr_h(inst,
"%s: min quality not supported with roi metadata\n",
__func__);
adjusted_value = 0;
goto update_and_exit;
}
if (enh_layer_count && inst->hfi_layer_type != HFI_HIER_B) {
i_vpr_h(inst,
"%s: min quality not supported for HP encoding\n",
__func__);
adjusted_value = 0;
goto update_and_exit;
}
/* Above conditions are met. Hence enable min quality */
adjusted_value = MAX_SUPPORTED_MIN_QUALITY;
update_and_exit:
msm_vidc_update_cap_value(inst, MIN_QUALITY,
adjusted_value, __func__);
return 0;
}
int msm_vidc_adjust_lowlatency_mode(void *instance, struct v4l2_ctrl *ctrl)
{
struct msm_vidc_inst_capability *capability;
@@ -2839,33 +3039,6 @@ int msm_vidc_set_rotation(void *instance,
return rc;
}
int msm_vidc_set_blur_type(void *instance,
enum msm_vidc_inst_capability_type cap_id)
{
int rc = 0;
struct msm_vidc_inst *inst = (struct msm_vidc_inst *)instance;
u32 hfi_value;
if (!inst || !inst->capabilities) {
d_vpr_e("%s: invalid params\n", __func__);
return -EINVAL;
}
if (inst->vb2q[OUTPUT_PORT].streaming)
return 0;
rc = msm_vidc_v4l2_to_hfi_enum(inst, cap_id, &hfi_value);
if (rc)
return -EINVAL;
rc = msm_vidc_packetize_control(inst, cap_id, HFI_PAYLOAD_U32_ENUM,
&hfi_value, sizeof(u32), __func__);
if (rc)
return rc;
return rc;
}
int msm_vidc_set_blur_resolution(void *instance,
enum msm_vidc_inst_capability_type cap_id)
{

View File

@@ -130,8 +130,6 @@ enum v4l2_mpeg_vidc_blur_types {
/* Encoder Input Compression Ratio control */
#define V4L2_CID_MPEG_VIDC_ENC_INPUT_COMPRESSION_RATIO \
(V4L2_CID_MPEG_VIDC_BASE + 0x2C)
#define V4L2_CID_MPEG_VIDC_MIN_QUALITY \
(V4L2_CID_MPEG_VIDC_BASE + 0x2D)
#define V4L2_CID_MPEG_VIDC_METADATA_DEC_QP_METADATA \
(V4L2_CID_MPEG_VIDC_BASE + 0x2E)
/* Encoder Complexity control */