EXPORT_C #endif GstCaps * gst_type_find_helper_for_extension (GstObject * obj, const gchar * extension) { GList *l, *type_list; GstCaps *result = NULL; g_return_val_if_fail (extension != NULL, NULL); GST_LOG_OBJECT (obj, "finding caps for extension %s", extension); type_list = gst_type_find_factory_get_list (); type_list = g_list_sort (type_list, type_find_factory_rank_cmp); for (l = type_list; l; l = g_list_next (l)) { GstTypeFindFactory *factory; gchar **ext; gint i; factory = GST_TYPE_FIND_FACTORY (l->data); /* get the extension that this typefind factory can handle */ ext = gst_type_find_factory_get_extensions (factory); if (ext == NULL) continue; /* we only want to check those factories without a function */ if (factory->function != NULL) continue; /* there are extension, see if one of them matches the requested * extension */ for (i = 0; ext[i]; i++) { if (strcmp (ext[i], extension) == 0) { /* we found a matching extension, take the caps */ if ((result = gst_type_find_factory_get_caps (factory))) { gst_caps_ref (result); goto done; } } } } done: gst_plugin_feature_list_free (type_list); GST_LOG_OBJECT (obj, "Returning %" GST_PTR_FORMAT, result); return result; }
static HashSet<String> mimeTypeCache() { do_gst_init(); static HashSet<String> cache; static bool typeListInitialized = false; if (!typeListInitialized) { // These subtypes are already beeing supported by WebKit itself HashSet<String> ignoredApplicationSubtypes; ignoredApplicationSubtypes.add(String("javascript")); ignoredApplicationSubtypes.add(String("ecmascript")); ignoredApplicationSubtypes.add(String("x-javascript")); ignoredApplicationSubtypes.add(String("xml")); ignoredApplicationSubtypes.add(String("xhtml+xml")); ignoredApplicationSubtypes.add(String("rss+xml")); ignoredApplicationSubtypes.add(String("atom+xml")); ignoredApplicationSubtypes.add(String("x-ftp-directory")); ignoredApplicationSubtypes.add(String("x-java-applet")); ignoredApplicationSubtypes.add(String("x-java-bean")); ignoredApplicationSubtypes.add(String("x-java-vm")); ignoredApplicationSubtypes.add(String("x-shockwave-flash")); GList* factories = gst_type_find_factory_get_list(); for (GList* iterator = factories; iterator; iterator = iterator->next) { GstTypeFindFactory* factory = GST_TYPE_FIND_FACTORY(iterator->data); GstCaps* caps = gst_type_find_factory_get_caps(factory); // Splitting the capability by comma and taking the first part // as capability can be something like "audio/x-wavpack, framed=(boolean)false" GOwnPtr<gchar> capabilityString(gst_caps_to_string(caps)); gchar** capability = g_strsplit(capabilityString.get(), ",", 2); gchar** mimetype = g_strsplit(capability[0], "/", 2); // GStreamer plugins can be capable of supporting types which WebKit supports // by default. In that case, we should not consider these types supportable by GStreamer. // Examples of what GStreamer can support but should not be added: // text/plain, text/html, image/jpeg, application/xml if (g_str_equal(mimetype[0], "audio") || g_str_equal(mimetype[0], "video") || (g_str_equal(mimetype[0], "application") && !ignoredApplicationSubtypes.contains(String(mimetype[1])))) { cache.add(String(capability[0])); // These formats are supported by GStreamer, but not correctly advertised if (g_str_equal(capability[0], "video/x-h264") || g_str_equal(capability[0], "audio/x-m4a")) { cache.add(String("video/mp4")); cache.add(String("audio/aac")); } if (g_str_equal(capability[0], "video/x-theora")) cache.add(String("video/ogg")); if (g_str_equal(capability[0], "audio/x-wav")) cache.add(String("audio/wav")); if (g_str_equal(capability[0], "audio/mpeg")) { // This is what we are handling: mpegversion=(int)1, layer=(int)[ 1, 3 ] gchar** versionAndLayer = g_strsplit(capability[1], ",", 2); if (g_str_has_suffix (versionAndLayer[0], "(int)1")) { for (int i = 0; versionAndLayer[1][i] != '\0'; i++) { if (versionAndLayer[1][i] == '1') cache.add(String("audio/mp1")); else if (versionAndLayer[1][i] == '2') cache.add(String("audio/mp2")); else if (versionAndLayer[1][i] == '3') cache.add(String("audio/mp3")); } } g_strfreev(versionAndLayer); } } g_strfreev(capability); g_strfreev(mimetype); } gst_plugin_feature_list_free(factories); typeListInitialized = true; } return cache; }
// Obtains a list of supported extensions from typefind factories // TODO: improve the list. It is obviously incomplete. wxArrayString GStreamerImportPlugin::GetSupportedExtensions() { // We refresh the extensions each time this is called in case the // user had installed additional gstreamer plugins while Audacity // was active. mExtensions.Empty(); // Gather extensions from all factories that support audio GList *factories = gst_type_find_factory_get_list(); for (GList *list = factories; list != NULL; list = g_list_next(list)) { GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY(list->data); // We need the capabilities to determine if it handles audio GstCaps *caps = gst_type_find_factory_get_caps(factory); if (!caps) { continue; } // Check each structure in the caps for audio for (guint c = 0, clen = gst_caps_get_size(caps); c < clen; c++) { // Bypass if it isn't for audio GstStructure *str = gst_caps_get_structure(caps, c); if (!g_str_has_prefix(gst_structure_get_name(str), "audio")) { continue; } // This factory can handle audio, so get the extensions const gchar *const *extensions = gst_type_find_factory_get_extensions(factory); if (!extensions) { continue; } // Add each extension to the list for (guint i = 0; extensions[i] != NULL; i++) { wxString extension = wxString::FromUTF8(extensions[i]); if (mExtensions.Index(extension.c_str(), false) == wxNOT_FOUND) { mExtensions.Add(extension); } } } } gst_plugin_feature_list_free(factories); // Get them in a decent order mExtensions.Sort(); // Log it for debugging wxString extensions = wxT("Extensions:"); for (size_t i = 0; i < mExtensions.GetCount(); i++) { extensions = extensions + wxT(" ") + mExtensions[i]; } wxLogMessage(wxT("%s"), extensions.c_str()); return mExtensions; }
/* * Method: caps * * Gets the caps associated with a type find factory. * * Returns: the Gst::Caps object associated with this factory. */ static VALUE rg_caps (VALUE self) { return RGST_CAPS_NEW (gst_type_find_factory_get_caps (RGST_TYPE_FIND_FACTORY (self))); }