• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3#
4# Copyright (c) 2019 by Mauro Carvalho Chehab <mchehab@kernel+samsung.org>
5#
6# Licensed under the terms of the GNU GPL License version 2
7#
8
9#
10# Script to test M2M transform drivers like vim2m and GStreamer v4l2 plugin
11#
12# NOTE:
13#
14# 1. This script assumes that vim2m driver is loaded
15# 2. GStreamer (up to version 1.14.4) silently ignores M2M convert devices
16#    that supports Bayer. That includes newer versions of vim2m driver.
17#    To use GStreamer with older versions, this patch requires backporting:
18#	https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/commit/dc7bd483260d6a5299f78a312740a74c7b3d7994
19# 3. GStreamer also usually just passes data through if capture format is
20#	identical to output format. Since version 1.14, this can be disabled.
21#	This script disables it, on such versions.
22# 4. Right now, GStreamer's v4l2 convert plugin is not capable of negotiating
23#	Bayer formats. So, by default, it tests only YUY2 format. If you want
24#	to test bayer as well, there's an experimental patch available at:
25#	https://gitlab.freedesktop.org/mchehab_kernel/gst-plugins-good/commit/9dd48f551c4b8c8c841b32f61658b1f88ef08995
26
27#
28# Default values
29#
30HOST=127.0.0.1
31PORT=8632
32VDEV=""
33CAPFMT=""
34OUTFMT=RGB
35CAPWIDTH=340
36OUTWIDTH=320
37CAPHEIGHT=240
38OUTHEIGHT=200
39COUNT=120
40HELP=""
41
42#
43# Parse command line arguments
44#
45while [ "$1" != "" ]; do
46	case $1 in
47	--help)
48		HELP=1
49		;;
50	--host)
51		shift
52		HOST="$1"
53		;;
54	--port)
55		shift
56		PORT="$1"
57		;;
58	--vdev)
59		shift
60		VDEV="$1"
61		;;
62	--count)
63		shift
64		COUNT="$1"
65		;;
66	--capfmt)
67		shift
68		CAPFMT="$CAPFMT $1"
69		;;
70	--outfmt)
71		shift
72		OUTFMT="$1"
73		;;
74	--capwidth)
75		shift
76		CAPWIDTH="$1"
77		;;
78	--outwidth)
79		shift
80		OUTWIDTH="$1"
81		;;
82	--capheight)
83		shift
84		CAPHEIGHT="$1"
85		;;
86	--outheight)
87		shift
88		OUTHEIGHT="$1"
89		;;
90
91	*)
92		echo "Unknown argument '$1'"
93		HELP=1
94		;;
95
96	esac
97	shift
98done
99
100if [ "$HELP" != "" ]; then
101	echo "$0 [--help] [--vdev videodev] [--host host_name_or_ip] [--port tcp_port]"
102	echo "		[--capfmt capture_format] [--outfmt output_format]"
103	echo "		[--capwidth capture_width] [--capheight capture_height]"
104	echo "		[--capwidth output_width] [--capheight output_height]"
105	exit -1
106fi
107
108# At Gstreamer 1.15 (unstable), the first m2m convert device receives a
109# nice name: v4l2convert. The other ones use the same name convention as
110# before
111
112GST_VER=$(gst-launch-1.0 --version|grep "gst-launch-1.0 version"|cut -d' ' -f 3)
113GST_SUBVER=$(echo $GST_VER|cut -d'.' -f2)
114if [ $GST_SUBVER -lt 15 ]; then
115	if [ "$VDEV" == "" ]; then
116		VDEV="video0"
117	fi
118fi
119
120M2M="v4l2${VDEV}convert"
121if [ "$(gst-inspect-1.0 $M2M 2>/dev/null)" == "" ]; then
122	echo "GStreamer doesn't recognized $M2M."
123	echo "Don't forget to load vim2m."
124	exit 1
125fi
126
127SUP_CAPFMTS=$(gst-inspect-1.0 $M2M 2>/dev/null|perl -e 'while (<>) { $T="$1" if (m/(SRC|SINK)\s+template/);  $T="" if (m/^\S/); $f{$T}.= $1 if ($T ne "" && m/format:\s+(.*)/); }; $f{SRC}=~s/[\{\}\,]//g; $f{SRC}=~s/\(string\)//g; print $f{SRC}')
128
129# TODO: validate the output format qas well
130SUP_OUTFMTS=$(gst-inspect-1.0 $M2M 2>/dev/null|perl -e 'while (<>) { $T="$1" if (m/(SRC|SINK)\s+template/); $T="" if (m/^\S/); $f{$T}.= $1 if ($T ne "" && m/format:\s+(.*)/); }; $f{SINK}=~s/[\{\}\,]//g; $f{SINK}=~s/\(string\)//g; print $f{SINK}')
131
132
133# If input and output formats are identical, we need to explicitly disable
134# passthrough mode.
135# Unfortunately, such feature may not be available
136
137HAS_DISABLE_PASSTHROUGH=""
138if [ "$(gst-inspect-1.0 $M2M|grep disable-passthrough)" != "" ]; then
139	M2M="$M2M disable-passthrough=1"
140	HAS_DISABLE_PASSTHROUGH="1"
141fi
142
143#
144# For each selected capture format, call Gst
145#
146# In order for the user to check if passthrough mode is disabled, do both
147# horizontal and vertical flip
148#
149BAYERFMTS="bggr gbrg grbg rggb"
150
151# Check it bayer is supported
152HAS_BAYER=""
153if [ "$(gst-inspect-1.0 bayer2rgb 2>/dev/null)" != "" ]; then
154	HAS_BAYER=1
155fi
156
157# Select a default that would test more formats, as possible by GStreamer
158# version and compilation
159
160if [ "$CAPFMT" == "" ]; then
161	if [ "$HAS_BAYER" == "" ]; then
162		DISABLE_FMTS="$BAYERFMTS $DISABLE_FMTS"
163	fi
164	if [ "$HAS_DISABLE_PASSTHROUGH" == "" ]; then
165		DISABLE_FMTS="$BAYERFMTS $OUTFMT"
166	fi
167
168	CAPFMT=" $SUP_CAPFMTS "
169	for i in $DISABLE_FMTS; do
170		CAPFMT=${CAPFMT/ $i / }
171	done
172else
173	if [ "$HAS_DISABLE_PASSTHROUGH" == "" ]; then
174		DISABLE_FMTS="$OUTFMT"
175		echo "Can't use capture format $OUTFMT"
176	fi
177
178	CAPFMT=" $SUP_CAPFMTS "
179	for i in $DISABLE_FMTS; do
180		CAPFMT=${CAPFMT/ $i / }
181	done
182fi
183
184#
185# Displays all used command line parameters and default values
186#
187CAPFMT=${CAPFMT//  / }
188SUP_CAPFMTS=${SUP_CAPFMTS//  / }
189SUP_OUTFMTS=${SUP_OUTFMTS//  / }
190
191echo "Using ${M2M}, source ${OUTWIDTH}x${OUTHEIGHT}, sink ${CAPWIDTH}x${CAPHEIGHT}".
192echo "Supported output formats :$SUP_OUTFMTS (using $OUTFMT)"
193echo "Supported capture formats:$SUP_CAPFMTS"
194echo "Testing those cap formats:$CAPFMT"
195echo "Sending stream to ${HOST}:${PORT}"
196echo
197echo "Be sure that port ${PORT} is enabled at the ${HOST} host."
198echo "At ${HOST} host, you should run:"
199echo
200echo "  $ while :; do gst-launch-1.0 tcpserversrc port=${PORT} host=0.0.0.0 ! decodebin ! videoconvert ! autovideosink; done"
201
202for FMT in $CAPFMT; do
203	echo
204
205	VIDEOFMT="video/x-raw,format=${FMT},width=${CAPWIDTH},height=${CAPHEIGHT} "
206	NOT_SUPPORTED=""
207	for i in $BAYERFMTS; do
208		if [ "$FMT" == "$i" ]; then
209			if [ "$HAS_BAYER" == "" ]; then
210				NOT_SUPPORTED=1
211			fi
212
213			VIDEOFMT="video/x-bayer,format=${FMT},width=${CAPWIDTH},height=${CAPHEIGHT} ! bayer2rgb "
214			break
215		fi
216	done
217	if [ "$NOT_SUPPORTED" != "" ]; then
218		echo "Bayer formats like $FMT aren't supported by GStreamer"
219		continue
220	fi
221
222	NOT_SUPPORTED="1"
223	for i in $SUP_CAPFMTS; do
224		if [ "$FMT" == "$i" ]; then
225			NOT_SUPPORTED=""
226			break
227		fi
228	done
229	if [ "$NOT_SUPPORTED" != "" ]; then
230		echo "Format $FMT not supported by GStreamer"
231		continue
232	fi
233
234	echo "Format $FMT";
235
236	gst-launch-1.0 -q \
237	  videotestsrc num-buffers=${COUNT} ! \
238	  video/x-raw,format=${OUTFMT},width=${OUTWIDTH},height=${OUTHEIGHT} ! \
239	  ${M2M} extra-controls="s,horizontal_flip=1,vertical_flip=1" ! \
240	  ${VIDEOFMT} ! videoconvert ! \
241	  jpegenc ! tcpclientsink host=${HOST} port=${PORT}
242
243	sleep 3
244done
245