summaryrefslogtreecommitdiff
path: root/gst/gstindexfactory.c
blob: ed8bfb6e18d3956a66027305580a89833720e0e0 (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* GStreamer
 * Copyright (C) 2001 RidgeRun (http://www.ridgerun.com/)
 * Written by Erik Walthinsen <omega@ridgerun.com>
 *
 * gstindexfactory.c: Index for mappings and other data
 *
 * 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.
 */

/**
 * SECTION:gstindexfactory
 * @short_description: Create GstIndexes from a factory
 * @see_also: #GstIndex
 *
 * GstIndexFactory is used to dynamically create GstIndex implementations.
 */


#include "gst_private.h"

#include "gstinfo.h"
#include "gstindex.h"
#include "gstindexfactory.h"
#include "gstmarshal.h"
#include "gstregistry.h"

static void gst_index_factory_class_init (GstIndexFactoryClass * klass);
static void gst_index_factory_init (GstIndexFactory * factory);
static void gst_index_factory_finalize (GObject * object);

static GstPluginFeatureClass *factory_parent_class = NULL;

/* static guint gst_index_factory_signals[LAST_SIGNAL] = { 0 }; */

GType
gst_index_factory_get_type (void)
{
  static GType indexfactory_type = 0;

  if (!indexfactory_type) {
    static const GTypeInfo indexfactory_info = {
      sizeof (GstIndexFactoryClass),
      NULL,
      NULL,
      (GClassInitFunc) gst_index_factory_class_init,
      NULL,
      NULL,
      sizeof (GstIndexFactory),
      0,
      (GInstanceInitFunc) gst_index_factory_init,
      NULL
    };

    indexfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
        "GstIndexFactory", &indexfactory_info, 0);
  }
  return indexfactory_type;
}

static void
gst_index_factory_class_init (GstIndexFactoryClass * klass)
{
  GObjectClass *gobject_class;
  GstObjectClass *gstobject_class;
  GstPluginFeatureClass *gstpluginfeature_class;

  gobject_class = (GObjectClass *) klass;
  gstobject_class = (GstObjectClass *) klass;
  gstpluginfeature_class = (GstPluginFeatureClass *) klass;

  factory_parent_class = g_type_class_ref (GST_TYPE_PLUGIN_FEATURE);

  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_index_factory_finalize);
}

static void
gst_index_factory_init (GstIndexFactory * factory)
{
}

static void
gst_index_factory_finalize (GObject * object)
{
  GstIndexFactory *factory = GST_INDEX_FACTORY (object);

  g_free (factory->longdesc);

  G_OBJECT_CLASS (factory_parent_class)->finalize (object);

}

/**
 * gst_index_factory_new:
 * @name: name of indexfactory to create
 * @longdesc: long description of indexfactory to create
 * @type: the GType of the GstIndex element of this factory
 *
 * Create a new indexfactory with the given parameters
 *
 * Returns: a new #GstIndexFactory.
 */
GstIndexFactory *
gst_index_factory_new (const gchar * name, const gchar * longdesc, GType type)
{
  GstIndexFactory *factory;

  g_return_val_if_fail (name != NULL, NULL);
  factory = GST_INDEX_FACTORY (g_object_new (GST_TYPE_INDEX_FACTORY, NULL));

  GST_PLUGIN_FEATURE_NAME (factory) = g_strdup (name);
  if (factory->longdesc)
    g_free (factory->longdesc);
  factory->longdesc = g_strdup (longdesc);
  factory->type = type;

  return factory;
}

/**
 * gst_index_factory_destroy:
 * @factory: factory to destroy
 *
 * Removes the index from the global list.
 */
void
gst_index_factory_destroy (GstIndexFactory * factory)
{
  g_return_if_fail (factory != NULL);

  /* we don't free the struct bacause someone might  have a handle to it.. */
}

/**
 * gst_index_factory_find:
 * @name: name of indexfactory to find
 *
 * Search for an indexfactory of the given name.
 *
 * Returns: #GstIndexFactory if found, NULL otherwise
 */
GstIndexFactory *
gst_index_factory_find (const gchar * name)
{
  GstPluginFeature *feature;

  g_return_val_if_fail (name != NULL, NULL);

  GST_DEBUG ("gstindex: find \"%s\"", name);

  feature = gst_registry_find_feature (gst_registry_get_default (), name,
      GST_TYPE_INDEX_FACTORY);
  if (feature)
    return GST_INDEX_FACTORY (feature);

  return NULL;
}

/**
 * gst_index_factory_create:
 * @factory: the factory used to create the instance
 *
 * Create a new #GstIndex instance from the
 * given indexfactory.
 *
 * Returns: A new #GstIndex instance.
 */
GstIndex *
gst_index_factory_create (GstIndexFactory * factory)
{
  GstIndexFactory *newfactory;
  GstIndex *new = NULL;

  g_return_val_if_fail (factory != NULL, NULL);

  newfactory =
      GST_INDEX_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE
          (factory)));
  if (newfactory == NULL)
    return NULL;

  new = GST_INDEX (g_object_new (newfactory->type, NULL));

  gst_object_unref (newfactory);

  return new;
}

/**
 * gst_index_factory_make:
 * @name: the name of the factory used to create the instance
 *
 * Create a new #GstIndex instance from the
 * indexfactory with the given name.
 *
 * Returns: A new #GstIndex instance.
 */
GstIndex *
gst_index_factory_make (const gchar * name)
{
  GstIndexFactory *factory;

  g_return_val_if_fail (name != NULL, NULL);

  factory = gst_index_factory_find (name);

  if (factory == NULL)
    return NULL;

  return gst_index_factory_create (factory);
}