[Unofficial] moonlight-embedded

yeah, so I am at the same issue.
I can’t see the digits to enter because the dialogue box is in the way.
I tried entering random digits on my PC after reading that a few messages back, but my device then offers me the option to try again or quit. I don;t get the option on my PC to enter the correct code :frowning:
I had already tried dmesg and tail -f kodi.log but see that code doesn;t appear until after that stage is cancelled.
So is there anyway to bypass the randomizer section of the script and manually set the 4digit pin on my device? (edit2clarify - pehaps setting the code to always be 1234 pehaps?)

for completeness I’m sporting 9.2.5 on a s905x2 device (A95X F2) running from SD card.

edit2add.
nvm. I ssh’d to device and executed “moonlight pair” and I could see the code to enter. pairing was successfull. I have briefly loaded into a game and it worked, albeit with no audio. I will keep prodding

another issue is now that I have quit the game (cyberpunk 2077, the only game I have on my laptop, I am seeing my desktop streamed to my device)

edit2add2
I have quickly installed another game (Borderlands 2) and when quitting the game, I am retruned back to the kodi GUI, so it looks like it is an issue with CyberPunk not exitting cleanly.

Still no audio over hdmi though. I will test using a USB soundcard I have (I have 3 different types to pick from)

unrelated to initial querie but worthy of a mention, the streaming is quite laggy. I would say it is delayed by approx 0.5 seconds. I have raised the bitrate in the luna settings but didn;t notice an improvement. Definitely noticeable compared to rebooting to android and using the steam link app

Audio problems: If audio works in Kodi, it probably will work in moonlight too. If you are using surround audio, I think none of the setups currently work, but I will look into it. Surround should be working but I can’t test it because I don’t have a surround setup at home. Otherwise, stereo should be working, BUT you may need to set the correct Audio Device (this can be done in Luna settings panel, test every option until it works).

Video problems: I am not sure about Amlogic-ng builds, but my device doesn’t support moonlight in Amlogic-ng build, only Amlogic build works. I have to find out what has changed in libamcodec and if there’s anything I can do to fix it. Depending on the complexity of the scene, Amlogic-ng gets more broken and broken and it looks like latency builds up A LOT. I tried with a full black video on Youtube, and the latency increased to seconds! It’s very unusual behaviour so if that’s what you’re experiencing, it’s currently broken.
There can also be latency with audio problems, I experienced latency when audio was broken.

fairly sure the s905x2 is amlogic-ng. I know I always need to download a different version to my s912 box.
Cheers for the heads up regarding codecs. I had tried playing around with the backend audio system but didn’t touch the codecs. I will try again alter when I have a bit more time

Hi everyone!

Luna 0.6.6.4~alpha uploaded… Fix attempt at pairing pin not returning for those affected.

Notice: The in-app update service seems to be broken for the time being… Please update manually until I get this fixed.

Github Release: https://github.com/stickman89/Luna/releases/tag/v0.6.6.4-alpha
Direct Download: https://github.com/stickman89/Luna/releases/download/v0.6.6.4-alpha/script.luna-0.6.6.4-alpha.zip

Changelog:

*     Periodically flush stdout whilst moonlight pairing process is still alive.

Let me know whether this fixes your pairing problems… Until then. Wishing everyone a merry Xmas.

Best Regards,

stickman89

Unfortinatly i’m unable to test it right now, cause i don’t have a coreelec box atm. I gave it to my brother.
I only have my Vero4k+ Box for now.
But idk if it will be working.

Hello everyone!

Long changelog

I’ve been working on moonlight-embedded since upgrading to Kodi Matrix. That also means I had to upgrade to Amlogic-ng build, which doesn’t work as good as Amlogic build for moonlight-embedded.

The exact same code, different branch --> performance changes from good to very bad.
I’ve been experimenting a lot with the codec and found out that adding PTS support should fix the performance issues. So I’ve added a one line fix that feeds libamcodec with moonlight-embedded’s internal PTS value. Performance greatly improved, latency is now much less noticeable. BUT, it is still present.

I recommend to increase packet size to at least 1536 bytes in order to bypass the optimized decoder changes that can decrease performance on higher resolutions. Also, I’ve found out that the decoder might not keep up with higher resolutions because dynamic_buf_num_magin is set to a too low number.

Updated moonlight_experiment.tar.gz with all the mentioned changes. Should increase performance in both branches, please test & give feedback.

TL;DR moonlight_experiment.tar.gz updated for better performance. Test it and give feedback.
Check out the first post to see how to install experimental version.
Thank you for testing!
@wodgey as reported, I can confirm the latency was high. The old version had latency >1s. Can you try testing this version?

1 Like

Curious about this new version… In what area’s are improvements expected? Above 1080P resolutions or all round improvements?

Also. The us to ms conversion confuses me. If I have 31us latency. That equates to 0.031ms? Is that even right? On Android it’s around 21ms. I think Android 9 does improve latency even further, but 0.031ms can’t be right.

The latency is very inaccurate, it’s basically the amount of time it took to write the frame to the decoder. I still haven’t figured out the correct way to calculate it… I think I’m supposed to read it from the codec API. But I don’t want to modify many things. First I want to see how this performs.

I cannot test 4K, so I cannot report how it performs. I have added pts support which reduced latency and added support for new/old code. Old code (every packet is directly sent to decoder) is used for higher packet sizes. The “optimized” algorithm is copying all the packets to one frame buffer and sending all those bytes at once to the codec. I’ve decided to use this method as testing has shown decoder doesn’t like many calls with small packet sizes.

Cool. Good to hear you’ve got some ideas for optimisations. So, to test those commits should I be using the experimental build?

Exactly, testing is done via experimental build. Stable build isn’t updated. So check out first post, do everything as specified and give feedback.

Still can’t pair with latest version. Is not showing code.

Dear @kodiwpigulce_pl, I have updated the moonlight binary which will now flush output for this pairing process to work. Please, use internal Luna’s Setup Moonlight PKG or ssh into the box and run the command (its the same thing). After that, try pairing again. It should work now.

For everyone else, I’d like to mention the latest experimental update is now switched to the stable version. Please test the binaries. My internal testing has shown that there is almost no way to decrease latency anymore (or its not worth it). From now on, I will only update moonlight for bug fixes.

1 Like

You are right. It’s working. Thanks!

1 Like

Hello!
It’s been some days since the last update of moonlight-embedded. How is everything working? Latency etc. any good?

I have been researching surround audio and found out why it doesn’t work. Apparently, amlogic doesn’t support 6 audio channels, only 2 or 8 audio channels. So when launching with -surround option, it is broken because moonlight-embedded only works with 6 channels which amlogic driver doesn’t support. The workaround is to force 8 channels and make unused channels silent, but this workaround is not implemented in moonlight-embedded. I am working on a fix, but I’m not sure if I’m capable of doing that.
At least now the steps to reproduce bug have been found.

Thank you everyone for testing!

Hi,
just switched my khadas vim to coreelec for this.
Sadly i cant get it working.

When i try to pair with my pc i get the code displayed in kodi and the popup on my pc but after entering the code kodi seems to be stuck, i have waited 15 minutes after i restarted kodi using ssh.

After starting the addon again it displayed my games tho.
Sadly i can’t get the stream working either.

After lauchning a game from kodi, the game will launch on the pc. Kodi will display the intro animation but the game auto closes after arround 5 seconds and on my coreelec box the screen stays black.

2021-02-19 14:08:19.954 T:3678655360  NOTICE: [script.luna] [CoreService] - initialized
2021-02-19 14:08:20.007 T:3678655360  NOTICE: [xbmcswift2] Request for "/games/launch/Steam" matches rule for function "launch_ga
2021-02-19 14:08:20.226 T:3678655360  NOTICE: [script.luna] Launching game Steam
2021-02-19 14:08:20.232 T:3678655360  NOTICE: [script.luna] [ConfigHelper] - Dumped config to disk.
2021-02-19 14:08:20.328 T:4089111104  NOTICE: VideoPlayer::OpenFile: /storage/.kodi/addons/script.luna/resources/statics/loading.
2021-02-19 14:08:20.329 T:3611292544  NOTICE: Creating InputStream
2021-02-19 14:08:20.333 T:3611292544  NOTICE: Creating Demuxer
2021-02-19 14:08:20.476 T:3611292544  NOTICE: Opening stream: 0 source: 256
2021-02-19 14:08:20.476 T:3611292544  NOTICE: CVideoPlayerVideo::OpenStream - Creating codec: 27
2021-02-19 14:08:20.479 T:3611292544  NOTICE: Creating video thread
2021-02-19 14:08:20.479 T:3602899840  NOTICE: running thread: video_thread
2021-02-19 14:08:20.480 T:3611292544  NOTICE: Opening stream: 1 source: 256
2021-02-19 14:08:20.480 T:3611292544  NOTICE: Finding audio codec for: 86018
2021-02-19 14:08:20.481 T:3611292544  NOTICE: CDVDAudioCodecFFmpeg::Open() Successful opened audio decoder aac
2021-02-19 14:08:20.481 T:3611292544  NOTICE: Creating audio thread
2021-02-19 14:08:20.482 T:3594507136  NOTICE: running thread: CVideoPlayerAudio::Process()
2021-02-19 14:08:20.502 T:3594507136  NOTICE: Creating audio stream (codec id: 86018, channels: 2, sample rate: 48000, no pass-th
2021-02-19 14:08:20.522 T:3602899840  NOTICE: CAMLCodec::OpenDecoder - using V4L2 pts format: 64Bit
2021-02-19 14:08:20.717 T:4089111104  NOTICE: Whitelist search for: width: 1920, height: 1080, fps: 60.000, 3D: false
2021-02-19 14:08:20.717 T:4089111104  NOTICE: Display resolution ADJUST : 1920x1080 @ 60.00 - Full Screen (16) (weight: 0.000)
2021-02-19 14:08:30.318 T:3594507136   ERROR: CDVDAudio::AddPacketsRenderer - timeout adding data to renderer
2021-02-19 14:08:30.911 T:4089111104   ERROR: Control 50 in window 10001 has been asked to focus, but it can't
2021-02-19 14:08:30.912 T:4089111104  NOTICE: CVideoPlayer::CloseFile()
2021-02-19 14:08:30.912 T:4089111104  NOTICE: VideoPlayer: waiting for threads to exit
2021-02-19 14:08:30.912 T:3611292544  NOTICE: CVideoPlayer::OnExit()
2021-02-19 14:08:30.913 T:3611292544  NOTICE: Closing stream player 1
2021-02-19 14:08:30.913 T:3611292544  NOTICE: Waiting for audio thread to exit
2021-02-19 14:08:32.128 T:3594507136   ERROR: CDVDAudio::AddPacketsRenderer - timeout adding data to renderer
2021-02-19 14:08:32.129 T:3594507136  NOTICE: thread end: CVideoPlayerAudio::OnExit()
2021-02-19 14:08:32.130 T:3611292544  NOTICE: Closing audio device
2021-02-19 14:08:33.135 T:3611292544   ERROR: CActiveAE::FreeStream - failed
2021-02-19 14:08:33.136 T:3611292544  NOTICE: Deleting audio codec
2021-02-19 14:08:33.138 T:3611292544  NOTICE: Closing stream player 2
2021-02-19 14:08:33.138 T:3611292544  NOTICE: waiting for video thread to exit
2021-02-19 14:08:33.183 T:3602899840  NOTICE: thread end: video_thread
2021-02-19 14:08:33.183 T:3611292544  NOTICE: deleting video codec
2021-02-19 14:08:33.229 T:4089111104  NOTICE: VideoPlayer: finished waiting
2021-02-19 14:08:33.229 T:4089111104  NOTICE: CVideoPlayer::CloseFile()
2021-02-19 14:08:33.230 T:4089111104  NOTICE: VideoPlayer: waiting for threads to exit
2021-02-19 14:08:33.231 T:4089111104  NOTICE: VideoPlayer: finished waiting

I am running CoreELEC stable (9.2.5) with the luna 6.6.4 on a Khadas VIM1.
I have tested moonlight on my windows laptop sucessfully so i dont think my desktop is the issue.

Thank you for testing. Please provide moonlight.log, kodi doesnt provide useful information about moonlight crashing…

Thanks for the reply :wink:
i have found “/storage/moonlight/moonlight.log” but it is empty…

CoreELEC:~/moonlight # ls -l
total 847
-rw-r--r--    1 1000     1000         58753 Nov  1 10:03 gamecontrollerdb.txt
-rwxrwxrwx    1 root     root         38480 Aug 19  2020 libenet.so.7
-rwxrwxrwx    1 root     root        132572 Aug 19  2020 libgamestream.so.4
-rwxr-xr-x    1 1000     1000         27440 Jan 12 17:06 libmoonlight-aml.so
-rwxrwxrwx    1 root     root        139892 Aug 19  2020 libmoonlight-common.so.                                                             4
-rwxrwxrwx    1 root     root        320876 Aug 11  2020 libopus.so.0
-rwxr-xr-x    1 1000     1000        145232 Jan 12 17:06 moonlight
-rw-r--r--    1 root     root           270 Feb 20 10:49 moonlight.conf
-rw-r--r--    1 root     root             0 Feb 20 10:49 moonlight.log

Am i looking at the wrong file? I even enabled moonlight debug output in the addons settings.


so as i couldnt get logging working here is the verbose output from executing moonlight using ssh access, maybe this helps as well?

Pairing:

INFO: i got the pairing info on the desktop and the response in the shell, tho moonlight would not quit on its own. I had to “CTRL-C” it. Put pairing was successful as i could list and start streams afterwards.
Maybe this is the issue why the addon didnt dismiss the pairing dialog as the executed command didnt stop.

List:

Launching App:

C:\ProgramData\NVIDIA Corporation\NvStream\NVStreamerCurrent.log:
https://bin.snopyta.org/?afb4eccb46d044f4#DubtksVxbANF6pfsmb6qBeTmCWooH8ZYZC6FHTon7QzH


I have attached the NvStream log as well after searching for the RTSP Options Request Failed: 552 error online. As it list several issues with HEVC not beeing supported i changed the moonlight configuration from h265 to h264. And well now it worked. Tho i had to repair moonlight again first.

after i stopped the working h264 stream i could get it working again yet, same rtsp issue…


Another Update…
I got it working… somehow. Played arround alot with settings and firewall and then i paired my system again using ssh and this time the process ended automatically… after this the addon worked perfectly as well (h265 and h264) opening, closing and resuming streams…

what are the limitations tho of a 905X board like the khadas vim? I couldnt get smooth 60fps streams working. 30fps games works great but with 60fps title you can really see its no running a smoothly as it should.
Any idea how to tweaks settings a bit more? (PC and VIM are connected through ethernet, not WIFI)

So it looks like you got into an unfortunate problem with networking or smth like that, I’ve never seen an RTSP error, so it was probably something with your firewall or possibly your PC’s firewall decided to block VIM from connecting to moonlight. If you’re using the latest version, this is the last thing I did before dropping the video part as there are no more simple changes to be done.

This embedded client sends every built frame to the amlogic decoder as-is. There are no mechanisms to drop a frame in order to reduce latency or anything like that. On my S905D system though, 60 fps was working but it does drop frames sometimes. It’s not designed for e-sports titles or anything like that. I didn’t do any back-to-back testing with my other system to see how the latency compares with the latest versions. Try switching between h264 and h265 and see what works best for you. H265 should work better.

Yeah i guess it was my system config in the end… but weird that it worked fine with moonlight on my laptop.
Seems to be stable now tho and surving reboots as well.

Input lag is no issue.
30fps streaming works great, almost never drops below that. 60fps is another topic tho, framerate is very inconsistent and ranging betwenn 40-60fps on coreelec. Changing between 720p or 1080p stream doesnt change this. No dropped frames because of connection (atleast thats what luna is reporting).

Im not looking on running e-sports titles :wink: mainly want to use this for emulating games that wont work natively like gamecube/wii/wii u and stuff like that.
Made my test using a 60fps jump and run and sadly this ruins the experience with streaming with 60fps, better to switch to 30 as it is more consistent.

H265 definatly works a bit better, noticed this as well. Playing arround with bitrate settings made it worse as far as i have tried yet :slight_smile:

As I saw from logs it is using alternative decoding algorithm, which helps the whole code run on some unsupported devices. Now @stickman89 designed Luna for Kodi Leia, which I see you are using, but lately I haven’t heard from him and he hasn’t updated some things. I have updated to Kodi Matrix and updated Luna for Matrix with many many other optimizations. Because Leia addon is not yet update, try the following.

When you write ./moonlight you will see a help screen.
If parameter -altdecalgorithm is on the list, try using that algorithm for small packet sizes. To use the algorithm, just specify it in the parameter list, as in:
./moonlight stream Steam -1080 -fps 60 -altdecalgorithm
If the algorithm is not specified, then you are already using it now. Then try increasing the packet size.