Dynamic and Static Elements in GStreamer¶
How static pipelines differ from pipelines that add, remove, or link elements dynamically while running.
This English edition preserves the original commands, configuration fragments, and diagrams so the steps can be reproduced directly.
Commands and configuration¶
GstElement *videoconvert = gst_element_factory_make("videoconvert", "videoconvert");
GstPad *sinkpad = gst_element_get_static_pad(videoconvert, "sink");
GstPad *srcpad = gst_element_get_static_pad(videoconvert, "src");
g_signal_connect(decodebin, "pad-added", G_CALLBACK(pad_added_handler), NULL);
static void pad_added_handler(GstElement *src, GstPad *new_pad, gpointer user_data) {
GstPad *sink_pad = gst_element_get_static_pad(videoconvert, "sink");
// 检查新 pad 的类型是否为 video/x-raw
GstCaps *new_pad_caps = gst_pad_query_caps(new_pad, NULL);
GstStructure *new_pad_struct = gst_caps_get_structure(new_pad_caps, 0);
const gchar *new_pad_type = gst_structure_get_name(new_pad_struct);
if (g_strrstr(new_pad_type, "video/x-raw") != NULL) {
if (gst_pad_link(new_pad, sink_pad) != GST_PAD_LINK_OK) {
g_print("Failed to link pads!\n");
}
}
gst_caps_unref(new_pad_caps);
gst_object_unref(sink_pad);
}
Notes¶
Use these examples as a starting point and adjust versions, device names, codecs, and network addresses for the target platform.