Closed fnoop closed 4 years ago
Need to work out how to access the RTSPMedia created by RTSPMediaFactory and set reusable to true.
If the RTSPMediaFactory is set to shared, and the RTSPMedia is set to reusable, then the subclassed factory no longer tears down the pipeline and can be shared by multiple clients. However, after the last client has disconnected the media seems to be destroyed, or no longer useable. There needs to be a way to block this from happening, or else recreating the factory once the media is unuseable. Either we can try to look at factory client callbacks, or a more brute force approach might be to create a client connection from within the server so no matter what external clients do there will always be a connected client to prevent the media from being pulled down.
https://github.com/GStreamer/gst-rtsp-server/tree/master/docs https://lazka.github.io/pgi-docs/GstRtspServer-1.0/classes/RTSPMediaFactory.html https://lazka.github.io/pgi-docs/GstRtspServer-1.0/classes/RTSPMedia.html https://lazka.github.io/pgi-docs/GstRtspServer-1.0/classes/RTSPServer.html https://github.com/gkralik/python-gst-tutorial
Listen to clients being removed, and then if this is the last client destroy the server, release the resources and recreate:
self.rtspsessions = self.rtspserver.get_session_pool()
self.rtspsessions.connect("session_removed", self.on_rtspsession_removed)
All seems very unnecessary - why can't it just keep the pipeline alive and wait for the next client?
* TEARDOWN
A TEARDOWN request will first locate the GstRTSPSessionMedia of the URL. It
will then remove all transports from the streams, making sure that streaming
stops to the clients. It will then remove the GstRTSPSessionMedia and
GstRTSPStreamTransport objects. Finally the GstRTSPSession is released back
into the pool.
When there are no more references to the GstRTSPMedia, the media pipeline is
shut down (with _unprepare) and destroyed. This will then also destroy the
GstRTSPStream objects.
This implies that if we can create a reference to GstRTSPMedia and hold it, then the media pipeline will stay intact.
OK creating a fake client works - it holds open the constructed media object forever, at the expense of some CPU usage. Will do for now.
Once a successful connection and stream is made, any subsequent connections fail: