gst, queue插件sinkpad buffer探针附加字符串, queue插件srcpad buffer探针获取它, c实现完整列子, 仔细想想
时间: 2023-05-11 19:02:49 浏览: 155
可以使用以下代码实现:
```
#include <gst/gst.h>
static GstPadProbeReturn
sink_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
gchar *str = (gchar *) user_data;
GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
g_print ("%s: Received buffer of size %u\n", str, gst_buffer_get_size (buf));
return GST_PAD_PROBE_OK;
}
static GstPadProbeReturn
src_probe_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
gchar *str = (gchar *) user_data;
GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
g_print ("%s: Received buffer of size %u\n", str, gst_buffer_get_size (buf));
return GST_PAD_PROBE_OK;
}
int
main (int argc, char *argv[])
{
GstElement *pipeline, *src, *queue, *sink;
GstPad *srcpad, *sinkpad;
GstBus *bus;
GstMessage *msg;
GMainLoop *loop;
gchar *str = "Custom string";
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
src = gst_element_factory_make ("videotestsrc", "src");
queue = gst_element_factory_make ("queue", "queue");
sink = gst_element_factory_make ("fakesink", "sink");
/* Create the pipeline */
pipeline = gst_pipeline_new ("test-pipeline");
/* Add the elements to the pipeline */
gst_bin_add_many (GST_BIN (pipeline), src, queue, sink, NULL);
/* Link the elements together */
gst_element_link_many (src, queue, sink, NULL);
/* Get the pads */
srcpad = gst_element_get_static_pad (src, "src");
sinkpad = gst_element_get_static_pad (sink, "sink");
/* Add the probes */
gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER, sink_probe_cb, str, NULL);
gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_BUFFER, src_probe_cb, str, NULL);
/* Start playing */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Wait until error or EOS */
loop = g_main_loop_new (NULL, FALSE);
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
/* Free resources */
if (msg != NULL)
gst_message_unref (msg);
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}
```
这段代码演示了如何使用 GStreamer 中的 queue 插件的 sinkpad 和 srcpad 的 buffer 探针。在这个例子中,我们使用了 videotestsrc 元素生成一个视频流,然后将其传递给 queue 元素,最后传递给 fakesink 元素。我们在 sinkpad 和 srcpad 上添加了 buffer 探针,以便在数据流经过这些 pad 时打印一条消息。
阅读全文