[Unofficial] moonlight-embedded

[Update]

  • updated moonlight-embedded to the latest upstream with new Amlogic optimizations
  • experimental hdr support
  • update launchscripts for new decoder updates

script.luna-1.2.0-matrix.150.zip (2.7 MB)

If i try this version in CE 20 beta 1, it crashes :frowning:

Does Luna crash or moonlight when you run it through ssh?
I think executable flag is not set correctly on all files causing it to crash… Try running launchscripts again.

I updated from 19.5 rc2 to 20 beta 1 but can’t connect via SSH to test, if moonlight itself is crashing. I need to fix the ssh problem first. I guess installing CE 20 from scratch is better than updating from 19 to 20.

[quickfix]

  • fix a bug where sometimes stream is not displayed and screen is black

script.luna-1.2.0-matrix.151.zip (2.7 MB)

Hi smg04. I was able to fix my ssh issue and did some tests:

All of your scripts are still not working on my CE 20 beta 1 setup. Only the script / version from luizkun ( script.luna.1.44_modded_2.zip) is working (but i need to copy the libcrypto.so.1.1 file to the lib folder first).

I tried all launch scripts of your version, but none of these fix my issue. I see the games list and if I start one of them, my controller disconnects and nothing is starting. I see still the overview of the luna options (quickplay and so on). I need to reconnect the controller and pressing the disconnect combination to return to KODI.

So what has luizkun added/changed in his launch script, compared to your included launch scripts? Can you maybe add the launch script of luizkun also in your release? Just copy the launch script from his version to your latest release did not work for me (see 2nd logfile output)

Here is the output of the logfile:

Request https://192.168.0.152:47984/launch?uniqueid=0123456789ABCDEF&uuid=13db7364-c796-4ddb-88af-3881f89df179&appid=84297552&mode=2560x1440x60&additionalStates=1&sops=0&rikey=3220ee031039c678542f8a867c1ccdca&rikeyid=1858382939&localAudioPlayMode=0&surroundAudioInfo=196610&remoteControllersBitmap=0&gcmap=0
Response:
<?xml version="1.0" encoding="UTF-16"?><root protocol_version="0.1" query="launch" status_code="200" status_message="OK"><DisplayHeight>720</DisplayHeight><DisplayWidth>1280</DisplayWidth><EnhancedStreamMode>1</EnhancedStreamMode><HdrMode>0</HdrMode><RefreshRate>60</RefreshRate><avkey>ok</avkey><gamesession>4a3acf05c891a901ef4a4241c3e3b0ae</gamesession><rikey>ok</rikey><sessionUrl0>rtsp://192.168.0.152:48010</sessionUrl0><wssignaling>0</wssignaling></root>

Stream 2560 x 1440, 60 fps, 80000 kbps
RTSP port: 48010
Initializing platform...done
Resolving host name...done
Initializing audio stream...done
Starting RTSP handshake...Audio port: 48000
Video port: 47998
Control port: 47999
done
Initializing control stream...done
Initializing video stream...done
Initializing input stream...done
Starting control stream...done
Starting video stream...Using display thread for amlvideo pipeline
done
Starting audio stream...done
Starting input stream...done
Received first audio packet after 0 ms
Initial audio resync period: 500 milliseconds
Received first video packet after 0 ms
Detected Wireless Controller (050000004c050000e60c000000810000) on /dev/input/event2 as Sony DualSense 
Detected Wireless Controller Motion Sensors (050000004c050000e60c000000810000) on /dev/input/event3 as Sony DualSense 
Ignoring accelerometer: Wireless Controller Motion Sensors
Assigned Wireless Controller as player 1
Detected Wireless Controller Touchpad (050000004c050000e60c000000810000) on /dev/input/event4 as Sony DualSense 
Not mapping Wireless Controller Touchpad as a gamepad
Stopping input stream...done
Stopping audio stream...ENet wait interrupted
Control stream connection failed: -1
done
Stopping video stream...Display thread terminated
done
Stopping control stream...ENet peer acknowledged disconnection
done
Cleaning up input stream...done
Cleaning up video stream...done
Cleaning up control stream...done
Cleaning up audio stream...done
Cleaning up platform...done

If i copy the launch script from luizkun to your latest release, i get the following output in the log file:

Moonlight Embedded 2.5.3 (AML;ALSA;PULSE;EMBEDDED)
Connecting to 192.168.0.152...
Request http://192.168.0.152:47989/serverinfo?uniqueid=0123456789ABCDEF&uuid=81a20254-c8dd-484d-bec4-056f5c1fabd2
Response:
<?xml version="1.0" encoding="UTF-16"?><root protocol_version="0.1" query="serverinfo" status_code="200" status_message="OK"><AuthenticationType>1</AuthenticationType><ConnectionState></ConnectionState><CurrentClient>0</CurrentClient><GfeVersion>3.26.0.154</GfeVersion><GsVersion>gs_04_46_31648965</GsVersion><HttpsPort>47984</HttpsPort><LocalIP>192.168.0.152</LocalIP><LocalIPs><Address>192.168.0.152</Address></LocalIPs><LoginState>2</LoginState><MaxLumaPixelsH264>1721324928</MaxLumaPixelsH264><MaxLumaPixelsHEVC>1869449984</MaxLumaPixelsHEVC><Mode>0</Mode><PairStatus>0</PairStatus><ServerCapability>3895</ServerCapability><ServerCodecModeSupport>3843</ServerCodecModeSupport><ServerColorSpaceSupport>2</ServerColorSpaceSupport><SupportedDisplayMode><DisplayMode><Height>2160</Height><RefreshRate>60</RefreshRate><Width>3840</Width></DisplayMode><DisplayMode><Height>2160</Height><RefreshRate>30</RefreshRate><Width>3840</Width></DisplayMode><DisplayMode><Height>1080</Height><RefreshRate>60</RefreshRate><Width>1920</Width></DisplayMode><DisplayMode><Height>1080</Height><RefreshRate>30</RefreshRate><Width>1920</Width></DisplayMode><DisplayMode><Height>720</Height><RefreshRate>60</RefreshRate><Width>1280</Width></DisplayMode><DisplayMode><Height>720</Height><RefreshRate>30</RefreshRate><Width>1280</Width></DisplayMode></SupportedDisplayMode><accountId>975870C4CE165DDEFBAED96BAA87CA6C8B4F64EB359FD1A8E94376E0A14DE53C</accountId><appversion>7.1.446.0</appversion><currentgame>0</currentgame><gamelistid>e2208238775b4d12796e35a21350832e</gamelistid><gputype>NVIDIA GeForce RTX 2080 Ti</gputype><hostname>FUSION-WS</hostname><mac>D8:5E:D3:A2:57:C7</mac><numofapps>0</numofapps><resyncSuccessful>0</resyncSuccessful><state>MJOLNIR_STATE_SERVER_AVAILABLE</state><uniqueid>bb5763dd-2dd9-47d3-879c-f4659a192831</uniqueid></root>

Request https://192.168.0.152:47984/serverinfo?uniqueid=0123456789ABCDEF&uuid=30b21752-8a2e-4dc5-8fa5-c84533848be6
Response:
<?xml version="1.0" encoding="UTF-16"?><root protocol_version="0.1" query="serverinfo" status_code="200" status_message="OK"><AuthenticationType>1</AuthenticationType><ConnectionState></ConnectionState><CurrentClient>0</CurrentClient><GfeVersion>3.26.0.154</GfeVersion><GsVersion>gs_04_46_31648965</GsVersion><HttpsPort>47984</HttpsPort><LocalIP>192.168.0.152</LocalIP><LocalIPs><Address>192.168.0.152</Address></LocalIPs><LoginState>2</LoginState><MaxLumaPixelsH264>1721324928</MaxLumaPixelsH264><MaxLumaPixelsHEVC>1869449984</MaxLumaPixelsHEVC><Mode>0</Mode><PairStatus>1</PairStatus><ServerCapability>3895</ServerCapability><ServerCodecModeSupport>3843</ServerCodecModeSupport><ServerColorSpaceSupport>2</ServerColorSpaceSupport><SupportedDisplayMode><DisplayMode><Height>2160</Height><RefreshRate>60</RefreshRate><Width>3840</Width></DisplayMode><DisplayMode><Height>2160</Height><RefreshRate>30</RefreshRate><Width>3840</Width></DisplayMode><DisplayMode><Height>1080</Height><RefreshRate>60</RefreshRate><Width>1920</Width></DisplayMode><DisplayMode><Height>1080</Height><RefreshRate>30</RefreshRate><Width>1920</Width></DisplayMode><DisplayMode><Height>720</Height><RefreshRate>60</RefreshRate><Width>1280</Width></DisplayMode><DisplayMode><Height>720</Height><RefreshRate>30</RefreshRate><Width>1280</Width></DisplayMode></SupportedDisplayMode><accountId>975870C4CE165DDEFBAED96BAA87CA6C8B4F64EB359FD1A8E94376E0A14DE53C</accountId><appversion>7.1.446.0</appversion><currentgame>0</currentgame><gamelistid>e2208238775b4d12796e35a21350832e</gamelistid><gputype>NVIDIA GeForce RTX 2080 Ti</gputype><hostname>FUSION-WS</hostname><mac>D8:5E:D3:A2:57:C7</mac><numofapps>0</numofapps><resyncSuccessful>0</resyncSuccessful><state>MJOLNIR_STATE_SERVER_AVAILABLE</state><uniqueid>bb5763dd-2dd9-47d3-879c-f4659a192831</uniqueid></root>

GPU: NVIDIA GeForce RTX 2080 Ti, GFE: 3.26.0.154 (gs_04_46_31648965, 7.1.446.0)
Platform AMLogic VPU
Loading mappingfile gamecontrollerdb.txt
Detected Wireless Controller (050000004c050000e60c000000810000) on /dev/input/event2 as Sony DualSense 
Detected Wireless Controller Motion Sensors (050000004c050000e60c000000810000) on /dev/input/event3 as Sony DualSense 
Ignoring accelerometer: Wireless Controller Motion Sensors
Detected Wireless Controller Touchpad (050000004c050000e60c000000810000) on /dev/input/event4 as Sony DualSense 
Not mapping Wireless Controller Touchpad as a gamepad
Not mapping meson-ir as a gamepad
Not mapping cec_input as a gamepad
Ccodec_init amstream version : 2.0
EVIOCGRAB failed with error 16
Error: cannot keep up

I updated to coreelec20 and some of the nexus builds of luna and it was still very stuttery.

This N2+ has huge potential with the gpu having 4x the horsepower of the rpi4b gpu but its closed source driver performance is really bad comparatively. So it’s getting outperformed by something that is about 25% of it’s power.

I moved back to coreelec19.5 and the 151 matrix build posted 8 days ago and accidently removed my configs of luna. I discovered the pairing functionality is currently broken between luna and sunshine. Clearing out the configs of moonlight-qt on the pi and setting it up from scratch lets me know that the client and server side pairing still works, just not on the luna client. No matter which version of luna I use, it wont pair anymore. It just says pairing failed or already paired, it never generates a pairing code.

So current status seems to be not working at all, and if there are grand-fathered in pairing keys to make the pairing work, it doesnt perform well.

also, why is the coreelec repo version 143 and the current 151

You’re right about the version on repo, I just haven’t updated it since I still don’t have a stable version!

I really don’t like the fact that my device works but it doesn’t work on all CoreELEC devices and now devices outside are broken too.

If someone had the time, I would like someone to test a few configurations. But you should use the latest version so CoreELEC 20 would be required.

But as you’ve also noticed it, getting this to work is not easy since closed source means no documentation on why it is underperforming…

Also, RIP my box just died. So I can no longer test stuff :sob:

I can help you test, as my n2+ has been rotated out of use in favor of the pi4b as a gamestream reciever. I do *nix based dev-ops support irl so can probably help you develop to some extent if need be, i can do some scripting and packaging but cant code things as deep as C or rust

Just let me know

edit: In an earlier post you said you are just compiling for 20 now, but the latest post is script.luna-1.2.0-matrix.151.zip

matrix is 19, so is this mislabeled or this one really for 19? I think 20 is called nexus

matrix is added from the Luna version (the addon). The addon does not have anything new for nexus. It would probably be best if I removed matrix there so it was more clear.

Thanks, missed that!

For what it is worth, I can pair moonlight with sunshine from the cli

EDIT: I have managed to get a full blown stream up and going from cli with

moonlight stream -app Desktop -verbose -mapping /storage/.kodi/addons/script.luna/bin/gamecontrollerdb.txt -1080 -fps 60 -bitrate 15000 -codec h265 -audio hw:0,0

and manually running a few of the script lines

CoreELEC:~ # echo 1 > /sys/class/graphics/fb0/blank
CoreELEC:~ # echo 0 > /sys/class/video/disable_video
CoreELEC:~ # for X in /sys/bus/usb/devices/*

do
# echo “Discovered: $X”
if [ -e “$X/idVendor” ] && [ -e “$X/idProduct” ]
then
echo “Resetting device: $(cat “$X/idVendor”) : $(cat “$X/idProduct”)”
echo 0 >“$X/authorized”
echo 1 >“$X/authorized”
fi
done
Resetting device: 05e3 : 0610
Resetting device: 05e3 : 0620
Resetting device: 1d6b : 0002
Resetting device: 1d6b : 0003

(the 0 into framebuffer1 seems unneccessary)

Im not sure if it’s upstream updates to amlogic drivers or the new coreelec20, but 15mbps is much less stutter on the same cave i’ve been clearing over and over to test with in elden ring. Its only very slight now. We’re talking <5fps long stutters before to hiccups where it only hits 40 for a split second. It’s still much worse than where the pi4b stabilizes around 28mbps with only 25% of the horsepower, but with things being closed source, it kind of is what it is.

So I’ve tested things as far as getting moonlight-embedded and sunshine talking and a fully operational stream, its just the luna frontend doesnt seem to be getting any traction when it tries to do things. So things seem much less broken than they seemed earlier

1 Like

When these hiccups occur, do you see any output in the SSH? Does it drop audio packets or something like that?

Oh it’s constantly dropping audio stuff, it doesn’t seem to coincide with the frame rate drops though

hi. my first time with luna but getting error in host addres process (host addres working in other system). CE matrix and last addon downloaded from post

i am reading about manually connect but how to do?

greetings and thanks

1 Like

You have to SSH into the box and then manually Pair and start the moonlight stream

Sometimes I can get the luna addon working and sometimes I cant. Using coreelec 20 and the latest luna build from this thread. I have just been circumventing it and using the moonlight-embedded pacakged with luna manually, and someone asked what I was talking about and I gave a vague answer before. Here it is more fleshed out.

I have 3 script files that can be used to launch a stream after you have paired once before. (moonlight pair from cli)
manualmoonlight.tar.xz (384 Bytes)

moonlightlaunch.sh

#!/bin/bash
moonlight stream -app Desktop -mapping /storage/.kodi/addons/script.luna/bin/gamecontrollerdb.txt -1080 -fps 60 -bitrate 15000 -codec h265 -audio hw:0,0 >> logfile 2>&1
killall -STOP kodi.bin

moonlightfixes.sh

#!/bin/bash
echo 1 > /sys/class/graphics/fb0/blank
echo 0 > /sys/class/video/disable_video
for X in /sys/bus/usb/devices/*
    do
    # echo “Discovered: $X”
    if [ -e “$X/idVendor” ] && [ -e “$X/idProduct” ]
        then
        echo “Resetting device: $(cat “$X/idVendor”) : $(cat “$X/idProduct”)”
        echo 0 >“$X/authorized”
        echo 1 >“$X/authorized”
    fi
done

postscript.sh

#!/bin/bash
killall -CONT kodi.bin
echo 0 > /sys/class/graphics/fb0/blank

If you put each of these files on your coreelec box(doesnt matter where, I have them in /storage/ and make them executable(chmod +x filename) you can run them (./filename) in the order of moonlightlaunch.sh moonlightfixes.sh, and then postscript.sh when done. Doing this gets me 100% reliable functioning, but is kind of a pain to ssh into coreelec to start the streams each time.

There are a lot of things in the scripts for luna I have been unable to tell what they do or what difference they make, maybe this is where some of the instability is coming from. I looks like they are trying to set the default video decoder to amvideo manually, but it’s already amvideo

CoreELEC:~ # cat /sys/class/vfm/map 
[00]  default { decoder(0) amvideo}
[01]  dvblpath { dvbldec(0) amvideo}
[02]  dvelpath { dveldec(0) dvel}
[03]  dvhdmiin { dv_vdin(0) amvideo}

thus, all of this from pre seems not to do anything

##echo 1 > /sys/class/graphics/fb1/blank
echo "rm default" > /sys/class/vfm/map
echo "add default vdec.$2.00 amvideo" > /sys/class/vfm/map
##find /sys/bus/usb/devices/*/authorized -exec sh -c 'echo 0 > ${0}; echo 1 > ${0}' {} \;
python reset_hid.py

and all of this from post seems not to do anything

echo 0 > /sys/class/graphics/fb1/blank
echo "rm default" > /sys/class/vfm/map
echo "add default decoder ppmgr amlvideo deinterlace amvideo" > /sys/class/vfm/map
python reset_hid.py

switching framebuffer1 from 0 and 1 seems to do nothing. Framebuffer 0 is where all the action is. I also suspect that killing kodi.bin BEFORE launching the stream from the addon may be causing some instability. In my manual scripts I moved it to after the stream launches we kill kodi.bin.

Also, luizikin’s fix script that puts a 0 in framebuffer0 once a second for 11 seconds also seems unneccessary using my manual scripts. You just have to do it once. That script seems to be attempting to beat the instability coming from luna into submission

1 Like

This part of code was required before the new upstream changes because it forced the display code to output frames to display. It is no longer required. Now with the latest changes it should be only framebuffer that gets cleared (even though moonlight itself is clearing it).

Yeah i did some poking around with that file and it seems to add vdec.$codec on the fly, clearing default doesnt seem to help or hurt it, so i’ve just left it alone

I have a set of fully up to date scripts inside custom im testing luna with, but i am hitting the crux of the issue with the instability/non-starts

subprocess.run([scripts_path + 'prescript.sh', binary_path, codec], cwd=scripts_path, start_new_session=True)
            launch_cmd = subprocess.Popen([scripts_path + 'launch.sh', game_id], cwd=binary_path, start_new_session=True)
            launch_cmd.wait()
            subprocess.run([scripts_path + 'postscript.sh', binary_path], cwd=scripts_path, start_new_session=True)

The moonlight client is launched with launch_cmd, and it waits until the proccess exits to do anything else. Inside of launch, the moonlight proccess itself hangs open until it is closed and then it continues proccessing. So we’re stuck after start. The problem is the fixes need to be applied AFTER moonlight is brought up. I’ve been moving these lines around, adding sleep statements, etc, but they seem to execute serially. If i just manually run the fixes file i have, which is what luiziken was doing x11, everything works as intended.

This is not an issue manually executing because i can just
moonlight &
fixes
post

If we can solve this one then the functioning moonlight stream part is done. There’s still a pairing issue to track down though

Here is a working set of launchscripts as of 12/10/2022, I solved the “fixes after moonlight” problem by putting it in a function and forking the function into the background with a sleep 5 at the start. This may not be the cleanest way to do it, but it works reliably now.
praxis_scripts.zip (827 Bytes)

#!/usr/bin/bash

fixes(){
        sleep 5
        echo 1 > /sys/class/graphics/fb0/blank
        echo 0 > /sys/class/video/disable_video

        for X in /sys/bus/usb/devices/*
                do
                # echo “Discovered: $X”
                if [ -e “$X/idVendor” ] && [ -e “$X/idProduct” ]
                        then
                        echo “Resetting device: $(cat “$X/idVendor”) : $(cat “$X/idProduct”)”
                        echo 0 >“$X/authorized”
                        echo 1 >“$X/authorized”
                fi
                done
}

killall -STOP kodi.bin
fixes &
mv logfile logfile.old
moonlight stream -app "$@" >> logfile 2>&1
killall -CONT kodi.bin

I dont know about the pairing issue, that one sorted itself out randomly and ive not been able to reproduce it. but there was at least one other person that had ran into that issue in this thread