Deleting unlinked uricodebin from muxer

I have peculiar bug here. If I delete a sourcebin from streammux and add another bin with the same uri, running the pipeline will grab a single frame before crashing. If I remove a decodebin and add another with a different uri then I am fine.

I have removed and unreferenced the source and set it to null, so I do not understand quite whats going on here.

I have referenced that add_delete_runtime program that has been floating around, and this should be a simpler case because I am not doing this at runtime, it is done when the pipeline is set to null.

Can you share one workable test code which can build and run
within nvidia environments for a further recreate and check?

Unfortunately I cannot, I can however provide some code pertaining to adding the source bin and deleting.

Here is how I would add a source bin to a pipeline called muxer (which has the streammux), notice I am not linking the sourcebin by setting the pipeline to play, I only add it.

void add_sources(char uri[],int index)
{
        GstElement *source_bin = create_uridecode_bin (index, uri);
        if(!source_bin)
        {
                g_printerr ("Failed to create source bin. Exiting.\n");
                return;
        }
        gst_bin_add (GST_BIN (muxer), source_bin);
}

GstElement *create_uridecode_bin (guint index, gchar * filename)
{
	    GstElement *bin = NULL;
        gchar bin_name[16] = { };

        g_print ("creating uridecodebin for [%s]\n", filename);
        g_snprintf (bin_name, 15, "source-bin-%02d", index-1);	
        printf ("ADDING source-bin-%02d\n", index-1);
	    bin = gst_element_factory_make ("uridecodebin", bin_name);
        g_object_set (G_OBJECT (bin), "uri", filename, NULL);
	    g_source_id_list[index] = index;
        g_signal_connect (G_OBJECT (bin), "pad-added",   G_CALLBACK (cb_newpad), &g_source_id_list[index]-1);
        g_signal_connect (G_OBJECT (bin), "child-added", G_CALLBACK (decodebin_child_added), &g_source_id_list[index]-1); 

        return bin;
}

Here is how I am deleting it

void stop_release_source (int index)
{
	char source_bin_string[1024];
       memset(source_bin_string,0,sizeof(source_bin_string));
       char str[100];
       memset(str,0,sizeof(str));
       sprintf(str,"%02d",index);
       strncpy(source_bin_string,"source-bin-",1024-1);
       strncat(source_bin_string,str,1024-strlen(source_bin_string)-1);
	   printf("REMOVING %s\n",source_bin_string);
       GstElement *source_bin = gst_bin_get_by_name( GST_BIN(muxer),source_bin_string);
       gst_element_set_state (source_bin, GST_STATE_NULL);
	   gst_element_get_state (source_bin, NULL, NULL, GST_CLOCK_TIME_NONE);
	   gst_bin_remove (GST_BIN (muxer), source_bin);
	   gst_object_unref (source_bin);
}

Once I remove source bins from the pipeline, do the source bin’s “g_signal_connect” attribute go away as well? That could explain why I have this problem.

Hi
Can you confirm if these below are the repro steps?

  • Create a uridecodebin, set uri to <A>, but do not link to streammux
  • Set pipeline to PLAYING
  • Set pipeline to NULL
  • Remove uridecodebin from pipeline and unref it to delete it
  • Create a * NEW * uridecodebin, set uri to <A>, but do not link to streammux
  • set pipeline to playing

Results in a crash.

  • Create a uridecodebin, set uri to <A>, but do not link to streammux
  • Set pipeline to PLAYING
  • Set pipeline to NULL
  • Remove uridecodebin from pipeline and unref it to delete it
  • Create a * NEW * uridecodebin, set uri to <B>, but do not link to streammux
  • set pipeline to playing

This does not result in a crash

These are the steps

  • Create a uridecodebin, set uri to “A”, but do not link to streammux
  • Remove uridecodebin from pipeline and unref it to delete it
  • Create a * NEW * uridecodebin, set uri to “A”, but do not link to streammux
  • set pipeline to playing

Results in a crash.

  • Create a uridecodebin, set uri to “A”, but do not link to streammux
  • Remove uridecodebin from pipeline and unref it to delete it
  • Create a * NEW * uridecodebin, set uri to “B”, but do not link to streammux
  • set pipeline to playing

This does not result in a crash

We tried this but without reproducible code, it is impossible to know what the issue is.
Can you check the backtrace of the crash using gdb, It might provide further debug points.

I made more progress. It was NOT the code above.
It appears that doing what we talked about above triggers this case.

In trying to pull the buffer from appsink, the application hangs. This tells me I have a timing issue of some sort.

Solved.
This was a naming problem. I name my uridecodebins from my PK column in mysql. Refreshing the PK index so it starts from 0 after deleting a camera solves this.