--- /dev/null
+#!/usr/bin/env bash
+
+if [[ "$SSATAPILOADED" != "1" ]]
+then
+ SILENT=0
+ INDEPENDENT=1
+ search="ssat-api.sh"
+ source $search
+
+ retcode=$?
+ count=0
+ while (( ${retcode} != 0 ))
+ do
+ count=$((count+1))
+ if (( ${count} > 5 ))
+ then
+ echo "Cannot find ssat-api.sh"
+ exit 1
+ fi
+
+ search="../${search}"
+ source $search
+ retcode=$?
+ done
+ printf "${Blue}Independent Mode${NC}\n"
+fi
+
+testInit $1
+
+command -v gst-launch-1.0 || report
+command -v gst-inspect-1.0 || report
+
+filename=$(mktemp)
+gstTestBackground "videotestsrc num-buffers=5 is-live=true ! video/x-raw,width=64,height=48,framerate=1/1 ! filesink location=${filename}" GBKG1 0 0 5
+testResult 1 GBKG1-AFT "After launching the background" 0
+wait $pid
+testResult 1 GBKG1-CMP "After the background is completed" 0
+
+gst-inspect-1.0 udpsrc &> /dev/null
+val=$?
+if [ "${val}" == "0" ]; then
+ gstTestBackground "udpsrc ! video/x-raw,width=64,height=48,framerate=1/1 ! fakesink async=false" GBKG2 0 0 5
+ testResult 1 GBKG2-AFT "After launching the background" 0
+ kill $pid
+ testResult 1 GBKG2-CMP "After the background is killed" 0
+
+ gstTestBackground "udpsrc ! video/x-raw,width=64,height=48,framerate=1/1 ! fakesink" GBKG3 0 1 5
+ testResult 1 GBKG3-AFT "After launching the background" 0
+ kill $pid
+ testResult 1 GBKG3-CMP "After the background is killed" 0
+else
+ testResult 0 GBKG2 "udpsrc-based gst background test failed: udpsrc not found: gst-inspect returns ${val}." 1
+fi
+
+
+report
fi
}
+
+## @fn gstTestBackground()
+## @brief Execute gst-launch in background with given arguments.
+## @param $1 gst-launch-1.0 Arguments, with pipeline description at the end. The pipeline should have async=false for sink elements (skip preroll!).
+## @param $2 test case ID
+## @param $3 set 1 if this is not critical (don't care if it's pass or fail)
+## @param $4 set 1 if this passes if launching the pipeline fails. (pass if timeout expires)
+## @param $5 set timeout for launching the pipeline in seconds (not the pipeline EOS). default = 10.
+## @return $pid The PID of the background gstreamer pipeline.
+function gstTestBackground() {
+ local marker=$(mktemp)
+ local timeout=10
+ local launchSuccess
+ local launchFail
+ local pipeline
+
+ if [ "$4" == "1" ]; then
+ launchSuccess=0
+ launchFail=1
+ else
+ launchSuccess=1
+ launchFail=0
+ fi
+ if [ "$5" == "" ]; then
+ # no changes in timeout. do nothing
+ sleep 0
+ else
+ if [ $5 -gt 0 ]; then
+ timeout=$5
+ else
+ # ignore if it's < 1. do nothing
+ sleep 0
+ fi
+ fi
+
+ pipeline="$1 videotestsrc num-buffers=1 ! video/x-raw,width=4,height=4,format=RGB ! filesink location=${marker}"
+ gst-launch-1.0 $pipeline &
+ pid=$!
+
+ for i in $(seq 1 ${timeout})
+ do
+ if [ -f "$marker" ]; then
+ markersize=$(stat -c%s ${marker})
+ if [ $markersize -ge 48 ]; then
+ testResult ${launchSuccess} $2 "gst-launch in background of case $2" $3
+ rm ${marker}
+ return $pid
+ fi
+ fi
+ sleep 1
+ done
+ rm ${marker}
+ testResult ${launchFail} $2 "gst-launch in background of case $2" $3
+ return ${pid}
+}
+
## @fn convertBMP2PNG()
## @brief Convert all *.bmp to *.png in the current directory
## @todo macronice "bmp2png" searching.