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

Commit 5dd137bb authored by Chinmay Sawarkar's avatar Chinmay Sawarkar
Browse files

msm: vidc: Update internal rate control selection



Remap unused rate control types and configure HRD_SIZE and
Low Latency is required.

CRs-Fixed: 2384822
Change-Id: Ifafa729fc2fdfbbd0ba42a069601e2b8a417fcdf
Signed-off-by: default avatarChinmay Sawarkar <chinmays@codeaurora.org>
parent a52d1034
Loading
Loading
Loading
Loading
+45 −4
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@
#define MAX_INTRA_REFRESH_MBS ((7680 * 4320) >> 8)
#define MAX_LTR_FRAME_COUNT 10
#define MAX_NUM_B_FRAMES 1
#define MIN_CBRPLUS_W 1280
#define MIN_CBRPLUS_H 720

#define L_MODE V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY
#define MIN_NUM_ENC_OUTPUT_BUFFERS 4
@@ -2258,13 +2260,55 @@ int msm_venc_set_rate_control(struct msm_vidc_inst *inst)
{
	int rc = 0;
	struct hfi_device *hdev;
	u32 hfi_rc;
	u32 hfi_rc, codec;
	u32 height, width, mbpf;
	struct hfi_vbv_hrd_buf_size hrd_buf_size;

	if (!inst || !inst->core) {
		dprintk(VIDC_ERR, "%s: invalid params\n", __func__);
		return -EINVAL;
	}

	hdev = inst->core->device;
	inst->clk_data.is_cbr_plus = false;
	codec = inst->fmts[CAPTURE_PORT].fourcc;
	height = inst->prop.height[OUTPUT_PORT];
	width = inst->prop.width[OUTPUT_PORT];
	mbpf = NUM_MBS_PER_FRAME(height, width);

	if (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_MBR_VFR)
		inst->rc_type = V4L2_MPEG_VIDEO_BITRATE_MODE_MBR;
	else if (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
			   inst->clk_data.low_latency_mode)
		inst->rc_type = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;

	if ((inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
		inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR_VFR) &&
		(codec != V4L2_PIX_FMT_VP8)) {
		hrd_buf_size.vbv_hrd_buf_size = 500;
		inst->clk_data.low_latency_mode = true;

		if ((width > MIN_CBRPLUS_W && height > MIN_CBRPLUS_H) ||
			(width > MIN_CBRPLUS_H && height > MIN_CBRPLUS_W) ||
			mbpf > NUM_MBS_PER_FRAME(720, 1280)) {
			hrd_buf_size.vbv_hrd_buf_size = 1000;
			inst->clk_data.is_cbr_plus = true;
		}

		dprintk(VIDC_DBG, "Set hrd_buf_size %d",
				hrd_buf_size.vbv_hrd_buf_size);

		rc = call_hfi_op(hdev, session_set_property,
			(void *)inst->session,
			HFI_PROPERTY_CONFIG_VENC_VBV_HRD_BUF_SIZE,
			(void *)&hrd_buf_size, sizeof(hrd_buf_size));
		if (rc) {
			dprintk(VIDC_ERR, "%s: set HRD_BUF_SIZE %u failed\n",
					__func__,
					hrd_buf_size.vbv_hrd_buf_size);
			inst->clk_data.is_cbr_plus = false;
		}
	}

	switch (inst->rc_type) {
	case RATE_CONTROL_OFF:
@@ -2282,9 +2326,6 @@ int msm_venc_set_rate_control(struct msm_vidc_inst *inst)
	case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR_VFR:
		hfi_rc = HFI_RATE_CONTROL_CBR_VFR;
		break;
	case V4L2_MPEG_VIDEO_BITRATE_MODE_MBR_VFR:
		hfi_rc = HFI_RATE_CONTROL_MBR_VFR;
		break;
	case V4L2_MPEG_VIDEO_BITRATE_MODE_CQ:
		hfi_rc = HFI_RATE_CONTROL_CQ;
		break;
+0 −66
Original line number Diff line number Diff line
@@ -794,64 +794,6 @@ static inline int msm_vidc_verify_buffer_counts(struct msm_vidc_inst *inst)
	return rc;
}

int msm_vidc_set_internal_config(struct msm_vidc_inst *inst)
{
	int rc = 0;
	u32 rc_mode = RATE_CONTROL_OFF;
	struct hfi_vbv_hdr_buf_size hrd_buf_size;
	struct hfi_enable latency;
	struct hfi_device *hdev;
	u32 codec;
	u32 mbps, fps;
	u32 output_width, output_height;

	if (!inst || !inst->core || !inst->core->device) {
		dprintk(VIDC_WARN, "%s: Invalid parameter\n", __func__);
		return -EINVAL;
	}

	if (inst->session_type != MSM_VIDC_ENCODER)
		return rc;

	hdev = inst->core->device;

	codec = inst->fmts[CAPTURE_PORT].fourcc;
	latency.enable =  msm_comm_g_ctrl_for_id(inst,
			V4L2_CID_MPEG_VIDC_VIDEO_LOWLATENCY_MODE);

	if (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_MBR_VFR)
		rc_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_MBR;
	else if (inst->rc_type == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
			   latency.enable == V4L2_MPEG_MSM_VIDC_ENABLE &&
			   codec != V4L2_PIX_FMT_VP8)
		rc_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;

	output_height = inst->prop.height[CAPTURE_PORT];
	output_width = inst->prop.width[CAPTURE_PORT];
	fps = inst->clk_data.frame_rate >> 16;
	mbps = NUM_MBS_PER_SEC(output_height, output_width, fps);
	if ((rc_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
		 rc_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR_VFR) &&
		(codec != V4L2_PIX_FMT_VP8)) {
		if ((rc_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR &&
		    mbps <= CBR_MB_LIMIT) ||
		   (rc_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR_VFR &&
		    mbps <= CBR_VFR_MB_LIMIT))
			hrd_buf_size.vbv_hdr_buf_size = 500;
		else
			hrd_buf_size.vbv_hdr_buf_size = 1000;
		dprintk(VIDC_DBG, "Enable hdr_buf_size %d :\n",
				hrd_buf_size.vbv_hdr_buf_size);
		rc = call_hfi_op(hdev, session_set_property,
			(void *)inst->session,
			HFI_PROPERTY_CONFIG_VENC_VBV_HRD_BUF_SIZE,
			(void *)&hrd_buf_size, sizeof(hrd_buf_size));
		inst->clk_data.low_latency_mode = true;
	}

	return rc;
}

static int msm_vidc_set_rotation(struct msm_vidc_inst *inst)
{
	int rc = 0;
@@ -994,14 +936,6 @@ static inline int start_streaming(struct msm_vidc_inst *inst)
		goto fail_start;
	}

	rc = msm_vidc_set_internal_config(inst);
	if (rc) {
		dprintk(VIDC_ERR,
			"Set internal config failed %pK\n", inst);
		goto fail_start;
	}


	/* Decide work mode for current session */
	rc = call_core_op(inst->core, decide_work_mode, inst);
	if (rc) {
+1 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ struct clock_data {
	u32 opb_fourcc;
	u32 work_mode;
	bool low_latency_mode;
	bool is_cbr_plus;
	bool turbo_mode;
	u32 work_route;
	u32 dcvs_flags;
+2 −2
Original line number Diff line number Diff line
@@ -1097,8 +1097,8 @@ struct hfi_hdr10_pq_sei {
	struct msm_vidc_content_light_level_sei_payload cll_info;
};

struct hfi_vbv_hdr_buf_size {
	u32 vbv_hdr_buf_size;
struct hfi_vbv_hrd_buf_size {
	u32 vbv_hrd_buf_size;
};

#endif