Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # OMXPlayer launcher script.
  4. #
  5.  
  6. OMXPLAYER_DIR=`dirname $0`
  7. OMXPLAYER_BIN="$OMXPLAYER_DIR/omxplayer.bin"
  8. OMXPLAYER_LIBS="/opt/vc/lib"
  9.  
  10. if [ -e "$OMXPLAYER_DIR/ffmpeg_compiled" ]; then
  11. OMXPLAYER_LIBS="$OMXPLAYER_LIBS:$OMXPLAYER_DIR/ffmpeg_compiled/usr/local/lib"
  12. elif [ -d /usr/lib/omxplayer ]; then
  13. OMXPLAYER_LIBS="$OMXPLAYER_LIBS:/usr/lib/omxplayer"
  14. fi
  15.  
  16. refresh_regex='(|.* )(-r|--refresh)( .*|$)'
  17. audio_regex='.*\.(mp3|wav|wma|cda|ogg|ogm|aac|ac3|flac)( .*|$)'
  18.  
  19. fbset_bin=`which fbset`
  20. xset_bin=`which xset`
  21. xrefresh_bin=`which xrefresh`
  22.  
  23. if [ -z $NOREFRESH ] || [ "$NOREFRESH" == "0" ]; then
  24. if [[ $@ =~ $refresh_regex ]] && [[ ! $@ =~ $audio_regex ]]; then
  25. check_failed=0
  26.  
  27. if [ -z $fbset_bin ]; then
  28. echo "WARNING: You are going to run omxplayer with -r/--refresh and you don't have fbset installed, this can cause black screen when it finishes playing."
  29. check_failed=1
  30. fi
  31.  
  32. if [ ! -z $DISPLAY ]; then
  33. if [ -z $xset_bin ] || [ -z $xrefresh_bin ]; then
  34. echo "WARNING: You are going to run omxplayer with -r/--refresh and you don't have xset and xrefresh installed (x11-xserver-utils package on Debian/Raspbian), this can cause black screen when it finishes playing."
  35. check_failed=1
  36. fi
  37. fi
  38.  
  39. if [ "$check_failed" == "1" ]; then
  40. read -sn 1 -p "Press any key to continue or Ctrl-C to quit."
  41. echo
  42. fi
  43. fi
  44. fi
  45.  
  46. DBUS_CMD="dbus-daemon --fork --print-address 5 --print-pid 6 --session"
  47. OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.${USER:-root}"
  48. OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.${USER:-root}.pid"
  49.  
  50. if [ ! -s "$OMXPLAYER_DBUS_PID" ] || ! pgrep -f "$DBUS_CMD" -F "$OMXPLAYER_DBUS_PID" >/dev/null; then
  51. #echo "starting dbus for the first time" >&2
  52. exec 5> "$OMXPLAYER_DBUS_ADDR"
  53. exec 6> "$OMXPLAYER_DBUS_PID"
  54. $DBUS_CMD
  55. until [ -s "$OMXPLAYER_DBUS_ADDR" ]; do
  56. echo "waiting for dbus address to appear" >&2
  57. sleep .2
  58. done
  59. fi
  60.  
  61. DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR`
  62. DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`
  63.  
  64. export DBUS_SESSION_BUS_ADDRESS
  65. export DBUS_SESSION_BUS_PID
  66.  
  67. LD_LIBRARY_PATH="$OMXPLAYER_LIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" $OMXPLAYER_BIN "$@"
  68. RESULT=$?
  69.  
  70. if [ ! -z $NOREFRESH ] && [ "$NOREFRESH" == "1" ]; then
  71. exit $RESULT
  72. fi
  73.  
  74. if [[ $@ =~ $audio_regex ]]; then
  75. exit $RESULT
  76. fi
  77.  
  78. if [[ $@ =~ $refresh_regex ]]; then
  79. if [ ! -z $fbset_bin ]; then
  80. DEPTH2=`$fbset_bin | head -3 | tail -1 | cut -d " " -f 10`
  81.  
  82. if [ "$DEPTH2" == "8" ]; then
  83. DEPTH1=16
  84. elif [ "$DEPTH2" == "16" ] || [ "$DEPTH2" == "32" ]; then
  85. DEPTH1=8
  86. else
  87. DEPTH1=8
  88. DEPTH2=16
  89. fi
  90.  
  91. $fbset_bin -depth $DEPTH1 > /dev/null 2>&1
  92. $fbset_bin -depth $DEPTH2 > /dev/null 2>&1
  93. fi
  94.  
  95. if [ ! -z $xset_bin ] && [ ! -z $xrefresh_bin ]; then
  96. if [ -z $DISPLAY ]; then
  97. DISPLAY=":0"
  98. fi
  99.  
  100. $xset_bin -display $DISPLAY -q > /dev/null 2>&1
  101. if [ "$?" == "0" ]; then
  102. $xrefresh_bin -display $DISPLAY > /dev/null 2>&1
  103. fi
  104. fi
  105. fi
  106.  
  107. exit $RESULT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement