How to create a RTSP Server that immediately starts the pipeline and reuses it in Python

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to create a RTSP Server that immediately starts the pipeline and reuses it in Python

Peter Gerten
Hi,

I have and RTP source that I want to republish using a RTSP server.
I am using the python code below for it. The problem I have: The pipeline only gets created after the first client connects. But then I have an issue with my RTP source not being ready at the same time.
What I want: start the pipeline immediately, even if no client is connected (and then reuse it; what should already be the case).
I do not understand what actually triggers the creation of the pipeline. It seems to be somehow implicitly done via the RTSPMediaFactory?

------------------------------
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GObject, GstRtspServer

GObject.threads_init()
Gst.init(None)


class RTSP_Server:
    def __init__(self):
        self.server = GstRtspServer.RTSPServer.new()
        self.address = '172.17.0.4'
        self.port = '8554'
        self.launch_description = '( udpsrc port=6784 caps="application/x-rtp,payload=96,config-interval=1" ! rtph264depay ! rtph264pay name=pay0 pt=96 )'
        self.server.set_address(self.address)
        self.server.set_service(self.port)
        self.server.connect("client-connected",self.client_connected)
        self.factory = GstRtspServer.RTSPMediaFactory.new()
        self.factory.set_launch(self.launch_description)
        self.factory.set_shared(True)
        self.factory.construct('/video')
        self.factory.set_transport_mode(GstRtspServer.RTSPTransportMode.PLAY)
        self.mount_points = self.server.get_mount_points()
        self.mount_points.add_factory('/video', self.factory)

        self.server.attach(None) 
        print('Stream ready')
        GObject.MainLoop().run()

    def client_connected(self, arg1, arg2):
        print('Client connected')

server = RTSP_Server()
------------------------------

Regards

Peter

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to create a RTSP Server that immediately starts the pipeline and reuses it in Python

Peter Gerten
Does anybody have an idea on how to solve this?
Basically I need to have a pipeline that runs all the time and is (re-)used for clients of my RTSP server.

Peter

On Tue, Jul 19, 2016 at 11:04 PM, Peter Gerten <[hidden email]> wrote:
Hi,

I have and RTP source that I want to republish using a RTSP server.
I am using the python code below for it. The problem I have: The pipeline only gets created after the first client connects. But then I have an issue with my RTP source not being ready at the same time.
What I want: start the pipeline immediately, even if no client is connected (and then reuse it; what should already be the case).
I do not understand what actually triggers the creation of the pipeline. It seems to be somehow implicitly done via the RTSPMediaFactory?

------------------------------
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GObject, GstRtspServer

GObject.threads_init()
Gst.init(None)


class RTSP_Server:
    def __init__(self):
        self.server = GstRtspServer.RTSPServer.new()
        self.address = '172.17.0.4'
        self.port = '8554'
        self.launch_description = '( udpsrc port=6784 caps="application/x-rtp,payload=96,config-interval=1" ! rtph264depay ! rtph264pay name=pay0 pt=96 )'
        self.server.set_address(self.address)
        self.server.set_service(self.port)
        self.server.connect("client-connected",self.client_connected)
        self.factory = GstRtspServer.RTSPMediaFactory.new()
        self.factory.set_launch(self.launch_description)
        self.factory.set_shared(True)
        self.factory.construct('/video')
        self.factory.set_transport_mode(GstRtspServer.RTSPTransportMode.PLAY)
        self.mount_points = self.server.get_mount_points()
        self.mount_points.add_factory('/video', self.factory)

        self.server.attach(None) 
        print('Stream ready')
        GObject.MainLoop().run()

    def client_connected(self, arg1, arg2):
        print('Client connected')

server = RTSP_Server()
------------------------------

Regards

Peter


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: How to create a RTSP Server that immediately starts the pipeline and reuses it in Python

Tim Müller
On Wed, 2016-08-03 at 19:38 +0200, Peter Gerten wrote:

Hi Peter,

> Does anybody have an idea on how to solve this?
> Basically I need to have a pipeline that runs all the time and is
> (re-)used for clients of my RTSP server.

The simplest way to achieve this might be to just mark the rtsp media
factory as shared with gst_rtsp_media_factory_set_shared() and start
the first client yourself immediately after starting the server :)

Cheers
-Tim

--

Tim Müller, Centricular Ltd - http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel