g_对象_未引用:Assert“G_IS_OBJECT(对象)”失败

s5a0g9ez  于 2023-03-01  发布在  其他
关注(0)|答案(1)|浏览(252)

我正在尝试使用C语言通过Gstreamer实现一个视频播放器。我可以正确运行我的程序,但发生了一个错误:(drmDemo:871): GLib-GObject-CRITICAL **: 14:14:57.520: g_object_unref: assertion 'G_IS_OBJECT (object)' failed.这里是我的代码:

static void linkElements(GstElement* element, GstPad* sourcePad, gpointer sinkElement)
{
    GstPad* sinkPad=gst_element_get_static_pad((GstElement*)sinkElement, "sink");
    gst_pad_link(sourcePad,sinkPad);
    gst_object_unref(sinkPad);
}

int MyTest(int argc, char** argv)
{
    GstElement *pipeline;
    GstElement *source, *demuxer, *queue, *parser, *decoder, *converter, *sink;

    GstBus *bus;
    GstMessage *msg;
    GstStateChangeReturn ret;
    gboolean terminate = FALSE;
    int retval = 0;

    /* Initialize GStreamer */
    gst_init(&argc, &argv);

    /* Create the elements */
    source = gst_element_factory_make("filesrc", "file-source");
    demuxer = gst_element_factory_make("qtdemux", "demuxer");
    queue = gst_element_factory_make("queue", "queue");
    parser = gst_element_factory_make("h264parse", "parser");
    decoder = gst_element_factory_make("mppvideodec", "decoder");
    converter = gst_element_factory_make("videoconvert", "converter");
    sink = gst_element_factory_make("waylandsink", "sink");

    /* Create the empty pipeline */
    pipeline = gst_pipeline_new("test-pipeline");

    /* Check creation */
    if (!pipeline || !source || !demuxer || !queue || !parser || !decoder || !converter || !sink) {
        g_printerr("Not all elements could be created.\n");
        goto out_return;
    }

    /* Set the location of the input file */
    g_object_set(G_OBJECT(source), "location", "13850_h264.mp4", NULL);

    /* Build the pipeline */
    gst_bin_add_many(GST_BIN(pipeline), source, demuxer, queue, parser, decoder, converter, sink, NULL);
    if (!gst_element_link(source, demuxer)) {
        g_printerr("Source and demuxer could not be linked.\n");
        retval = -1;
        goto out_unref;
    }
    if (!gst_element_link(queue, parser)) {
        g_printerr("Queue and parser could not be linked.\n");
        retval = -2;
        goto out_unref;
    }
    if (!gst_element_link(parser, decoder)) {
        g_printerr("Parser and decoder could not be linked.\n");
        retval = -3;
        goto out_unref;
    }
    if (!gst_element_link(decoder, converter)) {
        g_printerr("Decoder and converter could not be linked.\n");
        retval = -4;
        goto out_unref;
    }

    /* Manually connect the demuxer to the queue */
    g_signal_connect(demuxer, "pad-added", G_CALLBACK(linkElements), queue);

    if (!gst_element_link(converter, sink)) {
        g_printerr("Converter and sink could not be linked.\n");
        retval = -5;
        goto out_unref;
    }

    /* Set the pipeline to "playing" state */
    ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);
    if (ret == GST_STATE_CHANGE_FAILURE) {
        g_printerr("Unable to set the pipeline to the playing state.\n");
        retval = -6;
        goto out_unref;
    }

    /* Bus */
    bus = gst_element_get_bus(pipeline);
    msg = gst_bus_timed_pop_filtered(
        bus, GST_CLOCK_TIME_NONE,
        GST_MESSAGE_ERROR | GST_MESSAGE_EOS
    );

    /* Parse message */
    if (msg != NULL)
    {
        GError *err;
        gchar *debug_info;

        switch (GST_MESSAGE_TYPE(msg))
        {
            case GST_MESSAGE_ERROR:
                gst_message_parse_error(msg, &err, &debug_info);

                g_printerr("Error received from element %s: %s\n",
                    GST_OBJECT_NAME (msg->src), err->message
                );
                g_printerr("Debugging information: %s\n",
                    debug_info ? debug_info : "none"
                );
                
                g_clear_error(&err);
                g_free(debug_info);
                break;
            case GST_MESSAGE_EOS:
                g_print("End-Of-Stream reached.\n");
                break;
            default:
                g_printerr("Unexpected message received.\n");
                break;
        }

        gst_object_unref(msg);
    }

printf("before unref\n");
    gst_object_unref(bus);
printf("unref bus\n");
    gst_element_set_state(pipeline, GST_STATE_NULL);
printf("set null\n");
out_unref:
    gst_object_unref(pipeline);
printf("unref pipeline\n");
out_return:
    return retval;
}

当我运行应用程序时,它显示:

mpp[871]: mpp_rt: NOT found ion allocator
mpp[871]: mpp_rt: found drm allocator
mpp[871]: mpp_info: mpp version: unknown mpp version for missing VCS info
mpp[871]: h264d_api: is_avcC=1
mpp[871]: hal_h264d_vdpu34x: control info: fmt 7, w 640, h 480
mpp[871]: mpp_buf_slot: set frame info: w  640 h  480 hor  640 ver  480
mpp[871]: mpp_dec: setting default w  640 h  480 h_str  640 v_str  480
End-Of-Stream reached.

(drmDemo:871): GLib-GObject-CRITICAL **: 14:14:57.520: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
before unref
unref bus
set null
unref pipeline

g_signal_connect引起的unref异常吗?还是我在unref这些元素时犯了错误。任何回答或评论都非常感谢。

kx7yvsdv

kx7yvsdv1#

对于GstMessage,使用gst_message_unref()代替gst_object_unref()
参见:www.example.com。https://gstreamer.freedesktop.org/documentation/gstreamer/gstmessage.html?gi-language=c#gst_message_unref.

相关问题