linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Cox <jc@kynesim.co.uk>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org
Subject: Re: [RFC] media: v4l2: Variable length controls (for h265 slice headers)
Date: Fri, 09 Apr 2021 13:07:21 +0100	[thread overview]
Message-ID: <16g07g50tol5128laqq557i8tfca3i2mbd@4ax.com> (raw)
In-Reply-To: <8ff86418-5fa3-e1ae-51e4-b10788be7991@xs4all.nl>

Hi Hans

Thanks for looking at this

>Hi John,
>
>On 23/03/2021 15:12, John Cox wrote:
>> Hi all
>> 
>> I am developing a H265 V4L2 stateless decoder. After some
>> experimentation it looks like the best way to achieve performance would
>> be to submit bitstream data for an entire frame in a single buffer with
>> an array of slice headers that point into it. The number of slices in a
>> frame can be very variable, often there will be just one, in nearly all
>> cases there will be less than 16 but the worst case could be hundreds
>> (actually theoretically it could be thousands but I'm prepared to, and
>> it is probably sensible to, reject any stream that looks like this).
>> 
>> Given the large range of possible array sizes a (large) fixed length
>> array is very wasteful and probably slow in nearly all cases. As it
>> stands V4L2 has no variable length structure so there is a problem here.
>> My experience with v4l2 controls in minimal so trying to add a variable
>> length array control myself seems brave.  Luckily (in other channels) I
>> was told "Hans offered multiple times to implement variable array
>> controls himself, he just needs someone to send an RFC with details on
>> what's needed." so here I am.
>> 
>> So as a suggestion for the interface:
>> 
>> From the user point of view:
>> 
>> Only the last dimension of the array can be dynamic (like a C array "int
>> a[10][15][];")  Otherwise we add a lot of complexity.
>
>I would limit this to single dimensional arrays for now.
>
>I think it is the first (not the last) dimension that can be dynamic: if
>you want 8 3x3 matrices, then you would set dims to [8][3][3]. So a variable
>length array of 3x3 matrices would have the first dimension as the variable
>one.

I would like to say that you have spotted my deliberate mistake, but no
- I was just wrong and you are right.

>> 
>> VIDIOC_S_EXT_CTRLS
>> In v4l2_ext_control the user can pass in any size that is a multiple of
>> the element size.  If greater than the max then .size is set to the max
>> by the ioctl on return.
>> 
>> VIDIOC_G_EXT_CTRLS
>> On entry .size contains the buffer size to receive the values and on
>> return it contains the size actually wanted - if the buffer can contain
>> the data then it is also the number filled in.
>> 
>> VIDIOC_QUERY_EXT_CTRLS
>> Add a flag to indicate variable length and either use .maximum/.minimum
>> or some of the currently reserved structure to give max/min sizes
>
>dims[0] can set the maximum size of the array.

Sounds good and has obvious extensions for (later) multi-dimensional
stuff.

>> From the driver point of view - frankly anything will do as long as I
>> can find out how many headers I have. I think it is probably a good idea
>> to dynamically allocate the storage for such an array rather than having
>> a fixed size block on the end of the ctrl structure to avoid unnecessary
>> overallocation.
>
>The hevc slice structures are quite large, so it definitely has to be a
>dynamic allocation.
>
>> 
>> I imagine that I've missed many important details in the sketch above,
>> but probably good to start the discussion and Hans, am I trying to take
>> you up on an offer you didn't actually make?
>
>So the uAPI part is fairly simple, the biggest problem is in the internal
>implementation. As the control framework becomes ever more complex (esp.
>with the requests support) it is getting harder and harder to add new features.
>
>I think that this might be a good time to start refactoring code, but for
>that I also need to add better testing in v4l2-compliance of esp. requests.
>
>It will also make it more time consuming, but I don't feel comfortable
>to continue hacking on the code without doing a cleanup first.

I look forward to our brave new cleaner dynamic world :-)

Many thanks

John Cox

      reply	other threads:[~2021-04-09 12:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 14:12 [RFC] media: v4l2: Variable length controls (for h265 slice headers) John Cox
2021-04-09 10:52 ` Hans Verkuil
2021-04-09 12:07   ` John Cox [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16g07g50tol5128laqq557i8tfca3i2mbd@4ax.com \
    --to=jc@kynesim.co.uk \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).