FDH2 / UxPlay

AirPlay Unix mirroring server
GNU General Public License v3.0
1.53k stars 78 forks source link

uxplay running as root on a dedicated R Pi as a uxplay server ( Standby Image / Screensaver) #271

Closed hkfuertes closed 7 months ago

hkfuertes commented 7 months ago

I don't know if this is possible or not, but maybe it could be an enhancement.

I'm working on creating a prebuilt image of raspberry pi with no X11... for now I'm trying to boot to black (no luck so far) so that not transition happens when a device is connected, but I was wondering, can the uxplay be enhance with a "screensaver"?

I see 2 ways of doing this:

Maybe this is already implemented, if so, my apologies.

hkfuertes commented 7 months ago

Also, maybe a process is spawned when a device connects so that I could check with pgrep when it finishes. Is there a simple way of doing this?

fduncanh commented 7 months ago
  1. There is some discussion ( #269 ) of making uxplay a systemd item, but I think it's for a user, not root.

  2. Right now, uxplay only shows video when a mirror-mode connection is open. In Audio mode, if writes cover art to a file, but relies on an external image viewer process to reload the image every 1 sec.

hkfuertes commented 7 months ago

I think I found a solution/workaround... fbi (framebuffer image) on linux, can display image and text directly on the framebuffer. If I run it first, then after a disconnection it returns to the fbi command, effectively achieving what I want.

fduncanh commented 7 months ago

Interesting!

I guess you run it as a user who also runs uxplay?

hkfuertes commented 7 months ago

If you are interested, this is what I did: https://github.com/hkfuertes/UxPlay-Packer/blob/main/sources/uxplayfb.sh

That project repacks the Raspberry Pi image with UxPlay and adds a service to run that uxplayfb script on boot. It uses Packer. Now I'm trying to do the same but with buildroot.

fduncanh commented 7 months ago

Good work!

give us progress reports here!

fduncanh commented 7 months ago

I guess you could make fbi show the cover art if uxplay is in audio-only mode from apple music etc.

hkfuertes commented 7 months ago

Updates... I made buildroot build uxplay... but its complaining of some gstreamer plugins... I will try to continue on sunday. My first atempt is to make a qemu image and manually start uxplay. If/when that works I will make qemu work like the packer repository, and then y will pack a rpi image. Ill keep you posted.

I saw that the original RPIPlay has a -b option to make the screen black when nothing is playing... could that be implemented? I will look into your idea of displaying the cover art :)

thiccaxe commented 7 months ago

I wonder if you could make gsrreamer stream to a Unix socket, then use that as a proxy for another gstreamer instance that would actually display the image data

hkfuertes commented 7 months ago

If someone is interested, here is my defconfig. I'm able to run it! (its using kmssink) but the framerate is horrible. I'm running it in a rpi3. My guess is that I don't have v4l2h264dec enabled. For what I have read, this comes with the module bcm2835-codec. I'm still figuring out how to enable it in buildroot.

In fact with gst-inspect-1.10 video4linux2 I dont get the v4l2h264dec required (and obviously, uxplay -v4l2 complains it does not exist...)

If someone knows and can help? Once I have it running with the framerate acceptable (similar to oficial rpi image) I will make the repo public and continue working on the UI (as with the packer version)

raspberrypi3_64_defconfig.txt

btw, it requires dtoverlay=vc4-kms-v3d in config.txt

fduncanh commented 7 months ago

You didn't say what OS you are running. You are probably running R Pi OS bookworm Lite with GStreamer 1.22.x (which doesnt need patching), but the Wiki page on patching also discusses the bcm2835-code and how to see if you have it, https://github.com/FDH2/UxPlay/wiki/Gstreamer-Video4Linux2-plugin-patches#next-verify-that-you-have-a-complete-video4linux2-plugin

The kernel module bcm2835_codec is maintained by Raspberry Pi at https://github.com/raspberrypi/linux/tree/rpi-5.15.y/drivers/staging/vc04_services and is not in the mainline Linux kernel. It merely accesses the Broadcom firmware, which does the actual video decoding. Only Raspberry Pi OS and distributions available with Raspberry Pi Imager (Ubuntu, Manjaro) appear to have it. If you want to use this module, and your distribution does not supply it, you need to build and use a kernel with the Raspberry Pi kernel source: instructions for this are beyond the scope of this guide.

hkfuertes commented 7 months ago

haha, maybe I didn't explained myself, sorry for that... this issue is related to this other https://github.com/FDH2/UxPlay/issues/270. What I'm trying to do is to build a "dongle" using the raspberry pi, so that we could have a 20€ device that can replace the ATV (I intend to use it in my church, so that I can project the sunday songs from an ipad).

To achieve this what I want to do is have a pi that ONLY does this. I found that I could use the default factory image (Raspberry PI OS) with a program from Hashicorp (the ones behind Terraform) called Packer, to generate an image with UxPlay pre installed (https://github.com/hkfuertes/UxPlay-Packer). It worked! but it also loaded the whole OS, that I don't needed. So now I'm trying to build the OS around the UxPlay necesities to only have what its needed. My tests images with Buildroot (an embedded linux OS builder) are merely 128mb in size (and 51mb compressed).

Is in this images where I was able to run UxPlay, although as I said, only with software decoding. I'm figuring out now how to add this hardware decoding capabilities, how to make bcm2835-codec also have v4l2h264dec (because the bcm2835-code it DOES exists)

This current issue #271, Will be the next step. Once I have a stable build of buildroot (with wifi compatibility...) then I will continue to create a GUI, I don't yet know if via images and framebuffer or maybe something in QT... we'll see.

Sorry for the long message, I'm adding here this context, as you suggested to use this issue to track my progress. I guess I don't have any other query regarding this issue, and this ticket indeed can be closed whenever you want.

Regarding the original issue, yes, it could be nice if an option --screen-saver [video | image] could be implemented, or at least a -b as it had the original RPiPlay, But as I told you, the solution / work around works for now.

hkfuertes commented 7 months ago

Its not finished yet, but if you guys want to have a look, I made it public: https://github.com/hkfuertes/UxPlay-Buildroot

hkfuertes commented 7 months ago

Latest commit got it working... I was missing some modules from rpi firmware.

fduncanh commented 7 months ago

The option -dacp creates a file $HOME/.uxplay.dacp that exists only during connections. Its absence could be used to trigger a "screensaver" when no connection exists?

*EDIT: the .uxplay.dacp file contains information that can be used by a remote control to connect to the active client, but could be used for your purpose too.

thiccaxe commented 7 months ago

You could just buy a second hand Apple TV generation 3, I got one for 10-15 USD with shipping

(Keep doing what you are doing! But this will probably give you an easier experience. In case you are in a time crunch)

hkfuertes commented 7 months ago

Yes, I know, hahahaha, but this is more fun. I just made it work (nothing fancy), but I built the image for the Pi3 and the Pi0W, and both of them work flawlessly (the zero using an ethernet dongle). Im now figuring out the audio, and the Wifi.

Then I will do the GUI. @fduncanh Thanks for the heads up, I will investigate that, adding a file watcher and launching the screensaver (with the name and pin) or the connection itself.

Thank you for the help :)

fduncanh commented 7 months ago

Nice work! closing now, but feel free to add more comments

hkfuertes commented 7 months ago

If anyone wants to try I made the first release: https://github.com/hkfuertes/UxPlay-Buildroot/releases/tag/0.0.1b

Barebone ISO images for Raspberry PI. It will boot to sh root user (password: toor). See release notes for more info (wifi, usb, audio, etc...). You will need to run uxplay manually...

Now that this is done, I will work on flutter to add a nice UI.