msm: vidc: Enable color space conversion
Control for color space conversion is enabled with new HFI macro.
New control created for enabling custom matrix. Custom matrix
values moved to platform file.
CRs-Fixed: 2091104
Change-Id: I426b50f9d63995113f4b8836ee299fdff2a28a6b
Signed-off-by: Chinmay Sawarkar <chinmays@codeaurora.org>
diff --git a/drivers/media/platform/msm/vidc/hfi_packetization.c b/drivers/media/platform/msm/vidc/hfi_packetization.c
index 4512409..295e08f 100644
--- a/drivers/media/platform/msm/vidc/hfi_packetization.c
+++ b/drivers/media/platform/msm/vidc/hfi_packetization.c
@@ -1618,6 +1618,9 @@
HFI_PROPERTY_PARAM_VPE_COLOR_SPACE_CONVERSION;
hfi = (struct hfi_vpe_color_space_conversion *)
&pkt->rg_property_data[1];
+
+ hfi->input_color_primaries = hal->input_color_primaries;
+ hfi->custom_matrix_enabled = hal->custom_matrix_enabled;
memcpy(hfi->csc_matrix, hal->csc_matrix,
sizeof(hfi->csc_matrix));
memcpy(hfi->csc_bias, hal->csc_bias, sizeof(hfi->csc_bias));
diff --git a/drivers/media/platform/msm/vidc/msm_venc.c b/drivers/media/platform/msm/vidc/msm_venc.c
index 03b4e4d..a4c746a 100644
--- a/drivers/media/platform/msm/vidc/msm_venc.c
+++ b/drivers/media/platform/msm/vidc/msm_venc.c
@@ -42,25 +42,6 @@
#define MIN_NUM_ENC_OUTPUT_BUFFERS 4
#define MIN_NUM_ENC_CAPTURE_BUFFERS 5
-/*
- * Default 601 to 709 conversion coefficients for resolution: 176x144 negative
- * coeffs are converted to s4.9 format (e.g. -22 converted to ((1 << 13) - 22)
- * 3x3 transformation matrix coefficients in s4.9 fixed point format
- */
-static u32 vpe_csc_601_to_709_matrix_coeff[HAL_MAX_MATRIX_COEFFS] = {
- 470, 8170, 8148, 0, 490, 50, 0, 34, 483
-};
-
-/* offset coefficients in s9 fixed point format */
-static u32 vpe_csc_601_to_709_bias_coeff[HAL_MAX_BIAS_COEFFS] = {
- 34, 0, 4
-};
-
-/* clamping value for Y/U/V([min,max] for Y/U/V) */
-static u32 vpe_csc_601_to_709_limit_coeff[HAL_MAX_LIMIT_COEFFS] = {
- 16, 235, 16, 240, 16, 240
-};
-
static const char *const mpeg_video_rate_control[] = {
"No Rate Control",
"VBR VFR",
@@ -1046,6 +1027,15 @@
.default_value = 0,
.step = 1,
},
+ {
+ .id = V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC_CUSTOM_MATRIX,
+ .name = "Enable/Disable CSC Custom Matrix",
+ .type = V4L2_CTRL_TYPE_BOOLEAN,
+ .minimum = 0,
+ .maximum = 1,
+ .default_value = 0,
+ .step = 1,
+ },
};
@@ -1124,7 +1114,8 @@
},
};
-static int msm_venc_set_csc(struct msm_vidc_inst *inst);
+static int msm_venc_set_csc(struct msm_vidc_inst *inst,
+ u32 color_primaries, u32 custom_matrix);
static int msm_venc_toggle_hier_p(struct msm_vidc_inst *inst, int layers)
{
@@ -1198,6 +1189,7 @@
struct hal_video_signal_info signal_info = {0};
struct hal_vui_timing_info vui_timing_info = {0};
enum hal_iframesize_type iframesize_type = HAL_IFRAMESIZE_TYPE_DEFAULT;
+ u32 color_primaries, custom_matrix;
if (!inst || !inst->core || !inst->core->device) {
dprintk(VIDC_ERR, "%s invalid parameters\n", __func__);
@@ -1898,11 +1890,23 @@
break;
}
case V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC:
- if (ctrl->val == V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC_ENABLE) {
- rc = msm_venc_set_csc(inst);
- if (rc)
- dprintk(VIDC_ERR, "fail to set csc: %d\n", rc);
- }
+ if (ctrl->val != V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC_ENABLE)
+ break;
+ temp_ctrl = TRY_GET_CTRL(V4L2_CID_MPEG_VIDC_VIDEO_COLOR_SPACE);
+ color_primaries = temp_ctrl->val;
+ temp_ctrl =
+ TRY_GET_CTRL(V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC_CUSTOM_MATRIX);
+ custom_matrix = temp_ctrl->val;
+ rc = msm_venc_set_csc(inst, color_primaries, custom_matrix);
+ if (rc)
+ dprintk(VIDC_ERR, "fail to set csc: %d\n", rc);
+ break;
+ case V4L2_CID_MPEG_VIDC_VIDEO_VPE_CSC_CUSTOM_MATRIX:
+ temp_ctrl = TRY_GET_CTRL(V4L2_CID_MPEG_VIDC_VIDEO_COLOR_SPACE);
+ color_primaries = temp_ctrl->val;
+ rc = msm_venc_set_csc(inst, color_primaries, ctrl->val);
+ if (rc)
+ dprintk(VIDC_ERR, "fail to set csc: %d\n", rc);
break;
case V4L2_CID_MPEG_VIDC_VIDEO_LOWLATENCY_MODE:
{
@@ -2291,22 +2295,42 @@
return rc;
}
-static int msm_venc_set_csc(struct msm_vidc_inst *inst)
+static int msm_venc_set_csc(struct msm_vidc_inst *inst,
+ u32 color_primaries, u32 custom_matrix)
{
int rc = 0;
int count = 0;
struct hal_vpe_color_space_conversion vpe_csc;
+ struct msm_vidc_platform_resources *resources;
+ u32 *bias_coeff = NULL;
+ u32 *csc_limit = NULL;
+ u32 *csc_matrix = NULL;
- while (count < HAL_MAX_MATRIX_COEFFS) {
- if (count < HAL_MAX_BIAS_COEFFS)
- vpe_csc.csc_bias[count] =
- vpe_csc_601_to_709_bias_coeff[count];
- if (count < HAL_MAX_LIMIT_COEFFS)
- vpe_csc.csc_limit[count] =
- vpe_csc_601_to_709_limit_coeff[count];
- vpe_csc.csc_matrix[count] =
- vpe_csc_601_to_709_matrix_coeff[count];
- count = count + 1;
+ resources = &(inst->core->resources);
+ bias_coeff =
+ resources->csc_coeff_data->vpe_csc_custom_bias_coeff;
+ csc_limit =
+ resources->csc_coeff_data->vpe_csc_custom_limit_coeff;
+ csc_matrix =
+ resources->csc_coeff_data->vpe_csc_custom_matrix_coeff;
+
+ vpe_csc.input_color_primaries = color_primaries;
+ /* Custom bias, matrix & limit */
+ vpe_csc.custom_matrix_enabled = custom_matrix;
+
+ if (vpe_csc.custom_matrix_enabled && bias_coeff != NULL
+ && csc_limit != NULL && csc_matrix != NULL) {
+ while (count < HAL_MAX_MATRIX_COEFFS) {
+ if (count < HAL_MAX_BIAS_COEFFS)
+ vpe_csc.csc_bias[count] =
+ bias_coeff[count];
+ if (count < HAL_MAX_LIMIT_COEFFS)
+ vpe_csc.csc_limit[count] =
+ csc_limit[count];
+ vpe_csc.csc_matrix[count] =
+ csc_matrix[count];
+ count = count + 1;
+ }
}
rc = msm_comm_try_set_prop(inst,
HAL_PARAM_VPE_COLOR_SPACE_CONVERSION, &vpe_csc);
diff --git a/drivers/media/platform/msm/vidc/msm_vidc_internal.h b/drivers/media/platform/msm/vidc/msm_vidc_internal.h
index 1ad28ba..c5fd060 100644
--- a/drivers/media/platform/msm/vidc/msm_vidc_internal.h
+++ b/drivers/media/platform/msm/vidc/msm_vidc_internal.h
@@ -169,6 +169,12 @@
enum buffer_owner buffer_ownership;
};
+struct msm_vidc_csc_coeff {
+ u32 *vpe_csc_custom_matrix_coeff;
+ u32 *vpe_csc_custom_bias_coeff;
+ u32 *vpe_csc_custom_limit_coeff;
+};
+
struct msm_vidc_common_data {
char key[128];
int value;
@@ -187,6 +193,7 @@
unsigned int common_data_length;
struct msm_vidc_codec_data *codec_data;
unsigned int codec_data_length;
+ struct msm_vidc_csc_coeff csc_data;
};
struct msm_vidc_format {
diff --git a/drivers/media/platform/msm/vidc/msm_vidc_platform.c b/drivers/media/platform/msm/vidc/msm_vidc_platform.c
index 7ca6ab0..16ed4f4 100644
--- a/drivers/media/platform/msm/vidc/msm_vidc_platform.c
+++ b/drivers/media/platform/msm/vidc/msm_vidc_platform.c
@@ -52,6 +52,26 @@
CODEC_ENTRY(V4L2_PIX_FMT_VP9, MSM_VIDC_DECODER, 50, 200, 200),
};
+/*
+ * Custom conversion coefficients for resolution: 176x144 negative
+ * coeffs are converted to s4.9 format
+ * (e.g. -22 converted to ((1 << 13) - 22)
+ * 3x3 transformation matrix coefficients in s4.9 fixed point format
+ */
+static u32 vpe_csc_custom_matrix_coeff[HAL_MAX_MATRIX_COEFFS] = {
+ 470, 8170, 8148, 0, 490, 50, 0, 34, 483
+};
+
+/* offset coefficients in s9 fixed point format */
+static u32 vpe_csc_custom_bias_coeff[HAL_MAX_BIAS_COEFFS] = {
+ 34, 0, 4
+};
+
+/* clamping value for Y/U/V([min,max] for Y/U/V) */
+static u32 vpe_csc_custom_limit_coeff[HAL_MAX_LIMIT_COEFFS] = {
+ 16, 235, 16, 240, 16, 240
+};
+
static struct msm_vidc_common_data default_common_data[] = {
{
.key = "qcom,never-unload-fw",
@@ -112,6 +132,9 @@
.codec_data_length = ARRAY_SIZE(default_codec_data),
.common_data = default_common_data,
.common_data_length = ARRAY_SIZE(default_common_data),
+ .csc_data.vpe_csc_custom_bias_coeff = vpe_csc_custom_bias_coeff,
+ .csc_data.vpe_csc_custom_matrix_coeff = vpe_csc_custom_matrix_coeff,
+ .csc_data.vpe_csc_custom_limit_coeff = vpe_csc_custom_limit_coeff,
};
static struct msm_vidc_platform_data sdm845_data = {
@@ -119,6 +142,9 @@
.codec_data_length = ARRAY_SIZE(sdm845_codec_data),
.common_data = sdm845_common_data,
.common_data_length = ARRAY_SIZE(sdm845_common_data),
+ .csc_data.vpe_csc_custom_bias_coeff = vpe_csc_custom_bias_coeff,
+ .csc_data.vpe_csc_custom_matrix_coeff = vpe_csc_custom_matrix_coeff,
+ .csc_data.vpe_csc_custom_limit_coeff = vpe_csc_custom_limit_coeff,
};
static const struct of_device_id msm_vidc_dt_match[] = {
diff --git a/drivers/media/platform/msm/vidc/msm_vidc_res_parse.c b/drivers/media/platform/msm/vidc/msm_vidc_res_parse.c
index 46fb75f..01e7aaa 100644
--- a/drivers/media/platform/msm/vidc/msm_vidc_res_parse.c
+++ b/drivers/media/platform/msm/vidc/msm_vidc_res_parse.c
@@ -788,6 +788,8 @@
res->non_fatal_pagefaults = find_key_value(platform_data,
"qcom,domain-attr-non-fatal-faults");
+ res->csc_coeff_data = &platform_data->csc_data;
+
return rc;
}
diff --git a/drivers/media/platform/msm/vidc/msm_vidc_resources.h b/drivers/media/platform/msm/vidc/msm_vidc_resources.h
index 31d5a42..8309fce 100644
--- a/drivers/media/platform/msm/vidc/msm_vidc_resources.h
+++ b/drivers/media/platform/msm/vidc/msm_vidc_resources.h
@@ -192,6 +192,7 @@
bool non_fatal_pagefaults;
struct msm_vidc_codec_data *codec_data;
int codec_data_count;
+ struct msm_vidc_csc_coeff *csc_coeff_data;
};
static inline bool is_iommu_present(struct msm_vidc_platform_resources *res)
diff --git a/drivers/media/platform/msm/vidc/vidc_hfi.h b/drivers/media/platform/msm/vidc/vidc_hfi.h
index 8e9e51f..e899af3 100644
--- a/drivers/media/platform/msm/vidc/vidc_hfi.h
+++ b/drivers/media/platform/msm/vidc/vidc_hfi.h
@@ -226,8 +226,6 @@
(HFI_DOMAIN_BASE_VENC + HFI_ARCH_OX_OFFSET + 0x6000)
#define HFI_PROPERTY_PARAM_VPE_OX_START \
(HFI_DOMAIN_BASE_VPE + HFI_ARCH_OX_OFFSET + 0x7000)
-#define HFI_PROPERTY_PARAM_VPE_COLOR_SPACE_CONVERSION \
- (HFI_PROPERTY_PARAM_VPE_OX_START + 0x001)
#define HFI_PROPERTY_CONFIG_VPE_OX_START \
(HFI_DOMAIN_BASE_VPE + HFI_ARCH_OX_OFFSET + 0x8000)
diff --git a/drivers/media/platform/msm/vidc/vidc_hfi_api.h b/drivers/media/platform/msm/vidc/vidc_hfi_api.h
index f350f25..360c000 100644
--- a/drivers/media/platform/msm/vidc/vidc_hfi_api.h
+++ b/drivers/media/platform/msm/vidc/vidc_hfi_api.h
@@ -863,6 +863,8 @@
};
struct hal_vpe_color_space_conversion {
+ u32 input_color_primaries;
+ u32 custom_matrix_enabled;
u32 csc_matrix[HAL_MAX_MATRIX_COEFFS];
u32 csc_bias[HAL_MAX_BIAS_COEFFS];
u32 csc_limit[HAL_MAX_LIMIT_COEFFS];
diff --git a/drivers/media/platform/msm/vidc/vidc_hfi_helper.h b/drivers/media/platform/msm/vidc/vidc_hfi_helper.h
index 6a239b3..9732868 100644
--- a/drivers/media/platform/msm/vidc/vidc_hfi_helper.h
+++ b/drivers/media/platform/msm/vidc/vidc_hfi_helper.h
@@ -358,6 +358,8 @@
(HFI_DOMAIN_BASE_VPE + HFI_ARCH_COMMON_OFFSET + 0x7000)
#define HFI_PROPERTY_PARAM_VPE_ROTATION \
(HFI_PROPERTY_PARAM_VPE_COMMON_START + 0x001)
+#define HFI_PROPERTY_PARAM_VPE_COLOR_SPACE_CONVERSION \
+ (HFI_PROPERTY_PARAM_VPE_COMMON_START + 0x002)
#define HFI_PROPERTY_CONFIG_VPE_COMMON_START \
(HFI_DOMAIN_BASE_VPE + HFI_ARCH_COMMON_OFFSET + 0x8000)
@@ -715,6 +717,8 @@
};
struct hfi_vpe_color_space_conversion {
+ u32 input_color_primaries;
+ u32 custom_matrix_enabled;
u32 csc_matrix[HFI_MAX_MATRIX_COEFFS];
u32 csc_bias[HFI_MAX_BIAS_COEFFS];
u32 csc_limit[HFI_MAX_LIMIT_COEFFS];