vsp-lib: Add support for pausing and resuming yavta
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Sun, 19 Jun 2016 21:44:41 +0000 (00:44 +0300)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 20 Jun 2016 09:24:22 +0000 (12:24 +0300)
When the --pause argument to vsp_runner() is specified, the
corresponding yavta instance will pause after capturing or outputting
the given number of frames and wait for a signal before resuming. The
new vsp_runner_wait() and vsp_runner_resume() functions can be used to
respectively wait for yavta to pause and instruct it to resume.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
scripts/vsp-lib.sh

index bf80aa0..a2af586 100755 (executable)
@@ -249,6 +249,7 @@ compare_frames() {
                mv ref-frame.bin ${0/.sh/}-ref-frame-$params.bin
        else
                rm -f ref-frame.bin
+               rm -f frame-*.bin
        fi
 
        echo $result
@@ -291,6 +292,7 @@ compare_histograms() {
                mv ref-histogram.bin ${0/.sh/}-ref-histogram-$fmt.bin
        else
                rm -f ref-histogram.bin
+               rm -f histo-*.bin
        fi
 
        echo $result
@@ -649,6 +651,7 @@ vsp_runner() {
        local option
        local buffers=4
        local count=10
+       local pause=
        local skip=7
 
        for option in $* ; do
@@ -661,6 +664,10 @@ vsp_runner() {
                        count=${option/--count=/}
                        ;;
 
+               --pause=*)
+                       pause=${option/--pause=/}
+                       ;;
+
                --skip=*)
                        skip=${option/--skip=/}
                        ;;
@@ -700,8 +707,60 @@ vsp_runner() {
        esac
 
        $yavta -c$count -n $buffers ${format:+-f $format} ${size:+-s $size} \
-               ${skip:+--skip $skip} ${file:+--file=$file} $videodev \
-               | ./logger.sh $entity >> $logfile
+               ${skip:+--skip $skip} ${file:+--file=$file} ${pause:+-p$pause} \
+               $videodev | ./logger.sh $entity >> $logfile
+}
+
+vsp_runner_find() {
+       local entity=$1
+       local videodev
+
+       case $entity in
+       hgo)
+               videodev=$(vsp1_entity_subdev "hgo histo")
+               ;;
+
+       rpf.*)
+               videodev=$(vsp1_entity_subdev "$entity input")
+               ;;
+
+       wpf.*)
+               videodev=$(vsp1_entity_subdev "$entity output")
+               ;;
+       esac
+
+       local pid
+
+       for pid in $(pidof yavta) ; do
+               (ls -l /proc/$pid/fd/ | grep -q "$videodev$") && {
+                       echo $pid ;
+                       break
+               }
+       done
+}
+
+vsp_runner_wait() {
+       local timeout=5
+       local pid
+
+       while [ $timeout != 0 ] ; do
+               pid=$(vsp_runner_find $1)
+               [ x$pid != x ] && break
+               sleep 1
+               timeout=$((timeout-1))
+       done
+
+       [ x$pid != x ] || return
+
+       while [ ! -f .yavta.wait.$pid ] ; do
+               sleep 1
+       done
+}
+
+vsp_runner_resume() {
+       local pid=$(vsp_runner_find $1)
+
+       [ x$pid != x ] && kill -USR1 $pid
 }
 
 # ------------------------------------------------------------------------------