swetoast / steamlink-launcher

Steamlink launcher for OSMC
GNU General Public License v2.0
155 stars 19 forks source link

[WIP] Support Raspberry pi 4 #18

Closed xsellier closed 3 years ago

xsellier commented 3 years ago

For LibreElec on Raspberry pi 4 it missees this dependency libjpeg.so.62, but also some other fixes are needed but on the steam installation script, which is quite annoying since we cannot update it (it doesn't use any global variable.

I also reworked a bit the steam installation bash script, but it doesn't work quite atm.

#!/bin/bash
#
# Script to launch the Steam Link app on Raspberry Pi

TOP=$(cd "$(dirname "$0")" && pwd)

function show_message()
{
  style=$1
  shift
  if ! zenity "$style" --no-wrap --text="$*" 2>/dev/null; then
    case "$style" in
    --error)
      title=$"Error"
      ;;
    --warning)
      title=$"Warning"
      ;;
    *)
      title=$"Note"
      ;;
    esac

    # Save the prompt in a temporary file because it can have newlines in it
    tmpfile="$(mktemp || echo "/tmp/steam_message.txt")"
    echo -e "$*" >"$tmpfile"
    if [ "$DISPLAY" = "" ]; then
      cat $tmpfile; echo -n 'Press enter to continue: '; read input
    else
      xterm -T "$title" -e "cat $tmpfile; echo -n 'Press enter to continue: '; read input"
    fi
    rm -f "$tmpfile"
  fi
}

# Check to make sure the hardware is capable of streaming at 1080p60
# Model code information from:
# https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
if [ ! -f "$TOP/.ignore_cpuinfo" ]; then
  revision=$(cat /proc/cpuinfo | fgrep "Revision" | sed 's/.*: //')

  # NOTE:
  # This is not needed since we are running the script on Raspberry pi 4

# revision=$((16#$revision))
# processor=$(($(($revision >> 12)) & 0xf)) # 0: BCM2835, 1: BCM2836, 2: BCM2837, 3: BCM2711
# if [ $processor -lt 2 ]; then
#   show_message --error $"You need to run on a Raspberry Pi 3 or newer - aborting."
#   exit 1
# fi
fi

# Check to make sure the experimental OpenGL driver isn't enabled
if [ ! -f "$TOP/.ignore_kms" ]; then
  if egrep '^dtoverlay=vc4-kms-v3d' /boot/config.txt >/dev/null 2>&1; then
    show_message --error $"You have dtoverlay=vc4-kms-v3d in /boot/config.txt, which will cause a black screen when starting streaming - aborting.\nTry commenting out that line and rebooting."
    exit 1
  fi
fi

# Install any additional dependencies, as needed
if [ -z "${STEAMSCRIPT:-}" ]; then
  STEAMSCRIPT=/usr/bin/steamlink
fi
STEAMDEPS="$(dirname $STEAMSCRIPT)/steamlinkdeps"
if [ -f "$STEAMDEPS" -a -f "$TOP/steamlinkdeps.txt" ]; then
  "$STEAMDEPS" "$TOP/steamlinkdeps.txt"
fi

# Check to make sure the Steam Controller rules are installed
# NOTE:
# LibreElect doesn't use the same directory so we use the udev rules from the storage directory
UDEV_RULES_DIR=/storage/.config/udev.rules.d
UDEV_RULES_FILE=56-steamlink.rules

if [ ! -f "$UDEV_RULES_DIR/$UDEV_RULES_FILE" ];
then
  title="Updating udev rules"

  script="$(mktemp || echo "/tmp/steamlink_copy_udev_rules.sh")"
  cat >$script <<__EOF__
echo "Copying Steam Link udev rules into place..."
rm -f $UDEV_RULES_DIR/*-steamlink.rules
cp -v $TOP/udev/modules-load.d/* /etc/modules-load.d/ && modprobe uinput && sleep 3

# NOTE:
# usermod is not required since LibreElect runs as root (WTF right?!)
cp -v $TOP/udev/rules.d/$UDEV_RULES_FILE $UDEV_RULES_DIR/$UDEV_RULES_FILE && udevadm trigger
echo -n "Press return to continue: "
read line
__EOF__
  if [ "$DISPLAY" = "" ]; then
    /bin/sh $script
  elif which lxterminal >/dev/null; then
    lxterminal -t "$title" -e /bin/sh $script

    # Wait for the script to complete
    sleep 3
    while ps aux | grep -v grep | grep $script >/dev/null; do
      sleep 1
    done
  elif which xterm >/dev/null; then
    xterm -bg "#383635" -fg "#d1cfcd" -T "$title" -e /bin/sh $script
  else
    /bin/sh $script
  fi
  rm -f $script
fi

# Set up the temporary directory
export TMPDIR="$TOP/.tmp"
rm -rf "$TMPDIR"
mkdir -p "$TMPDIR"

# Restore the display when we're done
cleanup()
{
  if [ "$CEC_PID" != "" ]; then
    kill $CEC_PID 2>/dev/null
  fi
  screenblank -k
}
trap cleanup 2 3 15

# Run the shell application and launch streaming
QT_VERSION=5.14.1
export PATH="$TOP/bin:$PATH"
export QTDIR="$TOP/Qt-$QT_VERSION"
export QT_PLUGIN_PATH="$QTDIR/plugins"
export LD_LIBRARY_PATH="$TOP/lib:$QTDIR/lib:$LD_LIBRARY_PATH"
export SDL_GAMECONTROLLERCONFIG_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/Valve Corporation/SteamLink/controller_map.txt"

if [ "$DISPLAY" = "" ]; then
  QPLATFORM="eglfs"
  export QT_QPA_EGLFS_FORCE888=1
else
  QPLATFORM="xcb"
fi

if [ -f "$TOP/.ignore_cec" ]; then
  CEC_PID=""
else
  cec-client </dev/null | steamlink-cec &
  CEC_PID="$(jobs -p) $!"
fi

restart=false
while true; do
  shell -platform "$QPLATFORM" "$@"

  # See if the shell wanted to launch anything
  cmdline_file="$TMPDIR/launch_cmdline.txt"
  if [ -f "$cmdline_file" ]; then
    cmd=`cat "$cmdline_file"`
    if [ "$cmd" = "\"steamlink\"" ]; then
      restart=true
      rm -f "$cmdline_file"
      break
    else
      eval $cmd
      rm -f "$cmdline_file"

      # We're all done if it was a single session launch
      if echo "$cmd" | fgrep "://" >/dev/null; then
        break
      fi
    fi
  else
    # We're all done...
    break
  fi
done
cleanup

if [ "$restart" = "true" ]; then
  exec steamlink "$@"
fi
exit 0
swetoast commented 3 years ago

Cool tnx for the work dont have a rpi4 myself since its fairly unstable for daily usage yet but feel free to ping me once you feel confident about the install script and ill merge

xsellier commented 3 years ago

This update will break steamlink-launcher for any other platform, it will work only for Raspberry pi 4 and LibreElec. And, it doesn't work well, it opens Steam Link but there is no way to make it stream any game.

Im stuck at this error:

Feb 21 15:24:42 LibreELEC start-from-kodi.sh[1783]: INFO: Initializing player
Feb 21 15:24:42 LibreELEC start-from-kodi.sh[1783]: INFO: Refresh rate: 60.00
Feb 21 15:24:42 LibreELEC start-from-kodi.sh[1783]: INFO: Effective rate: 59.75
Feb 21 15:24:42 LibreELEC start-from-kodi.sh[1783]: * failed to add service - already in use?

Meaning, streaming_client is using eglfs and not linuxfb, (software renderer).

swetoast commented 3 years ago

could do an if and detect if its an rpi4 board that its running on else run the other script

xsellier commented 3 years ago

No idea, but I think Im gonna switch to OSMC because of that issue, meaning no need to work on that. I ask a qestion about that specific issue: https://steamcommunity.com/app/353380/discussions/6/3108017414039024813/

Closing this PR, I dont think they are going to implement it anytime soon