summaryrefslogtreecommitdiff
path: root/gst/gstautoplug.c
blob: 9b1a012afa5b87d1e06a79101c9bdb14bc51fa6b (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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
 *
 * gstautoplug.c: Autoplugging of pipelines
 *
 * 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.
 */

//#define GST_DEBUG_ENABLED
#include "gst_private.h"

#include "gstautoplug.h"
#include "gstplugin.h"

GList* _gst_autoplugfactories;

enum {
  NEW_OBJECT,
  LAST_SIGNAL
};

enum {
  ARG_0,
  /* FILL ME */
};

static void     gst_autoplug_class_init (GstAutoplugClass *klass);
static void     gst_autoplug_init       (GstAutoplug *autoplug);

static GstObjectClass *parent_class = NULL;
static guint gst_autoplug_signals[LAST_SIGNAL] = { 0 };

GType gst_autoplug_get_type(void)
{
  static GType autoplug_type = 0;

  if (!autoplug_type) {
    static const GTypeInfo autoplug_info = {
      sizeof(GstAutoplugClass),
      NULL,
      NULL,
      (GClassInitFunc)gst_autoplug_class_init,
      NULL,
      NULL,
      sizeof(GstAutoplug),
      4,
      (GInstanceInitFunc)gst_autoplug_init,
    };
    autoplug_type = g_type_register_static (GST_TYPE_OBJECT, "GstAutoplug", &autoplug_info, 0);
  }
  return autoplug_type;
}

static void
gst_autoplug_class_init(GstAutoplugClass *klass)
{
  GObjectClass *gobject_class;
  GstObjectClass *gstobject_class;

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

  parent_class = g_type_class_ref (GST_TYPE_OBJECT);

  gst_autoplug_signals[NEW_OBJECT] =
    g_signal_newc ("new_object", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
                    G_STRUCT_OFFSET (GstAutoplugClass, new_object), NULL, NULL,
                    g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
                    GST_TYPE_OBJECT);
}

static void gst_autoplug_init(GstAutoplug *autoplug)
{
}

void
_gst_autoplug_initialize (void)
{
  _gst_autoplugfactories = NULL;
}

/**
 * gst_autoplug_signal_new_object:
 * @autoplug: The autoplugger to emit the signal 
 * @object: The object that is passed to the signal
 *
 * Emit a new_object signal. autopluggers are supposed to
 * emit this signal whenever a new object has been added to 
 * the autoplugged pipeline.
 * 
 */
void
gst_autoplug_signal_new_object (GstAutoplug *autoplug, GstObject *object)
{
  g_signal_emit (G_OBJECT (autoplug), gst_autoplug_signals[NEW_OBJECT], 0, object);
}


/**
 * gst_autoplug_to_caps:
 * @autoplug: The autoplugger perform the autoplugging
 * @srccaps: The source cpabilities
 * @sinkcaps: The target capabilities
 * @...: more target capabilities
 *
 * Perform the autoplugging procedure on the given autoplugger. 
 * The src caps will be connected to the sink caps.
 * 
 * Returns: A new Element that connects the src caps to the sink caps.
 */
GstElement*
gst_autoplug_to_caps (GstAutoplug *autoplug, GstCaps *srccaps, GstCaps *sinkcaps, ...)
{
  GstAutoplugClass *oclass;
  GstElement *element = NULL;
  va_list args;

  va_start (args, sinkcaps);

  oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
  if (oclass->autoplug_to_caps)
    element = (oclass->autoplug_to_caps) (autoplug, srccaps, sinkcaps, args);

  va_end (args);

  return element;
}

/**
 * gst_autoplug_to_renderers:
 * @autoplug: The autoplugger perform the autoplugging
 * @srccaps: The source cpabilities
 * @target: The target element 
 * @...: more target elements
 *
 * Perform the autoplugging procedure on the given autoplugger. 
 * The src caps will be connected to the target elements.
 * 
 * Returns: A new Element that connects the src caps to the target elements.
 */
GstElement*
gst_autoplug_to_renderers (GstAutoplug *autoplug, GstCaps *srccaps, GstElement *target, ...)
{
  GstAutoplugClass *oclass;
  GstElement *element = NULL;
  va_list args;

  va_start (args, target);

  oclass = GST_AUTOPLUG_CLASS (G_OBJECT_GET_CLASS(autoplug));
  if (oclass->autoplug_to_renderers)
    element = (oclass->autoplug_to_renderers) (autoplug, srccaps, target, args);

  va_end (args);

  return element;
}


/**
 * gst_autoplugfactory_new:
 * @name: name of autoplugfactory to create
 * @longdesc: long description of autoplugfactory to create
 * @type: the gtk type of the GstAutoplug element of this factory
 *
 * Create a new autoplugfactory with the given parameters
 *
 * Returns: a new #GstAutoplugFactory.
 */
GstAutoplugFactory*
gst_autoplugfactory_new (const gchar *name, const gchar *longdesc, GType type)
{
  GstAutoplugFactory *factory;

  g_return_val_if_fail(name != NULL, NULL);

  factory = g_new0(GstAutoplugFactory, 1);

  factory->name = g_strdup(name);
  factory->longdesc = g_strdup (longdesc);
  factory->type = type;

  _gst_autoplugfactories = g_list_prepend (_gst_autoplugfactories, factory);

  return factory;
}

/**
 * gst_autoplugfactory_destroy:
 * @factory: factory to destroy
 *
 * Removes the autoplug from the global list.
 */
void
gst_autoplugfactory_destroy (GstAutoplugFactory *factory)
{
  g_return_if_fail (factory != NULL);

  _gst_autoplugfactories = g_list_remove (_gst_autoplugfactories, factory);

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

/**
 * gst_autoplugfactory_find:
 * @name: name of autoplugfactory to find
 *
 * Search for an autoplugfactory of the given name.
 *
 * Returns: #GstAutoplugFactory if found, NULL otherwise
 */
GstAutoplugFactory*
gst_autoplugfactory_find (const gchar *name)
{
  GList *walk;
  GstAutoplugFactory *factory;

  g_return_val_if_fail(name != NULL, NULL);

  GST_DEBUG (0,"gstautoplug: find \"%s\"\n", name);

  walk = _gst_autoplugfactories;
  while (walk) {
    factory = (GstAutoplugFactory *)(walk->data);
    if (!strcmp (name, factory->name))
      return factory;
    walk = g_list_next (walk);
  }

  return NULL;
}

/**
 * gst_autoplugfactory_get_list:
 *
 * Get the global list of autoplugfactories.
 *
 * Returns: GList of type #GstAutoplugFactory
 */
GList*
gst_autoplugfactory_get_list (void)
{
  return _gst_autoplugfactories;
}

/**
 * gst_autoplugfactory_create:
 * @factory: the factory used to create the instance
 *
 * Create a new #GstAutoplug instance from the 
 * given autoplugfactory.
 *
 * Returns: A new #GstAutoplug instance.
 */
GstAutoplug*
gst_autoplugfactory_create (GstAutoplugFactory *factory)
{
  GstAutoplug *new = NULL;

  g_return_val_if_fail (factory != NULL, NULL);

  if (factory->type == 0){
    factory = gst_plugin_load_autoplugfactory (factory->name);
  }
  g_return_val_if_fail (factory != NULL, NULL);
  g_return_val_if_fail (factory->type != 0, NULL);

  new = GST_AUTOPLUG (g_object_new(factory->type,NULL));

  return new;
}

/**
 * gst_autoplugfactory_make:
 * @name: the name of the factory used to create the instance
 *
 * Create a new #GstAutoplug instance from the 
 * autoplugfactory with the given name.
 *
 * Returns: A new #GstAutoplug instance.
 */
GstAutoplug*
gst_autoplugfactory_make (const gchar *name)
{
  GstAutoplugFactory *factory;

  g_return_val_if_fail (name != NULL, NULL);

  factory = gst_autoplugfactory_find (name);

  if (factory == NULL)
    return NULL;

  return gst_autoplugfactory_create (factory);;
}

/**
 * gst_autoplugfactory_save_thyself:
 * @factory: The facory to save
 * @parent: the parent XML node pointer
 *
 * Save the autoplugfactory into an XML representation
 *
 * Returns: The new XML parent.
 */
xmlNodePtr
gst_autoplugfactory_save_thyself (GstAutoplugFactory *factory, xmlNodePtr parent)
{
  g_return_val_if_fail(factory != NULL, NULL);

  xmlNewChild(parent,NULL,"name",factory->name);
  xmlNewChild(parent,NULL,"longdesc", factory->longdesc);

  return parent;
}

/**
 * gst_autoplugfactory_load_thyself:
 * @parent: the parent XML node pointer
 *
 * Load an autoplugfactory from the given XML parent node.
 *
 * Returns: A new factory based on the XML node.
 */
GstAutoplugFactory*
gst_autoplugfactory_load_thyself (xmlNodePtr parent)
{
  GstAutoplugFactory *factory = g_new0(GstAutoplugFactory, 1);
  xmlNodePtr children = parent->xmlChildrenNode;

  while (children) {
    if (!strcmp(children->name, "name")) {
      factory->name = xmlNodeGetContent(children);
    }
    if (!strcmp(children->name, "longdesc")) {
      factory->longdesc = xmlNodeGetContent(children);
    }
    children = children->next;
  }

  _gst_autoplugfactories = g_list_prepend (_gst_autoplugfactories, factory);

  return factory;
}