From: Hans de Goede <hdegoede@redhat.com>
To: "Frank Schäfer" <fschaefer.oss@googlemail.com>
Cc: linux-media@vger.kernel.org
Subject: Re: pac7302-webcams and libv4lconvert interaction
Date: Mon, 10 Sep 2012 20:31:12 +0200 [thread overview]
Message-ID: <504E31F0.7080804@redhat.com> (raw)
In-Reply-To: <504E0916.8010204@googlemail.com>
Hi,
On 09/10/2012 05:36 PM, Frank Schäfer wrote:
> Hi Hans,
>
> Am 09.09.2012 23:20, schrieb Hans de Goede:
>> Hi,
>>
>> On 09/06/2012 05:13 PM, Frank Schäfer wrote:
>>>
>>> Hi,
>>>
>>> I'm currently looking into the gspca_pac7302-driver and how it interacts
>>> with libv4lconvert.
>>> This is how it currently works
>>> - driver announces v4l2_pix_format 640x480 (width x height)
>>> - the frames (jpeg) passed to userspace are encoded as 480x640 and this
>>> complies with the jpeg-header we generate
>>> - libv4lconvert checks width/height in the jpeg-header and compares them
>>> with the image format announced by the kernel:
>>> a) values are the same:
>>> 1) V4LCONTROL_ROTATED_90_JPEG is NOT set for the device (standard
>>> case):
>>> => everything is fine, image is decoded
>>> 2) V4LCONTROL_ROTATED_90_JPEG is set for the device:
>>> => libv4lconvert bails out with -EIO displaying the error
>>> message "unexpected width / height in JPEG header: expected: 640x480,
>>> header: 480x640"
>>> b) values are different:
>>> 1) V4LCONTROL_ROTATED_90_JPEG is NOT set:
>>> => libv4lconvert bails out with -EIO displaying the error
>>> message "unexpected width / height in JPEG header: expected: 640x480,
>>> header: 480x640"
>>> 2) V4LCONTROL_ROTATED_90_JPEG is set:
>>> => image is decoded and rotated correctly
>>>
>>>
>>> Thinking about this for some minutes:
>>>
>>> 1) shouldn't the kernel always announce the real image format (size) of
>>> the data it passes to userspace ?
>>
>> It is passing the real size, the data is just in a vary funky format
>> which
>> needs rotation as part of its "decoding" / decompression.
>
> It is first decoded, then rotated, right ?
Yes, because rotating raw JPEG data is hard, but we believe that the
rotation happening inside the cam is a side-effect (or rather a bug) of how
the hardware encoding works. So that we split the 2 steps in software is just
for convenience. The fact is that these cams have a sensor which has 640x480
pixels, not 480x640. So the correct size to report to userspace is 640x480,
the rotation is a side effect of the special pixart pixel format / encoding.
> Are the frames encoded as 480x640 (that's what the header says) or 640x480 ?
> If the header is wrong, everything is fine. Otherwise we are passing the
> size we finally get AFTER decoding and rotation to userspace, which I
> think would be inconsistent.
They are encoded as 480x640, which is why the header says that (otherwise
even more pixart hacks to the jpeg decoder in tinyjpeg.c would be necessary),
but again the sensor has a resolution of 640x480, not 480x640. So both the
reported resolution and the header are right, they just don't agree because
these (dirt cheap) cameras are really funky.
>
>>
>>> Current behavior seems inconsistent to me...
>>> Announcing the actual image size allows applications which trust the API
>>> value more than the value in the frame header to decode the image
>>> correctly without using libv4lconvert (although the image would still be
>>> rotated).
>>
>> That assumes that the app would know how to decompress the data which it
>> will not know, these cams do not generate standard JPEG data,
>> libv4lconvert's
>> decompression code is the only decompression code for this fsck-ed up
>> JPEG-s,
>> short of the windows drivers code.
>
> Ok, that's true.
> Because of the special format, applications are forced to use
> libv4lconvert, so there is CURRENTLY no need to think about the kernel
> <-> userspace interface.
> But that might change in the future...
>
>>
>>> 2) shouldn't libv4lconvert always rotate the image if
>>> V4LCONTROL_ROTATED_90_JPEG is set for a device ?
>>> It seems like a2) is a bug, because the expected size should be 640x480,
>>> too.
>>
>> rotating by 90 degrees also swaps the width and height, which are usually
>> not the same, so rotating an image which starts at 640x480 will yield
>> a final image of 480x640 which will not be what the app expects.
>
> Well, I can't see why 480x640 should be an invalid format !? Depends on
> the hardware.
What I'm trying to say is that for the image to be 640x480 after rotation
by 90 degrees, it has to be 480x640 before rotation. So since the raw data
needs rotation it reports itself as 480x640, where as the end result
reports itself as 640x480 ...
Regards,
Hans
next prev parent reply other threads:[~2012-09-10 18:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-06 15:13 pac7302-webcams and libv4lconvert interaction Frank Schäfer
2012-09-09 21:20 ` Hans de Goede
2012-09-10 15:36 ` Frank Schäfer
2012-09-10 18:31 ` Hans de Goede [this message]
2012-09-10 20:24 ` Frank Schäfer
2012-09-11 7:29 ` Hans de Goede
2012-09-12 14:36 ` Frank Schäfer
2012-09-13 12:05 ` Hans de Goede
2012-09-16 12:21 ` Frank Schäfer
2012-09-17 9:39 ` Hans de Goede
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=504E31F0.7080804@redhat.com \
--to=hdegoede@redhat.com \
--cc=fschaefer.oss@googlemail.com \
--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).