public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* Query the meaning of variable in v4l2_pix_format and v4l2_plane
@ 2011-11-04 13:07 Jonghun Han
  2011-11-04 13:28 ` Marek Szyprowski
  2011-11-04 16:02 ` Tomasz Stanislawski
  0 siblings, 2 replies; 4+ messages in thread
From: Jonghun Han @ 2011-11-04 13:07 UTC (permalink / raw)
  To: linux-media; +Cc: m.szyprowski


Hi,

I'm not sure the meaning of variables in v4l2_pix_format and v4l2_plane.
Especially bytesperline, sizeimage, length and bytesused.

v4l2_pix_format.width		= width
v4l2_pix_format.height		= height
v4l2_pix_format.bytesperline	= bytesperline [in bytes]
v4l2_pix_format.sizeimage	= bytesperline * buf height  -> Is this
right ?

v4l2_plane.length	= bytesperline * buf height  -> Is this right ?
I don't which is right.
v4l2_plane.bytesused	= bytesperline * (top + height)
v4l2_plane.bytesused	= bytesperline * height
v4l2_plane.bytesused	= width * height * bytesperpixel
v4l2_plane.bytesused	= bytesperline * (top + height) - (pixelperline -
(left + width)) * bytesperpixel

I assumed the following buffer.

|                                                          |
|<--------------------- bytesperline --------------------->|
|                                                          |
+----------------------------------------------------------+-----
|          ^                                               |  ^
|          |                                               |  |
|                                                          |  |
|          t                                               |  |
|          o                                               |  |
|          p                                               |  |
|                                                          |  |
|          |                                               |  |
|          V |<--------- width ---------->|                |  |
|<-- left -->+----------------------------+ -              |  |
|            |                            | ^              |
|            |                            | |              |  b
|            |                            | |              |  u
|            |                            |                |  f
|            |                            | h              |
|            |                            | e              |  h
|            |                            | i              |  e
|            |                            | g              |  i
|            |                            | h              |  g
|            |                            | t              |  h
|            |                            |                |  t
|            |                            | |              |  
|            |                            | |              |  |
|            |                            | v              |  |
|            +----------------------------+ -              |  |
|                                                          |  |
|                                                          |  |
|                                                          |  v
+----------------------------------------------------------+-----


Best regards,



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Query the meaning of variable in v4l2_pix_format and v4l2_plane
  2011-11-04 13:07 Query the meaning of variable in v4l2_pix_format and v4l2_plane Jonghun Han
@ 2011-11-04 13:28 ` Marek Szyprowski
  2011-11-04 14:48   ` Hans Verkuil
  2011-11-04 16:02 ` Tomasz Stanislawski
  1 sibling, 1 reply; 4+ messages in thread
From: Marek Szyprowski @ 2011-11-04 13:28 UTC (permalink / raw)
  To: 'Jonghun Han', linux-media; +Cc: 'Hans Verkuil'

Hello,

On Friday, November 04, 2011 2:08 PM Jonghun Han wrote:

> I'm not sure the meaning of variables in v4l2_pix_format and v4l2_plane.
> Especially bytesperline, sizeimage, length and bytesused.
> 
> v4l2_pix_format.width		= width
> v4l2_pix_format.height		= height
> v4l2_pix_format.bytesperline	= bytesperline [in bytes]
> v4l2_pix_format.sizeimage	= bytesperline * buf height  -> Is this
> right ?

Yes, I would expect it to be calculated this way for formats where 
bytesperline can be defined (for macroblock format bytesperline is hard
to define).

> 
> v4l2_plane.length	= bytesperline * buf height  -> Is this right ?
> I don't which is right.
> v4l2_plane.bytesused	= bytesperline * (top + height)
> v4l2_plane.bytesused	= bytesperline * height
> v4l2_plane.bytesused	= width * height * bytesperpixel
> v4l2_plane.bytesused	= bytesperline * (top + height) - (pixelperline -
> (left + width)) * bytesperpixel

bytesused should indicate how many bytes have been modified from the 
beginning of the buffer, so memcpy(dst, buf->mem, byteused) will copy 
all the video data.

So probably the most appropriate value for bytesused is:
v4l2_plane.bytesused	= bytesperline * (top + height)

I hope my assumptions are correct, but I would also like Hans to comment 
on this.

> I assumed the following buffer.
> 
> |                                                          |
> |<--------------------- bytesperline --------------------->|
> |                                                          |
> +----------------------------------------------------------+-----
> |          ^                                               |  ^
> |          |                                               |  |
> |                                                          |  |
> |          t                                               |  |
> |          o                                               |  |
> |          p                                               |  |
> |                                                          |  |
> |          |                                               |  |
> |          V |<--------- width ---------->|                |  |
> |<-- left -->+----------------------------+ -              |  |
> |            |                            | ^              |
> |            |                            | |              |  b
> |            |                            | |              |  u
> |            |                            |                |  f
> |            |                            | h              |
> |            |                            | e              |  h
> |            |                            | i              |  e
> |            |                            | g              |  i
> |            |                            | h              |  g
> |            |                            | t              |  h
> |            |                            |                |  t
> |            |                            | |              |
> |            |                            | |              |  |
> |            |                            | v              |  |
> |            +----------------------------+ -              |  |
> |                                                          |  |
> |                                                          |  |
> |                                                          |  v
> +----------------------------------------------------------+-----
 
Best regards
-- 
Marek Szyprowski
Samsung Poland R&D Center



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Query the meaning of variable in v4l2_pix_format and v4l2_plane
  2011-11-04 13:28 ` Marek Szyprowski
@ 2011-11-04 14:48   ` Hans Verkuil
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Verkuil @ 2011-11-04 14:48 UTC (permalink / raw)
  To: 'Jonghun Han'
  Cc: Marek Szyprowski, linux-media, 'Hans Verkuil'

On Friday 04 November 2011 14:28:48 Marek Szyprowski wrote:
> Hello,
> 
> On Friday, November 04, 2011 2:08 PM Jonghun Han wrote:
> > I'm not sure the meaning of variables in v4l2_pix_format and v4l2_plane.
> > Especially bytesperline, sizeimage, length and bytesused.
> > 
> > v4l2_pix_format.width		= width
> > v4l2_pix_format.height		= height

buf_height, actually (based on your picture).

> > v4l2_pix_format.bytesperline	= bytesperline [in bytes]
> > v4l2_pix_format.sizeimage	= bytesperline * buf height  -> Is this
> > right ?
> 
> Yes, I would expect it to be calculated this way for formats where
> bytesperline can be defined (for macroblock format bytesperline is hard
> to define).

Correct. For formats where bytesperline is meaningless I guess most drivers
will leave this at 0. It's not actually specced what it should be in those
cases.

> > v4l2_plane.length	= bytesperline * buf height  -> Is this right ?
> > I don't which is right.
> > v4l2_plane.bytesused	= bytesperline * (top + height)
> > v4l2_plane.bytesused	= bytesperline * height
> > v4l2_plane.bytesused	= width * height * bytesperpixel
> > v4l2_plane.bytesused	= bytesperline * (top + height) - 
(pixelperline -
> > (left + width)) * bytesperpixel
> 
> bytesused should indicate how many bytes have been modified from the
> beginning of the buffer, so memcpy(dst, buf->mem, byteused) will copy
> all the video data.
> 
> So probably the most appropriate value for bytesused is:
> v4l2_plane.bytesused	= bytesperline * (top + height)

The bytesused field is set by the driver when you capture video and will 
typically be equal to bytesperline * buf_height. For compressed formats it can 
be any value <= sizeimage though.

For video output it is the application that fills in bytesused.

However, I want to add something here: it is currently not possible to specify
anything other than horizontal padding. I.e., bytesperline can be more than 
the width, allowing for a right margin, but you can't specify a left margin.
So left == 0 at the moment. Also, in the current API top == 0 as well.

Drivers can set the data_offset field in v4l2_plane to a non-zero value, and
that might be a way to create a top margin, but this is really meant for meta 
data that is carried at the beginning of a buffer.

Recent discussions led to a proposal to add a app_offset field where 
applications can specify an additional offset from the beginning of the 
buffer. But this has not been added.

Regards,

	Hans

> I hope my assumptions are correct, but I would also like Hans to comment
> on this.
> 
> > I assumed the following buffer.
> > 
> > |<--------------------- bytesperline --------------------->|
> > 
> > +----------------------------------------------------------+-----
> > 
> > |          ^                                               |  ^
> > |          
> > |          
> > |          t                                               |  |
> > |          o                                               |  |
> > |          p                                               |  |
> > |          
> > |          
> > |          V |<--------- width ---------->|                |  |
> > |
> > |<-- left -->+----------------------------+ -              |  |
> > |
> > |            |                            | ^              |
> > |            |                            | 
> > |            |                            | |              |  b
> > |            |                            | |              |  u
> > |            |                            | |              |  
> > |            |                            |                |  f
> > |            |                            | 
> > |            |                            | h              |
> > |            |                            | e              |  h
> > |            |                            | i              |  e
> > |            |                            | g              |  i
> > |            |                            | h              |  g
> > |            |                            | t              |  h
> > |            |                            | 
> > |            |                            |                |  t
> > |            |                            | 
> > |            |                            | v              |  |
> > |            
> > |            +----------------------------+ -              |  |
> > |            
> > |                                                          |  v
> > 
> > +----------------------------------------------------------+-----
> 
> Best regards

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Query the meaning of variable in v4l2_pix_format and v4l2_plane
  2011-11-04 13:07 Query the meaning of variable in v4l2_pix_format and v4l2_plane Jonghun Han
  2011-11-04 13:28 ` Marek Szyprowski
@ 2011-11-04 16:02 ` Tomasz Stanislawski
  1 sibling, 0 replies; 4+ messages in thread
From: Tomasz Stanislawski @ 2011-11-04 16:02 UTC (permalink / raw)
  To: Jonghun Han; +Cc: linux-media, m.szyprowski

On 11/04/2011 02:07 PM, Jonghun Han wrote:
>
> Hi,

Hi Mr. Han,

>
> I'm not sure the meaning of variables in v4l2_pix_format and v4l2_plane.
> Especially bytesperline, sizeimage, length and bytesused.
>
> v4l2_pix_format.width		= width
> v4l2_pix_format.height		= height

The fields width and height are undefined for some formats, like 
compressed JPEG and video streams.

> v4l2_pix_format.bytesperline	= bytesperline [in bytes]

The spec says "Distance in bytes between the leftmost pixels in two 
adjacent lines" for the largest plane. For YUV 4:2:0 the largest plane 
is luminance, where one pixel is one byte.

> v4l2_pix_format.sizeimage	= bytesperline * buf height  ->  Is this
> right ?

It is the upper limit for size of image of desired size. This value is 
needed if images are passed in compressed formats.

>
> v4l2_plane.length	= bytesperline * buf height  ->  Is this right ?
> I don't which is right.

This is the upper limit for a size of a given plane. For simple formats use:
v4l2_plane.length = plane_height * plane.bytesperline
The plane_height may be smaller the buf_height. For example for YUV420, 
the height of the chrominance plane, should be the half of buf_height.

For compressed formats it specify upper limit for plane size.

> v4l2_plane.bytesused	= bytesperline * (top + height)
> v4l2_plane.bytesused	= bytesperline * height
> v4l2_plane.bytesused	= width * height * bytesperpixel
> v4l2_plane.bytesused	= bytesperline * (top + height) - (pixelperline -
> (left + width)) * bytesperpixel

bytesused specify how much valid data is present in the buffer.
For simple formates you should use:
v4l2_plane.bytesused	= v4l2_plane.length
while queuing buffer into OUTPUT queue.

The inner rectangle refers to cropping rectangle for mem2mem devices. 
This rectangle should not be used in any computations of the buffer 
parameters.

Best regards,
Tomasz Stanislawski
>
> I assumed the following buffer.
>
> |                                                          |
> |<--------------------- bytesperline --------------------->|
> |                                                          |
> +----------------------------------------------------------+-----
> |          ^                                               |  ^
> |          |                                               |  |
> |                                                          |  |
> |          t                                               |  |
> |          o                                               |  |
> |          p                                               |  |
> |                                                          |  |
> |          |                                               |  |
> |          V |<--------- width ---------->|                |  |
> |<-- left -->+----------------------------+ -              |  |
> |            |                            | ^              |
> |            |                            | |              |  b
> |            |                            | |              |  u
> |            |                            |                |  f
> |            |                            | h              |
> |            |                            | e              |  h
> |            |                            | i              |  e
> |            |                            | g              |  i
> |            |                            | h              |  g
> |            |                            | t              |  h
> |            |                            |                |  t
> |            |                            | |              |
> |            |                            | |              |  |
> |            |                            | v              |  |
> |            +----------------------------+ -              |  |
> |                                                          |  |
> |                                                          |  |
> |                                                          |  v
> +----------------------------------------------------------+-----
>
>
> Best regards,
>
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-04 16:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-04 13:07 Query the meaning of variable in v4l2_pix_format and v4l2_plane Jonghun Han
2011-11-04 13:28 ` Marek Szyprowski
2011-11-04 14:48   ` Hans Verkuil
2011-11-04 16:02 ` Tomasz Stanislawski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox