source: trunk/third/gstreamer/tools/gst-register.c @ 21005

Revision 21005, 5.1 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/* GStreamer
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 *                    2000 Wim Taymans <wtay@chello.be>
4 *
5 * gst-register.c: Plugin subsystem for loading elements, types, and libs
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#  include "config.h"
25#endif
26
27#include <gst/gst.h>
28
29#include <stdlib.h>
30#include <stdio.h>
31
32#include <fcntl.h>
33#ifdef HAVE_UNISTD_H
34#include <unistd.h>
35#endif
36#include <string.h>
37#include <errno.h>
38#include <locale.h>
39
40#include "gst/gst-i18n-app.h"
41
42static gint num_features = 0;
43static gint num_plugins = 0;
44
45static void
46plugin_added_func (GstRegistry * registry, GstPlugin * plugin,
47    gpointer user_data)
48{
49  g_print (_("Added plugin %s with %d %s.\n"), plugin->desc.name,
50      plugin->numfeatures,
51      ngettext ("feature", "features", plugin->numfeatures));
52
53  num_features += plugin->numfeatures;
54  num_plugins++;
55}
56
57static void
58spawn_all_in_dir (const char *dirname)
59{
60  char *argv[2] = { NULL, NULL };
61  GDir *dir;
62  const char *file;
63
64  /* g_print("spawning all in %s\n", dirname); */
65
66  dir = g_dir_open (dirname, 0, NULL);
67  if (dir == NULL)
68    return;
69
70  while ((file = g_dir_read_name (dir))) {
71    argv[0] = g_build_filename (dirname, file, NULL);
72    g_print ("running %s\n", argv[0]);
73    g_spawn_sync (NULL, argv, NULL, G_SPAWN_FILE_AND_ARGV_ZERO, NULL, NULL,
74        NULL, NULL, NULL, NULL);
75    g_free (argv[0]);
76  }
77  g_dir_close (dir);
78}
79
80int
81main (int argc, char *argv[])
82{
83  GList *registries;
84  GList *path_spill = NULL;     /* used for path spill from failing registries */
85
86#ifdef GETTEXT_PACKAGE
87  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
88  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
89  textdomain (GETTEXT_PACKAGE);
90#endif
91
92  /* Init gst */
93  _gst_registry_auto_load = FALSE;
94  gst_init (&argc, &argv);
95
96  registries = gst_registry_pool_list ();
97  registries = g_list_reverse (registries);
98
99  while (registries) {
100    GstRegistry *registry = GST_REGISTRY (registries->data);
101    GList *dir_list;
102    GList *iter;
103    char *dir;
104
105    if (path_spill) {
106      GList *iter;
107
108      /* add spilled paths to this registry;
109       * since they're spilled they probably weren't loaded correctly
110       * so we should give a lower priority registry the chance to do them */
111      for (iter = path_spill; iter; iter = iter->next) {
112        g_print (_("Added path   %s to %s \n"),
113            (const char *) iter->data, registry->name);
114        gst_registry_add_path (registry, (const gchar *) iter->data);
115      }
116      g_list_free (path_spill);
117      path_spill = NULL;
118    }
119
120    g_signal_connect (G_OBJECT (registry), "plugin_added",
121        G_CALLBACK (plugin_added_func), NULL);
122
123    if (registry->flags & GST_REGISTRY_WRITABLE) {
124      char *location;
125
126      g_object_get (registry, "location", &location, NULL);
127      g_print (_("Rebuilding %s (%s) ...\n"), registry->name, location);
128      g_free (location);
129      gst_registry_rebuild (registry);
130      gst_registry_save (registry);
131    } else {
132      g_print (_("Trying to load %s ...\n"), registry->name);
133      if (!gst_registry_load (registry)) {
134        g_print (_("Error loading %s\n"), registry->name);
135        /* move over paths from this registry to the next one */
136        path_spill = g_list_concat (path_spill,
137            gst_registry_get_path_list (registry));
138        /* this assertion triggers for a non-readable/writable user registry,
139         * see #148283 */
140        /* g_assert (path_spill != NULL); */
141      }
142      /* also move over paths if the registry wasn't writable
143       * FIXME: we should check if the paths that were loaded from this
144       registry get removed from the path_list so we only try to
145       spill paths that could not be registered */
146      /* Until that is done, don't spill paths when registry is not writable
147         (e.g. case of user running gst-register and sysreg not writable) */
148
149      /*
150         path_spill = g_list_concat (path_spill,
151         gst_registry_get_path_list (registry));
152       */
153    }
154
155    dir_list = gst_registry_get_path_list (registry);
156    for (iter = dir_list; iter; iter = iter->next) {
157      dir =
158          g_build_filename ((const char *) iter->data, "register-scripts",
159          NULL);
160      spawn_all_in_dir (dir);
161      g_free (dir);
162    }
163    g_list_free (dir_list);
164
165    registries = g_list_next (registries);
166  }
167
168  g_print (_("Loaded %d plugins with %d %s.\n"), num_plugins, num_features,
169      ngettext ("feature", "features", num_features));
170
171  return (0);
172}
Note: See TracBrowser for help on using the repository browser.