summaryrefslogtreecommitdiff
path: root/gst/gstpluginfeature.c
blob: 788222f67f73fadacbf5a0943bcaea6e84971ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
 *
 * gstpluginfeature.c: Abstract base class for all plugin features
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gst_private.h"

#include "gstpluginfeature.h"
#include "gstplugin.h"
#include "gstregistry.h"
#include "gstinfo.h"

#include <string.h>

static void		gst_plugin_feature_class_init		(GstPluginFeatureClass *klass);
static void		gst_plugin_feature_init			(GstPluginFeature *feature);

static GObjectClass *parent_class = NULL;
/* static guint gst_plugin_feature_signals[LAST_SIGNAL] = { 0 }; */

GType
gst_plugin_feature_get_type (void)
{
  static GType plugin_feature_type = 0;

  if (!plugin_feature_type) {
    static const GTypeInfo plugin_feature_info = {
      sizeof (GObjectClass),
      NULL,
      NULL,
      (GClassInitFunc) gst_plugin_feature_class_init,
      NULL,
      NULL,
      sizeof (GObject),
      32,
      (GInstanceInitFunc) gst_plugin_feature_init,
      NULL
    };
    plugin_feature_type = g_type_register_static (G_TYPE_OBJECT, "GstPluginFeature", 
		    				  &plugin_feature_info, G_TYPE_FLAG_ABSTRACT);
  }
  return plugin_feature_type;
}

static void
gst_plugin_feature_class_init (GstPluginFeatureClass *klass)
{
  GObjectClass *gobject_class;

  gobject_class = (GObjectClass*) klass;

  parent_class = g_type_class_ref (G_TYPE_OBJECT);
}

static void
gst_plugin_feature_init (GstPluginFeature *feature)
{
  feature->manager = NULL;
}

/**
 * gst_plugin_feature_ensure_loaded:
 * @feature: the plugin feature to check
 *
 * Check if the plugin containing the feature is loaded,
 * if not, the plugin will be loaded.
 *
 * Returns: a boolean indicating the feature is loaded.
 */
gboolean
gst_plugin_feature_ensure_loaded (GstPluginFeature *feature)
{
  GstPlugin *plugin;
  
  g_return_val_if_fail (feature != NULL, FALSE);
  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), FALSE);

  plugin = (GstPlugin *) (feature->manager);

  if (plugin && !gst_plugin_is_loaded (plugin)) {
#ifndef GST_DISABLE_REGISTRY 
    if (GST_IS_REGISTRY (plugin->manager)) {
      GST_CAT_DEBUG (GST_CAT_PLUGIN_LOADING, 
	         "loading plugin %s for feature", plugin->desc.name);

      if (gst_registry_load_plugin (GST_REGISTRY (plugin->manager), plugin) != GST_REGISTRY_OK)
	return FALSE;
    }
    else
#endif /* GST_DISABLE_REGISTRY */
      return FALSE;
  }
  return TRUE;
}

/**
 * gst_plugin_feature_unload_thyself:
 * @feature: the plugin feature to check
 *
 * Unload the given feature. This will decrease the refcount
 * in the plugin and will eventually unload the plugin
 */
void
gst_plugin_feature_unload_thyself (GstPluginFeature *feature)
{
  GstPluginFeatureClass *oclass; 

  g_return_if_fail (feature != NULL);
  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
  
  oclass = GST_PLUGIN_FEATURE_GET_CLASS (feature);

  if (oclass->unload_thyself)
    oclass->unload_thyself (feature);
}

gboolean
gst_plugin_feature_type_name_filter (GstPluginFeature *feature,
		                     GstTypeNameData *data)
{
  return ((data->type == 0    || data->type == G_OBJECT_TYPE (feature)) &&
          (data->name == NULL || !strcmp (data->name, GST_PLUGIN_FEATURE_NAME (feature))));
}
/**
 * gst_plugin_feature_set_rank:
 * @feature: feature to rank
 * @rank: rank value - higher number means more priority rank
 *
 * Specifies a rank for a plugin feature, so that autoplugging uses
 * the most appropriate feature.
 */
void
gst_plugin_feature_set_rank (GstPluginFeature *feature, guint rank)
{
  g_return_if_fail (feature != NULL);
  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));

  feature->rank = rank;
}
/**
 * gst_plugin_feature_set_name:
 * @feature: a feature
 * @name: the name to set
 *
 * Sets the name of a plugin feature. The name uniquely identifies a feature
 * within all features of the same type. Renaming a plugin feature is not 
 * allowed.
 */
void
gst_plugin_feature_set_name (GstPluginFeature *feature, const gchar *name)
{
  g_return_if_fail (GST_IS_PLUGIN_FEATURE (feature));
  g_return_if_fail (name != NULL);

  if (feature->name) {
    g_return_if_fail (strcmp (feature->name, name) == 0);
  } else {
    feature->name = g_strdup (name);
  }
}
/**
 * gst_plugin_feature_get rank:
 * @feature: a feature
 *
 * Gets the rank of a plugin feature.
 *
 * Returns: The rank of the feature
 */
guint
gst_plugin_feature_get_rank (GstPluginFeature *feature)
{
  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), GST_RANK_NONE);
  
  return feature->rank;
}
/**
 * gst_plugin_feature_set_name:
 * @feature: a feature
 *
 * Gets the name of a pluginfeature.
 *
 * Returns: the name
 */
G_CONST_RETURN gchar *
gst_plugin_feature_get_name (GstPluginFeature *feature)
{
  g_return_val_if_fail (GST_IS_PLUGIN_FEATURE (feature), NULL);
  
  return feature->name;
}