You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
8.6KB

  1. #! /bin/sh
  2. export LC_ALL=C
  3. base=$(dirname $0)
  4. . "${base}/md5.sh"
  5. base64=tests/base64
  6. test="${1#fate-}"
  7. samples=$2
  8. target_exec=$3
  9. target_path=$4
  10. command=$5
  11. cmp=${6:-diff}
  12. ref=${7:-"${base}/ref/fate/${test}"}
  13. fuzz=${8:-1}
  14. threads=${9:-1}
  15. thread_type=${10:-frame+slice}
  16. cpuflags=${11:-all}
  17. cmp_shift=${12:-0}
  18. cmp_target=${13:-0}
  19. size_tolerance=${14:-0}
  20. cmp_unit=${15:-2}
  21. gen=${16:-no}
  22. hwaccel=${17:-none}
  23. report_type=${18:-standard}
  24. outdir="tests/data/fate"
  25. outfile="${outdir}/${test}"
  26. errfile="${outdir}/${test}.err"
  27. cmpfile="${outdir}/${test}.diff"
  28. repfile="${outdir}/${test}.rep"
  29. target_path(){
  30. test ${1} = ${1#/} && p=${target_path}/
  31. echo ${p}${1}
  32. }
  33. # $1=value1, $2=value2, $3=threshold
  34. # prints 0 if absolute difference between value1 and value2 is <= threshold
  35. compare(){
  36. awk "BEGIN { v = $1 - $2; printf ((v < 0 ? -v : v) > $3) }"
  37. }
  38. do_tiny_psnr(){
  39. psnr=$(tests/tiny_psnr "$1" "$2" $cmp_unit $cmp_shift 0)
  40. val=$(expr "$psnr" : ".*$3: *\([0-9.]*\)")
  41. size1=$(expr "$psnr" : '.*bytes: *\([0-9]*\)')
  42. size2=$(expr "$psnr" : '.*bytes:[ 0-9]*/ *\([0-9]*\)')
  43. val_cmp=$(compare $val $cmp_target $fuzz)
  44. size_cmp=$(compare $size1 $size2 $size_tolerance)
  45. if [ "$val_cmp" != 0 ] || [ "$size_cmp" != 0 ]; then
  46. echo "$psnr"
  47. return 1
  48. fi
  49. }
  50. oneoff(){
  51. do_tiny_psnr "$1" "$2" MAXDIFF
  52. }
  53. stddev(){
  54. do_tiny_psnr "$1" "$2" stddev
  55. }
  56. oneline(){
  57. printf '%s\n' "$1" | diff -u -b - "$2"
  58. }
  59. run(){
  60. test "${V:-0}" -gt 0 && echo "$target_exec" $target_path/"$@" >&3
  61. $target_exec $target_path/"$@"
  62. }
  63. probefmt(){
  64. run avprobe -show_format_entry format_name -v 0 "$@"
  65. }
  66. probestream(){
  67. run avprobe -show_stream_entry "$1" -v 0 "$2"
  68. }
  69. avconv(){
  70. dec_opts="-hwaccel $hwaccel -threads $threads -thread_type $thread_type"
  71. avconv_args="-nostats -cpuflags $cpuflags"
  72. for arg in $@; do
  73. [ x${arg} = x-i ] && avconv_args="${avconv_args} ${dec_opts}"
  74. avconv_args="${avconv_args} ${arg}"
  75. done
  76. run avconv ${avconv_args}
  77. }
  78. framecrc(){
  79. avconv "$@" -f framecrc -
  80. }
  81. framemd5(){
  82. avconv "$@" -f framemd5 -
  83. }
  84. crc(){
  85. avconv "$@" -f crc -
  86. }
  87. md5(){
  88. avconv "$@" md5:
  89. }
  90. pcm(){
  91. avconv "$@" -vn -f s16le -
  92. }
  93. enc_dec_pcm(){
  94. out_fmt=$1
  95. dec_fmt=$2
  96. pcm_fmt=$3
  97. src_file=$(target_path $4)
  98. shift 4
  99. encfile="${outdir}/${test}.${out_fmt}"
  100. cleanfiles=$encfile
  101. encfile=$(target_path ${encfile})
  102. avconv -i $src_file "$@" -f $out_fmt -y ${encfile} || return
  103. avconv -f $out_fmt -i ${encfile} -c:a pcm_${pcm_fmt} -f ${dec_fmt} -
  104. }
  105. FLAGS="-flags +bitexact -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  106. DEC_OPTS="-threads $threads -idct simple $FLAGS"
  107. ENC_OPTS="-threads 1 -idct simple -dct fastint"
  108. enc_dec(){
  109. src_fmt=$1
  110. srcfile=$2
  111. enc_fmt=$3
  112. enc_opt=$4
  113. dec_fmt=$5
  114. dec_opt=$6
  115. encfile="${outdir}/${test}.${enc_fmt}"
  116. decfile="${outdir}/${test}.out.${dec_fmt}"
  117. cleanfiles="$cleanfiles $decfile"
  118. test "$7" = -keep || cleanfiles="$cleanfiles $encfile"
  119. tsrcfile=$(target_path $srcfile)
  120. tencfile=$(target_path $encfile)
  121. tdecfile=$(target_path $decfile)
  122. avconv -f $src_fmt $DEC_OPTS -i $tsrcfile $ENC_OPTS $enc_opt $FLAGS \
  123. -f $enc_fmt -y $tencfile || return
  124. do_md5sum $encfile
  125. echo $(wc -c $encfile)
  126. avconv $DEC_OPTS -i $tencfile $ENC_OPTS $dec_opt $FLAGS \
  127. -f $dec_fmt -y $tdecfile || return
  128. do_md5sum $decfile
  129. tests/tiny_psnr $srcfile $decfile $cmp_unit $cmp_shift
  130. }
  131. # FIXME: There is a certain duplication between the avconv-related helper
  132. # functions above and below that should be refactored.
  133. avconv2="$target_exec ${target_path}/avconv"
  134. raw_src="${target_path}/tests/vsynth1/%02d.pgm"
  135. pcm_src="${target_path}/tests/data/asynth1.sw"
  136. crcfile="tests/data/$test.lavf.crc"
  137. target_crcfile="${target_path}/$crcfile"
  138. echov(){
  139. echo "$@" >&3
  140. }
  141. AVCONV_OPTS="-nostats -y -cpuflags $cpuflags -threads $threads"
  142. DEC_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact -fflags +bitexact"
  143. ENC_OPTS="$DEC_OPTS -threads 1 -dct fastint"
  144. run_avconv(){
  145. $echov $avconv2 $AVCONV_OPTS $*
  146. $avconv2 $AVCONV_OPTS $*
  147. }
  148. do_avconv(){
  149. f="$1"
  150. shift
  151. set -- $* ${target_path}/$f
  152. run_avconv $*
  153. do_md5sum $f
  154. echo $(wc -c $f)
  155. }
  156. do_avconv_crc(){
  157. f="$1"
  158. shift
  159. run_avconv $* -f crc "$target_crcfile"
  160. echo "$f $(cat $crcfile)"
  161. }
  162. lavf_audio(){
  163. t="${test#lavf-}"
  164. outdir="tests/data/lavf"
  165. file=${outdir}/lavf.$t
  166. do_avconv $file $DEC_OPTS $1 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2
  167. do_avconv_crc $file $DEC_OPTS $3 -i $target_path/$file
  168. }
  169. lavf_container(){
  170. t="${test#lavf-}"
  171. outdir="tests/data/lavf"
  172. file=${outdir}/lavf.$t
  173. do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le $1 -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2
  174. test $3 = "disable_crc" ||
  175. do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3
  176. }
  177. lavf_image(){
  178. t="${test#lavf-}"
  179. outdir="tests/data/images/$t"
  180. mkdir -p "$outdir"
  181. file=${outdir}/%02d.$t
  182. run_avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $1 $ENC_OPTS $2 -frames 12 -y -qscale 10 $target_path/$file
  183. do_md5sum ${outdir}/02.$t
  184. do_avconv_crc $file $DEC_OPTS $2 -i $target_path/$file
  185. echo $(wc -c ${outdir}/02.$t)
  186. }
  187. lavf_image2pipe(){
  188. t="${test#lavf-}"
  189. t="${t%pipe}"
  190. outdir="tests/data/lavf"
  191. file=${outdir}/${t}pipe.$t
  192. do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10
  193. do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file
  194. }
  195. lavf_video(){
  196. t="${test#lavf-}"
  197. outdir="tests/data/lavf"
  198. file=${outdir}/lavf.$t
  199. do_avconv $file $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 $1
  200. do_avconv_crc $file $DEC_OPTS -i $target_path/$file $1
  201. }
  202. pixfmt_conversion(){
  203. conversion="${test#pixfmt-}"
  204. outdir="tests/data/pixfmt"
  205. raw_dst="$outdir/$conversion.out.yuv"
  206. file=${outdir}/${conversion}.yuv
  207. run_avconv $DEC_OPTS -r 1 -f image2 -c:v pgmyuv -i $raw_src \
  208. $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $conversion $target_path/$raw_dst
  209. do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $conversion -i $target_path/$raw_dst \
  210. $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p
  211. }
  212. video_filter(){
  213. filters=$1
  214. shift
  215. label=${test#filter-}
  216. printf '%-20s' $label
  217. avconv $DEC_OPTS -f image2 -c:v pgmyuv -i $raw_src \
  218. $FLAGS $ENC_OPTS -vf "$filters" -c:v rawvideo -frames:v 5 $* -f nut md5:
  219. }
  220. pixfmts(){
  221. filter=${test#filter-pixfmts-}
  222. filter_args=$1
  223. showfiltfmts="$target_exec $target_path/libavfilter/tests/filtfmts"
  224. exclude_fmts=${outfile}${filter}_exclude_fmts
  225. out_fmts=${outfile}${filter}_out_fmts
  226. # exclude pixel formats which are not supported as input
  227. avconv -pix_fmts list 2>/dev/null | awk 'NR > 8 && /^\..\./ { print $2 }' | sort >$exclude_fmts
  228. $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts
  229. pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts)
  230. outertest=$test
  231. for pix_fmt in $pix_fmts; do
  232. test=$pix_fmt
  233. video_filter "format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt -frames:v 1
  234. done
  235. rm $exclude_fmts $out_fmts
  236. test=$outertest
  237. }
  238. null(){
  239. :
  240. }
  241. exec 3>&2
  242. eval $command >"$outfile" 2>$errfile
  243. err=$?
  244. if [ $err -gt 128 ]; then
  245. sig=$(kill -l $err 2>/dev/null)
  246. test "${sig}" = "${sig%[!A-Za-z]*}" || unset sig
  247. fi
  248. if test -e "$ref" || test $cmp = "oneline" || test $cmp = "null" ; then
  249. case $cmp in
  250. diff) diff -u -b "$ref" "$outfile" >$cmpfile ;;
  251. oneoff) oneoff "$ref" "$outfile" >$cmpfile ;;
  252. stddev) stddev "$ref" "$outfile" >$cmpfile ;;
  253. oneline)oneline "$ref" "$outfile" >$cmpfile ;;
  254. null) cat "$outfile" >$cmpfile ;;
  255. esac
  256. cmperr=$?
  257. test $err = 0 && err=$cmperr
  258. if [ "$report_type" = "ignore" ]; then
  259. test $err = 0 || echo "IGNORE\t${test}" && err=0 && unset sig
  260. else
  261. test $err = 0 || cat $cmpfile
  262. fi
  263. else
  264. echo "reference file '$ref' not found"
  265. err=1
  266. fi
  267. if [ $err -eq 0 ] && test $report_type = "standard" ; then
  268. unset cmpo erro
  269. else
  270. cmpo="$($base64 <$cmpfile)"
  271. erro="$($base64 <$errfile)"
  272. fi
  273. echo "${test}:${sig:-$err}:$cmpo:$erro" >$repfile
  274. if test $err != 0 && test $gen != "no" ; then
  275. echo "GEN $ref"
  276. cp -f "$outfile" "$ref"
  277. err=$?
  278. fi
  279. test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles
  280. exit $err