簡體   English   中英

g_main_loop_quit拋出GLib-CRITICAL錯誤。 如何在C ++中處理它?

[英]g_main_loop_quit throws GLib-CRITICAL error. How to handle it in C++?

我正在使用gstreamer 1.14.4庫來偵聽本地端口並將內容轉儲到文件中。 我用C ++編寫了代碼。

當我執行管道時, 它成功運行 (但並非總是如此)。 隨機有時,該程序拋出

GLib-CRITICAL **:g_main_loop_quit:斷言'g_atomic_int_get(&loop-> ref_count)> 0'失敗
終止Gstreamer管道

現在,我已經添加了try-catch ,但我不認為它是std::exception

gboolean GstRtpDepayloader::CallBackBus(GstBus *bus, GstMessage *message, gpointer my_gst_instance) {
    /*******************************************************
     * Recover your class instance
     *******************************************************/
    GstRtpDepayloader *pGstptr = (GstRtpDepayloader *) my_gst_instance;
    if (pGstptr) {
        /*******************************************************
         * Check the message type and perform actions accordingly
         *******************************************************/
        switch (GST_MESSAGE_TYPE(message)) {
        case GST_MESSAGE_ERROR: { //Error occured in gstreamer pipeline
            GError *err;
            gchar *debug;

            gst_message_parse_error(message, &err, &debug);
            g_print("Error: %s\n", err->message);
            g_error_free(err);
            g_free(debug);

            pGstptr->QuitLoop(pGstptr);
            break;
        }
        case GST_MESSAGE_EOS: { //End of stream reached
            pGstptr->QuitLoop(pGstptr);
            break;
        }
        case GST_MESSAGE_ELEMENT: { //UDPSRC throws element message upon set timeout (1sec)
            //store and increament the timeout count every this block is executed
            if (//timeout is thrown 5 times) {
                pGstptr->QuitLoop(pGstptr);
            }
            break;
        default: {
            /* unhandled message */
            break;
        }
        }
        return (TRUE);
    }
    return (FALSE);
}

void GstRtpDepayloader::QuitLoop(GstRtpDepayloader *pGstptr){
    /*******************************************************
     * Quit the main loop
     *******************************************************/
    try{
        g_main_loop_quit(msLoop);
    }catch (exception *e) {
        /*******************************************************
         * Catch any standard exception type failures
         *******************************************************/
        cerr << "Error: " << e->what() << endl;
    }
}

void GstRtpDepayloader::GstPipelineCreation() {
    try {
        GstBus *bus;
        guint bus_watch_id;

        auto msLoop = g_main_loop_new(NULL, FALSE);
        if (NULL==msLoop){
            throw ("Null Loop pointer received @ ");
        }

        GstElement *pPipeline = gst_pipeline_new("PIPELINE");
        /**
         * Create the pipeline elements  
         *  udpsrc 
         *  rtppcmudepay
         *  filesink
         */

        /**
         * Add elements in pipeline and link them
         */

        /*****************************************************************
         * adds a watch for new message on our pipeline's message bus to
         * the default GLib main context, which is the main context that
         * our GLib main loop is attached to below
         *****************************************************************/
        bus = gst_pipeline_get_bus(GST_PIPELINE(pPipeline));
        bus_watch_id = gst_bus_add_watch(bus, CallBackBus, this);
        gst_object_unref(bus);
        /**********************************************************************
         * Pipeline state - PLAYING
       **********************************************************************/
        gst_element_set_state(pPipeline, GST_STATE_PLAYING);

        /**********************************************************************
         * Start the loop
         **********************************************************************/
        g_main_loop_run(msLoop);

        /**********************************************************************
         * Clean up after GMainLoop ends
         **********************************************************************/
        gst_element_set_state(pPipeline, GST_STATE_NULL);
        gst_object_unref(GST_OBJECT(pPipeline));
        g_source_remove(bus_watch_id);
        g_main_loop_unref(msLoop);
    } catch (exception *e) {
        /*******************************************************
         * Catch any standard exception type failures
         *******************************************************/
        cerr << "Error: " << e->what() << endl; 
    } catch (const char *msg) {
        /*******************************************************
         * Catch user defined type failures
         *******************************************************/
        cerr << "Error: " << msg << __FUNCTION__ << __LINE__ << endl;
    }
}

有關如何處理此類錯誤的任何建議/經驗?

來自GLib的嚴重警告意味着您以某種方式濫用API。 它不應被捕獲和處理/忽略:修復是修復您的代碼以不正確調用API。

但是,如果沒有完整的錯誤消息和最小的工作再現示例,我無法告訴您API的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM