moonlight-embedded is a moonlight client designed for embedded low-power devices.
Luna is a Moonlight launcher script for Kodi.
You can now install Luna from the official CoreELEC Nightly repository.
Go to Addons → Install from repo → CoreELEC Nightly repo → Program addons → Luna.
If you are using v19 Matrix, download latest version that starts with script.luna from TheChoconut/Luna github (link above).
Install Luna in Kodi: Addons → Install from ZIP → script.luna.zip
(v18 only, Matrix users SKIP THIS STEP) Click “Setup Moonlight PKG” (Luna settings → Helper → Setup Moonlight PKG), this will download the latest version of moonlight to your tvbox and setup any permissions required.
Follow the instructions on-screen to setup your Host IP address.
Click on Pair Host and enter the code on your host machine. Set your wanted settings (resolution, framerate, etc.)
If there is any crashing, try disabling TheGamesDB provider:
Luna settings → Helper → Enable TheGamesDB as Game Information Provider (leave unchecked)
Your game library is available in “Games”. Clicking on a game will launch the game.
Gratz for the effort.
And bump for visibility.
Myself can’t help on development (lack of skills),
but a moonlight (and/or steam) client is more than welcome.
I did a build of moonlight a little while ago, didn’t have to use any outside stuff or add anything. I think just one network related package needed to be bumped.
using the osmc stuff can also cause issues with playback. since there are differences between the version of the library used by each project.
What compiler did you use for compiling moonlight?
Where could I locate libopus, libenet on CoreELEC?
What version of libamcodec were you using for compilation?
When I use libamcodec from CoreELEC, moonlight won’t accept libmoonlight-aml.so because /usr/lib/libamcodec.so: undefined symbol: audio_decode_set_pre_mute.
My first assumption would be missing libavutils or libamadec, but the CoreELEC build of libamcodec doesn’t require those. When I use OSMC’s version, it works just fine.
For now I consider these two packages unimportant, my main concern is libamcodec as this library is managing video output and how moonlight communicates to aml video drivers. I’m not sure how this one is getting built, I only saw CoreELEC is pulling it from your own sources but it originates from amlogic sites. How exactly are you getting the source code for libamlogic? And does that library work just fine or not? In my case it doesn’t want to load it at all because of missing symbols… Does it work for you?
I have checked out some issues of moonlight-embedded on github and found the solution for constant codec failures that kept disabling the video output and making the stream stutter. Applied the fixes from sdl decoder to amlogic and now it doesn’t drop any frames!
I have very good connection and I almost cannot experience frame drops. I am still not sure how good my coding skills are since this was my first attempt at doing this. Even though I do know programming, I never did anything close to this so I would need someone to test with wifi connections or something that can drop frames.
I will drop footage on Dropbox and more details on how to grab experimental version tmrw.
1080p60 was working on both H264 and H265 codec.
I have published experimental binaries of moonlight-embedded on Dropbox, it would be nice if you can checkout with poor wifi connection to see how the decoder performs (or doesn’t work at all).
I still wanna know if I could get libopus and libenet from /usr/lib? Where are these located on a CoreELEC installation? Also could you try updating libamcodec to osmc version? Or if not, I’d like to know what’s the build process for the current one. I only saw you are downloading prebuilt sources from your own site.
Seems unfortunate that there are no testers yet. I don’t think its so dangerous to run this.
Anyways, I have now added a script.luna addon to Dropbox, which is modified from the original to work with this experimental build. I did not build libraries so it cannot find hosts on its own, you have to write the host IP address and pair with code. After that it should be working fine.
I have also tried to remove the limitation of modifying LD_LIBRARY_PATH but unfortunately it has to be modified to load the modules because it always looks at /usr/lib before anything else and it always loads libamcodec.so from there instead of using the one I prepared which works fine.
The only solution is to update the libamcodec to a version that will work w/ moonlight or to remove it from /usr/lib or somehow find a linker workaround to not search in /usr/lib.
Best fix would be to implement moonlight back in CoreELEC repo and make it an optional addon which would simplify everything. With moonlight we could also add luna launcher so its easier to load games directly from Kodi. Before that happens, this binary has to be tested on multiple devices.
Installed it via Luna, but unfortunately I get an error if I want to change audio settings and nothing happens when I want to add a host.
Is there a log file anywhere I can give you?
Actually not sure about Luna. Could you try doing it manually, non-luna way?
I am still trying to understand the code structure of Luna.
If you are able to, provide kodi.log with debug logging enabled and click on controller settings, audio settings and add host. With that I can see what does and what doesn’t.
I can confirm… The luna script is the only thing not working. I’m not able to add the host. ‘Pairing failed… Try again’ loop. Using the same ip (known working setup) alongside the manual method works fine. It’d be good to have a working graphical interface though. I’ll see if I can help with that as having to connect via SSH each time is just so cumbersome imho.
Just noticed this in the logs… “Could not load advanced pairing manager. Reason: ImportError(‘No module named M2Crypto’,)”
I’m having a hard time getting m2crypto installed. I’m assuming that’ll solve the pairing screen dialog not showing for luna script’s interface. Even if I pair via SSH first… Luna script won’t make a connection using the pre-authenticated handshake. Any advice?
Tried installing m2crypto via PIP, since Coreelec doesn’t have OPKG installed by default and has purged useful repositories. Anyway I get this:
Defaulting to user installation because normal site-packages is not writeable
Collecting m2crypto
Using cached M2Crypto-0.36.0.tar.gz (1.1 MB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/storage/.opt/tmp/pip-install-0kZIu4/m2crypto/setup.py’"’"’; file=’"’"’/storage/.opt/tmp/pip-install-0kZIu4/m2crypto/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ egg_info --egg-base /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj
cwd: /storage/.opt/tmp/pip-install-0kZIu4/m2crypto/
Complete output (8 lines):
running egg_info
creating /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info
writing requirements to /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info/requires.txt
writing /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info/PKG-INFO
writing top-level names to /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info/top_level.txt
writing dependency_links to /storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info/dependency_links.txt
writing manifest file ‘/storage/.opt/tmp/pip-pip-egg-info-ZXWqNj/M2Crypto.egg-info/SOURCES.txt’
error: [Errno 2] No such file or directory
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Well, after a couple days of work… I managed to fixup an older version of luna script; the ‘Discovery Service’ breaks things on the newer iteration of Luna script - along with many other things. Anyway, I made a few UI inclusions to fit my need. Polished off some stuff, and fixed a few more things. Luna script is so outdated to the point it is broken on coreelec. Like the game image scraper stuff, override resolution settings, dependencies we can’t satisfy because no OPKG repo’s… Broken or not fit for use. So I removed them using alternatives where possible.
I am very sorry for not replying sooner, I am trying to focus on other things and I forgot to check out this forum. On my device I managed to fix Luna scripts but I did some hard-coding so that’s probably why its only working for me.
Please tell me what version did you use for Luna. In my opinion, this is a far more superior version of Luna as you can use whatever viewtype your skin supports. Maybe I could port this to Game section of Luna 18, and we could then ask CoreELEC team to add this as a package! When this happens, we wouldn’t have to use /storage/moonlight hardcoded and make the Luna launch scripts more cross-platform.
Thanks for the supportive words. I used Luna Script 1.6.3 as the base… Yeah I thought that too. The interface seems (imho) nicer than the newer versions, especially as it does support themes rather well.
Here’s some of the changes I made:
-Added my own solution for host pairing with ui prompts (requires ‘screen’… entware/opkg) - Pairing is accessible from the default location > Settings > Streaming > Pair host… This could be ‘an official package’ show stopper…
-Refined and optimized shell and python scripts to start stream after systemctl stop kodi. Otherwise you lose some input devices and performance is negatively affected.
-Added resume session support with prompts
-Added quit game support; with prompts when attempting to run a different game whilst a stream is still active…
-Added zerotier Switch… Starts zerotier on game launch and prior to stream if enabled (requires ‘zerotier-one’… entware/opkg)
-Disabled/hidden the broken online ‘Scraper’ stuff by default and prevented it from spamming Kodi logs… Geforce experience does that stuff for you anyway and is retrieved upon entering the ‘Games’ area.
-Reworked how the launch scripts obtains user defined app settings; since the untouched original didn’t pass those arguments properly, despite being user configurable.
-Hardcoded “-audio sysdefault” flag at launch scripts to fix no audio on stream.
-Remote Audio / Local Audio and NOPS flags prevent a stream from initiating. Instant close. Not sure what’s causing this. Binary related? Definitely not Luna Script’s fault. Removed for time being.
Probably a few more minor fixups; but I cannot for the life of me remember; wasn’t keeping track. Guilty as charged.
I’m just need (want) to alter a few resources then I’ll share it here. As mentioned above… The few additional software pre-requisites might be a show stopper for the ‘Official’ status? Perhaps we can figure something out.
@smg04 - I’ve removed my dependency on ‘screen’ for moonlight in order to keep the core app operational without relying on a 3rd party binary to do so; aside from zerotier, ofcoarse (non-core). I opted to use ‘screen’ at the time as a substitute for openvt (not available to coreelec) for it’s ability to detach and run as a daemon; along with capturing session output at any given time through command. The latter being handy for obtaining moonlight’s generated pairing PIN (as it is displayed). I later discovered why the original pairing library was broken, and have fixed it. Then just rewrote things to get rid of ‘screen’ altogether. I ended up translating 99% of the shell related scripts that existed into python code/calls… Moonlight-heartbeat is the only one that made it.
I do need to report an anomaly relating to moonlight though…
Every now and then moonlight will lock up to black screen early on initiating a connection. Logs are cut short and moonlight hangs in an unresponsive state. Sometimes you can recover with (START + SELECT + LB + RB - if quick enough), and when you cannot, you are forced to reboot via SSH. Have you noticed this? ‘systemctl stop kodi’ doesn’t visibly start Coreelec’s interface back up either, and ‘pkill moonlight’ seems to do nothing to. SSH is still responsive though. Pretty frustrating.
Trying to gracefully handle it but it’s really difficult to catch and recover from in a clean manner.
I kind of get the feeling the problem is related to the audio interface failing to attach properly. Moonlight’s logs sometimes spew ALSA audio related errors over and over, and you can sometimes hear the audio crunching during the beginning of a stream.
Anyway. I’ll keep investigating, pehaps you can to. You might have already seen it. I’ll try and collect some better logs with debugging enabled.
I did not notice moonlight failing to connect and not closing, I have noticed a black screen and alsa decoder errors and sound sometimes getting broken. I didn’t check out sound at all and I have no idea why it could fail.
You should always be able to kill moonlight and then restart kodi. This should be working. At worst you may have to set the disable_video flag to 0.
The only moment it really won’t work is if the display crashes and this is the problem echo 0 > /sys/class/video/disable_video.
Sometimes amvideo will just get disabled and this is most of the times shown in the logs. I have no idea when does this disable_video flag get set to 1. I think I noticed it when the decoder crashes. I still am not sure because the decoder API is not really well documented.
I have just updated the moonlight-embedded on GitHub.
I checked out a few codes and did an experiment and found out that when Kodi is stopped, disable_video flag will be set to 1. Because I think that flag is the only reason why video output wouldn’t work, I added a few lines that will set the flag to 0 before the stream is started. After the stream is stopped, the disable_video flag is set back to 1, but I might instead set it to the state it was in before moonlight was started. I also fixed a memory leak with the frame buffer. The memory leak was small but its better to be safe.
I have tested out and played a game on 1080p60 and I didn’t notice any black screens. I did notice short stutters and I am not sure what causes them. Most likely its the decoder that can’t keep up and I am not sure how I can stop that from happening.
On Dropbox you will find the compiled version of this binary that will patch disable_video flag and memory leak. Just extract it to /storage/moonlight and the rest stays the same. Continue runinng moonlight in debug mode. In case you get the codec to reset or black screen, please send logs so we can see if anything can be done about that.
I would really like to see what you did with Luna. This latest version I am running seems to be broken most of the times even though I tried to patch it. For now I keep running it from the console and everything seems to work fine. Recommended way to “pause” and “continue” Kodi while you start a game from Luna is to use: killall -STOP kodi.bin and killall -CONT kodi.bin. These seem to work just fine, but important notice is that Kodi must release the AMLCodec so the playback has to be stopped to get moonlight to work. If Kodi plays anything in the background it is probably utilizing AMLCodec for decoding and then moonlight cannot use it to decode the stream.