I have the following code:
GstBus *g_bus; //GStreamer bus to watch for stream errors GMainLoop *g_Loop; static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR: { g_print ("ERROR\n"); break; } default: g_print ("default\n"); break; } return TRUE; } static void on_rtsppad_added(GstElement *element, GstPad *pad, gpointer data) { GstElement *linkElement = (GstElement *) data; GstPad *sinkpad = gst_element_get_static_pad (linkElement, "sink"); gst_pad_link (pad, sinkpad); gst_object_unref(GST_OBJECT (sinkpad)); } static void on_pad_added(GstElement *element, GstPad *pad, gboolean last, gpointer data) { GstElement *linkElement = (GstElement *) data; GstPad *sinkpad = gst_element_get_static_pad (linkElement, "sink"); gst_pad_link (pad, sinkpad); gst_object_unref(GST_OBJECT (sinkpad)); } void task_gstreamer()//This is a new boost thread - see bottom of MyPipeLineClass constructor { g_main_loop_run (g_Loop); } class MyPipeLineClass { public: MyPipeLineClass( ); ~MyPipeLineClass(); bool startPlaying(); void stopPlaying(); private: GstPipeline *m_pPipeline; GstElement *m_pHtmlElem; }; MyPipeLineClass::MyPipeLineClass( ) : { g_Loop = g_main_loop_new (NULL, FALSE); // Create pipeline m_pPipeline = GST_PIPELINE(gst_pipeline_new("livemjpg-player")); //Get the pipeline bus so we can watch it g_bus = gst_pipeline_get_bus (GST_PIPELINE(m_pPipeline)); gst_object_unref (g_bus); // Create source elements GstElement *source = gst_element_factory_make("rtspsrc", "source"); // Set the source video file */ //Sometimes the rtspsrc element blocks for up to 20secs when its state is changed //so change its default tcp-timeout to 5secs g_object_set(source, "location", rtspUrl.c_str(), "tcp-timeout", TIMEOUT, NULL ); // Create decode element GstElement *decode = gst_element_factory_make("decodebin2", "decode"); // Create jpeg encoder element GstElement *encoder = gst_element_factory_make("jpegenc", "jpegenc"); // Create sink format element GstElement *sink = gst_element_factory_make("fdsink", "sink"); // Add elements to the pipeline gst_bin_add_many( GST_BIN(m_pPipeline), source, decode, encoder, sink, NULL); // Link all elements except source and decoder // The rtspsrc and decoder will automatically determine the appropriate pad // at run time and then they will link accordingly if (!gst_element_link_many(encoder, sink, NULL)) { vecgi::LOGMSG( vecgi::VELOG_ERROR, "Failed to link elements in MotionJpeg pipeline." ); } g_signal_connect(source, "pad-added", G_CALLBACK(on_rtsppad_added), decode ); g_signal_connect(decode, "new-decoded-pad", G_CALLBACK (on_pad_added), encoder ); boost::thread thread_gstreamer2(task_gstreamer); <------New thread } MyPipeLineClass::~MyPipeLineClass() { stopPlaying(); } bool MyPipeLineClass::startPlaying() { gst_element_set_state( GST_ELEMENT(m_pPipeline),GST_STATE_PLAYING ) ; return true; } void MyPipeLineClass::stopPlaying() { gst_element_set_state( GST_ELEMENT(m_pPipeline),GST_STATE_NULL ) gst_object_unref( m_pPipeline ); } static MyPipeLineClass *g_pMyPipelineClass = NULL; <--global pipeline variable int start_pipeline() { g_pMyPipelineClass = new MyPipeLineClass( ); g_pMyPipelineClass->startPlaying()) return 1; } 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?? |
Administrator
|
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 ------------------------------------------------------------------------------ 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 |
Hi,
Why not use: gst_bus_enable_sync_message_emission(bus); gst_bus_set_sync_handler(bus, (GstBusSyncHandler) my_sync_handler, &my_var); gst_object_unref(bus); ? Dime Edward Hervey wrote: > 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 > > > ------------------------------------------------------------------------------ > 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 > > ------------------------------------------------------------------------------ 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 |
Administrator
|
On Wed, 2010-03-24 at 14:59 +0000, Nicholas Panayis wrote:
> Hi, > > Why not use: > gst_bus_enable_sync_message_emission(bus); > gst_bus_set_sync_handler(bus, (GstBusSyncHandler) my_sync_handler, > &my_var); > gst_object_unref(bus); It's a valid alternative... but in that case your won't be guaranteed your sync handler will be called from the main thread. Edward > > ? > > Dime > > > Edward Hervey wrote: > > 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 > > > > > > ------------------------------------------------------------------------------ > > 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 > > > > > > > ------------------------------------------------------------------------------ > 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 ------------------------------------------------------------------------------ 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 |
In reply to this post by dime@dimebar.f2s.com
Thanks for giving one more way to get sync messages using only one gmainloop.
On Wed, Mar 24, 2010 at 8:29 PM, Nicholas Panayis <[hidden email]> wrote: Hi, ------------------------------------------------------------------------------ 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 |
Free forum by Nabble | Edit this page |