[gst-devel] running g_main_loop_run in separate thread question.
Edward Hervey
bilboed at gmail.com
Wed Mar 24 15:52:58 CET 2010
On Wed, 2010-03-24 at 06:29 -0800, wanting2learn wrote:
> I have the following code:
[...]
> int main()
> {
>
> start_pipeline();
>
> while(1)
> {
> //do stuff here
> }
>
> //blah blah
> }
>
> Now my pipeline runs fine but I have kicked off a new thread to handle the
> bus messages:
> boost::thread thread_gstreamer2(task_gstreamer);
>
> void task_gstreamer()
> {
> g_main_loop_run (g_Loop);
> }
>
>
> The reason I have added this in a new thread is because of the while(1) loop
> in my main() function. If I put the g_main_loop_run in my main() before my
> while(1) loop then it would block.
> But the problem is that I do not receive any bus messages at all when I
> implement it like this.
> Can I do it this way??
>
>
I don't get it... why are you asking again and again about the same
question ? Tim replied to you a week ago how to handle bus messages when
you already have a main loop yet your persist in wanting to add a
GMainLoop.
So, to summarize:
1) DO NOT USE GMAINLOOP IF YOU ALREADY HAVE A MAIN LOOP
2) Read 1) again at least 50 times times
3) Do as follow in your main()
int main()
{
start_pipeline();
while(1)
{
// Do stuff here
// See if we have pending messages on the bus and handle them
while ((msg = gst_bus_pop (g_bus))) {
// Call your bus message handler
bus_call (g_bus, msg, nada);
gst_message_unref (msg);
}
}
// Stuff before we exit the application
}
4) DO NOT USE GMAINLOOP IF YOU ALREADY HAVE A MAIN LOOP
Also : http://en.wikipedia.org/wiki/Event_loop will be an interesting
read if you still see a difference between GMainLoop and "Main Loop"
Now, start2digest
Edward
More information about the gstreamer-devel
mailing list