22 UVC Device Linux - Raspberry Pi 4
Rafael Caricio edited this page 2024-06-15 22:20:28 +00:00

Configure Kernel modules:

sudo nvim /boot/firmware/config.txt

Change line:

dtoverlay=dwc2

Edit:

sudo nvim /boot/firmware/cmdline.txt

Add to end of line:

modules-load=dwc2,libcomposite

Add to /etc/rc.local from https://git.ideasonboard.org/uvc-gadget.git/tree/scripts/uvc-gadget.sh:

/home/rafaelcaricio/uvc-gadget.sh start &

Reboot system: sudo reboot

Fix locales in Debian:

sudo dpkg-reconfigure locales
sudo locale-gen

Install dependencies:

sudo apt install libconfig-dev libtool autoconf flex bison build-essential libudev-dev  libunwind-dev libdw-dev libraspberrypi-dev raspberrypi-kernel-headers libdrm-dev libgbm-dev libegl-dev libjpeg-dev libgl-dev libpcre2-dev libharfbuzz-dev libffi-dev libgraphene-1.0-dev libopus-dev libcogl-pango-dev libxml2-dev libflac-dev libmp3lame-dev libjson-glib-dev libsoup-3.0-dev libopenjp2-7-dev libsqlite3-dev libsoundtouch-dev libsrtp2-dev libfdk-aac-dev libvorbis-dev

Clone repo:

git clone https://github.com/linux-usb-gadgets/libusbgx.git

List the USB gadgets:

ls -lah /sys/kernel/config/usb_gadget/

Empty at this point.

Show all camera devices:

ll /dev/video*

Initialize UVC device:

sudo ./libusbgx/examples/gadget-uvc

Show UVC device is active:

./libusbgx/examples/show-gadgets

List all video devices:

v4l2-ctl --list-devices

Can be visualized as camera device:

ll /dev/video*

Can test the camera passthrough using https://git.ideasonboard.org/uvc-gadget.git/tree/src/main.c:

./build/src/uvc-gadget g1/functions/uvc.0 -d /dev/video0

Install GStreamer:

sudo apt install gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-plugins-good gstreamer1.0-plugins-rtp gstreamer1.0-pipewire gstreamer1.0-opencv gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-vaapi gstreamer1.0-wpe

Build uvc plugin from source:

meson setup -Dglib:tests=false -Djson-glib:tests=false -Dpcre2:test=false -Dgst-plugins-bad:uvcgadget=enabled -Dgst-examples=disabled -Dpython=disabled -Ddoc=disabled -Dges=disabled -Dsharp=disabled -Dlibnice=disabled -Dlibav=disabled -Dgstreamer-1.0:rtsp_server=disabled -Dgstreamer-1.0:devtools=disabled -Dgstreamer-1.0:base=enabled -Dgstreamer-1.0:bad=enabled -Dgst-plugins-bad:videoparsers=enabled -Dgst-plugins-base:typefind=enabled -Dgst-plugins-base:tools=enabled -Dgstreamer-1.0:ugly=enabled -Dgst-plugins-good:vpx=disabled -Dgst-plugins-good:soup=disabled -Dgst-plugins-bad:openh264=disabled -Drtsp_server=disabled -Dprefix=$PWD/fake_install_dir builddir

Enter GStreamer context:

python ~/gstreamer/gst-env.py

Send content to camera device:

gst-launch-1.0 videotestsrc ! videoconvert ! videorate ! videoscale ! videoparse ! uvcsink v4l2sink::device=/dev/video2