veldenb / plugin.program.moonlight-qt

A launcher and updater for running Moonlight-qt on LibreELEC.
GNU General Public License v3.0
97 stars 15 forks source link

Support for x86_64 #1

Closed jhakonen closed 3 years ago

jhakonen commented 3 years ago

Hi there!

I've been looking for a solution for running Moonlight on my Intel's NUC Mini-PC and just recently found out your plugin. This one would have been great, but since I'm running Kodi on x86_64 architecture the plugin would not have worked for me. However since this seems to be the best solution I've seen I thought I would try to port it to work on my processor architecture.

After a few re-attempts I now have a version that works fine on x86_64 LibreELEC. The changes are here: https://github.com/jhakonen/plugin.program.moonlight-qt/compare/main...x86_64

Moonlight offers AppImage for x86_64 architecture so my code pulls that, includes missing .so files (like yours do) and then re-packages the AppImage. This appears to make it quite easy to run Moonlight as there's less paths to set in env variables. In addition I've added code that picks audio output device from Kodi's settings and configures Moonlight to use the same device.

The changes just replace the existing code so the plugin doesn't work anymore for PI 4. I would need to refactor the code so that x86_64's and PI 4's functionality would co-exist at same time.

But, before I attempt that, would you consider accepting this support for x86_64 to your plugin? If yes I can try to do the required refactoring and then make a proper PR.

veldenb commented 3 years ago

Hi,

Great to see you've put this effort into a port. I'm curious about the audio feature if it will also work on the Pi :)

Currently I don't have a spare x86_64 machine at hand to try it but I might be able to get things running in a VM. That will be needed in case I need to support the new code. It's probably the most convenient to create sub folder in the build folder with build/armhf/ for the Pi and build/x86_64/ for the x86 build.

I created a new x86_64 branch so I can accept your pull request on that branch after refactoring and I can fiddle a bit with it (also testing it on the Pi) on the branch. If it works on both architectures I can merge the branch to the main branch and create a new version.

I do this in my spare time so if I'm busy it may take a while but I have the intention to add the code and support it :)

jhakonen commented 3 years ago

Awesome! Thanks!

Sadly, I don't have have PI4 at hand so I can't test it out it works either. I hope you can do that :) I tried to setup an emulated RPI4 machine with qemu, but I'm not really familiar enough with it to figure out how to do it correctly, kept hitting from one error to another.

Setting up x86_64 VM I had an almost-success, but I couldn't get LibreELEC to boot all the way to Kodi itself. I assume that I would need to do GPU passthrough to get it fully working, but I'm using an optimus laptop, and neither of its GPUs appear to work for that purpose.

It's probably the most convenient to create sub folder in the build folder with build/armhf/ for the Pi and build/x86_64/ for the x86 build.

I had the exact same idea as well. moonlight.py could resolve the cpu architecture and then run the build at correct folder. Need to do similar thing for launch_moonlight-qt.sh. Although that file has only small variations between PI4 and x86_64, so maybe there the variations could be encapsulated to separate files, e.g. config.<arch>.sh? Those files could then be sourced from launch_moonlight-qt.sh.

Could you verify that both uname -m and python3 -c 'import platform; print(platform.machine())' print out armhf on LE? I could use those to resolve the architecture when needed.

veldenb commented 3 years ago

Setting up x86_64 VM I had an almost-success, but I couldn't get LibreELEC to boot all the way to Kodi itself. I assume that I would need to do GPU passthrough to get it fully working, but I'm using an optimus laptop, and neither of its GPUs appear to work for that purpose.

I figured that the LibreELEC Virtual build only supports VmWare Player because of the limited graphic drivers in the builds. Qemu doesn't work well at the moment.

I had the exact same idea as well. moonlight.py could resolve the cpu architecture and then run the build at correct folder. Need to do similar thing for launch_moonlight-qt.sh. Although that file has only small variations between PI4 and x86_64, so maybe there the variations could be encapsulated to separate files, e.g. config.<arch>.sh? Those files could then be sourced from launch_moonlight-qt.sh.

Sounds like a plan :)

Could you verify that both uname -m and python3 -c 'import platform; print(platform.machine())' print out armhf on LE? I could use those to resolve the architecture when needed.

It seems uname has a quirk for the Pi, it display's armv7l which is incorrect:

# python3 -c 'import platform; print(platform.machine())'
armv7l
# uname -m
armv7l

# uname -a
Linux kodi 5.10.27 #1 SMP Wed May 26 21:48:22 CEST 2021 armv7l GNU/Linux

It tried other methods from the platform module but the output wasn't very useful.

A better alternative seems to be the values from the device-tree:

# cat /proc/device-tree/compatible
raspberrypi,4-model-bbrcm,bcm2711

or

# cat /proc/device-tree/model
Raspberry Pi 4 Model B Rev 1.4
jhakonen commented 3 years ago

Looks like those paths do not exist in x86_64:

# cat /proc/device-tree/compatible
cat: can't open '/proc/device-tree/compatible': No such file or directory
# cat /proc/device-tree/model
cat: can't open '/proc/device-tree/model': No such file or directory

What about /etc/os-release? I got following:

# cat /etc/os-release
NAME="LibreELEC"
VERSION="9.95.4"
ID="libreelec"
VERSION_ID="10.0"
PRETTY_NAME="LibreELEC (official): 9.95.4"
HOME_URL="https://libreelec.tv"
BUG_REPORT_URL="https://github.com/LibreELEC/LibreELEC.tv"
BUILD_ID="04dc864eeba97cee2d5375981f898ea246440a21"
LIBREELEC_ARCH="Generic.x86_64"
LIBREELEC_BUILD="official"
LIBREELEC_PROJECT="Generic"

Could LIBREELEC_PROJECT's value be used as the folder/file name?

veldenb commented 3 years ago

Looks more promising :) I think LIBREELEC_PROJECT looks like the best candidate for now because there is a big chance the Pi4 moonlight-build will also work on the Pi3 and maybe below.

# cat /etc/os-release
NAME="LibreELEC"
VERSION="9.95.4"
ID="libreelec"
VERSION_ID="10.0"
PRETTY_NAME="LibreELEC (official): 9.95.4"
HOME_URL="https://libreelec.tv"
BUG_REPORT_URL="https://github.com/LibreELEC/LibreELEC.tv"
BUILD_ID="04dc864eeba97cee2d5375981f898ea246440a21"
LIBREELEC_ARCH="RPi4.arm"
LIBREELEC_BUILD="official"
LIBREELEC_PROJECT="RPi"
LIBREELEC_DEVICE="RPi4"

Edit: I tried running moonlight-qt on a Pi 3 today, the GUI works but it fails on starting a stream. It looks like using accelerated video output is causing problems (it may need X11). So for now I will only focus on testing the Pi 4.

jhakonen commented 3 years ago

Sorry for the delay, have had quite a hot weather here lately and I haven't had enough energy to do much of anything on my free time. But, here's the PR finally: https://github.com/veldenb/plugin.program.moonlight-qt/pull/2

veldenb commented 3 years ago

No problem, I will try to review en test your PR this week.

veldenb commented 3 years ago

Your code runs great! I refactored some scripts and updated the readme and language files to reflect the changes. The new build (v0.1.0) runs on my Pi4 and my LibreELEC Virtual VMWare machine (x86). Can you check if it still works (updating and running) on your device? If it does I can release the build :)

plugin.program.moonlight-qt.zip

jhakonen commented 3 years ago

Good to hear :)

I gave it a test and the plugin, including updating, seems to be working great. :+1: