Segmenration fault after restarting gstreamer pipeline

Hi,

I have an issue with Jetpack 6.1 using Jetson Orin NX 8 GB board. I’m trying to restart a gstreamer pipeline from a C++ program, but there is a segmentation fault in v4l2_fd_open function of libv4l2.so. The pipeline is stopped, but the seg fault occurs when I try to start it again using gst_element_set_state(pipeline, GST_STATE_PLAYING).

The pipeline is simple: v4l2src ! nvvidconv ! nvv4l2h264enc ! fakesink. The issue is gone when I remove the nvv4l2h264enc element. I have also seen that a thread of libnvbufsurftransform.so is still running after I completely stop the pipeline. I think that caused the issue since there is no any leftover thread when I don’t have the nvv4l2h264enc element. I didn’t experience a similar issue with Jetpack 6.0.

Is there any idea about this issue?

Hi akos.nagy,
Could you provide a sample code to demonstrate the issue? I was unable to replicate the error using our dev kit.
To better understand your setup, could you clarify whether using the dev kit or a custom carrier board?

Hi @DavidDDD,

Thanks for your reply! We use a custom carrier board. Here is a sample code about the issue:

#include <gst/gst.h>
#include <iostream>
#include <thread>
#include <chrono>

GstElement* start_pipeline() {
    std::cout << "Starting pipeline..." << std::endl;

    //Segmentation fault:
    GstElement *pipeline = gst_parse_launch("v4l2src ! nvv4l2h264enc ! fakesink", nullptr);
    //No issue:
    //GstElement *pipeline = gst_parse_launch("v4l2src ! x264enc ! fakesink", nullptr);
    if (!pipeline) {
        std::cerr << "Failed to create pipeline." << std::endl;
        exit(-1);
    }

    gst_element_set_state(pipeline, GST_STATE_PLAYING); //Segmenration fault in case of nvv4l2h264enc pipeline
    std::this_thread::sleep_for(std::chrono::seconds(5));  // Let it play for 5 seconds
    return pipeline;
}

void stop_pipeline(GstElement *pipeline) {
    std::cout << "Stopping pipeline..." << std::endl;
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(GST_OBJECT(pipeline));
    std::this_thread::sleep_for(std::chrono::seconds(2));  // Wait for 2 seconds before restarting
}

int main(int argc, char *argv[]) {
    gst_init(nullptr, nullptr);

    auto pipeline = start_pipeline();
    stop_pipeline(pipeline);
    pipeline = start_pipeline();

    // Cleanup
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(pipeline);
    gst_deinit();

    std::cout << "Pipeline stopped and cleaned up." << std::endl;
    return 0;
}

Hi,
Please try the pipeline:

"v4l2src ! nvvidconv ! nvv4l2h264enc ! fakesink"

You would need to have nvvidconv plugin to convert video/x-raw buffer to video/x-raw(memory:NVMM) buffer and then send the buffer to hardware encoder.

I have also tried with the nvvidconv plugin, but the result is the same: the issue is still there if I use nvv4l2h264enc.

Hi,
Please make sure the pipeline works in gst-launch-1.0 first and then apply to the C code. Please try like:

$ gst-launch-1.0 v4l2src ! nvvidconv ! nvv4l2h264enc ! fakesink

And also suggest configure caps precisely like:

$ gst-launch-1.0 v4l2src ! video/x-raw,format=YUY2,width=1920,height=1080 ! nvvidconv ! video/x-raw(memory:NVMM),format=NV12' ! nvv4l2h264enc ! fakesink

You can check the steps in

Jetson AGX Orin FAQ
Q: I have a USB camera. How can I launch it on AGX Orin?

To configure precise caps to the v4l2 source.

Hello @DaneLLL,

Thank you for your reply! The pipeline works with gst-launch, even if I don’t specify the caps. The problem - as I described earlier - is that there is a segmentation fault after restarting the pipeline in the same process, and there is no issue when I use x264enc.

Hi,
Please apply the patch to rebuild/replace libnvv4l2.so:

diff --git a/lib/libv4l2/v4l2-plugin.c b/lib/libv4l2/v4l2-plugin.c
index 7807799..e00caed 100644
--- a/lib/libv4l2/v4l2-plugin.c
+++ b/lib/libv4l2/v4l2-plugin.c
@@ -54,8 +54,7 @@ void v4l2_plugin_init(int fd, void **plugin_lib_ret, void **plugin_priv_ret,
 		      const struct libv4l_dev_ops **dev_ops_ret)
 {
 	char *error;
-	int glob_ret;
-        uint32_t i;
+	int glob_ret, i;
 	void *plugin_library = NULL;
 	const struct libv4l_dev_ops *libv4l2_plugin = NULL;
 	glob_t globbuf;

You can download the source code from:

Jetson Linux | NVIDIA Developer
Driver Package (BSP) Sources

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.