static GstElement * create_parser_for_caps (const GstCaps * caps) { GList *parser_list, *filtered_list, *l; GstElementFactory *parser_factory = NULL; GstElement *parser = NULL; parser_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_PARSER, GST_RANK_NONE); filtered_list = gst_element_factory_list_filter (parser_list, caps, GST_PAD_SINK, FALSE); for (l = filtered_list; l != NULL && parser_factory == NULL; l = l->next) { parser_factory = GST_ELEMENT_FACTORY (l->data); if (gst_element_factory_get_num_pad_templates (parser_factory) != 2) parser_factory = NULL; } if (parser_factory != NULL) { parser = gst_element_factory_create (parser_factory, NULL); } else { parser = gst_element_factory_make ("capsfilter", NULL); } gst_plugin_feature_list_free (filtered_list); gst_plugin_feature_list_free (parser_list); return parser; }
/* check if caps are found on given element */ static gboolean check_caps_compatibility (GstElementFactory *factory, GstCaps *caps, GstCaps **matched_caps) { const GList *pads; GstStaticPadTemplate *padtemplate; GstCaps *padtemplate_caps = NULL; if (!gst_element_factory_get_num_pad_templates (factory)) { return FALSE; } pads = gst_element_factory_get_static_pad_templates (factory); while (pads) { padtemplate = (GstStaticPadTemplate *) (pads->data); pads = g_list_next (pads); padtemplate_caps = gst_static_caps_get (&padtemplate->static_caps); if (gst_caps_is_any (padtemplate_caps)) { goto next; } if (caps) { GstCaps *intersection = gst_caps_intersect (padtemplate_caps, caps); gboolean have_intersection = !gst_caps_is_empty (intersection); if (have_intersection) { *matched_caps = intersection; gst_caps_unref (padtemplate_caps); return TRUE; } gst_caps_unref (intersection); } next: if (padtemplate_caps) { gst_caps_unref (padtemplate_caps); } } *matched_caps = NULL; return FALSE; }
static GstElement * create_payloader_for_caps (const GstCaps * caps) { GList *payloader_list, *filtered_list, *l; GstElementFactory *payloader_factory = NULL; GstElement *payloader = NULL; payloader_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_PAYLOADER, GST_RANK_NONE); filtered_list = gst_element_factory_list_filter (payloader_list, caps, GST_PAD_SRC, FALSE); for (l = filtered_list; l != NULL && payloader_factory == NULL; l = l->next) { payloader_factory = GST_ELEMENT_FACTORY (l->data); if (gst_element_factory_get_num_pad_templates (payloader_factory) != 2) payloader_factory = NULL; } if (payloader_factory != NULL) { payloader = gst_element_factory_create (payloader_factory, NULL); } if (payloader) { GParamSpec *pspec; pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (payloader), "config-interval"); if (pspec != NULL && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_UINT) { g_object_set (payloader, "config-interval", 1, NULL); } pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (payloader), "picture-id-mode"); if (pspec != NULL && G_TYPE_IS_ENUM (G_PARAM_SPEC_VALUE_TYPE (pspec))) { /* Set picture id so that remote peer can determine continuity if */ /* there are lost FEC packets and if it has to NACK them */ g_object_set (payloader, "picture-id-mode", PICTURE_ID_15_BIT, NULL); } } gst_plugin_feature_list_free (filtered_list); gst_plugin_feature_list_free (payloader_list); return payloader; }
static void print_pad_templates_info (GstElement * element, GstElementFactory * factory) { GstElementClass *gstelement_class; const GList *pads; GstStaticPadTemplate *padtemplate; n_print ("Pad Templates:\n"); if (gst_element_factory_get_num_pad_templates (factory) == 0) { n_print (" none\n"); return; } gstelement_class = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS (element)); pads = gst_element_factory_get_static_pad_templates (factory); while (pads) { padtemplate = (GstStaticPadTemplate *) (pads->data); pads = g_list_next (pads); if (padtemplate->direction == GST_PAD_SRC) n_print (" SRC template: '%s'\n", padtemplate->name_template); else if (padtemplate->direction == GST_PAD_SINK) n_print (" SINK template: '%s'\n", padtemplate->name_template); else n_print (" UNKNOWN!!! template: '%s'\n", padtemplate->name_template); if (padtemplate->presence == GST_PAD_ALWAYS) n_print (" Availability: Always\n"); else if (padtemplate->presence == GST_PAD_SOMETIMES) n_print (" Availability: Sometimes\n"); else if (padtemplate->presence == GST_PAD_REQUEST) { n_print (" Availability: On request\n"); n_print (" Has request_new_pad() function: %s\n", GST_DEBUG_FUNCPTR_NAME (gstelement_class->request_new_pad)); } else n_print (" Availability: UNKNOWN!!!\n"); if (padtemplate->static_caps.string) { n_print (" Capabilities:\n"); print_caps (gst_static_caps_get (&padtemplate->static_caps), " "); } n_print ("\n"); } }
static void kms_enc_tree_bin_create_encoder_for_caps (KmsEncTreeBin * self, const GstCaps * caps, gint target_bitrate) { GList *encoder_list, *filtered_list, *l; GstElementFactory *encoder_factory = NULL; encoder_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_ENCODER, GST_RANK_NONE); /* HACK: Augment the openh264 rank */ for (l = encoder_list; l != NULL; l = l->next) { encoder_factory = GST_ELEMENT_FACTORY (l->data); if (g_str_has_prefix (GST_OBJECT_NAME (encoder_factory), "openh264")) { encoder_list = g_list_remove (encoder_list, l->data); encoder_list = g_list_prepend (encoder_list, encoder_factory); break; } } encoder_factory = NULL; filtered_list = gst_element_factory_list_filter (encoder_list, caps, GST_PAD_SRC, FALSE); for (l = filtered_list; l != NULL && encoder_factory == NULL; l = l->next) { encoder_factory = GST_ELEMENT_FACTORY (l->data); if (gst_element_factory_get_num_pad_templates (encoder_factory) != 2) encoder_factory = NULL; } if (encoder_factory != NULL) { self->priv->enc = gst_element_factory_create (encoder_factory, NULL); kms_enc_tree_bin_set_encoder_type (self); configure_encoder (self->priv->enc, self->priv->enc_type, target_bitrate); } gst_plugin_feature_list_free (filtered_list); gst_plugin_feature_list_free (encoder_list); }