#!/bin/sh
#(c) Copyright Barry Kauler, march 2017. License: GPL v3 (/usr/share/doc/legal).

#testing vlc in easy linux, defaults to using libva for video output, which has
#errors -- no full-screen, crash after playing video.
#hence, preset to video output modes that do work...
XTYPE='xv'
[ "`readlink /usr/bin/X`" = "Xvesa" ] && XTYPE='x11' #old kdrive.
#code from /usr/sbin/report-video...
if [ -f /var/log/Xorg.0.log ];then
 LOADED="$(grep 'Loading .*/xorg/modules/drivers/.*_drv.so' /var/log/Xorg.0.log | rev | cut -f 1 -d '/' | rev | cut -f 1 -d '_' | tr '\n' ' ')"
 for ALOADED in $LOADED
 do
  aPTN="UnloadModule: \"$ALOADED\""
  bPTN="LoadModule: \"$ALOADED\""
  #cPTN="${aPTN}|${bPTN}"
  #precaution, in case a module gets loaded, unloaded, then loaded again...
  #[ "`grep -E "$cPTN" /var/log/Xorg.0.log | tail -n 1 | grep 'UnloadModule:'`" != "" ] && continue
  #130215 Xorg loaded noauveau, then tried to load it again, failed, then unloaded, so count them...
  CNTload=`grep "$bPTN" /var/log/Xorg.0.log | wc -l`
  CNTunload=`grep "$aPTN" /var/log/Xorg.0.log | wc -l`
  [ $CNTload -eq 0 ] && continue
  [ $CNTunload -ge $CNTload ] && continue
  case "$ALOADED" in #this is driver currently in use, ex: intel
   vesa|modesetting) XTYPE='x11' ;;
  esac
  break
 done
fi
case $XTYPE in
 x11) sed -i -s 's%^vout=xcb_xv$%vout=xcb_x11%' /root/.config/vlc/vlcrc ;;
 *)   sed -i -s 's%^vout=xcb_x11$%vout=xcb_xv%' /root/.config/vlc/vlcrc ;;
esac

exec vlc "$@"
