gst_element_factory_make("nvcamerasrc", NULL) returns NULL while a command line pipeline works well

Hi,

The following command runs successfully:

gst-launch-1.0 nvcamerasrc ! ‘video/x-raw(memory:NVMM),width=1280, height=720, framerate=30/1’ ! omxh265enc ! filesink location=test.mkv

gst-inspect-1.0 nvcamerasrc
also works well.

But when try to run the code:
gst_element_factory_make(“nvcamerasrc”, NULL)
it gets NULL

I guess it happens because of environment as my code runs within AWS kinesis SDK framework which probably sets specific environment.
Could you suggest where to dig?
Thank you!

If you check at gstreamer doc for this function, you’ll see that the second argument is a string with plugin name. Try to provide one with something like:

gst_element_factory_make("nvcamerasrc", "source")

.
Furthermore your pipeline above saves raw H265 stream, not a mkv. You may use plugin matroskamux for using such container:

gst-launch-1.0 -e nvcamerasrc ! 'video/x-raw(memory:NVMM),width=1280, height=720, framerate=30/1' ! omxh265enc ! h265parse ! matroskamux! filesink location=test.mkv

I tried it too with the same result.
BTW the second parameter can be NULL to allow the pipeline to assign a unique name.

The command is used only to check if nvcamerasrc works. It writes a file which is enough for now.
So, the reason of the problem is in something else. Probably in environment variables.
Thank you.

You may check with ldd which libs are found four your app in your environment and see if it is as expected.

Have you built your app in debug mode and run it from gdb in order to see where it faults ?

ldd gives: not a dynamic executable, that’s all

My test app has just this:

#include <gst/gst.h>

int main (gint argc, gchar * argv[])
{  
	GstElement *source;
	gst_init (&argc, &argv);
	source = gst_element_factory_make ("nvcamerasrc", NULL);
  if (!source) {
    g_print ("'nvcamerasrc' gstreamer plugin missing\n");
    return 1;
  }
  return 0;
}

It works for “v4l2src” but not for “nvcamerasrc”.
At the same time
gst-launch-1.0 nvcamerasrc <…>
works.

I ran
sha1sum -c /etc/nv_tegra_release
and get
/usr/lib/aarch64-linux-gnu/tegra/libnvcamerautils.so: OK

Do you have an idea why gst-launch-1.0 can see nvcamerasrc but the app can not?

How did you build your app ?
I cannot check now on TX2, but on a TK1 I just compiled your code with:

gcc -o test_gst test_gst.cpp `pkg-config --cflags --libs gstreamer-1.0`

ldd ./test_gst
	libgstreamer-1.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgstreamer-1.0.so.0 (0xb6e55000)
	libglib-2.0.so.0 => /lib/arm-linux-gnueabihf/libglib-2.0.so.0 (0xb6d8d000)
	libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6d6c000)
	libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6d51000)
	libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6c69000)
	libgobject-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgobject-2.0.so.0 (0xb6c2b000)
	libgmodule-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgmodule-2.0.so.0 (0xb6c20000)
	libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6bb4000)
	libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6ba9000)
	/lib/ld-linux-armhf.so.3 (0xb6f2e000)
	libpcre.so.3 => /lib/arm-linux-gnueabihf/libpcre.so.3 (0xb6b71000)
	libffi.so.6 => /usr/lib/arm-linux-gnueabihf/libffi.so.6 (0xb6b62000)

Execution on TK1 shows no error nor message.

[EDIT: confirmed on my TX2.

ldd ./test_gst         linux-vdso.so.1 =>  (0x0000007faf124000)
	libgstreamer-1.0.so.0 => /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so.0 (0x0000007faefd8000)
	libglib-2.0.so.0 => /lib/aarch64-linux-gnu/libglib-2.0.so.0 (0x0000007faeed1000)
	libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000007faeea5000)
	libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000007faed5d000)
	libgobject-2.0.so.0 => /usr/lib/aarch64-linux-gnu/libgobject-2.0.so.0 (0x0000007faed01000)
	libgmodule-2.0.so.0 => /usr/lib/aarch64-linux-gnu/libgmodule-2.0.so.0 (0x0000007faeced000)
	libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000007faec3f000)
	libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000007faec2c000)
	/lib/ld-linux-aarch64.so.1 (0x000000557197f000)
	libpcre.so.3 => /lib/aarch64-linux-gnu/libpcre.so.3 (0x0000007faebbb000)
	libffi.so.6 => /usr/lib/aarch64-linux-gnu/libffi.so.6 (0x0000007faeba2000)

Now, when I used your command:
gcc -o test_gst test_gst.cpp pkg-config --cflags --libs gstreamer-1.0

I could get a proper ldd output. Before I used makefile supplied by Kinesis SDK.

About the issue itself: the reason was that Kinesis SDK (https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/) has its own supply of gstreamer including plugins and overwrites the lib path so that an app cannot get /usr/lib/aarch64-linux-gnu/tegra/ to find nvcamerasrc.
It is resolved by:

export GST_PLUGIN_PATH=/usr/lib/aarch64-linux-gnu/tegra/:/usr/lib/aarch64-linux-gnu/gstreamer-1.0

More info is here: https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/issues/85

Thank you!