Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ddd1d975 authored by Chinmay Sawarkar's avatar Chinmay Sawarkar Committed by Vaibhav Deshu Venkatesh
Browse files

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: default avatarChinmay Sawarkar <chinmays@codeaurora.org>
parent 56213878
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1618,6 +1618,9 @@ int create_pkt_cmd_session_set_property(
				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));
+61 −37
Original line number Diff line number Diff line
@@ -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 @@ static struct msm_vidc_ctrl msm_venc_ctrls[] = {
		.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 struct msm_vidc_format venc_formats[] = {
	},
};

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 @@ int msm_venc_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
	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 @@ int msm_venc_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
		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 (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,23 +2295,43 @@ int msm_venc_enum_fmt(struct msm_vidc_inst *inst, struct v4l2_fmtdesc *f)
	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;

	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] =
				vpe_csc_601_to_709_bias_coeff[count];
					bias_coeff[count];
			if (count < HAL_MAX_LIMIT_COEFFS)
				vpe_csc.csc_limit[count] =
				vpe_csc_601_to_709_limit_coeff[count];
					csc_limit[count];
			vpe_csc.csc_matrix[count] =
			vpe_csc_601_to_709_matrix_coeff[count];
				csc_matrix[count];
			count = count + 1;
		}
	}
	rc = msm_comm_try_set_prop(inst,
			HAL_PARAM_VPE_COLOR_SPACE_CONVERSION, &vpe_csc);
	if (rc)
+7 −0
Original line number Diff line number Diff line
@@ -169,6 +169,12 @@ struct internal_buf {
	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 @@ struct msm_vidc_platform_data {
	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 {
+26 −0
Original line number Diff line number Diff line
@@ -52,6 +52,26 @@ static struct msm_vidc_codec_data sdm845_codec_data[] = {
	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 @@ static struct msm_vidc_platform_data default_data = {
	.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 @@ static struct msm_vidc_platform_data sdm845_data = {
	.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[] = {
+2 −0
Original line number Diff line number Diff line
@@ -788,6 +788,8 @@ int read_platform_resources_from_drv_data(
	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;

}
Loading