pxa_camera: Remove YUV planar formats hole
A message that is not in the archive (sent off-list or not yet received): 1402002204.2045281236327939805.JavaMail.root@zimbra20-e3.priv.proxad.net
----- Mail Original -----
De: "Guennadi Liakhovetski" <[email protected]>
À: "Trent Piepho" <[email protected]>
Cc: "Robert Jarzmik" <[email protected]>, [email protected], "Linux Media Mailing List" <[email protected]> Envoyé: Jeudi 5 Mars 2009 23h15:03 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [PATCH 1/4] pxa_camera: Remove YUV planar formats hole
Quoted 2 lines
Yes, adjusting both is also what I was suggesting in my original review. How about aligning the bigger of the two to 4 bytes and the smaller to 2?
Yes, sounds good.
I remade my calculations :
- if (width x height % 8 == 0) :
=> frame size = width x height x 2
=> U plane size = frame size / 4 = width x height /2
=> U plane size is a multiple of 4
As the last DMA load from QIF fifo will return 8 bytes (and not 4 as we would expect, cf. PXA Developer's Manual, 27.4.4.1), this is not good.
This implies that even if DMA is 8 bytes aligned, width x height should be a multiple of 16, not 8 as I stated in the first git comment. So that would align :
- width on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to width)
- and height on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to height)
Do we have an agreement on that specification, so that I can amend the code accordingly ?
Cheers.
--
Robert
Quoted 12 lines · On Fri, 6 Mar 2009 [email protected] wrote:
----- Mail Original -----
De: "Guennadi Liakhovetski" <[email protected]>
À: "Trent Piepho" <[email protected]>
Cc: "Robert Jarzmik" <[email protected]>, [email protected], "Linux Media Mailing List" <[email protected]> Envoyé: Jeudi 5 Mars 2009 23h15:03 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [PATCH 1/4]pxa_camera: Remove YUV planar formats holeQuoted 2 lines
Yes, adjusting both is also what I was suggesting in my original review. How about aligning the bigger of the two to 4 bytes and the smaller to 2?
Yes, sounds good.
Quoted 8 lines
I remade my calculations :
- if (width x height % 8 == 0) :
=> frame size = width x height x 2
=> U plane size = frame size / 4 = width x height /2
=> U plane size is a multiple of 4
As the last DMA load from QIF fifo will return 8 bytes (and not 4 as we would expect, cf. PXA Developer's Manual, 27.4.4.1), this is not good.
So it's only a requirement that the total size of all three planes put together is a multiple of 8? Or is it a requirement that each plane is a multiple of 8? And are you using 4:2:2 or 4:2:0?
Quoted 2 lines · On Fri, 6 Mar 2009, [email protected] wrote:
----- Mail Original -----
De: "Guennadi Liakhovetski" <[email protected]>
(hm, there's something strange about this and following emails in this thread, I didn't get them directly, only over the mailing list... strange)
Quoted 19 lines
Ã: "Trent Piepho" <[email protected]>
Cc: "Robert Jarzmik" <[email protected]>, [email protected], "Linux Media Mailing List" <[email protected]> Envoyé: Jeudi 5 Mars 2009 23h15:03 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [PATCH 1/4]pxa_camera: Remove YUV planar formats holeQuoted 2 lines
Yes, adjusting both is also what I was suggesting in my original review. How about aligning the bigger of the two to 4 bytes and the smaller to 2?
Yes, sounds good.
I remade my calculations :
- if (width x height % 8 == 0) :
=> frame size = width x height x 2
=> U plane size = frame size / 4 = width x height /2
=> U plane size is a multiple of 4
As the last DMA load from QIF fifo will return 8 bytes (and not 4 as we would expect, cf. PXA Developer's Manual, 27.4.4.1), this is not good.
Quoted 7 lines
This implies that even if DMA is 8 bytes aligned, width x height should
be a multiple of 16, not 8 as I stated in the first git comment. So that
would align :
- width on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to width)
- and height on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to height)Do we have an agreement on that specification, so that I can amend the code accordingly ?
Yep, looks good to me.
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
Quoted 11 lines · Guennadi Liakhovetski
Quoted 8 lines · On Fri, 6 Mar 2009, [email protected] wrote:
This implies that even if DMA is 8 bytes aligned, width x height should
be a multiple of 16, not 8 as I stated in the first git comment. So that
would align :
- width on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to width)
- and height on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to height)Do we have an agreement on that specification, so that I can amend the code accordingly ?
Yep, looks good to me.
I like the algorithm I posted, after another small improvement, better.
For instance, if width is aligned by 8 and height by 2, then you have already have 16 byte alignment and there is no need to align height by 4. E.g., 168x202 will be kept as 168x202 with my method but the rounding down method changes it to 168x200.
Another example, take 159x243. My algorithm produces 160x243, which seems much better than 156x240, what one gets by rounding each dimention down to a multiple of four.
Quoted 1 line · Trent Piepho
I like the algorithm I posted, after another small improvement, better.
So push it toward v4l2, to have wider audience.
If I were you, I'd have a peek at include/linux/kernel.h, which brings you beautiful functions like ALIGN(), IS_ALIGNED(), and so on ... That could make your next review easier.
Quoted 4 lines
For instance, if width is aligned by 8 and height by 2, then you have already have 16 byte alignment and there is no need to align height by 4. E.g., 168x202 will be kept as 168x202 with my method but the rounding down method changes it to 168x200.
In the algorithm I posted, I keep 168x202 as well.
Quoted 3 lines
Another example, take 159x243. My algorithm produces 160x243, which seems much better than 156x240, what one gets by rounding each dimention down to a multiple of four.
By better you mean "nearer" ? Well, why not. If your patch mades it through v4l2 stack, I'll push an update to use it, deal ?
--
Robert
Quoted 9 lines · Guennadi Liakhovetski
Quoted 7 lines
This implies that even if DMA is 8 bytes aligned, width x height should
be a multiple of 16, not 8 as I stated in the first git comment. So that
would align :
- width on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to width)
- and height on 4 bytes (aligning meaning the lowest multiple of 4 below or equal to height)Do we have an agreement on that specification, so that I can amend the code accordingly ?
Yep, looks good to me.
All right, this should amend patch 1/4. I'll wait for the complete review to resend the patch as a whole.
Cheers
--
Robert
commit 4d3bd5219dd3ef27f11c7061adf10f8249d2ba26
Author: Robert Jarzmik <[email protected]> Date: Fri Mar 6 22:39:41 2009 +0100
pxa_camera: Enforce YUV422P frame sizes to be 16 multiples
Due to DMA constraints, the DMA chain always transfers bytes from the QIF fifos to memory in 8 bytes units. In planar formats, that could mean 0 padding between Y and U plane (and between U and V plane), which is against YUV422P standard.
Therefore, a frame size is required to be a multiple of 16 (so U plane size is a multiple of 8). It is enforced in try_fmt() and set_fmt() primitives, be aligning height then width on 4 multiples as need be, to reach a 16 multiple.
--- drivers/media/video/pxa_camera.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-)
drivers/media/video/pxa_camera.c +15 -4
@@ -162,6 +162,8 @@ CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \ CICR0_EOFM | CICR0_FOM) +#define PIX_YUV422P_ALIGN 16/* YUV422P pix size should be a multiple of 16 */ +/* * Structures */
@@ -241,11 +243,8 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,dev_dbg (&icd->dev,"count=%d, size=%d\n" , *count, *size); -/* planar capture requires Y, U and V buffers to be page aligned */ if (pcdev->channels ==3 ) - *size =roundup (icd->width * icd->height,8 )/* Y pages */ - +roundup (icd->width * icd->height /2 ,8 )/* U pages */ - +roundup (icd->width * icd->height /2 ,8 );/* V pages */ + *size = icd->width * icd->height *2 ;else *size =roundup (icd->width * icd->height * ((icd->current_fmt->depth +7 ) >>3 ),8 );
@@ -1297,6 +1296,18 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd, pix->width =2048 ; pix->width &= ~0x01 ; +/* +* YUV422P planar format requires images size to be a 16 bytes +* multiple. If not, zeros will be inserted between Y and U planes, and +* U and V planes, and YUV422P standard would be violated. +*/ +if (xlate->host_fmt->fourcc ==V4L2_PIX_FMT_YUV422P ) { +if ((pix->width * pix->height) &PIX_YUV422P_ALIGN ) + pix->height =ALIGN (pix->height,PIX_YUV422P_ALIGN /2 ); +if ((pix->width * pix->height) &PIX_YUV422P_ALIGN ) + pix->width =ALIGN (pix->width,PIX_YUV422P_ALIGN /2 ); + } + pix->bytesperline = pix->width *DIV_ROUND_UP (xlate->host_fmt->depth,8 ); pix->sizeimage = pix->height * pix->bytesperline;