Demux usage

Hi,

I’m trying to modify the pipeline from test4 into something like:

[i]multiple input uri -> nvstreammux -> … -> tee -> queue1 -> nvstreamdemux -> sink_bin[n] {queue -> transform/videoconv -> capfilter -> … -> rtspoutput}

/////////////////////////////////////////////////////////tee (another branch) -> queue2 -> msgconv -> … [/i]

But I failed to link demux to sink_bin. Below is how I did this part, and I wonder what’s wrong.

Thanks in advance.

# include "deepstream_common.h"
# include "deepstream_config.h"
# include <gst/rtsp-server/rtsp-server.h>

//Basically same as create_udpsink_bin in "deepstream_sink_bin.c"
static GstElement * create_sink_bin (guint index)
{
  GstElement *bin = NULL;
  gchar elem_name[50];
  gchar encode_name[50];
  gchar rtppay_name[50];
  
  gchar bin_name[16] = { };
  g_snprintf (bin_name, 15, "sink-bin-%02d", index);
  bin = gst_bin_new (bin_name);
  
  GstElement *queue = NULL, *cap_filter = NULL, *transform = NULL, *encoder = NULL, 
	*rtppay = NULL, *codecparse = NULL, *sink = NULL;
  GstCaps *caps = NULL;
  
  g_snprintf (elem_name, sizeof (elem_name), "sink-bin-%02d-queue", index);
  queue = gst_element_factory_make (NVDS_ELEM_QUEUE, elem_name);
  
  g_snprintf (elem_name, sizeof (elem_name), "sink-bin-%02d-transform", index);
  transform = gst_element_factory_make (NVDS_ELEM_VIDEO_CONV, elem_name);
  
  g_snprintf (elem_name, sizeof (elem_name), "sink-bin-%02d-capfilter", index);
  cap_filter = gst_element_factory_make (NVDS_ELEM_CAPS_FILTER, elem_name);
  caps = gst_caps_from_string("video/x-raw(memory:NVMM), format=I420");
  g_object_set(G_OBJECT(cap_filter), "caps", caps, NULL);

  g_snprintf (encode_name, sizeof (encode_name), "sink-bin-%02d-encoder", index);
  g_snprintf (rtppay_name, sizeof (rtppay_name), "sink-bin-%02d-rtppay", index);

  codecparse = gst_element_factory_make("h264parse", "h264-parser");
  encoder = gst_element_factory_make(NVDS_ELEM_ENC_H264, "rtsp-encoder");
  rtppay = gst_element_factory_make("rtph264pay","rtsp-pay");
  
  g_object_set(G_OBJECT(encoder),"bitrate", rtspbitrate, NULL);
  g_object_set(G_OBJECT(encoder),"iframeinterval", rtspiframeitv, NULL);
  g_object_set(G_OBJECT(encoder),"gpu-id",rtspenc_gpuid, NULL);

  g_object_set(G_OBJECT(transform),"gpu-id",rtsptrans_gpuid, NULL);
  
  g_snprintf (elem_name, sizeof (elem_name), "sink-bin-%02d-udpsink", index);
  sink = gst_element_factory_make ("udpsink", elem_name);
  
  g_object_set(G_OBJECT(sink), "host", rtsphost, "port", rtspport, "async", FALSE, "sync", rtspsync, NULL);
  gst_bin_add_many(GST_BIN(bin),queue,cap_filter,transform,encoder,codecparse,rtppay,sink,NULL);

  NVGSTDS_LINK_ELEMENT (queue, transform);
  NVGSTDS_LINK_ELEMENT (transform, cap_filter);
  NVGSTDS_LINK_ELEMENT (cap_filter, encoder);
  NVGSTDS_LINK_ELEMENT (encoder, rtppay);
  NVGSTDS_LINK_ELEMENT (rtppay, sink);
  
  NVGSTDS_BIN_ADD_GHOST_PAD (bin, queue, "sink");
  start_rtsp_streaming(rtspport, udpport, NV_DS_ENCODER_H264);
  
  return bin;
}

GstElement *demux = gst_element_factory_make(NVDS_ELEM_STREAM_DEMUX, "demuxer");
//Only create and output src_01
GstElement *sink_bin = create_sink_bin(1);

//Function in "deepstream_common.h", which returns error msg "Failed to link 'demuxer' and 'sink-bin-01'"
link_element_to_demux_src_pad(demux,sink_bin,1);

It turns out I didn’t add sink_bin into main pipeline

But the rtsp output shows live555 demux error while I’m able to receive metadata with different sourceId from msgbroker.

I’m using a T4 with DS 4.0. Tested with deepstream-app (config: multiple sources, tiler and one rtsp sink) works fine.

I also tried with test3 which doesn’t work either as below, so I feel like create rtsp stream this way is wrong.

// In deepstream-test3

gst_bin_add_many (GST_BIN (pipeline), pgie, tiler, nvvidconv, nvosd,
      NULL);
  /* we link the elements together
   * nvstreammux -> nvinfer -> nvtiler -> nvvidconv -> nvosd -> video-renderer */
  if (!gst_element_link_many (streammux, pgie, tiler, nvvidconv, nvosd,
          NULL)) {
    g_printerr ("Elements could not be linked. Exiting.\n");
    return -1;
  }

  // Same function as before
  GstElement *sink_bin = create_sink_bin(0);
  gst_bin_add (GST_BIN (pipeline), sink_bin);
  
  if (!gst_element_link(nvosd,sink_bin)){
    g_printerr ("Nvosd and sink_bin link fail.\n");
    return -1;
  }

could you use gst-launch-1.0 tools to setup your pipeline and see if there is any error?

Can you refer to this, tiler can be replaced by streamDemux

multiple file-source -> h264-parser -> nvh264-decoder -> nvstreammux ->
  nvinfer -> tee -> |-> tiler -> nvvidconv -> nvosd -> video-renderer
                    |-> msgconv -> msgbroker