Link of second pad gets -1 (GST_PAD_LINK_WRONG_HIERARCHY) in rtsp pipeline with mp2T format

The following pipeline works fine from command line on Ubuntu
gst-launch-1.0 -v rtspsrc location=rtsp://admin:admin@172.16.4.47:554/rtsp_video_stream latency=2000 ! rtpjitterbuffer ! rtpmp2tdepay ! tsparse ! tsdemux ! h264parse ! avdec_h264 ! videoconvert ! xvimagesink

And this pipeline is coded in three steps:

  1. run rtspsrc location=rtsp://admin:admin@...:554/rtsp_video_stream latency=2000
  2. when the pad of rtspsrc arrives, build rtpjitterbuffer ! rtpmp2tdepay ! tsparse ! tsdemux and add them to bin1
  3. when the pad of tsdemux arrives, build h264parse ! avdec_h264 ! videoconvert ! qmlsink and add them to bin2

Both bin1 and bin2 are added to the pipeline. No issues with linking.

    GstPad * parse_pad = gst_element_get_static_pad( parse, "sink" );
    if ( nullptr != parse_pad ) {
        GstPad * ghost_sinkpad = gst_ghost_pad_new( "sink", parse_pad );
        gst_element_add_pad( bin2, ghost_sinkpad );
        if (!gst_pad_set_active(ghost_sinkpad, TRUE)) {
            g_warning("=========Failed to activate parse ghost pad!");
        }
        gst_object_unref( parse_pad );
    }

When pad of tsdemux arrives, the following code is applied.

    sink_pad = gst_element_get_static_pad( bin2, "sink" );
    gst_element_sync_state_with_parent( bin2 );
       
    if ( nullptr != sink_pad ) {
        bool pad_link_ok{ false };

        GstPadLinkReturn link_ret = gst_pad_link( pad, sink_pad );
        if ( GST_PAD_LINK_OK == link_ret ) {
            pad_link_ok = true;
            g_warning( "successful pad link for " );
        }
        else {
            g_warning( "failed pad link return " );
        }

        gst_object_unref( sink_pad );
    }
    
    link_ret is -1 <==GST_PAD_LINK_WRONG_HIERARCHY

What is wrong?
GstObject* pad_parent = gst_object_get_parent(GST_OBJECT(pad));
GstObject* bin_parent = gst_object_get_parent(GST_OBJECT(bin2));

pad_parent is tsdemux
bin parent is m_pipeline

Perhaps you could attach a pipeline graph snapshot from when it fails?

Wrong hierarchy usually means that you’re trying to link (pads of) elements that don’t have the same parent.

Often it means that you need ghostpads on bins. Sometimes it means you are linking the wrong things somehow :slight_smile:

PS: you don’t need the rtpjitterbuffer after rtspsrc here, as rtspsrc contains one already, The tsparse is also not required, tsdemux alone should be enough.

PPS: you could simply use uridecodebin3 uri=rtsp://... and pick up the video pad with the decoded video from there, if this is all you’re doing in your pipeline (depayload + decode).

1 Like

Good to know. Thanks a lot for your reply. Can not make a graph now because the connection to the repeater camera is not working properly now. Will do it next week.

rtpjitterbuffer and tsparse are dropped. Thank you.

The graph is here. No issues to link rtspsrc with rtpmp2tdepay. But the pad link between
tsdemux and h264parse failed with link_ret is -1 <==GST_PAD_LINK_WRONG_HIERARCHY

Adding bin2 to bin1 solved the problem.