FD- / RPiPlay

An open-source AirPlay mirroring server for the Raspberry Pi. Supports iOS 9 and up.
GNU General Public License v3.0
4.91k stars 355 forks source link

stop and restart server when gstreamer window is closed (missing callback is added) #263

Closed fduncanh closed 2 years ago

fduncanh commented 2 years ago

antimof's UxPlay fork of RPiPlay (which was backported into RPiPlay) did not include the required callback from the Gst bus when the gstreamer window was closed. This leaves the server running, including audio, without video. This pull request adds the missing callback, so when the gstreamer window is closed, the server is stopped and relaunched. ctrl-c in the terminal window will fully stop rpiplay in the usual way.

This fix is backported from the updated UxPlay at https://github.com/FDH2/UxPlay . and has been adjusted for the multiple renderers in RPiPlay.

  1. The call to sleep(1) (between checks for sigint signals while the server is running) is first moved into a new video function bool video_renderer->func->listen(video_renderer). This leaves the behavior of rpiplay unchanged for all renderers.

  2. for the gstreamer renderer, the callback is then implemented only in video_renderer_gstreamer_listen(renderer).

If something similar would be useful for rpi, it could be implemented in video_renderer_rpi_listen, which now just uses the sleep(1) call,

This pull request is completely independent of my other pull request #266 from a different github account.

fduncanh commented 2 years ago

The code in this PR has been replaced by a GLib MainLoop as of UxPlay 1.35 at http://github.com/FDH2/UxPlay.

FD- commented 2 years ago

Do you still want me to merge this in? Why are you restarting the server in case the window was closed? IMHO, we should either: 1) Stop the server when the window was closed, or 2) restart just the renderer, which should be possible by just changing the gstreamer renderer, without adding the listen callback.

What do you think?

fduncanh commented 2 years ago

The callback is essential. In the mode being used, gstreamer is opaque. I'll look and see if I can just restart the two renderers and leave the raop running.

I moved on after using this fix to a full g-mainloop in uxplay 1.3x but that doesn't fit well with the RPi renderers.

fduncanh commented 2 years ago

To summarize: gstreamer is being used in an opaque way: the raop server has no way to know the mirror window was closed, without a callback. When the window is closed, there are two possible ways to proceed (1) shut down everything (2) tell the client to close the connection, shut down the renderers, and wait for a new connection. I don't see any way to implement (2) other than shutting down and restarting the raop server.

If you think (1) is what you want, just tell me. Its trivial to implement. Please give the answer soon. Once this PR is pulled, I can use this Github account to feed you the API changes I would like, in small chunks for your review.


One issue is that in my setup at least, the mDNS-SD registration quickly becomes "stale" when the server has no connection. Only clients that are already seeking a connection at the time the server registers with avahi see the service. To counter this I gave uxplay1.3x an option to shut down and restart the server after a specified period with no connections, so it could be running in an "always available " mode. I am sure this shouldn't need to be done, but don't know why (that in my experience) the server becomes unavailable for connection attempts after a short period of inactivity.

fduncanh commented 2 years ago

@FD- If my PR's are useful, please let me know ASAP whether you want rpiplay to terminate when the gstreamer window is closed, or restart the server. (its your baby). What happens when the window produced by the RPi renderer is closed? IMHO it is better to relaunch, but you are the boss.

If this PR can be disposed of ASAP, I can use this GitHub account FDH2 to feed you the proposed improvements/ corrections to the AirPlay library in small digestible chunks, if you are willing to consider them.

fduncanh commented 2 years ago

I will redo this to shut down the server when the gstreamer window is closed and submit a new pull request.