1#!/bin/bash
2#
3# Any copyright is dedicated to the Public Domain.
4# http://creativecommons.org/publicdomain/zero/1.0/
5#
6# Script to generate <video src> reftest files, from corresponding reftest
7# files that use <video poster>.
8#
9# This script expects to be run from this working directory:
10#  mozilla-central/layout/reftests/w3c-css/submitted/images3
11#
12# It requires that the tools png2yuv and vpxenc be available, from the
13# Ubuntu packages 'mjpegtools' and 'vpx-tools'. More info here:
14#  http://wiki.webmproject.org/howtos/convert-png-frames-to-webm-video
15
16VIDEO_REFTEST_PATH="../../../webm-video"
17
18imageFileArr=("colors-16x8.png" "colors-8x16.png")
19numImageFiles=${#imageFileArr[@]}
20
21# Copy image files, and generate webm files:
22for ((i = 0; i < $numImageFiles; i++)); do
23  imageFileName=${imageFileArr[$i]}
24  imageDest=$VIDEO_REFTEST_PATH/$imageFileName
25
26  echo "Copying $imageDest."
27  hg cp support/$imageFileName $imageDest
28
29  videoDest=`echo $imageDest | sed "s/png/webm/"`
30  echo "Generating $videoDest."
31  png2yuv -f 1 -I p -b 1 -n 1 -j $imageDest \
32    | vpxenc --passes=1 --pass=1 --codec=vp9 --lossless=1 --max-q=0 -o $videoDest -
33  hg add $videoDest
34done
35
36reftestListFileName="$VIDEO_REFTEST_PATH/reftest.list"
37
38# Loop across all <video poster> tests:
39for origTestName in object-position-png-*p.html; do
40  # Find the corresponding reference case:
41  origReferenceName=$(echo $origTestName |
42                      sed "s/p.html/-ref.html/")
43
44  # The generated testcase will have "-webm" instead of "-png", and unlike
45  # the original png test, it won't have a single-letter suffix to indicate the
46  # particular container element. (since it's unnecessary -- there's only one
47  # possible container element for webm, "<video>")
48  videoTestName=$(echo $origTestName |
49                  sed "s/png/webm/" |
50                  sed "s/p.html/.html/")
51
52  videoReferenceName=$(echo $videoTestName |
53                       sed "s/.html/-ref.html/")
54
55  # Generate reference file (dropping "support" subdir from image paths):
56  echo "Copying $origReferenceName to $VIDEO_REFTEST_PATH."
57  videoReferenceFullPath=$VIDEO_REFTEST_PATH/$videoReferenceName
58  hg cp $origReferenceName $videoReferenceFullPath
59  sed -i "s,support/,," $videoReferenceFullPath
60
61  # Generate testcase
62  # (converting <video poster="support/foo.png"> to <video src="foo.webm">):
63  echo "Generating $videoTestName from $origTestName."
64  videoTestFullPath=$VIDEO_REFTEST_PATH/$videoTestName
65  hg cp $origTestName $videoTestFullPath
66  sed -i "s/PNG image/WebM video/" $videoTestFullPath
67  sed -i "s/poster/src/" $videoTestFullPath
68  sed -i "s,support/,," $videoTestFullPath
69  sed -i "s/png/webm/" $videoTestFullPath
70  sed -i "s/$origReferenceName/$videoReferenceName/" $videoTestFullPath
71
72  # Update reftest manifest:
73  annotation="fails-if(layersGPUAccelerated) skip-if(Android||B2G)"
74  comment="# Bug 1098417 for across-the-board failure, Bug 1083516 for layersGPUAccelerated failures, Bug 1084564 for Android/B2G failures"
75  echo "$annotation == $videoTestName $videoReferenceName $comment" \
76    >> $reftestListFileName
77
78done
79