#!/bin/bash
# mplayer_wrapper.sh to get around XVMC-problem
# make soft link from /usr/local/bin/mplayer to mplayer_wrapper.sh
# rename /usr/bin/mplayer to /usr/bin/mplayer-bin
# GPL (c) Jouni.Lohikoski O iki.fi
VERSION="2005.05.09.00"

# at first get rid of zombie mplayer processes (usually noticed because rtc
# device cannot be open)
killall mplayer-bin >/dev/null 2>/dev/null

# Count options and arguments which are *.mpg or *.mpeg filenames.
mpgcnt=0
optcnt=0
for i in $*; 
do
  case $i in ( -* | *.mpg | *.mpeg ) \
      optcnt=$(( $optcnt + 1))
      mpgcnt=$(( $mpgcnt + 1 ))
      ;;
  esac
done

# Run mplayer-bin differently if all files are MPEG1/2 files
if [ "$#" == "$mpgcnt" ]; then
  exec mplayer-bin -vo xvmc -vc ffmpeg12mc $*
else  
  exec mplayer-bin $*
fi

# This script cannot parse complex mplayer options which have arguments
# Those are assumed to have filenames which are something else but mpg/mpeg


