|
List Info
Thread: gtk and threads
|
|
| gtk and threads |

|
2006-08-29 14:01:08 |
hello
I'm using gstreamer for a small video analysis application
written in
gtk. I am trying to update the GUI with some information
about the
current frame of the video (i.e., the position of a tracked
target, ...).
To make it simpler, suppose I have a frame-counter plugin
and that I
want to show the current frame number in a GtkLabel. I can
think of two
ways of doing it:
1) have the frame-counter emit a custom signal with
the current
frame number, catch the signal from the application
and update
the label, or
2) have a GtkLabel property in the plugin, and
update if from
within the plugin on the _chain function.
Alas, none of the above work. When the pipeline is playing,
the
interface is frozen and does not repaint until the pipeline
is paused. I
tryed to queue_redraw() it, the I tryed with
gtk_main_iteration(), then
g_main_context_iteration(): they only make things worse
(deadlocks).
What can I do? What am I doing wrong?
thank you very much
alberto
--
ICQ#: 319420338
------------------------------------------------------------
-------------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to
make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/
sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstream
er-devel
|
|
| gtk and threads |

|
2006-08-29 14:40:53 |
On Tue, 2006-08-29 at 15:01 +0100, alberto colombo wrote:
> I'm using gstreamer for a small video analysis
application written in
> gtk. I am trying to update the GUI with some
information about the
> current frame of the video (i.e., the position of a
tracked
> target, ...).
>
> To make it simpler, suppose I have a frame-counter
plugin and that I
> want to show the current frame number in a GtkLabel. I
can think of two
> ways of doing it:
>
> 1) have the frame-counter emit a custom signal
with the current
> frame number, catch the signal from the
application and update
> the label, or
>
> 2) have a GtkLabel property in the plugin, and
update if from
> within the plugin on the _chain function.
>
> Alas, none of the above work. When the pipeline is
playing, the
> interface is frozen and does not repaint until the
pipeline is paused. I
> tried to queue_redraw() it, the I tried with
gtk_main_iteration(), then
> g_main_context_iteration(): they only make things worse
(deadlocks).
>
> What can I do? What am I doing wrong?
Since you haven't mentioned it, you should probably check
out
http://www.gtk.org/faq
/#AEN482
http://www.gtk.org/faq
/#AEN492
and the following questions. The gist of it is: Gtk+ isn't
thread-safe,
and if you use it from multiple threads you'll need to do
proper locking
or you'll get into trouble (or things just won't work as
expected).
Both your solutions aren't really good ideas IMHO.
GStreamer will create
threads of its own to do the data processing and outputting,
and your
chain function will be called from that one of those
GStreamer streaming
threads, which is guaranteed to be different from your main
thread where
you started the Gtk+ main loop with gtk_main().
Now, you could go and do proper Gtk/Gdk locking as per the
FAQs above,
but I'd advise against that. Your program will (in IMHO) be
much easier
to structure and to debug if you don't bother with doing
correct locking
and instead only do Gtk/Gdk things (like updating
labels/progress bars
etc.) from the main thread. If you want anything done to a
Gtk widget,
marshal the information into the main thread and let a
function handle
it there.
With GStreamer-0.10, the easiest way to marshal information
into the
main thread is by using the pipeline's GstBus. This is the
standard
mechanism for plugins to send information (like errors or
tags) to the
application in a thread-safe manner. Your element can post
custom
messages with arbitrary data (via the message's
GstStructure) on the bus
and your application can then catch that custom message in
its bus watch
callback. Since you will already have a bus watch to catch
errors, tags
and to recognise the end of the stream, adding support for
your custom
message should be fairly easy.
Check the application developer's manual and the GStreamer
API docs for
more information on how to use a pipeline's bus.
Btw, for your specific case (showing the current processing
position) it
might be sufficient to just set up a timeout with
g_timeout_add() and
query the pipeline for the current position in TIME format
(if you're
lucky DEFAULT format will work too and give you the frame
number).
Hope this helps.
Cheers
-Tim
------------------------------------------------------------
-------------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to
make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/
sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstream
er-devel
|
|
| gtk and threads |

|
2006-08-29 15:47:52 |
Tim,
thank you for your reply
> With GStreamer-0.10, the easiest way to marshal
information into the
> main thread is by using the pipeline's GstBus. This is
the standard
> mechanism for plugins to send information (like errors
or tags) to the
> application in a thread-safe manner. Your element can
post custom
> messages with arbitrary data (via the message's
GstStructure) on the bus
> and your application can then catch that custom message
in its bus watch
> callback. Since you will already have a bus watch to
catch errors, tags
> and to recognise the end of the stream, adding support
for your custom
> message should be fairly easy.
As it's often the case, the right solution is the simplest
one, and the
last one I think of Done, it
works, and it it THE ONE WAY of doing
it!
> Btw, for your specific case (showing the current
processing position) it
> might be sufficient to just set up a timeout with
g_timeout_add() and
> query the pipeline for the current position in TIME
format (if you're
> lucky DEFAULT format will work too and give you the
frame number).
I am not lucky :-( and I don't like to rely on luck...
anyway, this
specific case was just to solve the gst<->gtk
communication problem in
general, not really for counting frames. My plugin will
evolve in
something more elaborate, and may have something high level
to tell the
GUI.
Thanks a lot
alberto
>
> Hope this helps.
>
> Cheers
> -Tim
>
>
>
>
------------------------------------------------------------
-------------
> Using Tomcat but need to do more? Need to support web
services, security?
> Get stuff done quickly with pre-integrated technology
to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based
on Apache Geronimo
> http://sel.as-us.falkag.net/
sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gstream
er-devel
--
ICQ#: 319420338
------------------------------------------------------------
-------------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to
make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/
sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstream
er-devel
|
|
| gtk and threads |

|
2006-08-29 15:33:43 |
Hi,
On Tue, 2006-08-29 at 15:40 +0100, Tim Müller wrote:
> > I can think of two
> > ways of doing it:
Another one would be having the element post a message using
gst_element_post_message(). The app would then install the
signal
handler bus watch and connect to message::element or
message::application, and would then receive the message in
the main
thread of the app. Probably the easiest.
Regards,
--
http://wingolog.org/
------------------------------------------------------------
-------------
Using Tomcat but need to do more? Need to support web
services, security?
Get stuff done quickly with pre-integrated technology to
make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on
Apache Geronimo
http://sel.as-us.falkag.net/
sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstream
er-devel
|
|
[1-4]
|
|