public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Pawel Osciak <pawel@osciak.com>
Cc: LMML <linux-media@vger.kernel.org>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Sakari Ailus <sakari.ailus@iki.fi>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Hans Verkuil <hans.verkuil@cisco.com>
Subject: Re: [REVIEW PATCH 03/11] vb2: if bytesused is 0, then fill with output buffer length
Date: Mon, 07 Apr 2014 09:39:50 +0200	[thread overview]
Message-ID: <53425646.3000003@xs4all.nl> (raw)
In-Reply-To: <CAMm-=zCtWq=4_g9aweU6Hc=_ONscHLMegytFWXMjoC7edi1O2g@mail.gmail.com>

On 04/07/2014 09:20 AM, Pawel Osciak wrote:
> I'm thinking, that if we are doing this, perhaps we should just update
> the API to allow this case, i.e. say that if the bytesused is not set

With 'not set' you mean 'is 0', right?

> for any planes, length will be used by default?
> This would be backwards-compatible.

I agree with that. I'll update the doc.

Regards,

	Hans

> 
> On Tue, Mar 11, 2014 at 6:20 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> The application should really always fill in bytesused for output
>> buffers, unfortunately the vb2 framework never checked for that.
>>
>> So for single planar formats replace a bytesused of 0 by the length
>> of the buffer, and for multiplanar format do the same if bytesused is
>> 0 for ALL planes.
>>
>> This seems to be what the user really intended if v4l2_buffer was
>> just memset to 0.
>>
>> I'm afraid that just checking for this and returning an error would
>> break too many applications. Quite a few drivers never check for bytesused
>> at all and just use the buffer length instead.
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Acked-by: Pawel Osciak <pawel@osciak.com>
> 
>> ---
>>  drivers/media/v4l2-core/videobuf2-core.c | 32 +++++++++++++++++++++++++++-----
>>  1 file changed, 27 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
>> index 1a09442..83e78e9 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -1145,19 +1145,35 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
>>                         memset(v4l2_planes[plane].reserved, 0,
>>                                sizeof(v4l2_planes[plane].reserved));
>>                         v4l2_planes[plane].data_offset = 0;
>> +                       v4l2_planes[plane].bytesused = 0;
>>                 }
>>
>>                 /* Fill in driver-provided information for OUTPUT types */
>>                 if (V4L2_TYPE_IS_OUTPUT(b->type)) {
>> +                       bool bytesused_is_used;
>> +
>> +                       /* Check if bytesused == 0 for all planes */
>> +                       for (plane = 0; plane < vb->num_planes; ++plane)
>> +                               if (b->m.planes[plane].bytesused)
>> +                                       break;
>> +                       bytesused_is_used = plane < vb->num_planes;
>> +
>>                         /*
>>                          * Will have to go up to b->length when API starts
>>                          * accepting variable number of planes.
>> +                        *
>> +                        * If bytesused_is_used is false, then fall back to the
>> +                        * full buffer size. In that case userspace clearly
>> +                        * never bothered to set it and it's a safe assumption
>> +                        * that they really meant to use the full plane sizes.
>>                          */
>>                         for (plane = 0; plane < vb->num_planes; ++plane) {
>> -                               v4l2_planes[plane].bytesused =
>> -                                       b->m.planes[plane].bytesused;
>> -                               v4l2_planes[plane].data_offset =
>> -                                       b->m.planes[plane].data_offset;
>> +                               struct v4l2_plane *pdst = &v4l2_planes[plane];
>> +                               struct v4l2_plane *psrc = &b->m.planes[plane];
>> +
>> +                               pdst->bytesused = bytesused_is_used ?
>> +                                       psrc->bytesused : psrc->length;
>> +                               pdst->data_offset = psrc->data_offset;
>>                         }
>>                 }
>>
>> @@ -1183,9 +1199,15 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
>>                  * so fill in relevant v4l2_buffer struct fields instead.
>>                  * In videobuf we use our internal V4l2_planes struct for
>>                  * single-planar buffers as well, for simplicity.
>> +                *
>> +                * If bytesused == 0, then fall back to the full buffer size
>> +                * as that's a sensible default.
>>                  */
>>                 if (V4L2_TYPE_IS_OUTPUT(b->type))
>> -                       v4l2_planes[0].bytesused = b->bytesused;
>> +                       v4l2_planes[0].bytesused =
>> +                               b->bytesused ? b->bytesused : b->length;
>> +               else
>> +                       v4l2_planes[0].bytesused = 0;
>>                 /* Single-planar buffers never use data_offset */
>>                 v4l2_planes[0].data_offset = 0;
>>
>> --
>> 1.9.0
>>
> 
> 
> 


  reply	other threads:[~2014-04-07  7:40 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 21:20 vb2: various small fixes/improvements Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 01/11] vb2: stop_streaming should return void Hans Verkuil
2014-04-07  4:58   ` Pawel Osciak
2014-03-10 21:20 ` [REVIEW PATCH 02/11] vb2: fix handling of data_offset and v4l2_plane.reserved[] Hans Verkuil
2014-04-07  5:11   ` Pawel Osciak
2014-04-07 11:47     ` Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 03/11] vb2: if bytesused is 0, then fill with output buffer length Hans Verkuil
2014-04-07  7:20   ` Pawel Osciak
2014-04-07  7:39     ` Hans Verkuil [this message]
2014-04-07  7:46       ` Pawel Osciak
2014-03-10 21:20 ` [REVIEW PATCH 04/11] vb2: use correct prefix Hans Verkuil
2014-04-07  7:30   ` Pawel Osciak
2014-04-07  7:43     ` Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 05/11] vb2: move __qbuf_mmap before __qbuf_userptr Hans Verkuil
2014-04-07  8:09   ` Pawel Osciak
2014-03-10 21:20 ` [REVIEW PATCH 06/11] vb2: set timestamp when using write() Hans Verkuil
2014-04-07  8:32   ` Pawel Osciak
2014-04-07  9:02     ` Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 07/11] vb2: reject output buffers with V4L2_FIELD_ALTERNATE Hans Verkuil
2014-04-07  8:38   ` Pawel Osciak
2014-03-10 21:20 ` [REVIEW PATCH 08/11] vb2: simplify a confusing condition Hans Verkuil
2014-04-07  8:42   ` Pawel Osciak
2014-03-10 21:20 ` [REVIEW PATCH 09/11] vb2: add vb2_fileio_is_active and check it more often Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 10/11] vb2: set v4l2_buffer.bytesused to 0 for mp buffers Hans Verkuil
2014-04-09 17:21   ` Sakari Ailus
2014-04-11  7:42     ` Hans Verkuil
2014-03-10 21:20 ` [REVIEW PATCH 11/11] vb2: allow read/write as long as the format is single planar Hans Verkuil
2014-04-04 10:01 ` vb2: various small fixes/improvements Hans Verkuil
2014-04-09 17:27 ` Sakari Ailus

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=53425646.3000003@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=pawel@osciak.com \
    --cc=s.nawrocki@samsung.com \
    --cc=sakari.ailus@iki.fi \
    /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