Re: [PATCH] media: venus: amend buffer size for bitstream plane

From: Stanimir Varbanov
Date: Tue Nov 13 2018 - 03:12:40 EST


Hi Malathi,

On 11/13/18 9:28 AM, mgottam@xxxxxxxxxxxxxx wrote:
> On 2018-11-12 18:04, Stanimir Varbanov wrote:
>> Hi Tomasz,
>>
>> On 10/23/2018 05:50 AM, Tomasz Figa wrote:
>>> Hi Malathi,
>>>
>>> On Tue, Oct 9, 2018 at 4:58 PM Malathi Gottam
>>> <mgottam@xxxxxxxxxxxxxx> wrote:
>>>>
>>>> For lower resolutions, incase of encoder, the compressed
>>>> frame size is more than half of the corresponding input
>>>> YUV. Keep the size as same as YUV considering worst case.
>>>>
>>>> Signed-off-by: Malathi Gottam <mgottam@xxxxxxxxxxxxxx>
>>>> ---
>>>> Âdrivers/media/platform/qcom/venus/helpers.c | 2 +-
>>>> Â1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/media/platform/qcom/venus/helpers.c
>>>> b/drivers/media/platform/qcom/venus/helpers.c
>>>> index 2679adb..05c5423 100644
>>>> --- a/drivers/media/platform/qcom/venus/helpers.c
>>>> +++ b/drivers/media/platform/qcom/venus/helpers.c
>>>> @@ -649,7 +649,7 @@ u32 venus_helper_get_framesz(u32 v4l2_fmt, u32
>>>> width, u32 height)
>>>> ÂÂÂÂÂÂÂ }
>>>>
>>>> ÂÂÂÂÂÂÂ if (compressed) {
>>>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sz = ALIGN(height, 32) * ALIGN(width, 32) * 3 / 2 / 2;
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sz = ALIGN(height, 32) * ALIGN(width, 32) * 3 / 2;
>>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ALIGN(sz, SZ_4K);
>>>> ÂÂÂÂÂÂÂ }
>>>
>>> Note that the driver should not enforce one particular buffer size for
>>> bitstream buffers unless it's a workaround for broken firmware or
>>> hardware. The userspace should be able to select the desired size.
>>
>> Good point! Yes, we have to extend set_fmt to allow bigger sizeimage for
>> the compressed buffers (not only for encoder).
>
> So Stan you meant to say that we should allow s_fmt to accept client
> specified size?

yes but I do expect:

new_sizeimage = max(user_sizeimage, venus_helper_get_framesz)

and also user_sizeimage should be sanitized.

> If so should we set the inst->input_buf_size here in venc_s_fmt?
>
> @@ -333,10 +333,10 @@static const struct venus_format *
> venc_try_fmt_common(struct venus_inst *inst, struct v4l2_format *f)
>
> ÂÂÂÂÂÂÂ pixmp->num_planes = fmt->num_planes;
> ÂÂÂÂÂÂÂ pixmp->flags = 0;
> -
> -ÂÂÂÂÂÂ pfmt[0].sizeimage = venus_helper_get_framesz(pixmp->pixelformat,
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pixmp->width,
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pixmp->height);
> +ÂÂÂÂÂÂ if (!pfmt[0].sizeimage)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pfmt[0].sizeimage =
> venus_helper_get_framesz(pixmp->pixelformat,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pixmp->width,
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
> pixmp->height);

yes, but please make

pfmt[0].sizeimage = max(pfmt[0].sizeimage, venus_helper_get_framesz)

and IMO this should be only for CAPTURE queue i.e. inst->output_buf_size

I'm still not sure do we need it for OUTPUT encoder queue.

>
> ÂÂÂÂÂÂÂ if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pfmt[0].bytesperline = ALIGN(pixmp->width, 128);
> @@ -387,6 +387,7 @@ static int venc_s_fmt(struct file *file, void *fh,
> struct v4l2_format *f)
> ÂÂÂÂÂÂÂ venc_try_fmt_common(inst, &format);
>
> ÂÂÂÂÂÂÂ if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->input_buf_size = pixmp->plane_fmt[0].sizeimage;
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->out_width = format.fmt.pix_mp.width;
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->out_height = format.fmt.pix_mp.height;
>
> Similar implementation is already handled in case of decoder.
>
> Then in queue setup, we can compare this against calculated size to
> obtain final buffer size
>
> @@ -899,7 +900,8 @@ static int venc_queue_setup(struct vb2_queue *q,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizes[0] = venus_helper_get_framesz(inst->fmt_out->pixfmt,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->width,
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->height);
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->input_buf_size = sizes[0];
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if(inst->input_buf_size < sizes[0])
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ inst->input_buf_size = sizes[0];
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ break;
>
> I hope this meets are requirements.

--
regards,
Stan