bool GStreamerFormatHelper::HaveElementsToProcessCaps(GstCaps* aCaps) { NS_ASSERTION(sLoadOK, "GStreamer library not linked"); GList* factories = GetFactories(); /* here aCaps contains [containerCaps, [codecCaps1, [codecCaps2, ...]]] so process * caps structures individually as we want one element for _each_ * structure */ for (unsigned int i = 0; i < gst_caps_get_size(aCaps); i++) { GstStructure* s = gst_caps_get_structure(aCaps, i); GstCaps* caps = gst_caps_new_full(gst_structure_copy(s), nullptr); bool found = false; for (GList *elem = factories; elem; elem = elem->next) { if (SupportsCaps(GST_ELEMENT_FACTORY_CAST(elem->data), caps)) { found = true; break; } } gst_caps_unref(caps); if (!found) { return false; } } return true; }
static GstElement * find_demuxer (GstCaps * caps) { GList *factories = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DEMUXER, GST_RANK_MARGINAL); GList *compat_elements; GstElement *e = NULL; if (factories == NULL) return NULL; compat_elements = gst_element_factory_list_filter (factories, caps, GST_PAD_SINK, TRUE); if (compat_elements) { /* Just take the first (highest ranked) option */ GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (compat_elements->data); e = gst_element_factory_create (factory, NULL); gst_plugin_feature_list_free (compat_elements); } if (factories) gst_plugin_feature_list_free (factories); return e; }
static gboolean element_filter (GstPluginFeature * feature, FilterData * data) { gboolean res; /* we only care about element factories */ if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature))) return FALSE; res = (gst_plugin_feature_get_rank (feature) >= data->minrank) && gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (feature), data->type); return res; }
static gboolean FactoryFilter(GstPluginFeature *aFeature, gpointer) { if (!GST_IS_ELEMENT_FACTORY(aFeature)) { return FALSE; } // TODO _get_klass doesn't exist in 1.0 const gchar *className = gst_element_factory_get_klass(GST_ELEMENT_FACTORY_CAST(aFeature)); if (!strstr(className, "Decoder") && !strstr(className, "Demux")) { return FALSE; } return gst_plugin_feature_get_rank(aFeature) >= GST_RANK_MARGINAL; }
static gboolean FactoryFilter(GstPluginFeature *aFeature, gpointer) { if (!GST_IS_ELEMENT_FACTORY(aFeature)) { return FALSE; } const gchar *className = gst_element_factory_get_klass(GST_ELEMENT_FACTORY_CAST(aFeature)); if (!strstr(className, "Decoder") && !strstr(className, "Demux") && !strstr(className, "Parser")) { return FALSE; } return gst_plugin_feature_get_rank(aFeature) >= GST_RANK_MARGINAL && !GStreamerFormatHelper::IsPluginFeatureBlacklisted(aFeature); }
static gboolean FactoryFilter(GstPluginFeature *aFeature, gpointer) { if (!GST_IS_ELEMENT_FACTORY(aFeature)) { return FALSE; } const gchar *className = gst_element_factory_get_klass(GST_ELEMENT_FACTORY_CAST(aFeature)); // NB: We skip filtering parsers here, because adding them to // the list can give false decoder positives to canPlayType(). if (!strstr(className, "Decoder") && !strstr(className, "Demux")) { return FALSE; } return gst_plugin_feature_get_rank(aFeature) >= GST_RANK_MARGINAL && !GStreamerFormatHelper::IsPluginFeatureBlocked(aFeature); }
static void set_autoconvert_factories (GstElement * autoconvert) { const gchar *desired_features[] = { "testelement1", "testelement2" }; GstElementFactory *feature; GList *factories = NULL; gint i; for (i = 0; i < G_N_ELEMENTS (desired_features); i++) { feature = GST_ELEMENT_FACTORY_CAST (gst_registry_find_feature (gst_registry_get (), desired_features[i], GST_TYPE_ELEMENT_FACTORY)); fail_if (feature == NULL, "Test element %s was not found in registry", desired_features[i]); factories = g_list_prepend (factories, feature); } g_object_set (G_OBJECT (autoconvert), "factories", factories, NULL); g_list_free (factories); }
static gboolean gst_auto_video_convert_element_filter (GstPluginFeature * feature, GstAutoVideoConvert * autovideoconvert) { const gchar *klass; /* we only care about element factories */ if (G_UNLIKELY (!GST_IS_ELEMENT_FACTORY (feature))) return FALSE; klass = gst_element_factory_get_metadata (GST_ELEMENT_FACTORY_CAST (feature), GST_ELEMENT_METADATA_KLASS); /* only select color space converter */ if (strstr (klass, "Filter") && strstr (klass, "Converter") && strstr (klass, "Video")) { GST_DEBUG_OBJECT (autovideoconvert, "gst_auto_video_convert_element_filter found %s\n", gst_plugin_feature_get_name (GST_PLUGIN_FEATURE_CAST (feature))); return TRUE; } return FALSE; }
static GstElement * gst_auto_convert_get_subelement (GstAutoConvert * autoconvert, gboolean query_only) { GstElement *element = NULL; gboolean initial_identity; GST_AUTOCONVERT_LOCK (autoconvert); if (autoconvert->current_subelement) element = gst_object_ref (autoconvert->current_subelement); initial_identity = autoconvert->initial_identity; GST_AUTOCONVERT_UNLOCK (autoconvert); if (G_UNLIKELY (!query_only && element == NULL && initial_identity)) { /* No current sub-element - create an identity and install it */ GstElementFactory *identity_feature; GstElement *identity; GST_INFO_OBJECT (autoconvert, "No existing child element - instantiating identity"); /* if the identity feature doesn't exist - something is very wrong */ identity_feature = GST_ELEMENT_FACTORY_CAST (gst_default_registry_find_feature ("identity", GST_TYPE_ELEMENT_FACTORY)); identity = gst_auto_convert_get_or_make_element_from_factory (autoconvert, identity_feature); if (identity && gst_auto_convert_activate_element (autoconvert, identity, NULL)) { GST_AUTOCONVERT_LOCK (autoconvert); if (autoconvert->current_subelement) element = gst_object_ref (autoconvert->current_subelement); GST_AUTOCONVERT_UNLOCK (autoconvert); } } return element; }
/** * gst_element_register: * @plugin: (allow-none): #GstPlugin to register the element with, or NULL for * a static element (note that passing NULL only works in GStreamer 0.10.13 * and later) * @name: name of elements of this type * @rank: rank of element (higher rank means more importance when autoplugging) * @type: GType of element to register * * Create a new elementfactory capable of instantiating objects of the * @type and add the factory to @plugin. * * Returns: TRUE, if the registering succeeded, FALSE on error */ gboolean gst_element_register (GstPlugin * plugin, const gchar * name, guint rank, GType type) { GstPluginFeature *existing_feature; GstRegistry *registry; GstElementFactory *factory; GType *interfaces; guint n_interfaces, i; GstElementClass *klass; GList *item; g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (g_type_is_a (type, GST_TYPE_ELEMENT), FALSE); registry = gst_registry_get_default (); /* check if feature already exists, if it exists there is no need to update it * when the registry is getting updated, outdated plugins and all their * features are removed and readded. */ existing_feature = gst_registry_lookup_feature (registry, name); if (existing_feature) { GST_DEBUG_OBJECT (registry, "update existing feature %p (%s)", existing_feature, name); factory = GST_ELEMENT_FACTORY_CAST (existing_feature); factory->type = type; existing_feature->loaded = TRUE; g_type_set_qdata (type, _gst_elementclass_factory, factory); gst_object_unref (existing_feature); return TRUE; } factory = GST_ELEMENT_FACTORY_CAST (g_object_newv (GST_TYPE_ELEMENT_FACTORY, 0, NULL)); gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name); GST_LOG_OBJECT (factory, "Created new elementfactory for type %s", g_type_name (type)); /* provide info needed during class structure setup */ g_type_set_qdata (type, _gst_elementclass_factory, factory); klass = GST_ELEMENT_CLASS (g_type_class_ref (type)); if ((klass->details.longname == NULL) || (klass->details.klass == NULL) || (klass->details.author == NULL)) goto detailserror; factory->type = type; __gst_element_details_copy (&factory->details, &klass->details); if (klass->meta_data) { factory->meta_data = gst_structure_copy ((GstStructure *) klass->meta_data); } else { factory->meta_data = NULL; } for (item = klass->padtemplates; item; item = item->next) { GstPadTemplate *templ = item->data; GstStaticPadTemplate *newt; gchar *caps_string = gst_caps_to_string (templ->caps); newt = g_slice_new (GstStaticPadTemplate); newt->name_template = g_intern_string (templ->name_template); newt->direction = templ->direction; newt->presence = templ->presence; newt->static_caps.caps.refcount = 0; newt->static_caps.string = g_intern_string (caps_string); factory->staticpadtemplates = g_list_append (factory->staticpadtemplates, newt); g_free (caps_string); } factory->numpadtemplates = klass->numpadtemplates; /* special stuff for URI handling */ if (g_type_is_a (type, GST_TYPE_URI_HANDLER)) { GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_type_interface_peek (klass, GST_TYPE_URI_HANDLER); if (!iface || (!iface->get_type && !iface->get_type_full) || (!iface->get_protocols && !iface->get_protocols_full)) goto urierror; if (iface->get_type) factory->uri_type = iface->get_type (); else if (iface->get_type_full) factory->uri_type = iface->get_type_full (factory->type); if (!GST_URI_TYPE_IS_VALID (factory->uri_type)) goto urierror; if (iface->get_protocols) factory->uri_protocols = g_strdupv (iface->get_protocols ()); else if (iface->get_protocols_full) factory->uri_protocols = iface->get_protocols_full (factory->type); if (!factory->uri_protocols) goto urierror; } interfaces = g_type_interfaces (type, &n_interfaces); for (i = 0; i < n_interfaces; i++) { __gst_element_factory_add_interface (factory, g_type_name (interfaces[i])); } g_free (interfaces); if (plugin && plugin->desc.name) { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = plugin->desc.name; GST_PLUGIN_FEATURE_CAST (factory)->plugin = plugin; g_object_add_weak_pointer ((GObject *) plugin, (gpointer *) & GST_PLUGIN_FEATURE_CAST (factory)->plugin); } else { GST_PLUGIN_FEATURE_CAST (factory)->plugin_name = "NULL"; GST_PLUGIN_FEATURE_CAST (factory)->plugin = NULL; } gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE_CAST (factory), rank); GST_PLUGIN_FEATURE_CAST (factory)->loaded = TRUE; gst_registry_add_feature (registry, GST_PLUGIN_FEATURE_CAST (factory)); return TRUE; /* ERRORS */ urierror: { GST_WARNING_OBJECT (factory, "error with uri handler!"); gst_element_factory_cleanup (factory); return FALSE; } detailserror: { GST_WARNING_OBJECT (factory, "The GstElementDetails don't seem to have been set properly"); gst_element_factory_cleanup (factory); return FALSE; } }