diff mbox series

[v2] venus: enc: fix enum_frameintervals

Message ID 20190122105322.22096-1-stanimir.varbanov@linaro.org
State New
Headers show
Series [v2] venus: enc: fix enum_frameintervals | expand

Commit Message

Stanimir Varbanov Jan. 22, 2019, 10:53 a.m. UTC
This ixes an issue when setting the encoder framerate because of
missing precision. Now the frameinterval type is changed to
TYPE_CONTINUOUS and step = 1. Also the math is changed when
framerate property is called - the firmware side expects that
the framerate one is 1 << 16 units.

Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>

---
v2: replace DIV_ROUND_UP with do_div and make roundup manually

 drivers/media/platform/qcom/venus/venc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

-- 
2.17.1

Comments

Stanimir Varbanov Jan. 30, 2019, 10:35 a.m. UTC | #1
Hi Nicolas,

On 1/30/19 5:28 AM, Nicolas Dufresne wrote:
> Le mardi 22 janvier 2019 à 12:53 +0200, Stanimir Varbanov a écrit :

>> This ixes an issue when setting the encoder framerate because of

> 

> ixes -> fixes

> 

>> missing precision. Now the frameinterval type is changed to

>> TYPE_CONTINUOUS and step = 1. Also the math is changed when

>> framerate property is called - the firmware side expects that

>> the framerate one is 1 << 16 units.

> 

> Note sure, maybe you didn't mean to add 'one' here ? Why not just say

> that that firmware expect values in Q16 ?


yes, thanks for the suggestion.

> 

>>

>> Signed-off-by: Stanimir Varbanov <stanimir.varbanov@linaro.org>

> 

> Looking toward testing it, but I had the bad luck of using an USB

> storage rootfs, and apparently USB no longer works on 5.0rc+, if you

> have a baseline tree to suggest, I'll take it. Thanks for this patch.


try qcomlt-4.14 release branch at [1].

-- 
regards,
Stan

[1]
https://git.linaro.org/landing-teams/working/qualcomm/kernel.git/log/?h=release/qcomlt-4.14
diff mbox series

Patch

diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index 32cff294582f..99c94b155b46 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -31,6 +31,7 @@ 
 #include "venc.h"
 
 #define NUM_B_FRAMES_MAX	4
+#define FRAMERATE_FACTOR	(1 << 16)
 
 /*
  * Three resons to keep MPLANE formats (despite that the number of planes
@@ -581,7 +582,7 @@  static int venc_enum_frameintervals(struct file *file, void *fh,
 	struct venus_inst *inst = to_inst(file);
 	const struct venus_format *fmt;
 
-	fival->type = V4L2_FRMIVAL_TYPE_STEPWISE;
+	fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
 
 	fmt = find_format(inst, fival->pixel_format,
 			  V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
@@ -604,12 +605,12 @@  static int venc_enum_frameintervals(struct file *file, void *fh,
 	    fival->height < frame_height_min(inst))
 		return -EINVAL;
 
-	fival->stepwise.min.numerator = 1;
+	fival->stepwise.min.numerator = FRAMERATE_FACTOR;
 	fival->stepwise.min.denominator = frate_max(inst);
-	fival->stepwise.max.numerator = 1;
+	fival->stepwise.max.numerator = FRAMERATE_FACTOR;
 	fival->stepwise.max.denominator = frate_min(inst);
 	fival->stepwise.step.numerator = 1;
-	fival->stepwise.step.denominator = frate_max(inst);
+	fival->stepwise.step.denominator = 1;
 
 	return 0;
 }
@@ -654,6 +655,7 @@  static int venc_set_properties(struct venus_inst *inst)
 	struct hfi_quantization quant;
 	struct hfi_quantization_range quant_range;
 	u32 ptype, rate_control, bitrate, profile = 0, level = 0;
+	u64 framerate;
 	int ret;
 
 	ret = venus_helper_set_work_mode(inst, VIDC_WORK_MODE_2);
@@ -664,9 +666,16 @@  static int venc_set_properties(struct venus_inst *inst)
 	if (ret)
 		return ret;
 
+	framerate = inst->timeperframe.denominator * FRAMERATE_FACTOR;
+	/* next line is to round up */
+	framerate += inst->timeperframe.numerator - 1;
+	do_div(framerate, inst->timeperframe.numerator);
+
 	ptype = HFI_PROPERTY_CONFIG_FRAME_RATE;
 	frate.buffer_type = HFI_BUFFER_OUTPUT;
-	frate.framerate = inst->fps * (1 << 16);
+	frate.framerate = framerate;
+	if (frate.framerate > frate_max(inst))
+		frate.framerate = frate_max(inst);
 
 	ret = hfi_session_set_property(inst, ptype, &frate);
 	if (ret)