Segfault in nv3dsink when setting window handle using gst_video_overlay_set_window_handle()

When the gst_video_overlay_set_window_handle() function is used to set the window handle with nv3dsink it segfaults. I have patched the source code for a previous version of libgstnvvideosinks_src.tbz2 (32.4.3) to fix this bug but the current version (32.5) does not function properly when built from sources. The segfault is caused by some variables not getting initialized properly.

Hi merwin,

May I know which patch you’re referring to? From which topic?

It’s my own patch.

We would need to reproduce it and do further check. Is it possible to share the patch so that we can replicate it on r32.5/Jetson Nano?

--- a/gst-plugins-nv-video-sinks/nv3dsink/gstnv3dsink.c
+++ b/gst-plugins-nv-video-sinks/nv3dsink/gstnv3dsink.c
@@ -546,4 +546,7 @@ gst_nv3dsink_init (GstNv3dSink * nv3dsink)
   /* mutex to serialize create, set and get window handle calls */
   g_mutex_init (&nv3dsink->win_handle_lock);
+  /* init vars */
+  gst_nv3dsink_start (nv3dsink);

For more information, could we run the command to reproduce the issue?

$ gst-launch-1.0 videotestsrc ! nvvidconv ! 'video/x-raw(memory:NVMM),format=NV12' ! nv3dsink

gst-launch-1.0 can’t be used to reproduce the issue. The issue occurs when video sink’s window handle (typically obtained with XCreateWindow() ) is set with the gst_video_overlay_set_window_handle() function to override the window created internally by the video sink. It can only be done programmatically.

Please make a patch to this sample so that we can replicate the segment fault:

#include <cstdlib>
#include <cstring>
#include <sstream>
#include <gst/gst.h>

using namespace std;

#define USE(x) ((void)(x))

static GstPipeline *gst_pipeline = nullptr;
static string launch_string;

GstClockTime usec = 1000000;

int main(int argc, char** argv) {

    gst_init (&argc, &argv);

    GMainLoop *main_loop;
    main_loop = g_main_loop_new (NULL, FALSE);
    ostringstream launch_stream;

    << "videotestsrc is-live=1 name=mysource ! "
    << "nvvidconv ! video/x-raw(memory:NVMM),format=NV12 ! "
    << "nv3dsink ";

    launch_string = launch_stream.str();

    g_print("Using launch string: %s\n", launch_string.c_str());

    GError *error = nullptr;
    gst_pipeline  = (GstPipeline*) gst_parse_launch(launch_string.c_str(), &error);

    if (gst_pipeline == nullptr) {
        g_print( "Failed to parse launch: %s\n", error->message);
        return -1;
    if(error) g_error_free(error);

    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING); 
    GstElement* src = gst_bin_get_by_name(GST_BIN(gst_pipeline), "mysource");
    gst_element_send_event (src, gst_event_new_eos ());
    // Wait for EOS message
    GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(gst_pipeline));
    gst_bus_poll(bus, GST_MESSAGE_EOS, GST_CLOCK_TIME_NONE);
    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);


    g_print("going to exit \n");
    return 0;