Skip to content

RPi Steamlink Support #4029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed

Conversation

antonlacon
Copy link
Contributor

This is a WIP that currently does the foundation work, and includes a launcher script to get started. Tested on an RPi3; should work, but untested, on an RPi4.

Main changes are to build libpng and libjpeg-turbo as shared libs. Libjpeg-turbo also gets its jpeg8 eumlation turned off (I don't know why it was turned on as I don't think anything uses its features in the real world). This also adds a STEAMLINK_SUPPORT feature flag that, at the moment, just adds libXext and its depends to the image for RPi2 and RPi4 in order to make the bundled Qt libraries happy. The "fix indent" commits are cosmetics.

The steamlink-launcher script fetches the steamlink program from Valve, and takes over the cpucheck and udev rule updating from the steamlink program. (@slouken, if the ping works and you check this, you may want to use the cpucheck in this wrapper script: vcgencmd will get you the revision on both 64bit and 32bit kernels, and the substring extraction will work on bash + busybox's shell.)

The script will shutdown kodi (because otherwise input goes to both steamlink and kodi at once) & pulseaudio (or no audio) and then launch steamlink proper. On steamlink exit, pulseaudio and kodi are restored.

To use, login to the LE box with ssh and then run steamlink-launcher.sh. First run involves downloading the program and unpacking it, so it may take a little while to get started.

I have not attempted to package steamlink proper on purpose. Its license is the Steam Subscriber agreement, and from my skimming of it, nothing about it would authorizes hosting and redistribution from a party other than Valve. Raspbian does a similar approach with a launcher script that goes off and fetches steamlink proper from Valve. If someone has a different interpretation on this, they can assume that risk.

Draft because it needs:

Move the udev overlay to a systemd script
Proper integration to get it started form Kodi
Probably more

@antonlacon
Copy link
Contributor Author

antonlacon commented Dec 16, 2019

Converted to a Kodi addon. The addon is responsible for downloading, verifying and extracting the steamlink tarball. It then launches a preparation script to copy libs into steamlink's lib dir, and 'installs' a systemd script to control launching steamlink. The systemd script is used to survive kodi being shutdown, which would otherwise kill the addon's process and, in turn, steamlink. When prep is complete, the addon triggers the systemd script, which in turns launches steamlink. Steamlink then launches kodi again on exit.

Pending issues:
Audio not always happening from game streams (host issue? longer delay between shutting down pulseaudio and starting steamlink?)
Better way to insert the systemd script into LE?
Check what happens when the addon updates with current install
Cleanup pass on scripts / addon for leftover testing bits
Have cpucheck in addon?
RPi4 (probably another author / PR)
Icon artwork in Kodi (probably another author / PR)

Addon is written using python3 features, so don't test on LE9.2.

@chewitt
Copy link
Member

chewitt commented Dec 17, 2019

Here's a couple of icons following house style:

icon_steamlink1

icon_steamlink2

@antonlacon
Copy link
Contributor Author

antonlacon commented Dec 26, 2019

Update pushed. Changes:

  • Audio issue was a host setup problem (audio output didn't change to Steam's streaming speakers in Win10 desktop or in game)
  • PKG_REV is now set which was the missing piece regarding updating the addon.
  • Addon takes care of the cpucheck, so that it exits out if it's running on an RPi2 or earlier, before doing any work.
  • Icon artwork pulled in from chewitt (thanks!). Went with the first option to not mimic Steam's official logo. I imagine they're protective.
  • I added their logo/trademark legal attribution from https://partner.steamgames.com/doc/marketing/branding to the pkg long description. I don't think their copyright one applies as they have nothing to do with the addon itself (and for all I know this is the wrong documentation to be looking at anyway).

The remaining issue is the system.d unit file. I don't know if there is a better way to handle it. The other addons I looked at didn't have one. Right now, if the addon is uninstalled, the symlink hangs around (harmless but present).

The addon notification might be improvable for the steps it's completing. I mostly just wanted it reporting something to the user as otherwise it could be up to 1-2 minutes of wondering if you clicked the addon at all. Not having written a Kodi addon before, that will be for someone else.

Tested on RPi3. Wired connection strongly recommended. RPi4 may have issues; no idea.

@antonlacon antonlacon marked this pull request as ready for review December 26, 2019 05:13
from urllib.request import urlretrieve


STEAMLINK_VERSION = "1.1.45.105"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is quite ugly to have the version/hash at an unusual place, could we proxy in some not hacky way the version/hash to the package.mk ?
or are there a "latest.zip" somewhere ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a sed command to post_install_addon() to have package.mk store steamlink's version and hash.

@antonlacon
Copy link
Contributor Author

I believe this is done. I'm unlikely to be able to shepherd it further if there are other changes.

@CorneliaXaos
Copy link

I wanted to test this on a RPi 4, but it seems I'm having trouble building on master:
https://forum.libreelec.tv/thread/21435-raspberry-pi-4-latest-master-build-failure-for-target-kodi/
If I can figure it out, I'll test this and see if it it will work.

@CorneliaXaos
Copy link

CorneliaXaos commented Feb 24, 2020

I managed to get a build compiled. Specifically, I couldn't use the merge of @antonlacon 's branch with the current master. It wouldn't complete the build for either the image or the addon. Using @antonlacon 's branch directly, however, got me a build. I fired it up on a spare SD card, and things seem to partially work. The addon downloads the steamlink binaries and is capable of launching things, but it gets stuck for a second before kodi restarts.

Running directly, I see the following as output:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/storage/.kodi/addons/script.steamlink-rpi/steamlink/.tmp/runtime-root'
* failed to add service - already in use?
rm: can't remove '/tmp/steamlink.watchdog': No such file or directory

I'm not sure the significance of the first line, but some googling seems to indicate that the second one is steamlink failing to activate due to not being able to grab a graphics context. Some input I've found says to make sure a minimal X11 environment is running.. but I have no idea how to go about troubleshooting that here.

You mention in the first post that you added a STEAMLINK_SUPPORT flag.. How exactly is that enabled for building the image? I was compiling things like this:

$ PROJECT=RPi DEVICE=RPi4 ARCH=arm VERBOSE=yes STEAMLINK_SUPPORT=yes make image
$ PROJECT=RPi DEVICE=RPi4 ARCH=arm VERBOSE=yes STEAMLINK_SUPPORT=yes scripts/create_addon steamlink-rpi

(I'm kind of unfamiliar with the LibreELEC's custom toolchain.. so I was sort of fiddling around and canvasing the codebase to try and guess how flags are set. I'm not sure if the VERBOSE or STEAMLINK_SUPPORT flags actually did anything, however..)

So.. yea.. any ideas?

@antonlacon
Copy link
Contributor Author

antonlacon commented Feb 24, 2020

Master has changes to the buildsystem that will keep this from building. You can read PR 4088 to see what it did. If the chrome add-on changes are in there, that should be hint what needs to change, but it might have been a follow up PR.

The QStandardPath message is Qt being unhappy. QT_DEBUG_PLUGINS=1 may show something interesting when starting. It may need a custom build of Qt-5.12.0.

STEAMLINK_SUPPORT is no longer relevant. It was in an earlier version of this PR that built the necessary support libs into the image. Everything is an addon now, so it's unnecessary. VERBOSE, to my knowledge, doesn't do anything. You can find many, but not all, of the flags in various "options" files found in distributions, project, and device directories. Some are undocumented in scripts/image.

I'm away from any dev hardware for another month-ish, so won't be digging deeper myself for awhile.

@cwildfoerster
Copy link

Got it compiling, see https://github.com/cwildfoerster/LibreELEC.tv/commit/1ccc61470502cf74aec1a760329861f6a0045151
the x11 makekey patch is not necessary anymore in libX11-1.6.9. But still need to flash the image and test on my rpi3...

@cwildfoerster
Copy link

Okay, just tested it successfully on my rpi3, clean install, only finished the wizard and copied the script.steamlink-rpi-9.80.2.100.zip and driver.steamcontroller-9.80.2.100.zip addons and installed them.

First start of the steamlink addon took a little while, like 60 seconds after downloading, but steamlink started as expected, connected to my pc and played 2 minutes (limited time). Used the steam controller for testing.

PROJECT=RPi DEVICE=RPi2 ARCH=arm IMAGE_SUFFIX=testing make image
PROJECT=RPi DEVICE=RPi2 ARCH=arm IMAGE_SUFFIX=testing scripts/create_addon official

@WizzardMaker
Copy link

I struggle building the addon, are there any precompiled "binaries" to test?

@MilhouseVH
Copy link
Contributor

I struggle building the addon

FYI support is provided via the forum - but just out of interest what problem did you have? What command line did you use to build the add-on, and post details of the error.

, are there any precompiled "binaries" to test?

No, not until this PR merges, and then only for master nightly builds.

@MilhouseVH
Copy link
Contributor

@antonlacon hope you don't mind, I've pushed a couple of commits that address the outstanding issues with this PR:

  1. drop the upstream patch, fix the (potentially) out of scope python variable reference
  2. make autoremove compatible
  3. add RPi4 support (not sure if it actually works... can't test this beyond building it)

@MilhouseVH MilhouseVH force-pushed the le10-steamlink branch 2 times, most recently from 07d1881 to 60370aa Compare March 8, 2020 16:34
@antonlacon
Copy link
Contributor Author

Commits look fine. My expectation is the RPi4 addon will fail at runtime for incomplete lib support, or needing Qt replaced with one not looking for said libs.

@cwildfoerster
Copy link

Commits look fine. My expectation is the RPi4 addon will fail at runtime for incomplete lib support, or needing Qt replaced with one not looking for said libs.

Hm, maybe i will order myself a RPi4 to test this, my RPi2/3 run this addon just fine.

@CorneliaXaos
Copy link

I should note, I'm having trouble just getting libreelec to compile for the latest master or cwildfoerster@1ccc614 Kodi fails to build for some reason.

That being said, when I built @antonlacon 's branch, both Kodi and the plugin compiled just fine. The plugin just failed to launch steamlink when ran.

@MilhouseVH
Copy link
Contributor

@CorneliaXaos LibreELEC master 9f00cd2 is currently building OK - our Jenkins is green. I also built this PR on top of LE master earlier today (for both RPi2 and RPi4 devices). If you continue to have problems, post your build log (build master + #4029).

@CorneliaXaos
Copy link

@MilhouseVH I'm currently running off of a merge of master and this PR and it's failing on compiling Kodi, specifically something to do with dvdcss. I didn't know which part of the build log to post here.. so here's the "threads" file for Kodi:
257.log

@MilhouseVH
Copy link
Contributor

MilhouseVH commented Mar 9, 2020

@CorneliaXaos hmm yeah, the dvdcss autoreconf step is failing - can you describe your build host (distro, version, etc.) And what command line you used?

@CorneliaXaos
Copy link

Ubuntu 18.04.4 LTS
uname -a: Linux Xaos-Oryx-Pro 5.3.0-7629-generic #31~1581628854~18.04~2db8a7a~dev-Ubuntu SMP Fri Feb 14 19:57:43 x86_64 x86_64 x86_64 GNU/Linux
Built using PROJECT=RPi DEVICE=RPi4 ARCH=arm make image

I should note, this is the command that is failing (specifically, the bold part):

cd /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/build/kodi-3375a26606b3a6913bea18f4ef7b85a72b724915/.armv8a-libreelec-linux-gnueabihf/build/libdvd/src/dvdcss && "PATH=/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin:/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin:/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/sbin:~/Scripts:/home/cornelia/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/cornelia/.dotnet/tools" autoreconf -vif && /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin/cmake -E touch /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/build/kodi-3375a26606b3a6913bea18f4ef7b85a72b724915/.armv8a-libreelec-linux-gnueabihf/build/libdvd/src/dvdcss-stamp/dvdcss-autoreconf

If the command is altered as follows, it executes just fine:

cd /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/build/kodi-3375a26606b3a6913bea18f4ef7b85a72b724915/.armv8a-libreelec-linux-gnueabihf/build/libdvd/src/dvdcss && PATH=/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin:/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin:/home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/sbin:~/Scripts:/home/cornelia/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/cornelia/.dotnet/tools autoreconf -vif && /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/toolchain/bin/cmake -E touch /home/cornelia/Documents/Programming/GIT/LibreELEC.tv/build.LibreELEC-RPi4.arm-9.80-devel/build/kodi-3375a26606b3a6913bea18f4ef7b85a72b724915/.armv8a-libreelec-linux-gnueabihf/build/libdvd/src/dvdcss-stamp/dvdcss-autoreconf

The quotes seem to cause the shell to interpret the quoted section as being a command to run, not as a variable to set.

@CorneliaXaos
Copy link

/bin/bash is not symlinked to /bin/dash and echo $CONFIG_SHELL prints a blank line

@MilhouseVH
Copy link
Contributor

MilhouseVH commented Mar 9, 2020

I'm not sure why you are having this issue - it's not typical. I also don't see how this can be avoided as the command appears to be generated by cmake. There must be something about your environment/build host that's a little "unusual"...

@MilhouseVH
Copy link
Contributor

One more thing - can you tell if this error occurred with the previous version of Kodi? There have been some recent cmake changes.

@antonlacon
Copy link
Contributor Author

Rebased on master and updated steamlink to 1.1.60.143. Tested on RPi3; RPi4 expected to still be borked.

@cwildfoerster
Copy link

I've bought a RPI4 in the meanwhile, will test it some time this week hopefully.

@cwildfoerster
Copy link

Just quick info, have tested the build a created on 06.04.2019, installs fine, crashes on start. can't debug right now, do not have my laptop. kodi debug log shows nothing... well of course, kodi gets stopped in order to start steamlink. can't find any logs using samba access only.

@antonlacon
Copy link
Contributor Author

If memory serves, steamlink's log is /tmp/streaming_client.txt or similar.

@cwildfoerster
Copy link

cwildfoerster commented Apr 20, 2020

okay, steamlink doesn't even start, uses eglfs because $DISPLAY is not set: failed to add service - already in use?
According to the link (https://steamcommunity.com/app/353380/discussions/6/2145343313162988731/#c2260186248419735359) you posted in the 9.2 PR, this is due to rpi4 needing a full xserver, not just the eglfs.

Im no libreelec dev, i don't know how to include or start a xserver. Funny enough, calling DISPLAY=0 ./steamlink.sh to "emulate" the xserver results in:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

EDIT okay, currently building a rpi4 image with x11 by changing the options... lets see how that goes.

EDIT2 well, would have been way too easy FAILURE: scripts/build xorg-server:target during make_target (default)

@mdPlusPlus
Copy link

mdPlusPlus commented Jun 7, 2020

@cwildfoerster: I've run into the same error (qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.) with my approach (when including X11): swetoast/steamlink-launcher#13
I wish I was aware of this PR earlier.

mdPlusPlus added a commit to mdPlusPlus/steamlink-launcher that referenced this pull request Jun 11, 2020
@antonlacon
Copy link
Contributor Author

Rebased and squashed some patches. Updated to 1.1.64. Added necessary code to addon to handle updating steamlink when addon wants a newer version than what is installed. Merged steamlink-prep.sh's tasks into addon proper. Tested desktop/mouse emulation is working and CEC support in steamlink shell (not remote play).

Known issue is audio requires dtparam=audio=on in /flash/distroconfig.txt if not using an addon soundcard. I'll look deeper later. I'm currently half expecting to move to KMS to render all this moot, so it's mostly in a holding pattern.

@antonlacon antonlacon marked this pull request as draft June 24, 2020 01:46
@antonlacon
Copy link
Contributor Author

Closing as I don't believe this will be mergeable anytime soon. steamlink's launcher script (the one supplied by Valve) has a handy note that says something along the lines of "don't use KMS, it won't work." That note has been there since shortly after steamlink was released.

I've pushed my latest changes to the branch, and it will hang around if someone else wants to do their own builds using the firmware graphics stack. Note that such builds are probably on borrowed time with regards to Kodi 19 support.

@antonlacon antonlacon closed this Jul 21, 2020
@cwildfoerster
Copy link

Too bad, been using the 9.2er modified version of yours the last months. Works good for me. Thank you anyways.

@mdPlusPlus
Copy link

@antonlacon: Quick question to better understand why you closed this: Does standalone LibreELEC 19 "Matrix" not come with a window manager by default and therefore Steam Link would require DRM/KMS support, which it doesn't offer?
Or am I misunderstanding something here?

@lrusak
Copy link
Member

lrusak commented Jul 21, 2020

@antonlacon: Quick question to better understand why you closed this: Does standalone LibreELEC 19 "Matrix" not come with a window manager by default and therefore Steam Link would require DRM/KMS support, which it doesn't offer?
Or am I misunderstanding something here?

That's exactly it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants