NVIDIA Jetson AGX Thor - GstInterpipe GStreamer plugin for communicating between the pipelines

From RidgeRun Developer Wiki

Follow Us On Twitter LinkedIn Email Share this page



Previous: RidgeRun Open Source Projects/GStreamer Daemon Index Next: RidgeRun Open Source Projects/GstShark









Overview

GstInterpipe is a RidgeRun open-source GStreamer plug-in that allows communication between two or more independent pipelines. It consists of two elements: interpipesink and interpipesrc. The interpipesrc gets connected with an interpipesink, from which it receives buffers and events.

GstInterpipe is intended to reduce a big, complex pipeline system into smaller and simpler independent pipelines. So, you can view and handle those independent pipelines as different blocks that you can control independently (change their state or modify properties) and connect or disconnect them with other blocks in runtime. It allows us to have multiple source and sink pipelines in an application with the possibility of dynamically changing the source pipeline that a sink pipeline is listening to. It's like if you have a set of different pipes that you can plug and unplug between them in runtime, so the system changes its behavior according to the pipe interconnection configuration.

Promo/Demo Video


Simplifying complex pipelines

The concept behind the GstInterpipes project is to simplify the construction of GStreamer applications, which often have the complexity of requiring dynamic pipelines. It transforms the construction process from low-level pad probe manipulation to the higher level of setting an element's parameter value. Application developers don't get mired down in stalled pipelines due to one branch of a complex pipeline changing state.

For example, take a look at a complex pipeline:

Alt
Figure 2. Simple example with label and camera source

The complex pipeline of Figure 2 can be constructed into smaller, independent pipelines using interpipe elements as illustrated in Figure 3:

Alt
Figure 3: Ten independent simple pipelines using Interpipes

This way the stream flow in a complex pipeline is reduced to simply setting the correct listeners in the interpipe elements, taking away the complexity of reconfiguring pads or some other complex and error-prone logic.

Examples

GstInterpipe shines when combined with GSTD. With GSTD is possible to change which pipeline are connected during execution.

CCTV Example

More advanced examples include GstInterpipes. For this CCTV interpipes is in charge of interconnecitng the pipelines. More details in the structure of the example can be found in the wiki.

#!/bin/bash
 
echo -e "\n ====== Digital Camera Example (Switch the scr_pipe to listen in runtime) ====== \n"
 
END_MSJ="!!! Digital Camera Example Finished !!!"
REC_INDEX=0
 
# Graceful cleanup upon CTRL-C
trap "gstd-client pipeline_delete cam_src_pipe; gstd-client pipeline_delete live_preview_pipe; "\
"gstd-client pipeline_delete recording_pipe; gstd-client pipeline_delete snapshot_pipe; echo -e $END_MSJ; exit" SIGINT
 
# Create pipelines
echo -e "\n ====> Create the cam_src_pipe \n"
gstd-client pipeline_create cam_src_pipe videotestsrc pattern=ball is-live=true \
! "video/x-raw, framerate=15/1, width=640, height=480" ! queue max-size-buffers=3 leaky=downstream \
! interpipesink name=cam_src caps=video/x-raw,width=640,height=480,framerate=15/1 sync=true async=false
 
echo -e "\n ====> Create the live_preview_pipe \n"
gstd-client pipeline_create live_preview_pipe interpipesrc name=live_prev_intpsrc listen-to=cam_src \
is-live=true allow-renegotiation=true stream-sync=compensate-ts ! queue max-size-buffers=3 leaky=downstream \
! nvvidconv ! nv3dsink async=false sync=false
 
echo -e "\n ====> Create the recording_pipe \n"
gstd-client pipeline_create recording_pipe interpipesrc name=rec_intpsrc listen-to=cam_src is-live=false \
allow-renegotiation=true stream-sync=passthrough-ts format=time ! queue max-size-buffers=3 leaky=downstream ! nvvidconv ! queue ! \
nvv4l2h264enc ! h264parse ! mpegtsmux ! filesink name=rec_file_sink location=/tmp/recording_$REC_INDEX.ts async=false sync=false

echo -e "\n ====> Create the snapshot_pipe \n"
gstd-client pipeline_create snapshot_pipe interpipesrc name=snap_intpsrc listen-to=cam_src num-buffers=1 \
is-live=true allow-renegotiation=true stream-sync=passthrough-ts ! queue max-size-buffers=3 leaky=downstream \
! nvvidconv ! nvjpegenc ! multifilesink location=/tmp/snapshot_%d.jpg async=false sync=false


# Change pipelines to PLAYING STATE
echo -e "\n ====> Start cam_src_pipe and live_preview_pipe \n"
gstd-client pipeline_play cam_src_pipe
gstd-client pipeline_play live_preview_pipe
 
# Enable recording procedure
function enable_rec {
	gstd-client element_set recording_pipe rec_file_sink location /tmp/recording_$REC_INDEX.ts
	gstd-client bus_filter recording_pipe eos
	gstd-client pipeline_play recording_pipe
}
 
# Disable recording procedure
function disable_rec {
        gstd-client bus_timeout recording_pipe 1000000000
	gstd-client event_eos recording_pipe
	# wait eos
	gstd-client bus_read recording_pipe
	gstd-client pipeline_stop recording_pipe
	REC_INDEX=$(($REC_INDEX+1))
}
 
# Take snapshot procedure
function take_snap {
	gstd-client bus_filter snapshot_pipe eos
	gstd-client bus_timeout snapshot_pipe 1000000000
	gstd-client pipeline_play snapshot_pipe
	# wait eos
	gstd-client bus_read snapshot_pipe
	gstd-client pipeline_stop snapshot_pipe
}
 
 
echo -e "\n====> Press S to take a snapshot or R to start recording video for 15 seconds \n"
echo -e "====> Type Ctrl+C to stop the example execution, otherwise, it will iterate infinitely!\n"
 
 
# Start requesting actions to the user
while :
do
	read -rsn1 input
 
	if [ "$input" = "s" ];
	then
		echo -e "\n====> Take snapshot! \n"
		take_snap
		echo -e "\n====> Snapshot Taken! \n"
		echo -e "\n====> Press S to take a snapshot or R to start recording video for 15 seconds \n"
		echo -e "====> Type Ctrl+C to stop the example execution, otherwise, it will iterate infinitely!\n"
	fi
 
	if [ "$input" = "r" ];
	then
		enable_rec
		echo -e "\n====> Start to record video! \n"
		sleep 15
		disable_rec
		echo -e "\n====> Finish to record video! \n"
		echo -e "\n====> Press S to take a snapshot or R to start recording video for 15 seconds \n"
		echo -e "====> Type Ctrl+C to stop the example execution, otherwise, it will iterate infinitely!\n"
	fi
 
done

Getting Started

To know more about the extension, please refer to the GstInterpipe Overview wiki page.

How to Purchase



For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.


Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.




Previous: RidgeRun Open Source Projects/GStreamer Daemon Index Next: RidgeRun Open Source Projects/GstShark