]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
media: qcom: iris: Add hierarchical coding support for encoder
authorWangao Wang <wangao.wang@oss.qualcomm.com>
Tue, 12 May 2026 08:55:13 +0000 (16:55 +0800)
committerBryan O'Donoghue <bod@kernel.org>
Sat, 30 May 2026 07:41:48 +0000 (08:41 +0100)
Add hierarchical coding support for both gen1 and gen2 encoders by enabling
 the following V4L2 controls:
H264:
V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING,
V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE,
V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER
HEVC(gen2 only):
V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE,
V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER

Reviewed-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Signed-off-by: Wangao Wang <wangao.wang@oss.qualcomm.com>
Signed-off-by: Bryan O'Donoghue <bod@kernel.org>
drivers/media/platform/qcom/iris/iris_ctrls.c
drivers/media/platform/qcom/iris/iris_ctrls.h
drivers/media/platform/qcom/iris/iris_hfi_gen1.c
drivers/media/platform/qcom/iris/iris_hfi_gen1_command.c
drivers/media/platform/qcom/iris/iris_hfi_gen1_defines.h
drivers/media/platform/qcom/iris/iris_hfi_gen2.c
drivers/media/platform/qcom/iris/iris_hfi_gen2_defines.h
drivers/media/platform/qcom/iris/iris_instance.h
drivers/media/platform/qcom/iris/iris_platform_common.h
drivers/media/platform/qcom/iris/iris_vpu_buffer.c

index a6bd2eada52b68afd91032315c2701d8c74a9763..10e33b8a73f60759c4f1cb17b5c95897f0e1468f 100644 (file)
@@ -120,6 +120,40 @@ static enum platform_inst_fw_cap_type iris_get_cap_id(u32 id)
                return MARK_LTR;
        case V4L2_CID_MPEG_VIDEO_B_FRAMES:
                return B_FRAME;
+       case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING:
+               return LAYER_ENABLE;
+       case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE:
+               return LAYER_TYPE_H264;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE:
+               return LAYER_TYPE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER:
+               return LAYER_COUNT_H264;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER:
+               return LAYER_COUNT_HEVC;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR:
+               return LAYER0_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR:
+               return LAYER1_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR:
+               return LAYER2_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR:
+               return LAYER3_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR:
+               return LAYER4_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR:
+               return LAYER5_BITRATE_H264;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR:
+               return LAYER0_BITRATE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR:
+               return LAYER1_BITRATE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR:
+               return LAYER2_BITRATE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR:
+               return LAYER3_BITRATE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR:
+               return LAYER4_BITRATE_HEVC;
+       case V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR:
+               return LAYER5_BITRATE_HEVC;
        default:
                return INST_FW_CAP_MAX;
        }
@@ -229,6 +263,40 @@ static u32 iris_get_v4l2_id(enum platform_inst_fw_cap_type cap_id)
                return V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX;
        case B_FRAME:
                return V4L2_CID_MPEG_VIDEO_B_FRAMES;
+       case LAYER_ENABLE:
+               return V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING;
+       case LAYER_TYPE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE;
+       case LAYER_TYPE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE;
+       case LAYER_COUNT_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER;
+       case LAYER_COUNT_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER;
+       case LAYER0_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR;
+       case LAYER1_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR;
+       case LAYER2_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR;
+       case LAYER3_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR;
+       case LAYER4_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR;
+       case LAYER5_BITRATE_H264:
+               return V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR;
+       case LAYER0_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR;
+       case LAYER1_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR;
+       case LAYER2_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR;
+       case LAYER3_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR;
+       case LAYER4_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR;
+       case LAYER5_BITRATE_HEVC:
+               return V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR;
        default:
                return 0;
        }
@@ -575,7 +643,64 @@ int iris_set_header_mode_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_
                                     &hfi_val, sizeof(u32));
 }
 
-int iris_set_bitrate(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+int iris_set_bitrate_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       u32 entropy_mode = inst->fw_caps[ENTROPY_MODE].value;
+       u32 bitrate = inst->fw_caps[cap_id].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       struct hfi_bitrate hfi_val;
+       u32 max_bitrate;
+
+       if (!(inst->fw_caps[cap_id].flags & CAP_FLAG_CLIENT_SET) && cap_id != BITRATE)
+               return -EINVAL;
+
+       if (inst->codec == V4L2_PIX_FMT_HEVC) {
+               max_bitrate = CABAC_MAX_BITRATE;
+       } else {
+               if (entropy_mode == V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC)
+                       max_bitrate = CABAC_MAX_BITRATE;
+               else
+                       max_bitrate = CAVLC_MAX_BITRATE;
+       }
+
+       hfi_val.bitrate = min(bitrate, max_bitrate);
+
+       switch (cap_id) {
+       case BITRATE:
+       case LAYER0_BITRATE_H264:
+               hfi_val.layer_id = 0;
+               break;
+       case LAYER1_BITRATE_H264:
+               hfi_val.layer_id = 1;
+               break;
+       case LAYER2_BITRATE_H264:
+               hfi_val.layer_id = 2;
+               break;
+       case LAYER3_BITRATE_H264:
+               hfi_val.layer_id = 3;
+               break;
+       case LAYER4_BITRATE_H264:
+               hfi_val.layer_id = 4;
+               break;
+       case LAYER5_BITRATE_H264:
+               hfi_val.layer_id = 5;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (hfi_val.layer_id > 0 && !inst->fw_caps[LAYER_ENABLE].value)
+               return -EINVAL;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_STRUCTURE,
+                                            &hfi_val, sizeof(hfi_val));
+}
+
+int iris_set_bitrate_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
 {
        const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
        u32 entropy_mode = inst->fw_caps[ENTROPY_MODE].value;
@@ -1191,6 +1316,167 @@ int iris_set_intra_period(struct iris_inst *inst, enum platform_inst_fw_cap_type
                                             &intra_period, sizeof(intra_period));
 }
 
+int iris_set_layer_type(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       u32 layer_enable = inst->fw_caps[LAYER_ENABLE].value;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       u32 layer_type;
+
+       if (inst->hfi_rc_type == HFI_RATE_CONTROL_CQ ||
+           inst->hfi_rc_type == HFI_RATE_CONTROL_OFF)
+               return -EINVAL;
+
+       if (inst->codec == V4L2_PIX_FMT_H264) {
+               if (!layer_enable || !inst->fw_caps[LAYER_COUNT_H264].value)
+                       return -EINVAL;
+
+               if (inst->fw_caps[LAYER_TYPE_H264].value ==
+                       V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P) {
+                       if (inst->hfi_rc_type == HFI_RC_VBR_CFR)
+                               layer_type = HFI_HIER_P_HYBRID_LTR;
+                       else
+                               layer_type = HFI_HIER_P_SLIDING_WINDOW;
+               } else if (inst->fw_caps[LAYER_TYPE_H264].value ==
+                       V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B) {
+                       if (inst->hfi_rc_type == HFI_RC_VBR_CFR)
+                               layer_type = HFI_HIER_B;
+                       else
+                               return -EINVAL;
+               } else {
+                       return -EINVAL;
+               }
+       } else if (inst->codec == V4L2_PIX_FMT_HEVC) {
+               if (!inst->fw_caps[LAYER_COUNT_HEVC].value)
+                       return -EINVAL;
+
+               if (inst->fw_caps[LAYER_TYPE_HEVC].value ==
+                       V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P) {
+                       layer_type = HFI_HIER_P_SLIDING_WINDOW;
+               } else if (inst->fw_caps[LAYER_TYPE_HEVC].value ==
+                       V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B) {
+                       if (inst->hfi_rc_type == HFI_RC_VBR_CFR)
+                               layer_type = HFI_HIER_B;
+                       else
+                               return -EINVAL;
+               } else {
+                       return -EINVAL;
+               }
+       } else {
+               return -EINVAL;
+       }
+
+       inst->hfi_layer_type = layer_type;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32_ENUM,
+                                            &layer_type, sizeof(u32));
+}
+
+int iris_set_layer_count_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       struct vb2_queue *sq = v4l2_m2m_get_src_vq(inst->m2m_ctx);
+       struct vb2_queue *dq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+       u32 layer_enable = inst->fw_caps[LAYER_ENABLE].value;
+       u32 layer_count = inst->fw_caps[cap_id].value;
+       u32 hfi_id, ret;
+
+       if (!layer_enable || !layer_count)
+               return -EINVAL;
+
+       inst->hfi_layer_count = layer_count;
+
+       if (!vb2_is_streaming(sq) && !vb2_is_streaming(dq)) {
+               hfi_id = HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER;
+               ret = hfi_ops->session_set_property(inst, hfi_id,
+                                                   HFI_HOST_FLAGS_NONE,
+                                                   iris_get_port_info(inst, cap_id),
+                                                   HFI_PAYLOAD_U32,
+                                                   &layer_count, sizeof(u32));
+               if (ret)
+                       return ret;
+       }
+
+       hfi_id = inst->fw_caps[cap_id].hfi_id;
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32,
+                                            &layer_count, sizeof(u32));
+}
+
+int iris_set_layer_count_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       u32 layer_type = inst->hfi_layer_type;
+       u32 layer_count, layer_count_max;
+
+       layer_count = (inst->codec == V4L2_PIX_FMT_H264) ?
+               inst->fw_caps[LAYER_COUNT_H264].value :
+               inst->fw_caps[LAYER_COUNT_HEVC].value;
+
+       if (!layer_count)
+               return -EINVAL;
+
+       if (layer_type == HFI_HIER_B) {
+               layer_count_max = MAX_LAYER_HB;
+       } else if (layer_type == HFI_HIER_P_HYBRID_LTR) {
+               layer_count_max = MAX_AVC_LAYER_HP_HYBRID_LTR;
+       } else if (layer_type == HFI_HIER_P_SLIDING_WINDOW) {
+               if (inst->codec == V4L2_PIX_FMT_H264) {
+                       layer_count_max = MAX_AVC_LAYER_HP_SLIDING_WINDOW;
+               } else {
+                       if (inst->hfi_rc_type == HFI_RC_VBR_CFR)
+                               layer_count_max = MAX_HEVC_VBR_LAYER_HP_SLIDING_WINDOW;
+                       else
+                               layer_count_max = MAX_HEVC_LAYER_HP_SLIDING_WINDOW;
+               }
+       } else {
+               return -EINVAL;
+       }
+
+       if (layer_count > layer_count_max)
+               layer_count = layer_count_max;
+
+       layer_count += 1; /* base layer */
+       inst->hfi_layer_count = layer_count;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32,
+                                            &layer_count, sizeof(u32));
+}
+
+int iris_set_layer_bitrate(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id)
+{
+       const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+       struct vb2_queue *sq = v4l2_m2m_get_src_vq(inst->m2m_ctx);
+       struct vb2_queue *dq = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+       u32 hfi_id = inst->fw_caps[cap_id].hfi_id;
+       u32 bitrate = inst->fw_caps[cap_id].value;
+
+       /* ignore layer bitrate when total bitrate is set */
+       if (inst->fw_caps[BITRATE].flags & CAP_FLAG_CLIENT_SET)
+               return 0;
+
+       if (!(inst->fw_caps[cap_id].flags & CAP_FLAG_CLIENT_SET))
+               return -EINVAL;
+
+       if (!vb2_is_streaming(sq) && !vb2_is_streaming(dq))
+               return -EINVAL;
+
+       return hfi_ops->session_set_property(inst, hfi_id,
+                                            HFI_HOST_FLAGS_NONE,
+                                            iris_get_port_info(inst, cap_id),
+                                            HFI_PAYLOAD_U32,
+                                            &bitrate, sizeof(u32));
+}
+
 int iris_set_properties(struct iris_inst *inst, u32 plane)
 {
        const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
index 609258c81517b71523b682ca994786cdd020b07f..3c462ec9190be8935176b290588f224fe4f144a4 100644 (file)
@@ -22,7 +22,8 @@ int iris_set_level(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id
 int iris_set_profile_level_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_header_mode_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_header_mode_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
-int iris_set_bitrate(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_bitrate_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_bitrate_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_peak_bitrate(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_bitrate_mode_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_bitrate_mode_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
@@ -42,6 +43,10 @@ int iris_set_use_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_
 int iris_set_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_use_and_mark_ltr(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_intra_period(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_layer_type(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_layer_count_gen1(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_layer_count_gen2(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
+int iris_set_layer_bitrate(struct iris_inst *inst, enum platform_inst_fw_cap_type cap_id);
 int iris_set_properties(struct iris_inst *inst, u32 plane);
 
 #endif
index 792441463b4bad19da5a45b46c4dafcf2caa75c3..ca1545d28b5310d8c45a905287dcb69f6184d9cc 100644 (file)
@@ -136,7 +136,7 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8250_enc[] = {
                .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
                .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
                        CAP_FLAG_DYNAMIC_ALLOWED,
-               .set = iris_set_bitrate,
+               .set = iris_set_bitrate_gen1,
        },
        {
                .cap_id = BITRATE_MODE,
@@ -291,6 +291,98 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8250_enc[] = {
                .flags = CAP_FLAG_OUTPUT_PORT,
                .set = iris_set_intra_period,
        },
+       {
+               .cap_id = LAYER_ENABLE,
+               .min = 0,
+               .max = 1,
+               .step_or_mask = 1,
+               .value = 0,
+               .flags = CAP_FLAG_OUTPUT_PORT,
+       },
+       {
+               .cap_id = LAYER_TYPE_H264,
+               .min = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P,
+               .max = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P,
+               .step_or_mask = BIT(V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P),
+               .value = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_MENU,
+       },
+       {
+               .cap_id = LAYER_COUNT_H264,
+               .min = 0,
+               .max = MAX_HIER_CODING_LAYER_GEN1,
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER,
+               .flags = CAP_FLAG_OUTPUT_PORT,
+               .set = iris_set_layer_count_gen1,
+       },
+       {
+               .cap_id = LAYER0_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
+       {
+               .cap_id = LAYER1_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
+       {
+               .cap_id = LAYER2_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
+       {
+               .cap_id = LAYER3_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
+       {
+               .cap_id = LAYER4_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
+       {
+               .cap_id = LAYER5_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_bitrate_gen1,
+       },
 };
 
 static const u32 sm8250_vdec_input_config_param_default[] = {
index 05e7b5ff2b9224b201cf87858c0375ac6866e9bb..4cb54e5e4f1f15137d08027ac9a0d46c46784ea8 100644 (file)
@@ -604,11 +604,10 @@ iris_hfi_gen1_packet_session_set_property(struct hfi_session_set_property_pkt *p
                break;
        }
        case HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE: {
-               struct hfi_bitrate *brate = prop_data;
-               u32 *in = pdata;
+               struct hfi_bitrate *in = pdata, *brate = prop_data;
 
-               brate->bitrate = *in;
-               brate->layer_id = 0;
+               brate->bitrate = in->bitrate;
+               brate->layer_id = in->layer_id;
                packet->shdr.hdr.size += sizeof(u32) + sizeof(*brate);
                break;
        }
@@ -728,6 +727,20 @@ iris_hfi_gen1_packet_session_set_property(struct hfi_session_set_property_pkt *p
                packet->shdr.hdr.size += sizeof(u32) + sizeof(*intra_period);
                break;
        }
+       case HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER: {
+               u32 *in = pdata;
+
+               packet->data[1] = *in;
+               packet->shdr.hdr.size += sizeof(u32) + sizeof(u32);
+               break;
+       }
+       case HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER: {
+               u32 *in = pdata;
+
+               packet->data[1] = *in;
+               packet->shdr.hdr.size += sizeof(u32) + sizeof(u32);
+               break;
+       }
        default:
                return -EINVAL;
        }
index 4343661e86065f5623b2c02c7ee808a3c47a8c41..0e4dee19238464a9671a94eaab8eeda2d7f7ca9f 100644 (file)
 
 #define HFI_PROPERTY_PARAM_VENC_LTRMODE                                0x200501c
 #define HFI_PROPERTY_PARAM_VENC_MAX_NUM_B_FRAMES               0x2005020
+#define HFI_PROPERTY_PARAM_VENC_HIER_P_MAX_NUM_ENH_LAYER       0x2005026
 #define HFI_PROPERTY_CONFIG_VENC_TARGET_BITRATE                        0x2006001
 #define HFI_PROPERTY_CONFIG_VENC_INTRA_PERIOD                  0x2006003
 #define HFI_PROPERTY_CONFIG_VENC_MARKLTRFRAME                  0x2006009
 #define HFI_PROPERTY_CONFIG_VENC_USELTRFRAME                   0x200600a
 #define HFI_PROPERTY_CONFIG_VENC_SYNC_FRAME_SEQUENCE_HEADER    0x2006008
+#define HFI_PROPERTY_CONFIG_VENC_HIER_P_ENH_LAYER              0x200600b
 
 struct hfi_pkt_hdr {
        u32 size;
index 27878b70e516bec0eefbb094b58ecba882332bf5..7a85c1d4e5e699dc7c615865035b43d94217ce16 100644 (file)
@@ -391,7 +391,7 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8550_enc[] = {
                .hfi_id = HFI_PROP_TOTAL_BITRATE,
                .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
                        CAP_FLAG_DYNAMIC_ALLOWED,
-               .set = iris_set_bitrate,
+               .set = iris_set_bitrate_gen2,
        },
        {
                .cap_id = BITRATE_PEAK,
@@ -755,6 +755,188 @@ static const struct platform_inst_fw_cap inst_fw_cap_sm8550_enc[] = {
                .flags = CAP_FLAG_OUTPUT_PORT,
                .set = iris_set_u32,
        },
+       {
+               .cap_id = LAYER_ENABLE,
+               .min = 0,
+               .max = 1,
+               .step_or_mask = 1,
+               .value = 0,
+               .flags = CAP_FLAG_OUTPUT_PORT,
+       },
+       {
+               .cap_id = LAYER_TYPE_H264,
+               .min = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B,
+               .max = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P,
+               .step_or_mask = BIT(V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B) |
+                               BIT(V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P),
+               .value = V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P,
+               .hfi_id = HFI_PROP_LAYER_ENCODING_TYPE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_MENU,
+               .set = iris_set_layer_type,
+       },
+       {
+               .cap_id = LAYER_TYPE_HEVC,
+               .min = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B,
+               .max = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P,
+               .step_or_mask = BIT(V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B) |
+                               BIT(V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P),
+               .value = V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P,
+               .hfi_id = HFI_PROP_LAYER_ENCODING_TYPE,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_MENU,
+               .set = iris_set_layer_type,
+       },
+       {
+               .cap_id = LAYER_COUNT_H264,
+               .min = 0,
+               .max = 5,
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROP_LAYER_COUNT,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_count_gen2,
+       },
+       {
+               .cap_id = LAYER_COUNT_HEVC,
+               .min = 0,
+               .max = 5,
+               .step_or_mask = 1,
+               .value = 0,
+               .hfi_id = HFI_PROP_LAYER_COUNT,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_count_gen2,
+       },
+       {
+               .cap_id = LAYER0_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER1,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER1_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER2,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER2_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER3,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER3_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER4,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER4_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER5,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER5_BITRATE_H264,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER6,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER0_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER1,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER1_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER2,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER2_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER3,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER3_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER4,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER4_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER5,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       },
+       {
+               .cap_id = LAYER5_BITRATE_HEVC,
+               .min = 1,
+               .max = BITRATE_MAX,
+               .step_or_mask = 1,
+               .value = BITRATE_DEFAULT,
+               .hfi_id = HFI_PROP_BITRATE_LAYER6,
+               .flags = CAP_FLAG_OUTPUT_PORT | CAP_FLAG_INPUT_PORT |
+                       CAP_FLAG_DYNAMIC_ALLOWED,
+               .set = iris_set_layer_bitrate,
+       }
 };
 
 static const u32 sm8550_vdec_input_config_params_default[] = {
index aec19efc41a5ef47bbad2471d3c4575704859743..d09096a9d5f934acf072b05c2cf80f3007c3aa7e 100644 (file)
@@ -74,7 +74,22 @@ enum hfi_rate_control {
 #define HFI_PROP_LTR_COUNT                     0x03000134
 #define HFI_PROP_LTR_MARK                      0x03000135
 #define HFI_PROP_LTR_USE                       0x03000136
+
+enum hfi_layer_encoding_type {
+       HFI_HIER_P_SLIDING_WINDOW       = 0x1,
+       HFI_HIER_P_HYBRID_LTR           = 0x2,
+       HFI_HIER_B                      = 0x3,
+};
+
+#define HFI_PROP_LAYER_ENCODING_TYPE           0x03000138
+#define HFI_PROP_LAYER_COUNT                   0x03000139
 #define HFI_PROP_TOTAL_BITRATE                 0x0300013b
+#define HFI_PROP_BITRATE_LAYER1                        0x0300013c
+#define HFI_PROP_BITRATE_LAYER2                        0x0300013d
+#define HFI_PROP_BITRATE_LAYER3                        0x0300013e
+#define HFI_PROP_BITRATE_LAYER4                        0x0300013f
+#define HFI_PROP_BITRATE_LAYER5                        0x03000140
+#define HFI_PROP_BITRATE_LAYER6                        0x03000141
 #define HFI_PROP_MAX_GOP_FRAMES                        0x03000146
 #define HFI_PROP_MAX_B_FRAMES                  0x03000147
 #define HFI_PROP_QUALITY_MODE                  0x03000148
index 352af99699dd57641fd942d1fe3df9eb377d26b6..0041b0cc400195aaa29f4ed12c54372c26693441 100644 (file)
@@ -77,6 +77,8 @@ struct iris_fmt {
  * @enc_raw_height: source image height for encoder instance
  * @enc_scale_width: scale width for encoder instance
  * @enc_scale_height: scale height for encoder instance
+ * @hfi_layer_type: hierarchical coding layer type
+ * @hfi_layer_count: hierarchical coding layer count
  */
 
 struct iris_inst {
@@ -120,6 +122,8 @@ struct iris_inst {
        u32                             enc_raw_height;
        u32                             enc_scale_width;
        u32                             enc_scale_height;
+       u32                             hfi_layer_type;
+       u32                             hfi_layer_count;
 };
 
 #endif
index 422e83ae07884ce72d6e9aba8c176f474384b0f0..7ca37ca2dcca695816b2a285d0fe494a32b3671b 100644 (file)
@@ -31,6 +31,12 @@ struct iris_inst;
 #define INVALID_DEFAULT_MARK_OR_USE_LTR                -1
 #define MAX_LTR_FRAME_COUNT_GEN1               4
 #define MAX_LTR_FRAME_COUNT_GEN2               2
+#define MAX_LAYER_HB                           3
+#define MAX_AVC_LAYER_HP_HYBRID_LTR            5
+#define MAX_AVC_LAYER_HP_SLIDING_WINDOW                3
+#define MAX_HEVC_LAYER_HP_SLIDING_WINDOW       3
+#define MAX_HEVC_VBR_LAYER_HP_SLIDING_WINDOW   5
+#define MAX_HIER_CODING_LAYER_GEN1             6
 
 enum stage_type {
        STAGE_1 = 1,
@@ -159,6 +165,23 @@ enum platform_inst_fw_cap_type {
        MARK_LTR,
        B_FRAME,
        INTRA_PERIOD,
+       LAYER_ENABLE,
+       LAYER_TYPE_H264,
+       LAYER_TYPE_HEVC,
+       LAYER_COUNT_H264,
+       LAYER_COUNT_HEVC,
+       LAYER0_BITRATE_H264,
+       LAYER1_BITRATE_H264,
+       LAYER2_BITRATE_H264,
+       LAYER3_BITRATE_H264,
+       LAYER4_BITRATE_H264,
+       LAYER5_BITRATE_H264,
+       LAYER0_BITRATE_HEVC,
+       LAYER1_BITRATE_HEVC,
+       LAYER2_BITRATE_HEVC,
+       LAYER3_BITRATE_HEVC,
+       LAYER4_BITRATE_HEVC,
+       LAYER5_BITRATE_HEVC,
        INST_FW_CAP_MAX,
 };
 
index 0ed82dc2b8af8c789df1b8c10c1a5afc51ef39d8..c2cd4adc082394a9ab6f32a37fe4e57678019d89 100644 (file)
@@ -936,6 +936,8 @@ static u32 iris_vpu_enc_bin_size(struct iris_inst *inst)
 
 static inline u32 hfi_buffer_get_recon_count(struct iris_inst *inst)
 {
+       u32 layer_count = inst->hfi_layer_count;
+       u32 layer_type = inst->hfi_layer_type;
        u32 bframe_count, ltr_count;
        u32 num_ref = 1;
 
@@ -945,9 +947,35 @@ static inline u32 hfi_buffer_get_recon_count(struct iris_inst *inst)
        if (bframe_count)
                num_ref = 2;
 
+       /* The shift operation here is rounding logic, similar to [(x+1)/2]. */
+       if (layer_type == HFI_HIER_P_HYBRID_LTR)
+               num_ref = (layer_count + 1) >> 1;
+
+       if (layer_type == HFI_HIER_P_SLIDING_WINDOW) {
+               if (inst->codec == V4L2_PIX_FMT_HEVC)
+                       num_ref = (layer_count + 1) >> 1;
+               else if (inst->codec == V4L2_PIX_FMT_H264 && layer_count < 4)
+                       num_ref = (layer_count - 1);
+               else
+                       num_ref = layer_count;
+       }
+
        if (ltr_count)
                num_ref = num_ref + ltr_count;
 
+       /*
+        * The expression (1 << layers - 2) + 1 accounts for the number of reference
+        * frames in the Adaptive Hierarchical B-frame encoding case. In this scheme,
+        * the number of frames in a sub-GOP is related to (2^(number of layers) - 1),
+        * hence the use of the shift operation.
+        */
+       if (layer_type == HFI_HIER_B) {
+               if (inst->codec == V4L2_PIX_FMT_HEVC)
+                       num_ref = layer_count;
+               else
+                       num_ref = (1 << (layer_count - 2)) + 1;
+       }
+
        return num_ref;
 }