FD- / RPiPlay

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

Callback to terminate rpiplay when the gstreamer mirror window is closed by the user #291

Closed fduncanh closed 2 years ago

fduncanh commented 2 years ago

@FD- @pallas Following FD-'s comment on the older PR for this:

"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?"

My thoughts:

(1) Now just stop the server when the GStreamer Mirror window is closed by the user. This could later be changed to some other outcome that stops the connection and the renderers, without stopping the server, but this would be more complex to achieve.

The callback is needed because otherwise the opaque nature of the GStreamer window means that there is no way for the server to know that the GStreamer window was closed, and know that it needs to stop the connection.

The fix is achieved in two commit steps:

(i) move the "sleep(1) call into a simple callback that just sleeps 1 second then returns false. (If "true" is returned, break out of the while loop would occur, but this will never happen at this point.) The modification preserves the while loop behavior that ensures that receiving SIGINT or SIGTERM will cause a cleanup and stop the server. All three renderers, (rpi, gstreamer , and dummy) get such a callback.

At the same time a missing "static" attribute is added to the gstreamer renderer functions, for consistency with the "static" attribute of the rpi and dummy renderer functions.

This first commit does not change how rpiplay works.

(ii) In the second commit, video_renderer_gstreamer.c is given a bus on which to listen for a window-closing event. The bus is interrogated every 0.1 seconds (100msec) . If a window-closing event has happened, the callback now returns "true", which breaks out of the while loop in main of rpiplay.cpp, causing a cleanup and shutdown; otherwise, it returns "false" as before.

fduncanh commented 2 years ago

@FD- I messed up the "squash", so I just resubmitted as #292, in line with your comments above