Using gst-python with multiple pipelines

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

Using gst-python with multiple pipelines

Gary Thomas
I'm trying to build a Python (GUI) application which will need
multiple gstreamer pipelines active simultaneously.  I'm using
wxPython as the basis for my GUI.  Currently, I have a window
which has multiple (4) sub-panes.  If I try to create a pipeline
for each of those panes, sometimes it works, more often it fails,
typically with glib or free() errors which tells me this is a
multi-thread-safe problem.

Is this the right place to get help for my issue?
Is there something special, wrt threads, that I need to do to
make my application safe?

Thanks for any advice

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Using gst-python with multiple pipelines

Tim-Philipp Müller-2
On Wed, 2012-03-21 at 16:39 -0600, Gary Thomas wrote:

> I'm trying to build a Python (GUI) application which will need
> multiple gstreamer pipelines active simultaneously.  I'm using
> wxPython as the basis for my GUI.  Currently, I have a window
> which has multiple (4) sub-panes.  If I try to create a pipeline
> for each of those panes, sometimes it works, more often it fails,
> typically with glib or free() errors which tells me this is a
> multi-thread-safe problem.
>
> Is this the right place to get help for my issue?
> Is there something special, wrt threads, that I need to do to
> make my application safe?

So you're displaying 4 videos from 4 pipelines in that window, one per
pane?

What do you use as video sink(s)?

 Cheers
  -Tim

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

Re: Using gst-python with multiple pipelines

Gary Thomas
On 2012-03-21 17:00, Tim-Philipp Müller wrote:

> On Wed, 2012-03-21 at 16:39 -0600, Gary Thomas wrote:
>
>> I'm trying to build a Python (GUI) application which will need
>> multiple gstreamer pipelines active simultaneously.  I'm using
>> wxPython as the basis for my GUI.  Currently, I have a window
>> which has multiple (4) sub-panes.  If I try to create a pipeline
>> for each of those panes, sometimes it works, more often it fails,
>> typically with glib or free() errors which tells me this is a
>> multi-thread-safe problem.
>>
>> Is this the right place to get help for my issue?
>> Is there something special, wrt threads, that I need to do to
>> make my application safe?
>
> So you're displaying 4 videos from 4 pipelines in that window, one per
> pane?

Let's make sure we agree on terminology
   window = Top level X window (the kind of thing that can be minimized, etc)
   pane = a writeable subsurface within the window (which has a unique ID)

If we agree, then yes, that's what I want to do.  I've found that if I start
the videos separately, i.e. in "human" time by selecting and clicking, then
everything works well.  It only fails if I try to create the pipelines all
at once whilst creating the basic window+panes.

> What do you use as video sink(s)?

Not sure I understand the question.  I'm adapting some code I found
on the web which uses gst pipelines + wxPython (which was adapted from
the wxGTK version).

I create the pipeline like this
         self.player = gst.element_factory_make("playbin", "player")
         self.playing = False
         bus = self.player.get_bus()
         bus.add_signal_watch()
         bus.enable_sync_message_emission()
         bus.connect('message', self.on_message, colour)
         bus.connect('sync-message::element', self.on_sync_message, colour)
within the code that creates the pane.  Then I initiate the pipeline with
         self.player.set_property('uri',"file://" + path)
         self.player.set_state(gst.STATE_PLAYING)
         self.playing = True

I'm happy to share my actual code if that helps - it's currently just
a sandbox for ideas anyway.

Thanks for your help

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Using gst-python with multiple pipelines

Bruno Gonzalez-2
I'm having similar problems, with pipelines failing when their creation overlap, and always succeeding otherwise.

What errors do you get if you enable DEBUG logs?
What gstreamer versions are you using?

On Thu, Mar 22, 2012 at 00:51, Gary Thomas <[hidden email]> wrote:
On 2012-03-21 17:00, Tim-Philipp Müller wrote:
On Wed, 2012-03-21 at 16:39 -0600, Gary Thomas wrote:

I'm trying to build a Python (GUI) application which will need
multiple gstreamer pipelines active simultaneously.  I'm using
wxPython as the basis for my GUI.  Currently, I have a window
which has multiple (4) sub-panes.  If I try to create a pipeline
for each of those panes, sometimes it works, more often it fails,
typically with glib or free() errors which tells me this is a
multi-thread-safe problem.

Is this the right place to get help for my issue?
Is there something special, wrt threads, that I need to do to
make my application safe?

So you're displaying 4 videos from 4 pipelines in that window, one per
pane?

Let's make sure we agree on terminology
 window = Top level X window (the kind of thing that can be minimized, etc)
 pane = a writeable subsurface within the window (which has a unique ID)

If we agree, then yes, that's what I want to do.  I've found that if I start
the videos separately, i.e. in "human" time by selecting and clicking, then
everything works well.  It only fails if I try to create the pipelines all
at once whilst creating the basic window+panes.


What do you use as video sink(s)?

Not sure I understand the question.  I'm adapting some code I found
on the web which uses gst pipelines + wxPython (which was adapted from
the wxGTK version).

I create the pipeline like this
       self.player = gst.element_factory_make("playbin", "player")
       self.playing = False
       bus = self.player.get_bus()
       bus.add_signal_watch()
       bus.enable_sync_message_emission()
       bus.connect('message', self.on_message, colour)
       bus.connect('sync-message::element', self.on_sync_message, colour)
within the code that creates the pane.  Then I initiate the pipeline with
       self.player.set_property('uri',"file://" + path)
       self.player.set_state(gst.STATE_PLAYING)
       self.playing = True

I'm happy to share my actual code if that helps - it's currently just
a sandbox for ideas anyway.

Thanks for your help


--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



--
Saludos,
     Bruno González

_______________________________________________
Jabber: stenyak AT gmail.com
http://www.stenyak.com

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

Re: Using gst-python with multiple pipelines

Tim-Philipp Müller-2
In reply to this post by Gary Thomas

Hi,

> Not sure I understand the question.  I'm adapting some code I found
> on the web which uses gst pipelines + wxPython (which was adapted from
> the wxGTK version).
>
> I create the pipeline like this
>          self.player = gst.element_factory_make("playbin", "player")
>          self.playing = False
>          bus = self.player.get_bus()
>          bus.add_signal_watch()
>          bus.enable_sync_message_emission()
>          bus.connect('message', self.on_message, colour)
>          bus.connect('sync-message::element', self.on_sync_message, colour)
> within the code that creates the pane.  Then I initiate the pipeline with
>          self.player.set_property('uri',"file://" + path)
>          self.player.set_state(gst.STATE_PLAYING)
>          self.playing = True
>
> I'm happy to share my actual code if that helps - it's currently just
> a sandbox for ideas anyway.

Yes, a small example that demonstrates the issue would definitely be
useful.

What I was trying to find out was if you are using (for example)
ximagesink, or perhaps some other video sink or perhaps appsinks.

X11/Gtk doesn't do multi-threading well, so one must take care not to do
anything X11/Gtk related from GStreamer streaming threads (like a sync
message handler).

Cheers
 -Tim

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

Re: Using gst-python with multiple pipelines

Gary Thomas
On 2012-03-22 04:20, Tim-Philipp Müller wrote:

>
> Hi,
>
>> Not sure I understand the question.  I'm adapting some code I found
>> on the web which uses gst pipelines + wxPython (which was adapted from
>> the wxGTK version).
>>
>> I create the pipeline like this
>>           self.player = gst.element_factory_make("playbin", "player")
>>           self.playing = False
>>           bus = self.player.get_bus()
>>           bus.add_signal_watch()
>>           bus.enable_sync_message_emission()
>>           bus.connect('message', self.on_message, colour)
>>           bus.connect('sync-message::element', self.on_sync_message, colour)
>> within the code that creates the pane.  Then I initiate the pipeline with
>>           self.player.set_property('uri',"file://" + path)
>>           self.player.set_state(gst.STATE_PLAYING)
>>           self.playing = True
>>
>> I'm happy to share my actual code if that helps - it's currently just
>> a sandbox for ideas anyway.
>
> Yes, a small example that demonstrates the issue would definitely be
> useful.

Should I send it to this list or you directly?  Currently it's very
raw and around 200 lines.

>
> What I was trying to find out was if you are using (for example)
> ximagesink, or perhaps some other video sink or perhaps appsinks.

I'm just using the simple 'playbin'

> X11/Gtk doesn't do multi-threading well, so one must take care not to do
> anything X11/Gtk related from GStreamer streaming threads (like a sync
> message handler).

Here's my sync_message handler:
     def on_sync_message(self, bus, message, data):
         print "on_sync_message: " + data
         if message.structure is None:
             return
         message_name = message.structure.get_name()
         if message_name == 'prepare-xwindow-id':
             imagesink = message.src
             imagesink.set_property('force-aspect-ratio', True)
             imagesink.set_xwindow_id(self.GetHandle())

I tried moving the GetHandle() call which is the only X11 function
I can see out of the sync handler and it didn't change the behaviour.

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Using gst-python with multiple pipelines

Gary Thomas
On 2012-03-22 04:39, Gary Thomas wrote:

> On 2012-03-22 04:20, Tim-Philipp Müller wrote:
>>
>> Hi,
>>
>>> Not sure I understand the question. I'm adapting some code I found
>>> on the web which uses gst pipelines + wxPython (which was adapted from
>>> the wxGTK version).
>>>
>>> I create the pipeline like this
>>> self.player = gst.element_factory_make("playbin", "player")
>>> self.playing = False
>>> bus = self.player.get_bus()
>>> bus.add_signal_watch()
>>> bus.enable_sync_message_emission()
>>> bus.connect('message', self.on_message, colour)
>>> bus.connect('sync-message::element', self.on_sync_message, colour)
>>> within the code that creates the pane. Then I initiate the pipeline with
>>> self.player.set_property('uri',"file://" + path)
>>> self.player.set_state(gst.STATE_PLAYING)
>>> self.playing = True
>>>
>>> I'm happy to share my actual code if that helps - it's currently just
>>> a sandbox for ideas anyway.
>>
>> Yes, a small example that demonstrates the issue would definitely be
>> useful.
>
> Should I send it to this list or you directly? Currently it's very
> raw and around 200 lines.

I've put my program at http://www.mlbassoc.com/misc/gstreamer_demo.py
To run it, you'll need wxPython
To see the failure, enable the 'if False' on line 178.  You'll also need
to change the paths in the 3 following lines to be valid video files on
your system.

Try it - sometimes it runs, most times it just crashes randomly on startup.

>>
>> What I was trying to find out was if you are using (for example)
>> ximagesink, or perhaps some other video sink or perhaps appsinks.
>
> I'm just using the simple 'playbin'
>
>> X11/Gtk doesn't do multi-threading well, so one must take care not to do
>> anything X11/Gtk related from GStreamer streaming threads (like a sync
>> message handler).
>
> Here's my sync_message handler:
> def on_sync_message(self, bus, message, data):
> print "on_sync_message: " + data
> if message.structure is None:
> return
> message_name = message.structure.get_name()
> if message_name == 'prepare-xwindow-id':
> imagesink = message.src
> imagesink.set_property('force-aspect-ratio', True)
> imagesink.set_xwindow_id(self.GetHandle())
>
> I tried moving the GetHandle() call which is the only X11 function
> I can see out of the sync handler and it didn't change the behaviour.
>

--
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel