vsp-lib: Use gen-image to generate frames at runtime
[renesas/vsp-tests.git] / scripts / vsp-runner.sh
1 #!/bin/sh
2
3 set -e
4
5 source vsp-lib.sh
6
7 genimage='./gen-image'
8 mediactl='media-ctl'
9 yavta='yavta'
10
11 # -----------------------------------------------------------------------------
12 # Input frame generation
13 #
14
15 generate_input_frame() {
16         local file=$1
17         local format=$2
18         local size=$3
19
20         local alpha=
21         local options=
22
23         case $format in
24         ARGB555)
25                 alpha=255
26                 ;;
27         ABGR32 | ARGB32)
28                 alpha=200
29                 ;;
30         XRGB555 | XBGR32 | XRGB32)
31                 alpha=0
32                 ;;
33         *)
34                 alpha=255
35                 ;;
36         esac
37
38         $(format_v4l2_is_yuv $format) && options="$options -y"
39
40         $genimage -f $format -s $size -a $alpha $options -o $file \
41                 frames/frame-reference-1024x768.pnm
42 }
43
44 # ------------------------------------------------------------------------------
45 # Parse the command line and retrieve the formats
46 #
47
48 syntax() {
49         echo "Syntax: vsp-runner.sh dev cmd [...]"
50         echo ""
51         echo "Supported commands:"
52         echo "    hgo [options]"
53         echo "    input index infmt [options]"
54         echo "    output index outfmt [options]"
55 }
56
57 parse() {
58         if [ $# -lt 2 ] ; then
59                 syntax
60                 return 1
61         fi
62
63         mdev=$1
64         dev=`$mediactl -d $mdev -p | grep 'bus info' | sed 's/.*platform://'`
65
66         if [ -z $dev ] ; then
67                 echo "Error: Device $dev doesn't exist"
68                 syntax
69                 return 1
70         fi
71
72         cmd=$2
73
74         case $cmd in
75         hgo)
76                 options=$3
77                 ;;
78
79         input)
80                 index=$3
81                 infmt=$4
82                 options=$5
83                 ;;
84
85         output)
86                 index=$3
87                 outfmt=$4
88                 options=$5
89                 ;;
90
91         *)
92                 echo "Invalid command $cmd"
93                 ;;
94         esac
95 }
96
97 # ------------------------------------------------------------------------------
98 # Execute the command
99 #
100
101 execute() {
102         case $cmd in
103         hgo)
104                 if [ "x$options" = xinfinite ] ; then
105                         $yavta -c -n 4 \
106                                 `$mediactl -d $mdev -e "$dev hgo histo"`
107                 else
108                         $yavta -c10 -n 10 --file=histo-#.bin $options \
109                                 `$mediactl -d $mdev -e "$dev hgo histo"`
110                 fi
111                 ;;
112
113         input)
114                 rpf=rpf.$index
115                 size=$(vsp1_entity_get_size $rpf 0)
116                 file=${rpf}.bin
117
118                 generate_input_frame $file $infmt $size
119
120                 if [ "x$options" = xinfinite ] ; then
121                         $yavta -c -n 4 -f $infmt -s $size --file=$file $options \
122                                 `$mediactl -d $mdev -e "$dev $rpf input"`
123                 else
124                         $yavta -c10 -n 4 -f $infmt -s $size --file=$file $options \
125                                 `$mediactl -d $mdev -e "$dev $rpf input"`
126                 fi
127
128                 rm -f $file
129                 ;;
130
131         output)
132                 wpf=wpf.$index
133                 size=$(vsp1_entity_get_size $wpf 1)
134
135                 if [ "x$options" = xinfinite ] ; then
136                         $yavta -c -n 4 -f $outfmt -s $size \
137                                 `$mediactl -d $mdev -e "$dev $wpf output"`
138                 else
139                         $yavta -c10 -n 4 -f $outfmt -s $size --skip 7 -F $options \
140                                 `$mediactl -d $mdev -e "$dev $wpf output"`
141                 fi
142                 ;;
143         esac
144 }
145
146 parse $* && execute