New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.
Starred by 13 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
NextAction: ----
OS: ----
Pri: 2
Type: Patch

Blocking:
issue chromium:494698


Show other hotlists

Hotlists containing this issue:
Hotlist-1
Hotlist-2
Hotlist-1


Sign in to add a comment

Webcam upside down on Fujitsu T730 running Ubuntu 14.04

Reported by ofirr....@gmail.com, Sep 2 2014 Back to list

Issue description

On the apprtc demo my webcam is upside down.
I'm using a Fujitsu T730 laptop running Ubuntu 14.04 (64 bit).
http://www.shopfujitsu.com/pdf/notebooks/Notebook-Computer-LifeBook-T730-Tablet-PC-datasheet.pdf

In desktop apps like Cheese the webcam orientation is correct.

In Firefox 31 the webcam is upside down like in Chrome but with lib4vl it is fixed:
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libv4l/v4l1compat.so && firefox

When running Chrome with libv4l the webcam video is black:
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libv4l/v4l1compat.so && google-chrome
 
Project Member

Comment 1 by braveyao@webrtc.org, Sep 3 2014

Owner: braveyao@webrtc.org
First of all, WebRTC requests v4l2 on Linux.
Could this cam work properly on Win?

Yes, on the same laptop, the cam works properly with Windows 7 in Chrome.
Project Member

Comment 3 by braveyao@webrtc.org, Sep 3 2014

Could you please help to debug this problem since you can reproduce it at your side, to see if it's a problem in its driver or in webrtc? I suppose the easiest way is to try with webrtc standalone.
Do you mean compiling webrtc as explained here?http://www.webrtc.org/reference/getting-started
Or is there A binary I can download for standalone webrtc?
Project Member

Comment 5 by braveyao@webrtc.org, Sep 4 2014

Yes, you can build webrtc on Linux according to the getting-started page. And test/debug with ./out/Debug/vie_auto_test. The capture codes is at https://code.google.com/p/webrtc/source/browse/#svn%2Ftrunk%2Fwebrtc%2Fmodules%2Fvideo_capture%2Flinux. 
Since it sounds like a target specific issue and you have the replication, so please help to figure it out and possibly work on a patch.
I've built webrtc and run ./out/Debug/vie_auto_test.
When running the simple loopback call I see the webcam upside down.

Do you want me to run other tests?
How do you want me to debug it?
Project Member

Comment 7 by braveyao@webrtc.org, Sep 5 2014

I suppose you could start to debug with https://code.google.com/p/webrtc/source/browse/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc. Try to compare the capture format/data with a working case. 
Also try a external USB camera to see if it works on that machine or not.
I think it's important to figure out if this is a system issue or a webrtc issue.
There is a known problem with laptops that have the camera mounted upside down.
http://hansdegoede.livejournal.com/8140.html

The V4L2_IN_ST_VFLIP is set when the camera should be flipped:
http://lxr.free-electrons.com/source/include/uapi/linux/videodev2.h#L1197
And it is used here:
http://lxr.free-electrons.com/source/drivers/media/usb/gspca/sn9c2028.c#L195

Should v4l2 do it automatically or should WebRTC flip the camera when the flag is set?
Project Member

Comment 9 by braveyao@webrtc.org, Sep 8 2014

Cc: perkj@webrtc.org mflodman@webrtc.org
Good to know!
From the post, it seems that the libv4l would do the flip for the App. And your test shows libv4l won't work for Chrome. Would it work with vie_auto_test?

+devs for more comments!
External USB camera works fine.
The camera is upside down in the "simple loopback call" in vie_auto_test.

There are probably two options:
- libv4l knows that the camera is upside down but Chrome need to ask it to fix it.
- Chrome uses an older version of libv4l than that installed in Ubuntu 14.04 which makes cheese (desktop app) work and Firefox work with v4l1compat.so.
So Chrome currently ignore 
V4L2_IN_ST_HFLIP and V4L2_IN_ST_VFLIP ? 

Brave, can you file a Chrome issue and assign to magjed? 
Project Member

Comment 12 by perkj@webrtc.org, Sep 9 2014

Cc: magjed@webrtc.org
Project Member

Comment 13 by braveyao@webrtc.org, Sep 10 2014

It should be same for Chrome to handle V4L2_IN_ST_VFLIP directly or handle it through libv4l(which doesn't work well with Chrome currently).

@ofirr, since we don't have such a device to verify the fix here, it's better for you to help on it. Here is the proposed patch to handle the flip inside chrome, https://codereview.chromium.org/558663006/. If you have a chromium building, you can apply it and test directly. If you don't, please merge and test it with vie_auto_test with webrtc standalone.
I've applied the patch but the webcam is still upside down.
When I replace the patch and force SetRotation(180) it does flip the camera vertically so something is wrong with the if statement.
Project Member

Comment 15 by braveyao@webrtc.org, Sep 11 2014

@ofirr, could you please help on the patch and upload it? Since you are the only one having the target device.
@ofirr, can you replace the patch with:

// Check sensor orientation
struct v4l2_input input;
input.index = 0;
if (HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_ENUMINPUT, &input)) == 0) {
  LOG(ERROR) << "###### SENSOR ORIENTATION: 0x" << std::hex << input.status
             << " #######";
} else {
  LOG(ERROR) << "###### Failed to enumerate video input ######";
}

Compile and run 
./out/Debug/chrome 'https://simpl.info/getusermedia/'
and look for the error messages in the terminal. I get
[12413:12520:0911/093657:ERROR:video_capture_device_linux.cc(257)] ###### SENSOR ORIENTATION: 0x0 #######
on the first line in the terminal. Hopefully you will get something different from 0x0.

I'm getting the same
[16837:16914:0911/170706:ERROR:video_capture_device_linux.cc(257)] ###### SENSOR ORIENTATION: 0x0 #######

Comment 18 by gja...@gmail.com, Sep 11 2014

Hello,

This wont work that way. Chromium must use libv4l to benefit from the upside down table logic. You can see a boilerplate patch here:

https://trac.videolan.org/vlc/ticket/1804

If I find time during weekend I'll try to come up with a patch.

Thanks,
Gregor

Comment 19 by gja...@gmail.com, Sep 13 2014

Hello,

I have problems compiling Chromium on my Debian Sid. Something with the NaCl crt stuff fails to build. Therefor the attached patch is compile tested only.

With this patch the media library utilizes the libv4l2 library to handle webcams. libv4l2 contains mostly two things:
1) An upside down table: if a notebook (DMI information) and the built-in webcam is known to be upside down then libv4l flips the image to the correct orientation

2) Colorspace converter: some cheap webcams only deliver an obscure internal format like raw Bayer patterns or even more quirky things. It is general understanding that these fomrats should not be handled in kernel level but in userspace instead. libv4l known how to convert these formats to YUV and RGB. During the enumeration it adds fake pixel formats to the cameras supported list and does the conversion on the fly.

libv4l is bundles in most distributions since 2009. It is utilized by vlc, gstreamer, xawtv, etc. It's license is LGPL2.1+ so adding it a a Chromium dependency should be safe.

Ofir, could you please build and test the patch?

Thanks,
Gregor
I've applied the patch but the camera is still upside down.
This is what I've tried:
git apply chromium-use-libv4l2.diff 
ninja -C out/Debug chrome
out/Debug/chrome --no-sandbox

Comment 21 by gja...@gmail.com, Sep 14 2014

Hi,

Mea Culpa. The ifdef guard contained an extra underscore. Could you please test with the new patch? At my remote system it looks much better:

$ nm out/Debug/chrome|grep v4l2
                 U v4l2_close
                 U v4l2_ioctl
                 U v4l2_mmap
                 U v4l2_munmap
                 U v4l2_open

Thanks,
Gregor
0001-Use-libv4l2-for-Linux-V4L-grabber.patch
13.0 KB Download
This patch fixes the camera for me (0001-Use-libv4l2-for-Linux-V4L-grabber.patch).

In the previous patch I saw a problem with installing the libv4l package when running install-build-deps.sh but you probably fixed that.

Thank you for your awesome fix.

Project Member

Comment 23 by braveyao@webrtc.org, Sep 15 2014

Cc: -magjed@webrtc.org braveyao@webrtc.org
Owner: magjed@webrtc.org
@per & Pmagjed, please help to evaluate the patch in #21. If it's good to go, I could help to file a crbug for it.

Comment 24 by vrk@webrtc.org, Sep 29 2014

Labels: Area-GetUserMedia-Webcam
Project Member

Comment 25 by juberti@webrtc.org, Dec 17 2014

Labels: -Type-Bug Type-Patch
Project Member

Comment 26 by juberti@webrtc.org, Jan 7 2015

Labels: -Area-GetUserMedia-Webcam Area-Webcam
Project Member

Comment 27 by tommi@webrtc.org, Mar 12 2015

Magnus - can you take a look at the patch in #21?
Project Member

Comment 28 by magjed@webrtc.org, Mar 16 2015

Cc: posciak@chromium.org
I think it's best to ask posciak about this. libv4l2 is added to Chromium now, at least for ChromeOS, see: http://crbug/405861.
Yes, use of libv4l should fix this. We have not enabled it for linux. Please feel free to do so.

Comment 30 by cec...@gmail.com, May 31 2015

I hope v4l to be enabled for linux cause my camera is upside down. I'm using firefox because i don't have a choice. It works fine with v4l , but i don't like that heavy and buggy browser. I love Chrome! ;)

Comment 31 by cec...@gmail.com, Sep 23 2015

One year later and still nothing??
Sorry, I’m not working actively on this. The patch looks simple, but I don’t know what's the best way to enable libv4l2 for linux and how to modify the build dependencies.

posciak@ - Can you enable libv4l2 for linux?
Any progress on this? Any way to work around it without having to compile?
I fear my patch fell victim to code changes since September 2014 and is not applicable anymore.

As far as I can tell libv4l gets used for some input/output conversion in Chromium or Chrome OS. This patch would have to play nicely with that other code path.

If some committers could give me advise or prepare a patch to add the libv4l dependency properly I would start working on the issue, again.
Project Member

Comment 35 by magjed@webrtc.org, Apr 15 2016

Cc: magjed@webrtc.org
Owner: posciak@chromium.org
posciak@ - Can you prepare a CL to properly add the libv4l dependency, or triage to someone who can?
Blockedon: chromium:494698
Blocking: chromium:494698
Blockedon: -chromium:494698
2 years and still no progress? 

I'm forced to use external webcam for Chrome + GoToMeeting for a few years already (Ubuntu 14-16 on Asus U36 laptop)

Please help.
Owner: ----
Status: Available
Project Member

Comment 41 by tnakamura@webrtc.org, May 25 2016

Cc: niklas.enbom@webrtc.org mcasas@webrtc.org

Comment 42 by m...@lucidfox.org, Dec 24 2016

I'm interested in seeing libv4l used under Linux, as I have a laptop (Asus K40AB) on which the webcam image is displayed correctly in libv4l2 applications (cheese, etc.) and in Firefox with the v4l1compat.so LD_PRELOAD, but is flipped in Chromium.
Same issue here with chromium, chrome and electron based apps (e.g. wire-desktop), on Asus U36SG and 4.8.17-1-MANJARO x86_64.
This issue is now causing problems with the webcam in skypeforlinux, as it seems that it uses chromium on linux as backend. Was there any development in the last time? 

Sign in to add a comment