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:
- run rtspsrc location=rtsp://admin:admin@...:554/rtsp_video_stream latency=2000
- when the pad of rtspsrc arrives, build rtpjitterbuffer ! rtpmp2tdepay ! tsparse ! tsdemux and add them to bin1
- 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