RTSP url can't display stream, even when mainloop is running.

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

RTSP url can't display stream, even when mainloop is running.

rhythm87
I'm using Python Bindings of Gstreamer to create a RTSP Server Instance which
will generate an RTSP url for the incoming stream. As far I know,
GObject.MainLoop() is a blocking loop (correct me if I'm wrong), So I'm
trying to run MainLoop inside the child thread instead of Main Thread of
Process.
Now, If I initialise all required paramaters like RTSPServer, MediaFactory,
MainLoop etc, inside the overridden `run()` method and start the MainLoop
Instance, RTSP url displays the stream. But, on quitting the MainLoop from
Main Thread of process, `mainloop.is_running()` returns False. But if the
url was being open , mainloop.quit() doesn't notify the client and it
continues to stream.

And, if I initialise parameters like context, mainloop, RTSPServer inside
the constructor and just call mainloop.run() inside the overridden `run()`
method, RTSP url doesn't play the stream, even though mainloop.is_running()
returns True.

I can't understand the reason for either of the two cases.
Please tell what is it I could be doing wrong?

Regards,
Rhythm



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

Re: RTSP url can't display stream, even when mainloop is running.

hhony
Sounds like you're asking about threading issues rather than gstreamer. Might
be different, but a thread is_running would be valid for the scope of the
thread.. when it falls out of scope it would not be True anymore. I can't
say for sure if that's your issue.. as I don't entirely understand how
you're overridding 'run()'.. unless you're using Python 'def' to redefine it
somehow..

As far as I can tell GStreamer requires a mainloop instance to be running
before you use your pipeline. What I've done in the past is create a
MainLoop object, and then use threading.Thread.start to start a thread
around MainLoop.run function, prior to starting the pipeline.

Basic example of what I'm describing:

import gi
gi.require_version('Gst', '1.0')
from gi.repository import GLib, Gst
from threading import Thread

mainloop = GLib.MainLoop()
Gst.init(None)

loop_thread = Thread(target=mainloop.run, args=())
loop_thread.start()

.. do your pipeline stuff here while mainloop is running..

loop_thread.stop()
exit()



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

Re: RTSP url can't display stream, even when mainloop is running.

rhythm87
I understood the thing, you are trying, but here, mainloop.quit() is never
called, instead you are directly killing the thread in which mainloop is
running, without quitting the mainloop. But as per GObject.MainLoop
documentation. MainLoop must be quitted using mainloop.quit().

Moreover, this works fine. But since I have the gstreamer pipeline for the
RTSPServer , In order to start and stop the server before killing my main
process, I needed to attach GObject.MainContext with it, which I then need
to add to MainLoop as well. So when I do so, running mainloop.run() inside
the child thread as you are doing here won't play the stream at the
generated rtsp url.

Hope I was clear enough to explain the scenerio.

Regards,
Rhythm



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

Re: RTSP url can't display stream, even when mainloop is running.

Nicolas Dufresne-5
Overall, the server activity is not explicitly stopped by quitting the mainloop. You have to shut it down yourself.

Le 2 mars 2018 04:27, "rhythm87" <[hidden email]> a écrit :
I understood the thing, you are trying, but here, mainloop.quit() is never
called, instead you are directly killing the thread in which mainloop is
running, without quitting the mainloop. But as per GObject.MainLoop
documentation. MainLoop must be quitted using mainloop.quit().

Moreover, this works fine. But since I have the gstreamer pipeline for the
RTSPServer , In order to start and stop the server before killing my main
process, I needed to attach GObject.MainContext with it, which I then need
to add to MainLoop as well. So when I do so, running mainloop.run() inside
the child thread as you are doing here won't play the stream at the
generated rtsp url.

Hope I was clear enough to explain the scenerio.

Regards,
Rhythm



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

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

Re: RTSP url can't display stream, even when mainloop is running.

hhony
In reply to this post by rhythm87
Rhythm, I didn't claim it was perfect code.. just example code. :) Exiting
the interpreter would garbage collect those objects.. however, fair point
about 'mainloop.quit()'.

So, when I worked with RTSP last it was in C++.. not python.. but the
mapping looks the same:
https://lazka.github.io/pgi-docs/GstRtspServer-1.0/mapping.html

If I understand you correctly, you're saying 'MainLoop.get_context()' isn't
working for you? Or you seem to think you need MainContext before you
construct the MainLoop.. I don't follow your MainContext statement.. but
it's described here:
https://lazka.github.io/pgi-docs/GLib-2.0/classes/MainLoop.html

To do what you're proposing - I assume it would be similar to:

import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import GLib, Gst, GstRtspServer
from threading import Thread

mainloop = GLib.MainLoop()
Gst.init(None)

loop_thread = Thread(target=mainloop.run, args=())
loop_thread.start()

print('mainloop is running ', mainloop.is_running())

# can't you just attach it? - work for me.
rtsp = GstRtspServer.RTSPServer.new()
id = rtsp.attach(mainloop.get_context())

# this should return an ID higher than '0'
print('MainContext id: ', id)

.. other things here ..

loop_thread.stop()
exit()




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

Re: RTSP url can't display stream, even when mainloop is running.

rhythm87
In reply to this post by Nicolas Dufresne-5
So, do u mean that quitting the mainloop doesn't make any difference?

And moreover, my main concern is, when the run the mainloop with context
attached to it in seperate thread , why does there is no stream on the
serving rtsp url of the RTSPServer. And if I run the mainloop within the
main thread of process, there appears the stream  but since mainloop is
blocking, the only way to shutdown the server is to kill the process using
pid.

Can you please explain this phenomenon?

Regards
Rhythm



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

Re: RTSP url can't display stream, even when mainloop is running.

rhythm87
If someone is interested in how I got it resolved. Following is the answer.
The main reason for stream not appearing was initially, I was pushing custom
`GObject.MainContext` using GObject.MainContext.push_thread_default() into
the main thread while starting mainloop inside the child thread.

So, the only thing I needed to do was to call
GObject.Maincontext.push_thread_default() inside the child worker method.
And it worked.

Although a silly one, but did took quite a time for me to figure out.
Hope it helps someone.

Regards,
Rhythm



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel