Update
Unfortunately a recent update, I believe in one or more of the Intel drivers, has broken the camera setup again. I have not been able to resolve the new issue using the setup as outlined below. From what I’ve been able to see, the primary issue appears to be with the HAL drivers.
I’m leaving this here, in case it helps anybody get closer to having a working camera.
—
The Issue
I recently purchased myself a new Lenovo X1 Cabon Laptop for work. The problem is that I run a flavor of Ubuntu and, though the hardware is Ubuntu certified, there is a known issue with the MIPI webcam models and for the particular hardware combination I was looking for, I had no choice but to go with that model. Lenovo and Canonical have not managed to provide any simple instructions as to how to resolve this despite the issue being ongoing for years at this point.
The official approach seems to be to follow the steps outlined across 4 separate git repos.
The process is extremely technical, including the need to patch the Kernel with the intel drivers, and even when following the steps as outlined the issues are many. I managed to make it through the entire setup, only to be disappointed when gstreamer ended up throwing errors.
After spending my weekend powering through this, I managed to get a working solution running using some undocumented Canonical repos that contain the correct camera drivers and v4l2, and after configuring v4l2-relayd properly.
Full disclosure: This is undeniably a hack, essentially the idea is that v4l2-relayd turns your camera on when an app calls for it and it streams the camera to a v4l2loopback virtual device, which in turn is what your browser, Zoom, Discord, etc pick up. Is this crazy? Yes, but it is what Lenovo officially suggests until they can get a fix published. I have found occasionally my camera will stop working and I need to restart v4l2-relayd, I think this is the result of a race condition where the app requests the camera before the v4l2loopback device is serving it, but I am not certain. I also found that I was totally unable to get the default snap Firefox install to recognize my camera. That is somewhat unsurprising though, as the snap install has a number of issues connecting with gnome apps.
With that out of the way, I wanted to provide the steps that ultimately got me up and running since there is barely any documentation to this approach, even on the repos themselves, and I would have loved to have some instructions while I was doing this.
The Fix
First, you’ll need to add the OEM Solutions PPA to your system. This PPA includes kernel-specific binaries that are essentially prepared for you from the process outlined in the ipu6 repos linked above. If you don’t want to install the ppa, it is possible to accomplish everything done here manually, but I personally ran into issues with v4l2loopback.
sudo add-apt-repository ppa:oem-solutions-group/intel-ipu6
Once you’ve installed the ppa, you’ll need to update to find the new packages
sudo apt update
Next, you’ll need to identify your kernel version. You can do so with the uname command.
uname -r
After you’ve identified your kernel version, you can install the correct version from the list of packages installed by the ppa.
sudo apt install linux-modules-ipu6-<your-kernel-version>
After the kernel patch is installed, you’ll need to install v4l2loopback-dkms and v4l2-relayd. We’ll also install v4l-utils in order to confirm that things are set up correctly.
sudo apt install v4l2loopback-dkms v4l2-relayd v4l-utils
You’ll also want to make sure that gstreamer1.0-icamera is installed
sudo apt install gstreamer1.0-icamera
After installing everything, update the newly added modprobe config file for the Virtual Camera
# backup the conf file first
sudo cp /etc/modprobe.d/v4l2-relayd.conf /etc/modprobe.d/v4l2-relayd.conf.old
# you can also use nano if you don't have or don't like vim
sudo vim /etc/modprobe.d/v4l2-relayd.conf
In the editor, rename the device from “Virtual Camera” to the name that you want to see in device lists, I named mine “Intel MIPI Camera”, and add the devices and video_nr parameters.
options v4l2loopback devices=1 video_nr=0 exclusive_caps=1 card_label="Intel MIPI Camera"
Now we need to make sure that v4l2-relayd picks up our camera since the default is a test source. There is a conf file located in /etc/default that we can edit.
# backup the conf file first
sudo cp /etc/default/v4l2-relayd /etc/default/v4l2-relayd.old
# edit the file
sudo vim /etc/default/v4l2-relayd
In the editor, we need to update VIDEOSRC so it points at icamerasrc, we need to update the ouput format and dimensions, and we need to make sure that our card label matches what we defined in modprobe.
# GStreamer source element name:
VIDEOSRC="icamerasrc"
...
# Output format, width, height, and frame rate:
FORMAT=NV12
WIDTH=1280
HEIGHT=720
FRAMERATE=30/1
# Virtual video device name:
CARD_LABEL="Intel MIPI Camera"
...
Finally, reboot the system.
sudo reboot
After a reboot list the video devices and confirm that you see your virtual camera, the device number is correct, and it is not showing as busy.
v4l2-ctl --list-devices
If you see your device listed, you can also make sure that v4l2-relayd is enabled and running.
sudo systemctl status v4l2-relayd.service
If you see the service active, you should now be all set. Give your camera a test in Chrome or Cheese. Cheese may try to pick up ipu6 by default, if this happens just select the virtual camera and restart.
As mentioned above, if you are running the default snap install of Firefox, you will probably have issues with the camera in Firefox specifically. My solution for this was to install from apt as I was having other issues with the snap version of Firefox as well.
—
Important: You will, unfortunately, need to remove and re-install the drivers from time to time when your kernel version has minor updates
—
If the service is not active, make sure it is enabled and then try restarting it.
sudo systemctl enable v4l2-relayd.service
sudo systemctl restart v4l2-relayd.service
sudo systemctl status v4l2-relayd.service
If the service does not start on system startup or will not start after a restart, you’ll need to examine the logs to figure out what went wrong. The most likely culprit will be a syntax error in one of the conf files for v4l2-relayd.
Leave a comment