Gstd interpipes Demo

From RidgeRun Developer Connection
Jump to: navigation, search

The content of the gstd_interpipe.sh script is the following:

#!/bin/bash

echo -e "\n ====== Orion T-7 Cameras Example (Switch the src_pipe to listen in runtime) ====== \n"

#---------------------------------------------------------------------------------------------#
# Checking for the user input arguments
#---------------------------------------------------------------------------------------------#

if [ "$#" -ne 0 ] && [ "$#" -ne 1 ]; then
    echo "ERROR: Illegal number of parameters or parameters order"
    echo "Type ./$filename --help or ./$filename -h for usage information"
    exit

elif [ "$#" -eq 1 ] && ( [[ $1 == "--help" ]] || [[ $1 == "-h" ]] ); then
    # Script name
    filename=`basename "$0"`
    # Help message
    echo -e "\nOrion T-7: Gstd-Interpipes Demo"
    echo
    echo "Usage:"
    echo "  ./$filename"
    echo 
    echo "Arguments:"
    echo "  --help (-h)    This help message"
    echo
    echo "Usage example:"
    echo
    echo " => When the script is executed, only one-sensor video is displayed:" 
    echo "        ./$filename"
    echo " => You are able to set the number of camera streaming to be displayed by typing a number between 1 and 6." 
    echo " => Hit ESC if you want to finish the script execution." 
    echo
    exit
else
    echo "Waking up the gstd-daemon"
    gstd

    END_MSJ="!!! Orion T-7 Camera Example Finished !!!"

    # Make sure there is no pipeline with this name already
    gstd-client pipeline_delete cam_src_pipe_1
    gstd-client pipeline_delete cam_src_pipe_2
    gstd-client pipeline_delete cam_src_pipe_3
    gstd-client pipeline_delete cam_src_pipe_4
    gstd-client pipeline_delete cam_src_pipe_5
    gstd-client pipeline_delete cam_src_pipe_6
    gstd-client pipeline_delete display_pipe

    # Graceful cleanup upon CTRL-C
    trap "gstd-client pipeline_delete cam_src_pipe_1; gstd-client pipeline_delete cam_src_pipe_2; "\
    "gstd-client pipeline_delete cam_src_pipe_3; gstd-client pipeline_delete cam_src_pipe_4; "\
    " gstd-client pipeline_delete cam_src_pipe_5; gstd-client pipeline_delete cam_src_pipe_6; "\
    "echo -e $END_MSJ; killall gstd; exit;" SIGINT

    #---------------------------------------------------------------------------------------------#
    # Create pipelines
    #---------------------------------------------------------------------------------------------#

    # 1-Sensor
    echo -e "\n ====> Create the 1-sensor cam_src_pipe_1 \n"
    gstd-client pipeline_create cam_src_pipe_1 v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! interpipesink name=sink1 sync=false async=false

    # 2-Sensor
    echo -e "\n ====> Create the 2-sensor cam_src_pipe_2 \n"
    gstd-client pipeline_create cam_src_pipe_2 videomixer name=mix \
    sink_0::xpos=0 \
    sink_1::ypos=720 \
    ! interpipesink name=sink2 sync=false async=false \
    v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_0 \
    v4l2src device=/dev/video1 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_1

    # 3-Sensor
    echo -e "\n ====> Create the 3-sensor cam_src_pipe_3 \n"
    gstd-client pipeline_create cam_src_pipe_3 videomixer name=mix \
    sink_0::xpos=0 \
    sink_1::xpos=1280 \
    sink_2::xpos=640 sink_2::ypos=720 \
    ! interpipesink name=sink3 \
    v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_0 \
    v4l2src device=/dev/video1 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_1 \
    v4l2src device=/dev/video2 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_2

    # 4-Sensor
    echo -e "\n ====> Create the 4-sensor cam_src_pipe_4 \n"
    gstd-client pipeline_create cam_src_pipe_4 videomixer name=mix \
    sink_0::xpos=0 \
    sink_1::xpos=1280 \
    sink_2::ypos=720 \
    sink_3::xpos=1280 sink_3::ypos=720 \
    ! interpipesink name=sink4 \
    v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_0 \
    v4l2src device=/dev/video1 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_1 \
    v4l2src device=/dev/video2 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_2 \
    v4l2src device=/dev/video3 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_3


    # 5-Sensor
    echo -e "\n ====> Create the 5-sensor cam_src_pipe_5 \n"
    gstd-client pipeline_create cam_src_pipe_5 videomixer name=mix \
    sink_0::xpos=0 \
    sink_1::xpos=1280 sink_2::ypos=720 \
    sink_3::xpos=1280 sink_3::ypos=720 \
    sink_4::xpos=640 sink_4::ypos=1440 \
    ! interpipesink name=sink5 \
    v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_0 \
    v4l2src device=/dev/video1 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_1 \
    v4l2src device=/dev/video2 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_2 \
    v4l2src device=/dev/video3 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_3 \
    v4l2src device=/dev/video4 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_4


    # 6-Sensor
    echo -e "\n ====> Create the 6-sensor cam_src_pipe_6 \n"
    gstd-client pipeline_create cam_src_pipe_6 videomixer name=mix \
    sink_0::xpos=0 \
    sink_1::xpos=1280 sink_2::ypos=720 \
    sink_3::xpos=1280 sink_3::ypos=720 \
    sink_4::xpos=0 sink_4::ypos=1440 \
    sink_5::xpos=1280 sink_5::ypos=1440 \
    ! interpipesink name=sink6 \
    v4l2src device=/dev/video0 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_0 \
    v4l2src device=/dev/video1 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_1 \
    v4l2src device=/dev/video2 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_2 \
    v4l2src device=/dev/video3 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_3 \
    v4l2src device=/dev/video4 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_4 \
    v4l2src device=/dev/video5 \
    ! 'video/x-raw,format=(string)UYVY,width=(int)1280,height=(int)720,framerate=(fraction)30/1' \
    ! mix.sink_5


    #Display Pipeline
    echo -e "\n ====> Create the main display_pipe \n"
    gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink1 \
    max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
    ! xvimagesink sync=false async=false

    echo -e "\n Playing the initial pipelines \n"
    gstd-client pipeline_play cam_src_pipe_1
    gstd-client pipeline_play display_pipe

    bool=true

    echo -e "\n Starting Loop \n"

    while [ "$bool" = true ];
    do read -s -n 1 key  # read from the keyboard
        case $key in
            '1') 
                echo "1-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_5
                gstd-client pipeline_stop cam_src_pipe_6

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink1 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_1
                gstd-client pipeline_play display_pipe
                ;;
            '2')
                echo "2-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_5
                gstd-client pipeline_stop cam_src_pipe_6
                echo "Pipelines stopped"

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink2 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_2
                gstd-client pipeline_play display_pipe
                ;;
            '3')
                echo "3-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_5
                gstd-client pipeline_stop cam_src_pipe_6

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink3 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_3
                gstd-client pipeline_play display_pipe
                ;;
            '4')
                echo "4-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_5
                gstd-client pipeline_stop cam_src_pipe_6

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink4 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_4
                gstd-client pipeline_play display_pipe
                ;;
            '5')
                echo "5-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_6

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink5 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_5
                gstd-client pipeline_play display_pipe
                ;;
            '6')
                echo "6-sensor selected"
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_5

                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete display_pipe

                #Display Pipeline
                echo -e "\n ====> Create the main display_pipe \n"
                gstd-client pipeline_create display_pipe interpipesrc name=disp_intpsrc listen-to=sink6 \
                max-bytes=1 is-live=true enable-sync=true allow-renegotiation=true block=true \
                ! xvimagesink enable-last-sample=false sync=false async=false

                gstd-client pipeline_play cam_src_pipe_6
                gstd-client pipeline_play display_pipe
                ;;
            $'\e') 
                echo "Escape"
                # Use "ESC" key to exit to the application
                gstd-client pipeline_stop cam_src_pipe_1
                gstd-client pipeline_stop cam_src_pipe_2
                gstd-client pipeline_stop cam_src_pipe_3
                gstd-client pipeline_stop cam_src_pipe_4
                gstd-client pipeline_stop cam_src_pipe_5
                gstd-client pipeline_stop cam_src_pipe_6
                gstd-client pipeline_stop display_pipe
                gstd-client pipeline_delete cam_src_pipe_1
                gstd-client pipeline_delete cam_src_pipe_2
                gstd-client pipeline_delete cam_src_pipe_3
                gstd-client pipeline_delete cam_src_pipe_4
                gstd-client pipeline_delete cam_src_pipe_5
                gstd-client pipeline_delete cam_src_pipe_6
                gstd-client pipeline_delete display_pipe
                killall gstd
                break
                ;;
        esac
    done
fi