{"id":935,"date":"2023-03-02T09:12:32","date_gmt":"2023-03-02T01:12:32","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=935"},"modified":"2025-10-09T13:55:19","modified_gmt":"2025-10-09T05:55:19","slug":"gstreamer-03","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2023\/03\/02\/gstreamer-03\/","title":{"rendered":"GStreamer 03 Dynamic pipelines"},"content":{"rendered":"<p><div class=\"has-toc have-toc\"><\/div><\/p>\n<h2>\u4e00\u3001\u76ee\u6807<\/h2>\n<p>&emsp;&emsp;\u672c\u7bc7\u7684\u76ee\u6807\u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a8\u6001\u5730\u6784\u5efa\u7ba1\u7ebf\uff0c\u800c\u4e0d\u662f\u5728\u4e00\u5f00\u59cb\u7684\u7a0b\u5e8f\u4e2d\u6784\u5efa\u4e00\u4e2a\u56fa\u5b9a\u7684\u7ba1\u7ebf\u3002\u672c\u7bc7\u7684\u77e5\u8bc6\u8981\u70b9\u6709\uff1a<\/p>\n<ol>\n<li>\u5982\u4f55\u5728\u8fde\u63a5\u5143\u7d20\u65f6\u83b7\u5f97\u66f4\u597d\u7684\u63a7\u5236\u3002<\/li>\n<li>\u5982\u4f55\u83b7\u53d6\u611f\u5174\u8da3\u7684\u4e8b\u4ef6\u3002<\/li>\n<li>\u4e00\u4e2a\u5143\u7d20\u53ef\u7528\u7684\u4e0d\u7528\u72b6\u6001\u3002<\/li>\n<\/ol>\n<h2>\u4e8c\u3001\u7b80\u4ecb<\/h2>\n<p>&emsp;&emsp;\u5728\u672c\u7bc7\u4e2d\uff0c\u7ba1\u7ebf\u5728\u88ab\u8bbe\u7f6e\u4e3a\u64ad\u653e\u72b6\u6001\u524d\u5e76\u672a\u88ab\u5b8c\u5168\u6784\u5efa\u3002\u5982\u679c\u6211\u4eec\u4e0d\u91c7\u53d6\u8fdb\u4e00\u6b65\u7684\u884c\u52a8\uff0c\u6570\u636e\u5c06\u5230\u8fbe\u7ba1\u7ebf\u7684\u672b\u7aef\uff0c\u7ba1\u7ebf\u5c06\u4ea7\u751f\u4e00\u6761\u9519\u8bef\u6d88\u606f\u5e76\u505c\u6b62\u3002\u4f46\u6211\u4eec\u5c06\u91c7\u53d6\u8fdb\u4e00\u6b65\u884c\u52a8\u3002<\/p>\n<p>&emsp;&emsp;\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u6253\u5f00\u4e00\u4e2a\u591a\u8def\u590d\u7528\uff08\u6216\u591a\u8def\u590d\u7528\uff09\u6587\u4ef6\uff0c\u5373\u97f3\u9891\u548c\u89c6\u9891\u4e00\u8d77\u5b58\u50a8\u5728\u5bb9\u5668\u6587\u4ef6\u4e2d\u3002\u8d1f\u8d23\u6253\u5f00\u6b64\u7c7b\u5bb9\u5668\u7684\u5143\u7d20\u79f0\u4e3a\u5206\u79bb\u5668\uff0c\u5bb9\u5668\u683c\u5f0f\u7684\u4e00\u4e9b\u793a\u4f8b\u5305\u62ecMatroska (MKV)\u3001Quick Time\uff08QT\u3001MOV\uff09\u3001Ogg\u6216\u9ad8\u7ea7\u7cfb\u7edf\u683c\u5f0f\uff08ASF\u3001WMV\u3001WMA\uff09\u3002<\/p>\n<p>&emsp;&emsp;GStreamer\u5143\u7d20\u76f8\u4e92\u901a\u4fe1\u7684\u7aef\u53e3\u79f0\u4e3apads(GstPad)\u3002\u6709sink pads\uff0c\u6570\u636e\u901a\u8fc7\u5b83\u8fdb\u5165\u5143\u7d20\uff1b\u8fd8\u6709source pads\uff0c\u6570\u636e\u901a\u8fc7\u5b83\u9000\u51fa\u5143\u7d20\u3002\u5f88\u81ea\u7136\u5730\uff0csource\u5143\u7d20\u4ec5\u5305\u542bsource pad\uff0csink\u5143\u7d20\u4ec5\u5305\u542bsink pad\uff0c\u800cfilter\u5143\u7d20\u5305\u542b\u4e24\u8005\u3002<\/p>\n<figure style=\"width: 155px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/src-element.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"155\" height=\"101\" alt=\"\u56fe1\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/src-element.png\" width=\"155\" height=\"101\" alt=\"\u56fe1\" class=\"size-full\" \/><\/noscript> \u56fe1\uff1asource<\/figcaption><\/figure>\n<figure style=\"width: 155px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/sink-element.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"155\" height=\"101\" alt=\"\u56fe2\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/sink-element.png\" width=\"155\" height=\"101\" alt=\"\u56fe2\" class=\"size-full\" \/><\/noscript> \u56fe2\uff1asink<\/figcaption><\/figure>\n<figure style=\"width: 155px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/filter-element.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"155\" height=\"101\" alt=\"\u56fe3\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/filter-element.png\" width=\"155\" height=\"101\" alt=\"\u56fe3\" class=\"size-full\" \/><\/noscript> \u56fe3\uff1afilter<\/figcaption><\/figure>\n<p>&emsp;&emsp;\u4e00\u4e2a\u591a\u8def\u590d\u7528\u5668\u6709\u4e00\u4e2asink pad\u548c\u591a\u4e2asrc pads\u3002<\/p>\n<figure style=\"width: 155px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/filter-element-multi.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"155\" height=\"101\" alt=\"\u56fe4\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/filter-element-multi.png\" width=\"155\" height=\"101\" alt=\"\u56fe4\" class=\"size-full\" \/><\/noscript> \u56fe4\uff1ademuxer<\/figcaption><\/figure>\n<p>&emsp;&emsp;\u4e3a\u4e86\u4fbf\u4e8e\u7406\u89e3\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u64ad\u653e\u89c6\u9891\u7684\u7ba1\u7ebf\uff0c\u4e00\u4e2ademuxer\u6709\u4e24\u4e2a\u5206\u652f\uff0c\u4e00\u4e2a\u662f\u97f3\u9891\u6d41\u3001\u4e00\u4e2a\u662f\u89c6\u9891\u6d41\u3002\u8be5\u56fe\u7247\u4e0e\u672c\u7bc7\u7684\u4ee3\u7801\u6240\u6784\u5efa\u7684\u7ba1\u7ebf\u5e76\u4e0d\u662f\u540c\u4e00\u4e2a\uff08\u672c\u7bc7\u6784\u5efa\u7684\u662f\u4e00\u4e2a\u89c6\u9891\u64ad\u653e\u5668\uff0c\u800cGStreamer\u7684\u5bf9\u5e94\u6559\u7a0b\u6784\u5efa\u7684\u662f\u4e00\u4e2a\u97f3\u9891\u64ad\u653e\u5668\uff09\u3002<\/p>\n<figure style=\"width: 792px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/simple-player.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"792\" height=\"293\" alt=\"\u56fe5\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/GStreamer\/03\/simple-player.png\" width=\"792\" height=\"293\" alt=\"\u56fe5\" class=\"size-full\" \/><\/noscript> \u56fe5\uff1a\u7ba1\u7ebf\u793a\u4f8b<\/figcaption><\/figure>\n<p>&emsp;&emsp;demuxer\u7684\u4e3b\u8981\u590d\u6742\u6027\u5728\u4e8e\uff1a\u5b83\u4eec\u5728\u6536\u5230\u4e00\u4e9b\u6570\u636e\u5e76\u6709\u673a\u4f1a\u67e5\u770b\u5bb9\u5668\u5185\u5bb9\u4e4b\u524d\u65e0\u6cd5\u751f\u6210\u4efb\u4f55\u4fe1\u606f\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cdemuxer\u5f00\u59cb\u65f6\u6ca1\u6709\u5176\u4ed6\u5143\u7d20\u53ef\u4ee5\u94fe\u63a5\u5230\u7684source pads\uff0c\u56e0\u6b64\u7ba1\u7ebf\u5fc5\u987b\u5728\u5b83\u4eec\u5904\u7ec8\u6b62\u3002<\/p>\n<p>&emsp;&emsp;\u89e3\u51b3\u65b9\u6848\u662f\u6784\u5efa\u4ecesource\u5230demuxer\u7684\u7ba1\u7ebf\uff0c\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3a\u8fd0\u884c\uff08\u64ad\u653e\uff09\u3002\u5f53demuxer\u6536\u5230\u8db3\u591f\u7684\u4fe1\u606f\u6765\u4e86\u89e3\u5bb9\u5668\u4e2d\u6d41\u7684\u6570\u91cf\u548c\u79cd\u7c7b\u65f6\uff0c\u5b83\u5c06\u5f00\u59cb\u521b\u5efasource pad\u3002\u8fd9\u662f\u6211\u4eec\u5b8c\u6210\u7ba1\u7ebf\u6784\u5efa\uff0c\u5e76\u5c06\u5176\u9644\u52a0\u5230\u65b0\u6dfb\u52a0\u7684demuxer pad\u7684\u6b63\u786e\u65f6\u95f4\u3002<\/p>\n<h2>\u4e09\u3001\u4ee3\u7801<\/h2>\n<p>&emsp;&emsp;\u4e0b\u9762\u662f\u6587\u7ae001\u4e2d\u81ea\u52a8\u6784\u5efa\u7ba1\u7ebf\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"language-c\">gst-launch-1.0 v4l2src device=\/dev\/video0 !video\/x-raw, format=NV12, width=640, height=480, framerate=30\/1 ! autovideosink<\/code><\/pre>\n<p>\u57fa\u4e8e\u8fd9\u6761\u547d\u4ee4\uff0c\u6211\u4eec\u73b0\u5728\u624b\u52a8\u6784\u5efa\u7ba1\u7ebf\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-c\">static GstElement *pipeline;\nstatic GstElement *source, *demuxer, *queue, *parser, *decoder, *converter, *sink;\n\nstatic void linkElements(GstElement* element, GstPad* sourcePad, gpointer sinkElement)\n{\n    GstPad* sinkPad = gst_element_get_static_pad((GstElement*)sinkElement, &quot;sink&quot;);\n    gst_pad_link(sourcePad, sinkPad);\n    gst_object_unref(sinkPad);\n}\n\nint MyTest(int argc, char** argv)\n{\n    GstBus *bus;\n    GstMessage *msg;\n    GstStateChangeReturn ret;\n    gboolean terminate = FALSE;\n\n    \/* Initialize GStreamer *\/\n    gst_init(&amp;argc, &amp;argv);\n\n    \/* Create the elements *\/\n    source = gst_element_factory_make(&quot;filesrc&quot;, &quot;file-source&quot;);\n    demuxer = gst_element_factory_make(&quot;qtdemux&quot;, &quot;demuxer&quot;);\n    queue = gst_element_factory_make(&quot;queue&quot;, &quot;queue&quot;);\n    parser = gst_element_factory_make(&quot;h264parse&quot;, &quot;parser&quot;);\n    decoder = gst_element_factory_make(&quot;mppvideodec&quot;, &quot;decoder&quot;);\n    converter = gst_element_factory_make(&quot;videoconvert&quot;, &quot;converter&quot;);\n    sink = gst_element_factory_make(&quot;autovideosink&quot;, &quot;sink&quot;);\n\n    \/* Create the empty pipeline *\/\n    pipeline = gst_pipeline_new(&quot;test-pipeline&quot;);\n\n    \/* Check creation *\/\n    if (!pipeline || !source || !demuxer || !queue || !parser || !decoder || !converter || !sink) {\n        g_printerr(&quot;Not all elements could be created.\\n&quot;);\n        return -1;\n    }\n\n    \/* Set the location of the input file *\/\n    g_object_set(G_OBJECT(source), &quot;location&quot;, &quot;13850_h264.mp4&quot;, NULL);\n\n    \/* Build the pipeline *\/\n    gst_bin_add_many(GST_BIN(pipeline), source, demuxer, queue, parser, decoder, converter, sink, NULL);\n\n    \/* Link *\/\n    if (!gst_element_link(source, demuxer)) {\n        g_printerr(&quot;Source and demuxer could not be linked.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n    if (!gst_element_link(queue, parser)) {\n        g_printerr(&quot;Queue and parser could not be linked.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n    if (!gst_element_link(parser, decoder)) {\n        g_printerr(&quot;Parser and decoder could not be linked.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n    if (!gst_element_link(decoder, converter)) {\n        g_printerr(&quot;Decoder and converter could not be linked.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n\n    \/* Manually connect the demuxer to the queue *\/\n    g_signal_connect(demuxer, &quot;pad-added&quot;, G_CALLBACK(linkElements), queue);\n\n    \/* Link *\/\n    if (!gst_element_link(converter, sink)) {\n        g_printerr(&quot;Converter and sink could not be linked.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n\n    \/* Set the pipeline to &quot;playing&quot; state *\/\n    ret = gst_element_set_state(pipeline, GST_STATE_PLAYING);\n    if (ret == GST_STATE_CHANGE_FAILURE) {\n        g_printerr(&quot;Unable to set the pipeline to the playing state.\\n&quot;);\n        gst_object_unref(pipeline);\n        return -1;\n    }\n\n    \/* Bus *\/\n    bus = gst_element_get_bus(pipeline);\n    msg = gst_bus_timed_pop_filtered(\n        bus, GST_CLOCK_TIME_NONE,\n        GST_MESSAGE_ERROR | GST_MESSAGE_EOS\n    );\n\n    \/* Parse message *\/\n    if (msg != NULL)\n    {\n        GError *err;\n        gchar *debug_info;\n\n        switch (GST_MESSAGE_TYPE(msg))\n        {\n            case GST_MESSAGE_ERROR:\n                gst_message_parse_error(msg, &amp;err, &amp;debug_info);\n\n                g_printerr(&quot;Error received from element %s: %s\\n&quot;,\n                    GST_OBJECT_NAME (msg-&gt;src), err-&gt;message\n                );\n                g_printerr(&quot;Debugging information: %s\\n&quot;,\n                    debug_info ? debug_info : &quot;none&quot;\n                );\n\n                g_clear_error(&amp;err);\n                g_free(debug_info);\n                break;\n            case GST_MESSAGE_EOS:\n                g_print(&quot;End-Of-Stream reached.\\n&quot;);\n                break;\n            default:\n                g_printerr(&quot;Unexpected message received.\\n&quot;);\n                break;\n        }\n\n        gst_object_unref(msg);\n    }\n\n    gst_object_unref(bus);\n    gst_element_set_state(pipeline, GST_STATE_NULL);\nout_unref:\n    gst_object_unref(pipeline);\nout_return:\n    return 0;\n}<\/code><\/pre>\n<h2>\u56db\u3001\u5206\u6790<\/h2>\n<h3>4.1 \u521b\u5efa\u5143\u7d20<\/h3>\n<pre><code class=\"language-c\">\/* Initialize GStreamer *\/\ngst_init(&amp;argc, &amp;argv);\n\n\/* Create the elements *\/\nsource = gst_element_factory_make(&quot;filesrc&quot;, &quot;file-source&quot;);\ndemuxer = gst_element_factory_make(&quot;qtdemux&quot;, &quot;demuxer&quot;);\nqueue = gst_element_factory_make(&quot;queue&quot;, &quot;queue&quot;);\nparser = gst_element_factory_make(&quot;h264parse&quot;, &quot;parser&quot;);\ndecoder = gst_element_factory_make(&quot;mppvideodec&quot;, &quot;decoder&quot;);\nconverter = gst_element_factory_make(&quot;videoconvert&quot;, &quot;converter&quot;);\nsink = gst_element_factory_make(&quot;autovideosink&quot;, &quot;sink&quot;);<\/code><\/pre>\n<p>&emsp;&emsp;\u8fd9\u662f\u6211\u4eec\u4e4b\u524d\u63d0\u5230\u7684\u521d\u59cb\u5316\uff0c\u5e76\u521b\u5efa\u5143\u7d20\u3002<\/p>\n<pre><code class=\"language-c\">\/* Create the empty pipeline *\/\npipeline = gst_pipeline_new(&quot;test-pipeline&quot;);\n\n\/* Check creation *\/\nif (!pipeline || !source || !demuxer || !queue || !parser || !decoder || !converter || !sink) {\n    g_printerr(&quot;Not all elements could be created.\\n&quot;);\n    return -1;\n}\n\n\/* Set the location of the input file *\/\ng_object_set(G_OBJECT(source), &quot;location&quot;, &quot;13850_h264.mp4&quot;, NULL);\n\n\/* Build the pipeline *\/\ngst_bin_add_many(GST_BIN(pipeline), source, demuxer, queue, parser, decoder, converter, sink, NULL);<\/code><\/pre>\n<p>&emsp;&emsp;\u73b0\u5728\u6211\u4eec\u65b0\u5efa\u7ba1\u7ebf\uff0c\u5e76\u786e\u5c06\u6240\u6709\u5143\u7d20\u52a0\u5165\u5230bin\u4e2d\uff0c\u65b9\u4fbf\u540e\u9762\u8fde\u63a5\u3002<\/p>\n<h3>4.2 Signals<\/h3>\n<pre><code class=\"language-c\">\/* Link *\/\nif (!gst_element_link(source, demuxer)) {\n    g_printerr(&quot;Source and demuxer could not be linked.\\n&quot;);\n    gst_object_unref(pipeline);\n    return -1;\n}\nif (!gst_element_link(queue, parser)) {\n    g_printerr(&quot;Queue and parser could not be linked.\\n&quot;);\n    gst_object_unref(pipeline);\n    return -1;\n}\nif (!gst_element_link(parser, decoder)) {\n    g_printerr(&quot;Parser and decoder could not be linked.\\n&quot;);\n    gst_object_unref(pipeline);\n    return -1;\n}\nif (!gst_element_link(decoder, converter)) {\n    g_printerr(&quot;Decoder and converter could not be linked.\\n&quot;);\n    gst_object_unref(pipeline);\n    return -1;\n}\n\n\/* Manually connect the demuxer to the queue *\/\ng_signal_connect(demuxer, &quot;pad-added&quot;, G_CALLBACK(linkElements), queue);\n\n\/* Link *\/\nif (!gst_element_link(converter, sink)) {\n    g_printerr(&quot;Converter and sink could not be linked.\\n&quot;);\n    gst_object_unref(pipeline);\n    return -1;\n}<\/code><\/pre>\n<p>&emsp;&emsp;\u5728\u8fd9\u91cc\uff0c\u5982\u679c\u4f7f\u7528<code>gst_element_link<\/code>\u76f4\u63a5\u8fde\u63a5demuxer\u548cqueue\u662f\u4e0d\u884c\u7684\u3002\u6b64\u65f6\u5e94\u5f53\u5148\u521b\u5efademuxer\u7684pad\uff0c\u7136\u540e\u518d\u4e0equeue\u76f8\u8fde\u63a5\u3002<\/p>\n<p>&emsp;&emsp;GSignals\u662fGStreamer\u4e2d\u7684\u5173\u952e\u70b9\u3002\u5f53\u5174\u8da3\u70b9\u51fa\u73b0\u65f6\uff0c\u5b83\u4eec\u5141\u8bb8\u60a8\u6536\u5230\u901a\u77e5\uff08\u901a\u8fc7\u56de\u8c03\u7684\u65b9\u5f0f\uff09\u3002\u4fe1\u53f7\u7531\u540d\u79f0\u6807\u8bc6\uff0c\u6bcf\u4e2a GObject\u90fd\u6709\u81ea\u5df1\u7684\u4fe1\u53f7\u3002<\/p>\n<p>&emsp;&emsp;\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>g_signal_connect<\/code>\u6765\u4e3ademuxer\u521b\u5efa\u4e00\u4e2asource pad\uff0c\u5e76\u628a\u8fd9\u4e2asource pad\u548cqueue\u7684sink pad\u76f8\u8fde\u63a5\u3002<code>g_signal_connect<\/code>\u5e76\u4e0d\u76f4\u63a5\u5904\u7406\u6211\u4eec\u4f20\u5165\u7684\u53c2\u6570\uff0c\u800c\u662f\u5c06\u5176\u8f6c\u53d1\u7ed9\u56de\u8c03\u51fd\u6570\u3002<\/p>\n<pre><code class=\"language-c\">g_signal_connect(demuxer, &quot;pad-added&quot;, G_CALLBACK(linkElements), queue);\n\nstatic void linkElements(GstElement* element, GstPad* sourcePad, gpointer sinkElement)\n{\n    GstPad* sinkPad = gst_element_get_static_pad((GstElement*)sinkElement, &quot;sink&quot;);\n    gst_pad_link(sourcePad, sinkPad);\n    gst_object_unref(sinkPad);\n}<\/code><\/pre>\n<h3>4.3 GStreamer\u72b6\u6001<\/h3>\n<ul>\n<li>NULL\uff0c\u5143\u7d20\u7684null\u6216\u521d\u59cb\u72b6\u6001\u3002<\/li>\n<li>READY\uff0c\u5143\u7d20\u51c6\u5907\u597d\u8fdb\u5165\u6682\u505c\u72b6\u6001\u3002<\/li>\n<li>PAUSED\uff0c\u8be5\u5143\u7d20\u5df2\u6682\u505c\uff0c\u5b83\u5df2\u51c6\u5907\u597d\u63a5\u53d7\u548c\u5904\u7406\u6570\u636e\u3002\u7136\u800c\uff0c\u63a5\u6536\u5668\u5143\u7d20\u53ea\u63a5\u53d7\u4e00\u4e2a\u7f13\u51b2\u533a\u7136\u540e\u963b\u585e\u3002<\/li>\n<li>PLAYING\uff0c\u64ad\u653e\uff0c\u65f6\u949f\u8fd0\u884c\u3001\u6570\u636e\u6d41\u52a8\u3002<\/li>\n<\/ul>\n<p>&emsp;&emsp;\u8fd9\u51e0\u4e2a\u72b6\u6001\u5b83\u4eec\u53ea\u80fd\u4ece\u4e00\u4e2a\u72b6\u6001\u79fb\u52a8\u5230\u76f8\u90bb\u7684\u72b6\u6001\u3002\u4f8b\u5982\uff0cNULL\u4e0d\u80fd\u76f4\u63a5\u79fb\u52a8\u5230PLAYING\u72b6\u6001\uff0c\u800c\u5fc5\u987b\u5148\u79fb\u52a8\u5230READY\u3001PAUSED\u72b6\u6001\u540e\uff0c\u624d\u80fd\u8fdb\u5165PLAYING\u72b6\u6001\u3002\u5927\u591a\u6570\u7a0b\u5e8f\u53ea\u9700\u8981\u5173\u5fc3\u4ecePLAYING\u5f00\u59cb\u64ad\u653e\uff0c\u5230PAUSED\u6682\u505c\uff0c\u6700\u540e\u5230NULL\u91ca\u653e\u8d44\u6e90\u3002<\/p>\n<h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<p>&emsp;&emsp;\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\uff1a<\/p>\n<ol>\n<li>\u5982\u4f55\u4f7f\u7528GSignals\u901a\u77e5\u4e8b\u4ef6\u3002<\/li>\n<li>\u5982\u4f55\u76f4\u63a5\u8fde\u63a5GstPads\u800c\u4e0d\u662f\u5b83\u4eec\u7684\u7236\u5143\u7d20\u3002<\/li>\n<li>GStreamer\u5143\u7d20\u7684\u5404\u79cd\u72b6\u6001\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u76ee\u6807 &emsp;&emsp;\u672c\u7bc7\u7684\u76ee\u6807\u662f\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a8\u6001\u5730\u6784\u5efa\u7ba1\u7ebf\uff0c\u800c\u4e0d\u662f\u5728\u4e00\u5f00\u59cb\u7684\u7a0b\u5e8f\u4e2d\u6784\u5efa\u4e00\u4e2a\u56fa\u5b9a\u7684\u7ba1\u7ebf\u3002\u672c\u7bc7\u7684\u77e5\u8bc6\u8981\u70b9 &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[239],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/935"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=935"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/935\/revisions"}],"predecessor-version":[{"id":936,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/935\/revisions\/936"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}