How can I have two main loops in my program??

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

How can I have two main loops in my program??

wanting2learn
Hi I have a program with its own main 'while' loop that must be executed for my program to work.

I wish to add also a  g_main_loop_run (loop) so that I can monitor gstreamer event messages as in :http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html

Is it possible to have two loops running in my program.  I have tried adding the code to let me monitor messages but I can't seem to get it to work. (i.e. I cant seem to get any messages in my bus_call function)

I guess my question is: Can I have a g_main_loop_run as well as my own while loop?  Or will g_main_loop_run block my program?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

wl2776
Administrator
g_main_loop_run will create a new thread and shouldn't block your program.
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

Tim-Philipp Müller-2
On Tue, 2010-03-16 at 03:37 -0800, wl2776 wrote:

> g_main_loop_run will create a new thread and shouldn't block your program.

No, g_main_loop_run() will not create a new thread and will be blocking.

 Cheers
  -Tim



------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

Tim-Philipp Müller-2
In reply to this post by wanting2learn
On Tue, 2010-03-16 at 02:36 -0800, wanting2learn wrote:

> Hi I have a program with its own main 'while' loop that must be executed for
> my program to work.
>
> I wish to add also a  g_main_loop_run (loop) so that I can monitor gstreamer
> event messages as in
> :http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html
>
> Is it possible to have two loops running in my program.  I have tried adding
> the code to let me monitor messages but I can't seem to get it to work.
> (i.e. I cant seem to get any messages in my bus_call function)
>
> I guess my question is: Can I have a g_main_loop_run as well as my own while
> loop?  Or will g_main_loop_run block my program?

You don't need to run a GLib main loop to monitor messages on the
pipeline bus. It's how it's often done, especially with GUI
applications, but it's not the only way. You could just check for
messages using something like

  while ((msg = gst_bus_pop (bus))) {
    ... handle message ...
    gst_message_unref (msg);
  }

once in a while (if there is already another main loop, I'm sure you can
set up a timer or something).

 Cheers
  -Tim


------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

wanting2learn
Thanks for the quick replies.

Tim,  so if I use your method then do I need to do the following:?

g_bus = gst_pipeline_get_bus (GST_PIPELINE(m_pPipeline));
gst_bus_add_watch (g_bus, bus_call, g_loop);
//blah blah
g_main_loop_run (loop);


or do I just do simply:
g_bus = gst_pipeline_get_bus (GST_PIPELINE(m_pPipeline));
and then use your method

while ((msg = gst_bus_pop (g_bus))) {
    ... handle message ...
    gst_message_unref (msg);
  }


Thanks

harry
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

Tim-Philipp Müller-2
On Tue, 2010-03-16 at 04:15 -0800, wanting2learn wrote:

> or do I just do simply:
> g_bus = gst_pipeline_get_bus (GST_PIPELINE(m_pPipeline));
> and then use your method
>
> while ((msg = gst_bus_pop (g_bus))) {
>     ... handle message ...
>     gst_message_unref (msg);
>   }

This one.

Cheers
 -Tim



------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

wanting2learn
Excellent, I have tried this and it works :)

thank you very much indeed.
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

wl2776
Administrator
In reply to this post by Tim-Philipp Müller-2
Tim-Philipp Müller-2 wrote
> g_main_loop_run will create a new thread and shouldn't block your program.
No, g_main_loop_run() will not create a new thread and will be blocking.
That's right, thank you.
And what happens, when I create a new main loop with is_running=TRUE:
  m_loop = g_main_loop_new(NULL,TRUE);
?
Reply | Threaded
Open this post in threaded view
|

Re: How can I have two main loops in my program??

namus
In reply to this post by Tim-Philipp Müller-2
In case ,when we are using g_main_loop_run() :

before we run g_main_loop_run() we are initializing  pipeline state to GST_STATE_PAUSED
such as ..gst_element_set_state (pipeline,  GST_STATE_PAUSED)


my question is , should we need to initialise pipeline to GST_STATE_PAUSED or GST_STATE_PLAYING ? in case of below mentioned :
while ((msg = gst_bus_pop (g_bus))) {
>     ... handle message ...
>     gst_message_unref (msg);
>   }

please explain (or state any link) the significance of initialization of pipeline .?

i tried with initialising with either of states mentioned above and an error is obtained as shown below (if possible,please throw a light why this error comes):
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = state-changed  
: State changed
:385: State changed 1 -> 2
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = state-changed  
:383: State changed
385: State changed 1 -> 2
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = state-changed  
:383: State changed
385: State changed 1 -> 2
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = state-changed  
:383: State changed
:385: State changed 1 -> 2
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = state-changed  
:383: State changed
:385: State changed 2 -> 3
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = stream-status  
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = stream-status  
:373: In While() ,GST_MESSAGE_TYPE_NAME(msg) = error  
:417: Error: Internal data flow error. - Debug: gstbasesrc.c(2378): gst_base_src_loop (): /GstPipeline:metadata-pipeline/GstFileSrc:file-source: streaming task paused, reason not-linked (-1)