Building hardware-accelerated gstjpeg from source.

Has anybody managed to build the hardware-accelerated gstreamer jpeg plugin from source?

There’s a source package available at http://developer.nvidia.com/embedded/dlc/l4t-Jetson-TK1-Gstjpeg-Sources-R21-5, however the instructions in the README.txt file don’t actually work, even though it’s written by NVIDIA and is supposed to work even for cross-compilation.

I suspect that the README.txt is outdated and incomplete.

First of all, I don’t know why the README.txt says NVIDIA has used deb packages from Ubuntu Precise (12.04), as L4T 21.5 is based on Ubuntu Trusty (14.04).

Secondly, the paths mentioned in the README.txt are obviously wrong. For instance, /usr/lib/libglib-2.0.so should really be /usr/lib/arm-linux-gnueabihf/libglib-2.0.so.

Thirdly, and most importantly, the autogen.sh script and the resulting configure script are also wrong. configure won’t properly test for libnvjpeg; instead, it tests for libjpeg and libjpeg-mmx, and fails (because the compiler can’t even find the libjpeg.so file, with the given flags and environment variables), so configure thinks it can’t build the jpeg plugin and writes a Makefile that doesn’t do anything. At this point, I don’t even know how NVIDIA ever got it to cross-compile. configure tries to link with -ljpeg instead of -lnvjpeg, and there’s no mention of downloading libnvjpeg.so anywhere in the README.txt.

I don’t have the knowledge and time to fix this mess. Could somebody (preferably from NVIDIA) step forward and fix these issues?

We will check this. Could you please share why you need to build the source?

Please run the steps

sudo apt-get install autotools-dev autoconf autopoint libtool
sudo apt-get install build-essential
sudo apt-get install gstreamer1.0-tools
sudo apt-get install gstreamer-1.0 libgstreamer1.0-dev
sudo apt-get install gstreamer1.0-plugins-base libgstreamer-plugins-base1.0-dev
sudo apt-get install libjpeg-dev

cd gstjpeg_src/gst-jpeg/gst-jpeg-1.0/
export CFLAGS="-I/home/ubuntu/gstjpeg_src/nv_headers"
export NOCONFIGURE=true
./autogen.sh
./configure
make

sudo cp -i ext/jpeg/.libs/libgstjpeg.so /usr/lib/arm-linux-gnueabihf/gstreamer-1.0/
cd /usr/lib/arm-linux-gnueabihf/
sudo ln -sf tegra/libnvjpeg.so libjpeg.so
sudo ln -sf tegra/libnvjpeg.so libjpeg.so.8

Just me or it looks like you are compiling and linking against the regular libjpeg.so, and then replacing the libjpeg.so symlink with libnvjpeg.so so that the gstreamer plugin will call into libnvjpeg.so instead? That looks super hacky. XD

We link libgstjpeg.so to our own libnvjpeg.so. If you would like to link to the regular libjpeg.so, please download/build the original source code

According to your instructions, you are replacing the symlinks only after running make, so the resulting libgstjpeg.so is still linked to the regular libjpeg.so, no?

I think I got it working with slight modifications to your instructions.

First of all, CLAGS should be:

export CFLAGS="-I/home/ubuntu/gstjpeg_src/nv_headers -L/usr/lib/arm-linux-gnueabihf/tegra"

And then, because configure will generate a bunch of files, I just have to replace all occurrences of -ljpeg with -lnvjpeg in the generated files, before running make.

At least I got it to compile and link. ldd shows that libgstjpeg.so is linked to libnvjpeg.so.

Now I’ll check if the resulting plugin actually works.

The resulting plugin segfaults:

ubuntu@tegra-ubuntu:~$ gst-launch-1.0 filesrc location=test.jpg ! nvjpegdec ! filesink location=/dev/null -v
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstNvJpegDec:nvjpegdec0.GstPad:src: caps = video/x-raw(memory:NVMM), format=(string)I420, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)1:4:0:0, framerate=(fraction)0/1
/GstPipeline:pipeline0/GstFileSink:filesink0.GstPad:sink: caps = video/x-raw(memory:NVMM), format=(string)I420, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, colorimetry=(string)1:4:0:0, framerate=(fraction)0/1
Caught SIGSEGV
#0  0xb6cda0e0 in poll () at ../sysdeps/unix/syscall-template.S:81
#1  0xb6d884e6 in ?? () from /lib/arm-linux-gnueabihf/libglib-2.0.so.0
Spinning.  Please run 'gdb gst-launch-1.0 20802' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.

Changed CLAGS to:

export CFLAGS="-I/home/ubuntu/gstjpeg_src/nv_headers -L/usr/lib/arm-linux-gnueabihf/tegra -DUSE_TARGET_TEGRA"

And now it doesn’t segfault. Note the addition of -DUSE_TARGET_TEGRA.

Many thanks for figuring out the solution.