/** * gst_plugin_load_by_name: * @name: name of plugin to load * * Load the named plugin. Refs the plugin. * * Returns: A reference to a loaded plugin, or NULL on error. */ GstPlugin * gst_plugin_load_by_name (const gchar * name) { GstPlugin *plugin, *newplugin; GError *error = NULL; GST_DEBUG ("looking up plugin %s in default registry", name); plugin = gst_registry_find_plugin (gst_registry_get_default (), name); if (plugin) { GST_DEBUG ("loading plugin %s from file %s", name, plugin->filename); newplugin = gst_plugin_load_file (plugin->filename, &error); gst_object_unref (plugin); if (!newplugin) { GST_WARNING ("load_plugin error: %s", error->message); g_error_free (error); return NULL; } /* newplugin was reffed by load_file */ return newplugin; } GST_DEBUG ("Could not find plugin %s in registry", name); return NULL; }
/** * gst_plugin_load: * @plugin: plugin to load * * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is * untouched. The normal use pattern of this function goes like this: * * <programlisting> * GstPlugin *loaded_plugin; * loaded_plugin = gst_plugin_load (plugin); * // presumably, we're no longer interested in the potentially-unloaded plugin * gst_object_unref (plugin); * plugin = loaded_plugin; * </programlisting> * * Returns: A reference to a loaded plugin, or NULL on error. */ GstPlugin * gst_plugin_load (GstPlugin * plugin) { GError *error = NULL; GstPlugin *newplugin; if (gst_plugin_is_loaded (plugin)) { return plugin; } if (!(newplugin = gst_plugin_load_file (plugin->filename, &error))) goto load_error; return newplugin; load_error: { GST_WARNING ("load_plugin error: %s", error->message); g_error_free (error); return NULL; } }
static gboolean do_plugin_load (GstPluginLoader * l, const gchar * filename, guint tag) { GstPlugin *newplugin; GList *chunks = NULL; GST_DEBUG ("Plugin scanner loading file %s. tag %u", filename, tag); #if 0 /* Test code - crash based on filename */ if (strstr (filename, "coreelements") == NULL) { g_printerr ("Crashing on file %s\n", filename); g_printerr ("%d", *(gint *) (NULL)); } #endif newplugin = gst_plugin_load_file ((gchar *) filename, NULL); if (newplugin) { guint hdr_pos; guint offset; /* Now serialise the plugin details and send */ if (!_priv_gst_registry_chunks_save_plugin (&chunks, gst_registry_get_default (), newplugin)) goto fail; /* Store where the header is, write an empty one, then write * all the payload chunks, then fix up the header size */ hdr_pos = l->tx_buf_write; offset = HEADER_SIZE; put_packet (l, PACKET_PLUGIN_DETAILS, tag, NULL, 0); if (chunks) { GList *walk; for (walk = chunks; walk; walk = g_list_next (walk)) { GstRegistryChunk *cur = walk->data; put_chunk (l, cur, &offset); _priv_gst_registry_chunk_free (cur); } g_list_free (chunks); /* Store the size of the written payload */ GST_WRITE_UINT32_BE (l->tx_buf + hdr_pos + 4, offset - HEADER_SIZE); } #if 0 /* Test code - corrupt the tx buffer based on filename */ if (strstr (filename, "sink") != NULL) { int fd, res; g_printerr ("Corrupting tx buf on file %s\n", filename); fd = open ("/dev/urandom", O_RDONLY); res = read (fd, l->tx_buf, l->tx_buf_size); close (fd); } #endif gst_object_unref (newplugin); } else { put_packet (l, PACKET_PLUGIN_DETAILS, tag, NULL, 0); } return TRUE; fail: put_packet (l, PACKET_PLUGIN_DETAILS, tag, NULL, 0); if (chunks) { GList *walk; for (walk = chunks; walk; walk = g_list_next (walk)) { GstRegistryChunk *cur = walk->data; _priv_gst_registry_chunk_free (cur); } g_list_free (chunks); } return FALSE; }
int main (int argc, char *argv[]) { gboolean print_all = FALSE; gboolean do_print_blacklist = FALSE; gboolean plugin_name = FALSE; gboolean print_aii = FALSE; gboolean uri_handlers = FALSE; gboolean check_exists = FALSE; gchar *min_version = NULL; guint minver_maj = GST_VERSION_MAJOR; guint minver_min = GST_VERSION_MINOR; guint minver_micro = 0; #ifndef GST_DISABLE_OPTION_PARSING GOptionEntry options[] = { {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all, N_("Print all elements"), NULL}, {"print-blacklist", 'b', 0, G_OPTION_ARG_NONE, &do_print_blacklist, N_("Print list of blacklisted files"), NULL}, {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii, N_("Print a machine-parsable list of features the specified plugin " "or all plugins provide.\n " "Useful in connection with external automatic plugin " "installation mechanisms"), NULL}, {"plugin", '\0', 0, G_OPTION_ARG_NONE, &plugin_name, N_("List the plugin contents"), NULL}, {"exists", '\0', 0, G_OPTION_ARG_NONE, &check_exists, N_("Check if the specified element or plugin exists"), NULL}, {"atleast-version", '\0', 0, G_OPTION_ARG_STRING, &min_version, N_ ("When checking if an element or plugin exists, also check that its " "version is at least the version specified"), NULL}, {"uri-handlers", 'u', 0, G_OPTION_ARG_NONE, &uri_handlers, N_ ("Print supported URI schemes, with the elements that implement them"), NULL}, GST_TOOLS_GOPTION_VERSION, {NULL} }; GOptionContext *ctx; GError *err = NULL; #endif setlocale (LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif /* avoid glib warnings when inspecting deprecated properties */ g_setenv ("G_ENABLE_DIAGNOSTIC", "0", FALSE); g_set_prgname ("gst-inspect-" GST_API_VERSION); #ifndef GST_DISABLE_OPTION_PARSING ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]"); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_printerr ("Error initializing: %s\n", err->message); g_clear_error (&err); g_option_context_free (ctx); return -1; } g_option_context_free (ctx); #else gst_init (&argc, &argv); #endif gst_tools_print_version (); if (print_all && argc > 1) { g_printerr ("-a requires no extra arguments\n"); return -1; } if (uri_handlers && argc > 1) { g_printerr ("-u requires no extra arguments\n"); return -1; } /* --atleast-version implies --exists */ if (min_version != NULL) { if (sscanf (min_version, "%u.%u.%u", &minver_maj, &minver_min, &minver_micro) < 2) { g_printerr ("Can't parse version '%s' passed to --atleast-version\n", min_version); return -1; } check_exists = TRUE; } if (check_exists) { int exit_code; if (argc == 1) { g_printerr ("--exists requires an extra command line argument\n"); exit_code = -1; } else { if (!plugin_name) { GstPluginFeature *feature; feature = gst_registry_lookup_feature (gst_registry_get (), argv[1]); if (feature != NULL && gst_plugin_feature_check_version (feature, minver_maj, minver_min, minver_micro)) { exit_code = 0; } else { exit_code = 1; } } else { /* FIXME: support checking for plugins too */ g_printerr ("Checking for plugins is not supported yet\n"); exit_code = -1; } } return exit_code; } /* if no arguments, print out list of elements */ if (uri_handlers) { print_all_uri_handlers (); } else if (argc == 1 || print_all) { if (do_print_blacklist) print_blacklist (); else { if (print_aii) print_all_plugin_automatic_install_info (); else print_element_list (print_all); } } else { /* else we try to get a factory */ GstElementFactory *factory; GstPlugin *plugin; const char *arg = argv[argc - 1]; int retval; if (!plugin_name) { factory = gst_element_factory_find (arg); /* if there's a factory, print out the info */ if (factory) { retval = print_element_info (factory, print_all); gst_object_unref (factory); } else { retval = print_element_features (arg); } } else { retval = -1; } /* otherwise check if it's a plugin */ if (retval) { plugin = gst_registry_find_plugin (gst_registry_get (), arg); /* if there is such a plugin, print out info */ if (plugin) { if (print_aii) { print_plugin_automatic_install_info (plugin); } else { print_plugin_info (plugin); print_plugin_features (plugin); } } else { GError *error = NULL; if (g_file_test (arg, G_FILE_TEST_EXISTS)) { plugin = gst_plugin_load_file (arg, &error); if (plugin) { if (print_aii) { print_plugin_automatic_install_info (plugin); } else { print_plugin_info (plugin); print_plugin_features (plugin); } } else { g_printerr (_("Could not load plugin file: %s\n"), error->message); g_clear_error (&error); return -1; } } else { g_printerr (_("No such element or plugin '%s'\n"), arg); return -1; } } } } return 0; }
bool VideoPlayerBackend::initGStreamer(QString *errorMessage) { static bool loaded = false; if (loaded) return true; GError *err; if (gst_init_check(0, 0, &err) == FALSE) { Q_ASSERT(err); qWarning() << "GStreamer initialization failed:" << err->message; if (errorMessage) *errorMessage = QString::fromLatin1("initialization failed: ") + QString::fromLatin1(err->message); g_error_free(err); return false; } #ifdef Q_OS_LINUX if (QString::fromLatin1(GSTREAMER_PLUGINS).isEmpty()) return true; #endif #ifdef Q_OS_WIN #define EXT ".dll" #else #define EXT ".so" #endif const char *plugins[] = { "libgsttypefindfunctions"EXT, "libgstapp"EXT, "libgstdecodebin2"EXT, "libgstmatroska"EXT, "libgstffmpegcolorspace"EXT, "libgstcoreelements"EXT, #ifndef Q_OS_WIN "libgstffmpeg"EXT, #endif #ifdef Q_OS_WIN "libgstffmpeg-lgpl"EXT, "libgstautodetect"EXT, #elif defined(Q_OS_MAC) "libgstosxaudio"EXT, #endif 0 }; #undef EXT #if defined(Q_OS_MAC) QString pluginPath = QApplication::applicationDirPath() + QLatin1String("/../PlugIns/gstreamer/"); #else QString pluginPath = QDir::toNativeSeparators(QApplication::applicationDirPath() + QDir::separator()); #endif #if defined(GSTREAMER_PLUGINS) and not defined(Q_OS_MAC) QString ppx = QDir::toNativeSeparators(QString::fromLatin1(GSTREAMER_PLUGINS "/")); if (QDir::isAbsolutePath(ppx)) pluginPath = ppx; else pluginPath += ppx; #endif if (!QFile::exists(pluginPath)) { qWarning() << "gstreamer: Plugin path" << pluginPath << "does not exist"; if (errorMessage) *errorMessage = QString::fromLatin1("plugin path (%1) does not exist").arg(pluginPath); return false; } bool success = true; QByteArray path = QFile::encodeName(pluginPath); int pathEnd = path.size(); if (errorMessage) errorMessage->clear(); for (const char **p = plugins; *p; ++p) { path.truncate(pathEnd); path.append(*p); GError *err = 0; GstPlugin *plugin = gst_plugin_load_file(path.constData(), &err); if (!plugin) { Q_ASSERT(err); qWarning() << "gstreamer: Failed to load plugin" << *p << ":" << err->message; if (errorMessage) errorMessage->append(QString::fromLatin1("plugin '%1' failed: %2\n").arg(QLatin1String(*p)) .arg(QLatin1String(err->message))); g_error_free(err); success = false; } else { Q_ASSERT(!err); gst_object_unref(plugin); } } if (success) loaded = true; return success; }
int main (int argc, char *argv[]) { gboolean print_all = FALSE; gboolean print_aii = FALSE; GOptionEntry options[] = { {"print-all", 'a', 0, G_OPTION_ARG_NONE, &print_all, N_("Print all elements"), NULL}, {"print-plugin-auto-install-info", '\0', 0, G_OPTION_ARG_NONE, &print_aii, N_("Print a machine-parsable list of features the specified plugin " "provides.\n " "Useful in connection with external automatic plugin " "installation mechanisms"), NULL}, GST_TOOLS_GOPTION_VERSION, {NULL} }; GOptionContext *ctx; GError *err = NULL; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (!g_thread_supported ()) g_thread_init (NULL); ctx = g_option_context_new ("[ELEMENT-NAME | PLUGIN-NAME]"); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); gst_tools_print_version ("gst-inspect"); if (print_all && argc > 2) { g_print ("-a requires no extra arguments\n"); return 1; } /* if no arguments, print out list of elements */ if (argc == 1 || print_all) { print_element_list (print_all); /* else we try to get a factory */ } else { GstElementFactory *factory; GstPlugin *plugin; const char *arg = argv[argc - 1]; int retval; factory = gst_element_factory_find (arg); /* if there's a factory, print out the info */ if (factory) { retval = print_element_info (factory, print_all); gst_object_unref (factory); } else { retval = print_element_features (arg); } /* otherwise check if it's a plugin */ if (retval) { plugin = gst_default_registry_find_plugin (arg); /* if there is such a plugin, print out info */ if (plugin) { if (print_aii) { print_plugin_automatic_install_info (plugin); } else { print_plugin_info (plugin); print_plugin_features (plugin); } } else { GError *error = NULL; if (g_file_test (arg, G_FILE_TEST_EXISTS)) { plugin = gst_plugin_load_file (arg, &error); if (plugin) { if (print_aii) { print_plugin_automatic_install_info (plugin); } else { print_plugin_info (plugin); print_plugin_features (plugin); } } else { g_print (_("Could not load plugin file: %s\n"), error->message); g_error_free (error); return -1; } } else { g_print (_("No such element or plugin '%s'\n"), arg); return -1; } } } } return 0; }