GstInterpipe - Example 1: CCTV

From RidgeRun Developer Connection
Jump to: navigation, search



Previous: Examples Index Next: Example 2: Digital Camera




This page contains an example to demonstrate the usage of the interpipesink and interpipesrc elements.

This example demonstrates the usage of the dynamic switching property of the GstInterpipe. The objective of this sample is to show the simplicity that GstInterpipe offers in a real case of use where you have different source pipelines and one sink pipeline, and you want to alternate the source that is connected with the sink pipeline. For example a Closed Circuit Television (CCTV) system.

In this sample there are 3 source pipelines labeled as: scr_pipe_1, scr_pipe_2, scr_pipe_3. Each source pipeline is a videotestsrc with a different pattern (simulating different real cameras connected to a system). On the other side, there is 1 sink pipeline, which is labeled as sink_pipe_4. This sink pipeline consists of a videosink that displays on-screen the video buffers it receives.

In the sample, the source pipeline periodically (each 3 s) change the source pipeline it is listening to, so you will see a different video pattern on the rendering screen.

As you can view from the sample code, to change the source pipeline that the sink pipeline is listening to, is as easy as changing the value of the interpipesrc element "listen-to" property with the name of the desired interpipesink to listen.

The below diagram illustrates the concept.


CCTV Example (Dynamic Switching) diagram


Sample bash script code:

#!/bin/bash

echo -e "\n ====== CCTV Example (Switch the scr_pipe to listen in runtime) ====== \n"

STOP=0

# Graceful cleanup upon CTRL-C
trap "STOP=1" SIGINT

# Create pipelines
echo -e "\n ====> Create the scr_pipe_1 \n"
gstd-client pipeline_create pipe_1_src videotestsrc pattern=ball is-live=true \
! "video/x-raw, framerate=15/1, width=640, height=480" ! queue ! interpipesink name=src_1 \
caps=video/x-raw,width=640,height=480,framerate=15/1 sync=false async=false

echo -e "\n ====> Create the scr_pipe_2 \n"
gstd-client pipeline_create pipe_2_src videotestsrc pattern=snow is-live=true \
! "video/x-raw, framerate=15/1, width=640, height=480" ! queue ! interpipesink name=src_2 \
caps=video/x-raw,width=640,height=480,framerate=15/1 sync=false async=false

echo -e "\n ====> Create the scr_pipe_3 \n"
gstd-client pipeline_create pipe_3_src videotestsrc pattern=smpte is-live=true \
! "video/x-raw, framerate=15/1, width=640, height=480" ! queue ! interpipesink name=src_3 \
caps=video/x-raw,width=640,height=480,framerate=15/1 sync=false async=false

echo -e "\n ====> Create the sink_pipe_4 (listener) \n"
gstd-client pipeline_create pipe_4_sink interpipesrc name=interpipesrc1 listen-to=src_1 \
is-live=true allow-renegotiation=true stream-sync=compensate-ts ! queue ! fpsdisplaysink async=false sync=false

# Change pipelines to PLAYING STATE
echo -e "\n ====> Change to PLAYING STATE \n"
gstd-client pipeline_play pipe_1_src
gstd-client pipeline_play pipe_2_src
gstd-client pipeline_play pipe_3_src
gstd-client pipeline_play pipe_4_sink

echo -e "\n ====> Every 3 seconds the sink_pipe will change the src_pipe that is listening to \n"
echo -e "\n ====> Start listening to scr_pipe_1 \n"
sleep 3

# Start alternating the source pipeline being listened
while :
do
	gstd-client element_set pipe_4_sink interpipesrc1 listen-to src_2
	echo -e "\n ====> Change to listening to scr_pipe_2 \n"
	sleep 3
	if [ $STOP -ne 0 ]
	then
		break
	fi

	gstd-client element_set pipe_4_sink interpipesrc1 listen-to src_3
	echo -e "\n ====> Change to listening to scr_pipe_3 \n"
	sleep 3
	if [ $STOP -ne 0 ]
	then
		break
	fi

	gstd-client element_set pipe_4_sink interpipesrc1 listen-to src_1
	echo -e "\n ====> Change to listening to scr_pipe_1 \n"
	echo -e "\n ====> Type Ctrl+C to stop the example execution, otherwise it will iterate infinitely!\n"
	sleep 3
	if [ $STOP -ne 0 ]
	then
		break
	fi
	
done

# Delete Pipelines
gstd-client pipeline_delete pipe_1_src
gstd-client pipeline_delete pipe_2_src
gstd-client pipeline_delete pipe_3_src
gstd-client pipeline_delete pipe_4_sink

echo -e "\n ====> CCTV Example Finished!!! \n"


To run the sample follow these steps:

  1. Build and install GStreamer Daemon (gstd): Building GStreamer Daemon.
  2. Copy the script code in a file
  3. Change the file permissions to be executable:
    1. chmod 777 <file.sh>
  4. Run the GStreamer Daemon:
    1. gstd &
  5. Run the script:
    1. ./<file.sh>
  6. Kill the GStreamer Daemon:
    1. killall gstd

Tested versions:

  1. GStreamer version: v1.8.3
  2. GStreamer Daemon: v0.11.3
  3. GstInterpipe: v1.1.3


Previous: Examples Index Next: Example 2: Digital Camera