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

Commit 009108f4 authored by Vaibhav Deshu Venkatesh's avatar Vaibhav Deshu Venkatesh Committed by Maheshwar Ajja
Browse files

msm: vidc: Amend min buffer count maintenance logic



Initialize the min buffer count in driver based on the
codec format and ignore the min buffer count from firmware
except in case of sufficient/insufficient event. So the
min buffer count will never be updated in driver until
sufficient/insufficient event is received from firmware.

CRs-Fixed: 2257450
Change-Id: Ie3e02dcd59c62be2da8189e3d4c49eeec1b79c8e
Signed-off-by: default avatarVaibhav Deshu Venkatesh <vdeshuve@codeaurora.org>
Signed-off-by: default avatarMaheshwar Ajja <majja@codeaurora.org>
parent d210dd22
Loading
Loading
Loading
Loading
+62 −10
Original line number Diff line number Diff line
@@ -476,6 +476,8 @@ struct msm_vidc_format vdec_formats[] = {
		.get_frame_size = get_frame_size_compressed,
		.type = OUTPUT_PORT,
		.defer_outputs = false,
		.input_min_count = 4,
		.output_min_count = 6,
	},
	{
		.name = "H264",
@@ -484,6 +486,8 @@ struct msm_vidc_format vdec_formats[] = {
		.get_frame_size = get_frame_size_compressed,
		.type = OUTPUT_PORT,
		.defer_outputs = false,
		.input_min_count = 4,
		.output_min_count = 8,
	},
	{
		.name = "HEVC",
@@ -492,6 +496,8 @@ struct msm_vidc_format vdec_formats[] = {
		.get_frame_size = get_frame_size_compressed,
		.type = OUTPUT_PORT,
		.defer_outputs = false,
		.input_min_count = 4,
		.output_min_count = 8,
	},
	{
		.name = "VP8",
@@ -500,6 +506,8 @@ struct msm_vidc_format vdec_formats[] = {
		.get_frame_size = get_frame_size_compressed_full_yuv,
		.type = OUTPUT_PORT,
		.defer_outputs = false,
		.input_min_count = 4,
		.output_min_count = 6,
	},
	{
		.name = "VP9",
@@ -508,6 +516,8 @@ struct msm_vidc_format vdec_formats[] = {
		.get_frame_size = get_frame_size_compressed_full_yuv,
		.type = OUTPUT_PORT,
		.defer_outputs = true,
		.input_min_count = 4,
		.output_min_count = 11,
	},
};

@@ -769,6 +779,16 @@ int msm_vdec_inst_init(struct msm_vidc_inst *inst)
	inst->buff_req.buffer[3].buffer_count_min_host =
	inst->buff_req.buffer[3].buffer_count_actual =
		MIN_NUM_DEC_CAPTURE_BUFFERS;
	inst->buff_req.buffer[4].buffer_type = HAL_BUFFER_EXTRADATA_INPUT;
	inst->buff_req.buffer[5].buffer_type = HAL_BUFFER_EXTRADATA_OUTPUT;
	inst->buff_req.buffer[6].buffer_type = HAL_BUFFER_EXTRADATA_OUTPUT2;
	inst->buff_req.buffer[7].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH;
	inst->buff_req.buffer[8].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH_1;
	inst->buff_req.buffer[9].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH_2;
	inst->buff_req.buffer[10].buffer_type = HAL_BUFFER_INTERNAL_PERSIST;
	inst->buff_req.buffer[11].buffer_type = HAL_BUFFER_INTERNAL_PERSIST_1;
	inst->buff_req.buffer[12].buffer_type = HAL_BUFFER_INTERNAL_CMD_QUEUE;
	inst->buff_req.buffer[13].buffer_type = HAL_BUFFER_INTERNAL_RECON;

	/* By default, initialize OUTPUT port to H264 decoder */
	fmt = msm_comm_get_pixel_fmt_fourcc(vdec_formats,
@@ -811,6 +831,7 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
	struct hal_profile_level profile_level;
	struct hal_frame_size frame_sz;
	struct hal_buffer_requirements *bufreq;
	struct hal_buffer_requirements *bufreq_out2;

	if (!inst || !inst->core || !inst->core->device) {
		dprintk(VIDC_ERR, "%s invalid parameters\n", __func__);
@@ -1013,6 +1034,16 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
				dprintk(VIDC_ERR,
					"Failed:Disabling OUTPUT2 port : %d\n",
					rc);

			bufreq_out2 = get_buff_req_buffer(inst,
					HAL_BUFFER_OUTPUT2);
			if (!bufreq_out2)
				break;

			bufreq_out2->buffer_count_min =
				bufreq_out2->buffer_count_min_host =
				bufreq_out2->buffer_count_actual = 0;

			break;
		case V4L2_CID_MPEG_VIDC_VIDEO_STREAM_OUTPUT_SECONDARY:
			switch (inst->bit_depth) {
@@ -1079,21 +1110,43 @@ int msm_vdec_s_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
				dprintk(VIDC_ERR,
					"Failed setting OUTPUT2 size : %d\n",
					rc);
			/* Populate output2 bufreqs with output bufreqs */
			bufreq = get_buff_req_buffer(inst, HAL_BUFFER_OUTPUT);
			if (!bufreq)
				break;

			rc = msm_comm_try_get_bufreqs(inst);
			if (rc) {
				dprintk(VIDC_ERR,
					"%s Failed to get buffer reqs : %d\n",
					__func__, rc);
			bufreq_out2 = get_buff_req_buffer(inst,
						HAL_BUFFER_OUTPUT2);
			if (!bufreq_out2)
				break;
			}

			rc = msm_vidc_update_host_buff_counts(inst);
			memcpy(bufreq_out2, bufreq,
				sizeof(struct hal_buffer_requirements));
			bufreq_out2->buffer_type = HAL_BUFFER_OUTPUT2;
			rc = msm_comm_set_buffer_count(inst,
				bufreq_out2->buffer_count_min_host,
				bufreq_out2->buffer_count_actual,
				HAL_BUFFER_OUTPUT2);
			if (rc) {
				dprintk(VIDC_ERR,
					"%s Failed: update buff counts : %d\n",
					__func__, rc);
					"%s: Failed to set opb buffer count to FW\n");
				return -EINVAL;
			}
			/* Do the same for extradata but no set is required */
			bufreq = get_buff_req_buffer(inst,
					HAL_BUFFER_EXTRADATA_OUTPUT);
			if (!bufreq)
				break;

			bufreq_out2 = get_buff_req_buffer(inst,
					HAL_BUFFER_EXTRADATA_OUTPUT2);
			if (!bufreq_out2)
				break;

			memcpy(bufreq_out2, bufreq,
				sizeof(struct hal_buffer_requirements));
			bufreq_out2->buffer_type =
				HAL_BUFFER_EXTRADATA_OUTPUT2;
			break;
		default:
			dprintk(VIDC_ERR,
@@ -1228,7 +1281,6 @@ int msm_vdec_s_ext_ctrl(struct msm_vidc_inst *inst,
				dprintk(VIDC_ERR,
					"%s Failed setting stream output mode : %d\n",
					__func__, rc);
			rc = msm_vidc_update_host_buff_counts(inst);
			break;
		case V4L2_CID_MPEG_VIDC_VIDEO_CONCEAL_COLOR_8BIT:
			conceal_color.conceal_color_8bit = ext_control[i].value;
+22 −0
Original line number Diff line number Diff line
@@ -1160,6 +1160,8 @@ static struct msm_vidc_format venc_formats[] = {
		.fourcc = V4L2_PIX_FMT_H264,
		.get_frame_size = get_frame_size_compressed,
		.type = CAPTURE_PORT,
		.input_min_count = 4,
		.output_min_count = 4,
	},
	{
		.name = "VP8",
@@ -1167,6 +1169,8 @@ static struct msm_vidc_format venc_formats[] = {
		.fourcc = V4L2_PIX_FMT_VP8,
		.get_frame_size = get_frame_size_compressed,
		.type = CAPTURE_PORT,
		.input_min_count = 4,
		.output_min_count = 4,
	},
	{
		.name = "HEVC",
@@ -1174,6 +1178,8 @@ static struct msm_vidc_format venc_formats[] = {
		.fourcc = V4L2_PIX_FMT_HEVC,
		.get_frame_size = get_frame_size_compressed,
		.type = CAPTURE_PORT,
		.input_min_count = 4,
		.output_min_count = 4,
	},
	{
		.name = "YCrCb Semiplanar 4:2:0",
@@ -1195,6 +1201,8 @@ static struct msm_vidc_format venc_formats[] = {
		.fourcc = V4L2_PIX_FMT_TME,
		.get_frame_size = get_frame_size_compressed,
		.type = CAPTURE_PORT,
		.input_min_count = 4,
		.output_min_count = 4,
	},
	{
		.name = "YCbCr Semiplanar 4:2:0 10bit",
@@ -2414,6 +2422,20 @@ int msm_venc_inst_init(struct msm_vidc_inst *inst)
	inst->buff_req.buffer[2].buffer_count_min_host =
	inst->buff_req.buffer[2].buffer_count_actual =
		MIN_NUM_ENC_CAPTURE_BUFFERS;
	inst->buff_req.buffer[3].buffer_type = HAL_BUFFER_OUTPUT2;
	inst->buff_req.buffer[3].buffer_count_min_host =
	inst->buff_req.buffer[3].buffer_count_actual =
		MIN_NUM_ENC_CAPTURE_BUFFERS;
	inst->buff_req.buffer[4].buffer_type = HAL_BUFFER_EXTRADATA_INPUT;
	inst->buff_req.buffer[5].buffer_type = HAL_BUFFER_EXTRADATA_OUTPUT;
	inst->buff_req.buffer[6].buffer_type = HAL_BUFFER_EXTRADATA_OUTPUT2;
	inst->buff_req.buffer[7].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH;
	inst->buff_req.buffer[8].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH_1;
	inst->buff_req.buffer[9].buffer_type = HAL_BUFFER_INTERNAL_SCRATCH_2;
	inst->buff_req.buffer[10].buffer_type = HAL_BUFFER_INTERNAL_PERSIST;
	inst->buff_req.buffer[11].buffer_type = HAL_BUFFER_INTERNAL_PERSIST_1;
	inst->buff_req.buffer[12].buffer_type = HAL_BUFFER_INTERNAL_CMD_QUEUE;
	inst->buff_req.buffer[13].buffer_type = HAL_BUFFER_INTERNAL_RECON;

	/* By default, initialize OUTPUT port to UBWC YUV format */
	fmt = msm_comm_get_pixel_fmt_fourcc(venc_formats,
+4 −147
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@

static int try_get_ctrl(struct msm_vidc_inst *inst,
	struct v4l2_ctrl *ctrl);
static int msm_vidc_get_count(struct msm_vidc_inst *inst,
	struct v4l2_ctrl *ctrl);

static int get_poll_flags(void *instance)
{
@@ -376,7 +374,6 @@ int msm_vidc_g_ext_ctrl(void *instance, struct v4l2_ext_controls *control)
{
	struct msm_vidc_inst *inst = instance;
	struct v4l2_ext_control *ext_control;
	struct v4l2_ctrl ctrl;
	int i = 0, rc = 0;

	if (!inst || !control)
@@ -386,19 +383,10 @@ int msm_vidc_g_ext_ctrl(void *instance, struct v4l2_ext_controls *control)

	for (i = 0; i < control->count; i++) {
		switch (ext_control[i].id) {
		case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
		case V4L2_CID_MIN_BUFFERS_FOR_OUTPUT:
			ctrl.id = ext_control[i].id;
			ctrl.val = ext_control[i].value;

			msm_vidc_get_count(inst, &ctrl);
			ext_control->value = ctrl.val;
			break;
		default:
			dprintk(VIDC_ERR,
				"This control %x is not supported yet\n",
					ext_control[i].id);
			rc = -EINVAL;
			break;
		}
	}
@@ -742,29 +730,6 @@ static void msm_vidc_cleanup_buffer(struct vb2_buffer *vb)
			__func__, rc);
}

static int set_buffer_count(struct msm_vidc_inst *inst,
	int host_count, int act_count, enum hal_buffer type)
{
	int rc = 0;
	struct hfi_device *hdev;
	struct hal_buffer_count_actual buf_count;

	hdev = inst->core->device;

	buf_count.buffer_type = type;
	buf_count.buffer_count_actual = act_count;
	buf_count.buffer_count_min_host = host_count;
	dprintk(VIDC_DBG, "%s : Act count = %d Host count = %d\n",
		__func__, act_count, host_count);
	rc = call_hfi_op(hdev, session_set_property,
		inst->session, HAL_PARAM_BUFFER_COUNT_ACTUAL, &buf_count);
	if (rc)
		dprintk(VIDC_ERR,
			"Failed to set actual buffer count %d for buffer type %d\n",
			act_count, type);
	return rc;
}

static int msm_vidc_queue_setup(struct vb2_queue *q,
	unsigned int *num_buffers, unsigned int *num_planes,
	unsigned int sizes[], struct device *alloc_devs[])
@@ -811,7 +776,8 @@ static int msm_vidc_queue_setup(struct vb2_queue *q,
			sizes[i] = inst->bufq[OUTPUT_PORT].plane_sizes[i];

		bufreq->buffer_count_actual = *num_buffers;
		rc = set_buffer_count(inst, bufreq->buffer_count_min_host,
		rc = msm_comm_set_buffer_count(inst,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual, HAL_BUFFER_INPUT);
		}
		break;
@@ -844,7 +810,8 @@ static int msm_vidc_queue_setup(struct vb2_queue *q,
			sizes[i] = inst->bufq[CAPTURE_PORT].plane_sizes[i];

		bufreq->buffer_count_actual = *num_buffers;
		rc = set_buffer_count(inst, bufreq->buffer_count_min_host,
		rc = msm_comm_set_buffer_count(inst,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual, buffer_type);
		}
		break;
@@ -1555,114 +1522,6 @@ static int msm_vidc_op_s_ctrl(struct v4l2_ctrl *ctrl)
				inst, v4l2_ctrl_get_name(ctrl->id));
	return rc;
}

static int msm_vidc_get_count(struct msm_vidc_inst *inst,
	struct v4l2_ctrl *ctrl)
{
	int rc = 0;
	struct hal_buffer_requirements *bufreq;
	enum hal_buffer buffer_type;

	if (ctrl->id == V4L2_CID_MIN_BUFFERS_FOR_OUTPUT) {
		bufreq = get_buff_req_buffer(inst, HAL_BUFFER_INPUT);
		if (!bufreq) {
			dprintk(VIDC_ERR,
				"Failed to find bufreqs for buffer type = %d\n",
					HAL_BUFFER_INPUT);
			return 0;
		}
		if (inst->bufq[OUTPUT_PORT].vb2_bufq.streaming) {
			ctrl->val = bufreq->buffer_count_min_host;
			return 0;
		}
		if (ctrl->val > bufreq->buffer_count_min_host &&
			ctrl->val <= MAX_NUM_OUTPUT_BUFFERS) {
			dprintk(VIDC_DBG,
				"Buffer count Host changed from %d to %d\n",
					bufreq->buffer_count_min_host,
					ctrl->val);
			bufreq->buffer_count_actual =
			bufreq->buffer_count_min =
			bufreq->buffer_count_min_host =
				ctrl->val;
		} else {
			ctrl->val = bufreq->buffer_count_min_host;
		}
		rc = set_buffer_count(inst,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual,
			HAL_BUFFER_INPUT);

		msm_vidc_update_host_buff_counts(inst);
		ctrl->val = bufreq->buffer_count_min_host;
		dprintk(VIDC_DBG,
			"g_count: %x : OUTPUT:  min %d min_host %d actual %d\n",
			hash32_ptr(inst->session),
			bufreq->buffer_count_min,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual);
		return rc;

	} else if (ctrl->id == V4L2_CID_MIN_BUFFERS_FOR_CAPTURE) {

		buffer_type = msm_comm_get_hal_output_buffer(inst);
		bufreq = get_buff_req_buffer(inst,
			buffer_type);
		if (!bufreq) {
			dprintk(VIDC_ERR,
				"Failed to find bufreqs for buffer type = %d\n",
					buffer_type);
			return 0;
		}
		if (inst->bufq[CAPTURE_PORT].vb2_bufq.streaming) {
			if (ctrl->val != bufreq->buffer_count_min_host)
				return -EINVAL;
			else
				return 0;
		}

		if (inst->session_type == MSM_VIDC_DECODER &&
				!inst->in_reconfig &&
			inst->state < MSM_VIDC_LOAD_RESOURCES_DONE) {
			dprintk(VIDC_DBG,
				"Clients updates Buffer count from %d to %d\n",
				bufreq->buffer_count_min_host, ctrl->val);
			bufreq->buffer_count_actual =
			bufreq->buffer_count_min =
			bufreq->buffer_count_min_host =
				ctrl->val;
		}
		if (ctrl->val > bufreq->buffer_count_min_host &&
			ctrl->val <= MAX_NUM_CAPTURE_BUFFERS) {
			dprintk(VIDC_DBG,
				"Buffer count Host changed from %d to %d\n",
				bufreq->buffer_count_min_host,
				ctrl->val);
			bufreq->buffer_count_actual =
			bufreq->buffer_count_min =
			bufreq->buffer_count_min_host =
				ctrl->val;
		} else {
			ctrl->val = bufreq->buffer_count_min_host;
		}
		rc = set_buffer_count(inst,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual,
			HAL_BUFFER_OUTPUT);

		msm_vidc_update_host_buff_counts(inst);
		ctrl->val = bufreq->buffer_count_min_host;
		dprintk(VIDC_DBG,
			"g_count: %x : CAPTURE:  min %d min_host %d actual %d\n",
			hash32_ptr(inst->session),
			bufreq->buffer_count_min,
			bufreq->buffer_count_min_host,
			bufreq->buffer_count_actual);
		return rc;
	}
	return -EINVAL;
}

static int try_get_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
{
	int rc = 0;
@@ -1703,8 +1562,6 @@ static int try_get_ctrl(struct msm_vidc_inst *inst, struct v4l2_ctrl *ctrl)
		break;

	case V4L2_CID_MIN_BUFFERS_FOR_CAPTURE:
		if (inst->in_reconfig)
			msm_vidc_update_host_buff_counts(inst);
		buffer_type = msm_comm_get_hal_output_buffer(inst);
		bufreq = get_buff_req_buffer(inst,
			buffer_type);
+1 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
#include <media/msm_vidc_private.h>
#include <media/msm_vidc_utils.h>

#define HAL_BUFFER_MAX 0xd
#define HAL_BUFFER_MAX 0xe

enum smem_type {
	SMEM_DMA = 1,
@@ -133,5 +133,4 @@ int msm_vidc_g_crop(void *instance, struct v4l2_crop *a);
int msm_vidc_enum_framesizes(void *instance, struct v4l2_frmsizeenum *fsize);
int msm_vidc_private(void *vidc_inst, unsigned int cmd,
		struct msm_vidc_arg *arg);

#endif
+22 −10
Original line number Diff line number Diff line
@@ -971,18 +971,12 @@ int msm_dcvs_try_enable(struct msm_vidc_inst *inst)
			inst->clk_data.low_latency_mode ||
			inst->batch.enable) {
		dprintk(VIDC_PROF, "DCVS disabled: %pK\n", inst);
		inst->clk_data.extra_capture_buffer_count = 0;
		inst->clk_data.extra_output_buffer_count = 0;
		inst->clk_data.dcvs_mode = false;
		return false;
	}
	inst->clk_data.dcvs_mode = true;
	dprintk(VIDC_PROF, "DCVS enabled: %pK\n", inst);

	inst->clk_data.extra_capture_buffer_count =
		DCVS_DEC_EXTRA_OUTPUT_BUFFERS;
	inst->clk_data.extra_output_buffer_count =
		DCVS_DEC_EXTRA_OUTPUT_BUFFERS;
	return true;
}

@@ -1090,6 +1084,17 @@ void msm_clock_data_reset(struct msm_vidc_inst *inst)
			__func__);
}

static bool is_output_buffer(struct msm_vidc_inst *inst,
	enum hal_buffer buffer_type)
{
	if (msm_comm_get_stream_output_mode(inst) ==
			HAL_VIDEO_DECODER_SECONDARY) {
		return buffer_type == HAL_BUFFER_OUTPUT2;
	} else {
		return buffer_type == HAL_BUFFER_OUTPUT;
	}
}

int msm_vidc_get_extra_buff_count(struct msm_vidc_inst *inst,
	enum hal_buffer buffer_type)
{
@@ -1106,15 +1111,22 @@ int msm_vidc_get_extra_buff_count(struct msm_vidc_inst *inst,
	if (is_thumbnail_session(inst))
		return 0;

	count = buffer_type == HAL_BUFFER_INPUT ?
		inst->clk_data.extra_output_buffer_count :
		inst->clk_data.extra_capture_buffer_count;
	/* Add DCVS extra buffer count */
	if (inst->core->resources.dcvs) {
		if (is_decode_session(inst) &&
			is_output_buffer(inst, buffer_type)) {
			count += DCVS_DEC_EXTRA_OUTPUT_BUFFERS;
		} else if ((is_encode_session(inst) &&
			buffer_type == HAL_BUFFER_INPUT)) {
			count += DCVS_ENC_EXTRA_INPUT_BUFFERS;
		}
	}

	/*
	 * if platform supports decode batching ensure minimum
	 * batch size count of extra buffers added on output port
	 */
	if (buffer_type == HAL_BUFFER_OUTPUT) {
	if (is_output_buffer(inst, buffer_type)) {
		if (inst->core->resources.decode_batching &&
			is_decode_session(inst) &&
			count < inst->batch.size)
Loading