Hello,
Sometimes, app stuck in loop. Meaning, i starting loop, waiting for messages, but not always have control back after all messages processed. My code (with some simplification): //----------------------------- class GStreamer { protected: GMainLoop* _loop; }; //----------------------- GStreamer::GStreamer() { //init gstreamer library if (GStreamerInitialized == false) { gst_init(nullptr, nullptr); GStreamerInitialized = true; } _loop = g_main_loop_new(NULL, FALSE); } GStreamer::~GStreamer() { g_main_loop_unref(_loop); } //----------------------------- void GStreamer::StartWaitgLoop(GstElement* pipeline) { //get pipeline bus _bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); //register call back function for bus monitoring gst_bus_add_watch(_bus, CallBackFunction, NULL); Logger::Trace("GStreamer", "g_main_loop_run start"); //run loop: _loop is class g_main_loop_run(_loop); Logger::Trace("GStreamer", "g_main_loop_run stop"); //not necessary gst_bus_remove_watch(_bus); //free recources gst_object_unref(_bus); } //----------------------------- int CallBackFunction(GstBus* bus, GstMessage* message, void* data) { switch (GST_MESSAGE_TYPE(message)) { case GST_MESSAGE_WARNING: case GST_MESSAGE_ERROR: Logger::Trace("GStreamer", "CallBackFunction GST_MESSAGE_ERROR"); g_main_loop_quit(_loop); return false; break; case GST_MESSAGE_ASYNC_DONE: Logger::Trace("GStreamer", "CallBackFunction GST_MESSAGE_ASYNC_DONE"); g_main_loop_quit(_loop); return false; break; default: break; } //return true to be notified next time return true; } In log file GStreamer ii have to be like this for every call: g_main_loop_run start CallBackFunction GST_MESSAGE_ASYNC_DONE or CallBackFunction GST_MESSAGE_ERROR g_main_loop_run stop But sometimes i see this: g_main_loop_run start CallBackFunction GST_MESSAGE_ASYNC_DONE or CallBackFunction GST_MESSAGE_ERROR with no logging about stop. And app is stuck of course. It is happening, when i need to process 2000 files in function, calling StartWaitgLoop. And even worse if other instance of the GStreamer class in running. It is nothing special in gstreamer debug file. https://cloud.mail.ru/public/LPW1/Gruwezfca Full code is here. With some garbage, because i am trying to solve this problem already one week. https://cloud.mail.ru/public/8Xhe/DZ4BSwLh7 What i am doing wrong? Do you need more info? HELP ME PLEASE!!!!! Thanks in advance. Mikl |
Hi, your callbackFunction should be returning GST_BUS_PASS or one of the elements of GstBusSyncReply
-----Ursprüngliche Nachricht----- Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Mikl Gesendet: Mittwoch, 21. Juni 2017 13:12 An: [hidden email] Betreff: Loop callback problem (help me pleeeeease. extremely critical!) Hello, Sometimes, app stuck in loop. Meaning, i starting loop, waiting for messages, but not always have control back after all messages processed. My code (with some simplification): //----------------------------- class GStreamer { protected: GMainLoop* _loop; }; //----------------------- GStreamer::GStreamer() { //init gstreamer library if (GStreamerInitialized == false) { gst_init(nullptr, nullptr); GStreamerInitialized = true; } _loop = g_main_loop_new(NULL, FALSE); } GStreamer::~GStreamer() { g_main_loop_unref(_loop); } //----------------------------- void GStreamer::StartWaitgLoop(GstElement* pipeline) { //get pipeline bus _bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); //register call back function for bus monitoring gst_bus_add_watch(_bus, CallBackFunction, NULL); Logger::Trace("GStreamer", "g_main_loop_run start"); //run loop: _loop is class g_main_loop_run(_loop); Logger::Trace("GStreamer", "g_main_loop_run stop"); //not necessary gst_bus_remove_watch(_bus); //free recources gst_object_unref(_bus); } //----------------------------- int CallBackFunction(GstBus* bus, GstMessage* message, void* data) { switch (GST_MESSAGE_TYPE(message)) { case GST_MESSAGE_WARNING: case GST_MESSAGE_ERROR: Logger::Trace("GStreamer", "CallBackFunction GST_MESSAGE_ERROR"); g_main_loop_quit(_loop); return false; break; case GST_MESSAGE_ASYNC_DONE: Logger::Trace("GStreamer", "CallBackFunction GST_MESSAGE_ASYNC_DONE"); g_main_loop_quit(_loop); return false; break; default: break; } //return true to be notified next time return true; } In log file GStreamer ii have to be like this for every call: /g_main_loop_run start CallBackFunction GST_MESSAGE_ASYNC_DONE or CallBackFunction GST_MESSAGE_ERROR g_main_loop_run stop/ But sometimes i see this: /g_main_loop_run start CallBackFunction GST_MESSAGE_ASYNC_DONE or CallBackFunction GST_MESSAGE_ERROR/ *with no logging about stop.* And app is stuck of course. It is happening, when i need to process 2000 files in function, calling StartWaitgLoop. And even worse if other instance of the GStreamer class in running. It is nothing special in gstreamer debug file. https://cloud.mail.ru/public/LPW1/Gruwezfca Full code is here. With some garbage, because i am trying to solve this problem already one week. https://cloud.mail.ru/public/8Xhe/DZ4BSwLh7 What i am doing wrong? Do you need more info? *HELP ME PLEASE!!!!!* Thanks in advance. Mikl -- View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Loop-callback-problem-help-me-pleeeeease-extremely-critical-tp4683473.html Sent from the GStreamer-devel mailing list archive at Nabble.com. _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hello, Thornton
Thank you for the answer. I am not really get what you mean. According to this https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstBus.html#gst-bus-add-watch https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstBus.html#GstBusFunc i need to return false or true. Can you give small example, please? Mikl |
Sorry you are quite right. I was mixing this up with GstBusSyncHandler which I use
-----Ursprüngliche Nachricht----- Von: gstreamer-devel [mailto:[hidden email]] Im Auftrag von Mikl Gesendet: Mittwoch, 21. Juni 2017 14:02 An: [hidden email] Betreff: Re: AW: Loop callback problem (help me pleeeeease. extremely critical!) Hello, Thornton Thank you for the answer. I am not really get what you mean. According to this https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstBus.html#gst-bus-add-watch https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstBus.html#GstBusFunc i need to return false or true. Can you give small example, please? Mikl -- View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Loop-callback-problem-help-me-pleeeeease-extremely-critical-tp4683473p4683475.html Sent from the GStreamer-devel mailing list archive at Nabble.com. _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Hello, Thornton
The fact what i am "quite right" is not making my app work in "quite right" way. :) Do you have an idea on what is the problem? Maybe you have an idea how to solve it different? Maybe my way to do stuff is not "the best"? Maybe it is also a "pure evil", like gst_bus_poll (): https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstBus.html#gst-bus-poll I was thinking also about run loop in parallel thread and extract messages using call back functions. But not sure what this will solve my problem. I am building new pipeline for every file. And need to get new bus every time. In fact, i have always the same bus (i see it on memory address), but can be wrong approach. Mikl |
Hello, All
I found the problem. It was misusing GStreamer async mechanism. I was calling gst_element_seek and starting loop. But because my app was quite busy, GStreamer was finished seeking already send all messages. So, GST_MESSAGE_ASYNC_DONE was already gone and i am stuck while waiting it. Solution is to make callback always active and collecting messages from bus. And if GST_MESSAGE_ASYNC_DONE is already received, i am not starting loop. Till now it is working fine. Mikl |
Free forum by Nabble | Edit this page |