#!/bin/bash
set -e

log_dir="log"

vdpau_play()
{
	file="$1"
	decoder="$2"

	log="$log_dir/VDPAU_$file.log"

	echo "VDPAU_DRIVER=r600 mplayer -vc \"$decoder\" -vo vdpau \"$file\""
	echo "VDPAU_DRIVER=r600 mplayer -vc \"$decoder\" -vo vdpau \"$file\"" > "$log"
	(VDPAU_DRIVER=r600 mplayer -vc "$decoder" -vo vdpau "$file" &>>"$log") &
	sleep 10
	killall mplayer || true
}

xvmc_play()
{
	file=$1

	log="$log_dir/XvMC_$file.log"

	echo "mplayer -vo xvmc \"$file\""
	echo "mplayer -vo xvmc \"$file\"" > "$log"
	(mplayer -vo xvmc "$file" &>>"$log") &
	sleep 10
	killall mplayer || true
}

files=(
	"13 - Lifted.2007.720p.BluRay.AC3.x264.mkv" "ffh264vdpau" 
	"big_buck_bunny_720p_h264.mov" "ffh264vdpau"
	"big_buck_bunny_720p_stereo.avi" "ffodivxvdpau"
	"newmobcal1920.ts" "ffmpeg12vdpau"
)

mkdir -p "$log_dir"
echo "Begin vdpau test..."
f=
for fc in "${files[@]}"
do
	if [ -z "$f" ]; then
		f="$fc"
	else
		vdpau_play "$f" "$fc"
		f=
	fi
done

echo "Begin xvmc test..."
f=
for fc in "${files[@]}"
do
	if [ -z "$f" ]; then
		f="$fc"
	else
		xvmc_play "$f"
		f=
	fi
done

echo "Finished."
