#!/bin/bash
TESTFILE=/data/av/gta/test.ogg
TESTFILE2=/data/av/gta/test.mp3
TESTFILE3=/data/av/gta/test.avi
LOG=/tmp/mplayerTest
PARAM=" -endpos 30"
export TIME="| %E | %U | %S |"

echo "DATA" > ${LOG}
echo "LOG" > ${LOG}.3

cat << HEADER > ${LOG}.1
Testfiles:
ogg - AUDIO: 44100 Hz, 2 ch, s16le, 112.0 kbit/7.94% (ratio: 14000->176400)
mp3 - AUDIO: 44100 Hz, 2 ch, s16le, 112.0 kbit/7.94% (ratio: 14000->176400) the same as ogg, made by ogg2mp3
avi - VIDEO:  [FMP4]  240x320  24bpp  15.000 fps  164.1 kbps (20.0 kbyte/s)

Codecs:
tremor   - afm: tremor (OggVorbis audio)
vorbis   - afm: libvorbis (OggVorbis Audio)
ffvorbis - afm: ffmpeg (FFmpeg Vorbis decoder)
mad      - afm: libmad (libMAD MPEG layer 1-2-3)
ffmp3    - afm: ffmpeg (FFmpeg MPEG layer-3 audio)
glamo    - vfm: hwmp4 (MPEG-4 output (.mp4 or SMedia Glamo hardware))
sdl      - vfm: ffmpeg (FFmpeg MPEG-4)

Binaries:
mplayer13
http://jama.mk.cvut.cz/mplayer_0.0+1.0rc2+svnr29649-r13_armv4t.ipk
mplayer14
http://jama.mk.cvut.cz/mplayer_0.0+1.0rc2+svnr29415-r14_armv4t.ipk
mplayerOG
http://downloads.tuxfamily.org/3v1deb/openmoko/mplayer-glamo.tar.bz2
mplayerPT
http://www.paultt.org/downloads/openmoko/mplayer-ptt_dev-SVN-r28791-4.1.2_armv4t.ipk
mplayerTL
http://www.paultt.org/downloads/openmoko/mplayer_dev-SVN-r29155-4.1.2-tremor-low_armv4t.ipk
mplayerTT
http://www.paultt.org/downloads/openmoko/mplayer_dev-SVN-r29155-4.1.2_armv4t.ipk
mplayerUN
http://build.shr-project.org/shr-unstable/ipk//armv4t/mplayer_0.0+1.0rc2-r12_armv4t.ipk

F .. when command failed with error exit status
L .. see LOG below, codec not found or not used as expected


| Codec    | Build     | | real    | user  | sys   |
HEADER

for VER in 13 14 OG PT TL TT UN; do
  for AC in tremor ffvorbis vorbis; do
    echo -en "| ${AC} | mplayer${VER} | " | tee -a ${LOG} | tee -a ${LOG}.3
    /usr/bin/time -a -o ${LOG} -- \
      /usr/local/bin/mplayer${VER} -ac ${AC} ${PARAM} ${TESTFILE} >>${LOG}.3
  done
  for AC in mad ffmp3; do
    echo -en "| ${AC} | mplayer${VER} | " | tee -a ${LOG} | tee -a ${LOG}.3
    /usr/bin/time -a -o ${LOG} -- \
      /usr/local/bin/mplayer${VER} -ac ${AC} ${PARAM} ${TESTFILE2} >>${LOG}.3
  done
  for VO in sdl glamo; do
    echo -en "| ${VO} | mplayer${VER} | " | tee -a ${LOG} | tee -a ${LOG}.3
    /usr/bin/time -a -o ${LOG} -- \
      /usr/local/bin/mplayer${VER} -vo ${VO} ${PARAM} ${TESTFILE3} >>${LOG}.3
  done
done

sed -i "s/^A:.*$//g" ${LOG}.3
sed -i "s/^V:.*$//g" ${LOG}.3

# align and cleanup error message
sed "s/| Command exited with.*$/|F/g; \
       s/| tremor |/| tremor   |/g; \
       s/| vorbis |/| vorbis   |/g; \
     s/| ffvorbis |/| ffvorbis |/g; \
          s/| mad |/| mad      |/g; \
        s/| ffmp3 |/| ffmp3    |/g; \
          s/| sdl |/| sdl      |/g; \
        s/| glamo |/| glamo    |/g; \
     " ${LOG} > ${LOG}.2

# align numbers
sed -i "s/| \([0123456789]\.[0123456789][0123456789]\) |/|  \1 |/g" ${LOG}.2
sed -i "s/| \([0123456789]\.[0123456789][0123456789]\) |/|  \1 |/g" ${LOG}.2

echo "remove redundant empty lines from ${LOG}.2 by hand"
echo "then press ENTER to continue"
read

cat ${LOG}.1 ${LOG}.2 > ${LOG}.final
echo LOG_sorted_by_codec >> ${LOG}.final
sort ${LOG}.2 >> ${LOG}.final
cat ${LOG}.3 >> ${LOG}.final
