~ubuntu-branches/ubuntu/precise/gst0.10-python/precise

« back to all changes in this revision

Viewing changes to gst/gst.override

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2006-06-25 19:37:45 UTC
  • Revision ID: james.westby@ubuntu.com-20060625193745-9yeg0wq56r24n57x
Tags: upstream-0.10.4
ImportĀ upstreamĀ versionĀ 0.10.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset: 4 -*- */
 
2
/* gst-python
 
3
 * Copyright (C) 2002 David I. Lehn
 
4
 * Copyright (C) 2004 Johan Dahlin
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this library; if not, write to the
 
18
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
 * Boston, MA 02111-1307, USA.
 
20
 * 
 
21
 * Author: David I. Lehn <dlehn@users.sourceforge.net>
 
22
 */
 
23
%%
 
24
headers
 
25
/* define this for all source files that don't run init_pygobject()
 
26
 * before including pygobject.h */
 
27
#define NO_IMPORT_PYGOBJECT
 
28
 
 
29
#ifdef HAVE_CONFIG_H
 
30
# include <config.h>
 
31
#endif
 
32
 
 
33
#include "common.h"
 
34
 
 
35
#include <gst/gst.h>
 
36
#include <gst/gsterror.h>
 
37
#include <gst/gsttypefind.h>
 
38
#include <gst/gsttagsetter.h>
 
39
 
 
40
#include <gst/controller/gstcontroller.h>
 
41
#include <gst/dataprotocol/dataprotocol.h>
 
42
#include <gst/base/gstadapter.h>
 
43
#include <gst/base/gstbasesrc.h>
 
44
#include <gst/base/gstpushsrc.h>
 
45
#include <gst/base/gstbasesink.h>
 
46
#include <gst/base/gstbasetransform.h>
 
47
#include <gst/base/gstcollectpads.h>
 
48
#include <gst/base/gsttypefindhelper.h>
 
49
 
 
50
#include <gst/net/gstnet.h>
 
51
 
 
52
#include "pygstvalue.h"
 
53
#include "pygstminiobject.h"
 
54
#include "pygstexception.h"
 
55
 
 
56
/* These headers have been included directly to get around multiple 
 
57
 * GetAttrString calls */
 
58
#include <compile.h>
 
59
#include <frameobject.h>
 
60
 
 
61
GST_DEBUG_CATEGORY_EXTERN (python_debug);
 
62
GST_DEBUG_CATEGORY_EXTERN (pygst_debug);
 
63
#define GST_CAT_DEFAULT pygst_debug
 
64
 
 
65
/* This function checks if a former Python code threw an exception and if
 
66
 * so, transforms this exception into an error on the given GstElement.
 
67
 * This allows code run on the element to just raise an exception instead of
 
68
 * returning GStreamer specific return values.
 
69
 * The exception is cleared afterwards.
 
70
 */
 
71
gboolean
 
72
_pygst_element_check_error (GstElement *element)
 
73
{
 
74
  PyObject *type, *value, *traceback, *lineno, *msg, *typemsg;
 
75
  PyFrameObject *frame;
 
76
 
 
77
  if (!PyErr_Occurred())
 
78
          return FALSE;
 
79
 
 
80
  PyErr_Fetch (&type, &value, &traceback);
 
81
  if (traceback) {
 
82
    frame = (PyFrameObject *) PyObject_GetAttrString (traceback, "tb_frame");
 
83
    lineno = PyObject_GetAttrString (traceback, "tb_lineno");
 
84
  } else {
 
85
    frame = NULL;
 
86
    lineno = NULL;
 
87
  }
 
88
  msg = PyObject_Str (value);
 
89
  typemsg = PyObject_Str (type);
 
90
  if (msg && PyString_Check (msg)) {
 
91
            gst_element_message_full (element, GST_MESSAGE_ERROR,
 
92
                    GST_LIBRARY_ERROR,
 
93
                    GST_LIBRARY_ERROR_FAILED,
 
94
                    g_strdup (PyString_AsString (msg)), 
 
95
                    typemsg ? g_strconcat (PyString_AsString (typemsg), 
 
96
                            ": ", PyString_AsString (msg), NULL)
 
97
                    : g_strdup (PyString_AsString (msg)),
 
98
                    frame ? PyString_AsString(frame->f_code->co_filename) : "???",
 
99
                    frame ? PyString_AsString(frame->f_code->co_name) : "???",
 
100
                    lineno ? PyInt_AsLong (lineno) : 0);
 
101
  } else {
 
102
        gst_element_message_full (element, GST_MESSAGE_ERROR,
 
103
                    GST_LIBRARY_ERROR,
 
104
                    GST_LIBRARY_ERROR_TOO_LAZY,
 
105
                    NULL, NULL,
 
106
                    frame ? PyString_AsString(frame->f_code->co_filename) : "???",
 
107
                    frame ? PyString_AsString(frame->f_code->co_name) : "???",
 
108
                    lineno ? PyInt_AsLong (lineno) : 0);
 
109
  }
 
110
 
 
111
  PyErr_Clear ();
 
112
  Py_XDECREF (frame);
 
113
  Py_XDECREF (lineno);
 
114
  Py_DECREF (msg);
 
115
  Py_DECREF (typemsg);
 
116
 
 
117
  return TRUE;
 
118
}
 
119
 
 
120
#ifdef pyg_register_class_init
 
121
PyTypeObject PyGstPadTemplate_Type;
 
122
static int
 
123
add_templates (gpointer gclass, PyObject *templates)
 
124
{
 
125
  gint i, len;
 
126
  PyGObject *templ;
 
127
  
 
128
  if (pygobject_check(templates, &PyGstPadTemplate_Type)) {
 
129
    gst_element_class_add_pad_template (gclass, GST_PAD_TEMPLATE (pygobject_get (templates)));
 
130
    return 0;
 
131
  }
 
132
  
 
133
  if (!PyTuple_Check(templates)) {
 
134
    PyErr_SetString(PyExc_TypeError, "__gsttemplates__ attribute neither a tuple nor a GstPadTemplate!");
 
135
    return -1;
 
136
  }
 
137
  len = PyTuple_Size(templates);
 
138
  if (len == 0)
 
139
    return 0;
 
140
  
 
141
  for (i = 0; i < len; i++) {
 
142
    templ = (PyGObject*) PyTuple_GetItem(templates, i);
 
143
    if (!pygobject_check(templ, &PyGstPadTemplate_Type)) {
 
144
      PyErr_SetString(PyExc_TypeError, "entries for __gsttemplates__ must be of type GstPadTemplate");
 
145
      return -1;
 
146
    }
 
147
  }
 
148
        
 
149
  for (i = 0; i < len; i++) {
 
150
    templ = (PyGObject*) PyTuple_GetItem(templates, i);
 
151
    gst_element_class_add_pad_template (gclass, GST_PAD_TEMPLATE (templ->obj));
 
152
  }
 
153
  return 0;
 
154
}
 
155
 
 
156
static int
 
157
_pygst_element_set_details (gpointer gclass, PyObject *details)
 
158
{
 
159
  GstElementDetails gstdetails = { 0, };
 
160
  
 
161
  if (!PyTuple_Check (details)) {
 
162
    PyErr_SetString(PyExc_TypeError, "__gstdetails__ must be a tuple");
 
163
    return -1;
 
164
  }
 
165
  if (PyTuple_Size (details) != 4) {
 
166
    PyErr_SetString(PyExc_TypeError, "__gstdetails__ must be contain 4 elements");
 
167
    return -1;
 
168
  }
 
169
  if (!PyArg_ParseTuple (details, "ssss", &gstdetails.longname, &gstdetails.klass,
 
170
    &gstdetails.description, &gstdetails.author)) {
 
171
    PyErr_SetString (PyExc_TypeError, "__gstdetails__ must be contain 4 strings");
 
172
    return -1;
 
173
  }
 
174
  gst_element_class_set_details (gclass, &gstdetails);
 
175
  return 0;
 
176
}
 
177
 
 
178
static int
 
179
_pygst_element_init (gpointer gclass, PyTypeObject *pyclass)
 
180
{
 
181
  PyObject *templates, *details;
 
182
  
 
183
  templates = PyDict_GetItemString(pyclass->tp_dict, "__gsttemplates__");
 
184
  if (templates) {
 
185
    if (add_templates(gclass, templates) != 0)
 
186
      return -1;
 
187
  } else {
 
188
    PyErr_Clear();
 
189
  }
 
190
  details = PyDict_GetItemString(pyclass->tp_dict, "__gstdetails__");
 
191
  if (details) {
 
192
    if (_pygst_element_set_details (gclass, details) != 0)
 
193
      return -1;
 
194
    PyDict_DelItemString(pyclass->tp_dict, "__gstdetails__");
 
195
  } else {
 
196
    PyErr_Clear();
 
197
  }
 
198
 
 
199
  return 0;
 
200
}
 
201
#endif
 
202
 
 
203
static PyObject *
 
204
pygst_debug_log (PyObject *pyobject, PyObject *string, GstDebugLevel level,
 
205
    gboolean isgstobject)
 
206
{
 
207
    gchar       *str;
 
208
    gchar       *function;
 
209
    gchar       *filename;
 
210
    int         lineno;
 
211
    PyFrameObject       *frame;
 
212
    GObject   *object = NULL;
 
213
 
 
214
    if (!PyArg_ParseTuple(string, "s:gst.debug_log", &str)) {
 
215
        PyErr_SetString(PyExc_TypeError, "Need a string!");
 
216
        return NULL;
 
217
    }
 
218
 
 
219
    frame = PyEval_GetFrame();
 
220
    function = PyString_AsString(frame->f_code->co_name);
 
221
    filename = g_path_get_basename(PyString_AsString(frame->f_code->co_filename));
 
222
    lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
 
223
    /* gst_debug_log : category, level, file, function, line, object, format, va_list */
 
224
    if (isgstobject)
 
225
      object = G_OBJECT (pygobject_get (pyobject));
 
226
    gst_debug_log (python_debug, level, filename, function, lineno, object, "%s", str);
 
227
    if (filename)
 
228
        g_free(filename);
 
229
    Py_INCREF (Py_None);
 
230
    return Py_None;    
 
231
}
 
232
 
 
233
%%
 
234
include
 
235
  gstbin.override
 
236
  gstbuffer.override
 
237
  gstbus.override
 
238
  gstcaps.override
 
239
  gstelement.override
 
240
  gstelementfactory.override
 
241
  gstevent.override
 
242
  gstmessage.override
 
243
  gstobject.override
 
244
  gstpad.override
 
245
  gstquery.override
 
246
  gststructure.override
 
247
  gsttaglist.override
 
248
  gstlibs.override
 
249
  gstbase.override
 
250
  gstversion.override
 
251
%%
 
252
init
 
253
{
 
254
/* FIXME: new in pygtk-2.6 */
 
255
#ifdef pyg_register_class_init
 
256
    pyg_register_class_init (GST_TYPE_ELEMENT, _pygst_element_init);
 
257
#endif
 
258
    if (!pygst_value_init())
 
259
        return;
 
260
    gst_controller_init(NULL, NULL);
 
261
}
 
262
%%
 
263
modulename gst
 
264
%%
 
265
import gobject.GObject as PyGObject_Type
 
266
%%
 
267
ignore-glob
 
268
  _*
 
269
  *_copy
 
270
  *_error_quark
 
271
  *_free
 
272
  *_get_type
 
273
  *_private
 
274
  *_thyself
 
275
  *_valist
 
276
  *_ref
 
277
  *_unref
 
278
  *_init
 
279
  *_deinit
 
280
  *_full
 
281
  gst_class_*
 
282
  gst_init*
 
283
  gst_interface_*
 
284
  gst_value_*
 
285
  gst_param_spec_*
 
286
%%
 
287
ignore
 
288
  gst_alloc_trace_list
 
289
  gst_alloc_trace_get
 
290
  gst_error_get_message
 
291
  gst_parse_launchv
 
292
  gst_trace_read_tsc
 
293
  gst_debug_log
 
294
  gst_debug_log_default
 
295
  gst_iterator_new_list
 
296
  gst_task_set_lock
 
297
  gst_clock_id_compare_func
 
298
  gst_print_pad_caps
 
299
  gst_util_set_value_from_string
 
300
  gst_print_element_args
 
301
  gst_atomic_int_set
 
302
  gst_caps_replace
 
303
  gst_mini_object_replace
 
304
  gst_filter_run
 
305
  gst_flow_to_quark
 
306
  gst_implements_interface_cast
 
307
  gst_implements_interface_check
 
308
  gst_plugin_get_module
 
309
  gst_object_sink
 
310
  gst_version
 
311
%%
 
312
/*
 
313
  Magic to be able to use bugfixes of new releases without having to use
 
314
  newer core/base
 
315
*/
 
316
#warn your mom !
 
317
ignore
 
318
#if (GST_VERSION_MICRO < 5)
 
319
# if (GST_VERSION_MICRO < 4)
 
320
#  if (GST_VERSION_MICRO < 3)
 
321
#warning Version smaller than .3
 
322
/* API added between 0.10.2 and 0.10.3 */
 
323
  gst_bin_iterate_sources
 
324
  gst_bin_find_unconnected_pad
 
325
  gst_buffer_is_metadata_writable
 
326
  gst_buffer_make_metadata_writable
 
327
  gst_parse_bin_from_description
 
328
#  endif
 
329
#warning Version smaller than .4
 
330
/* API added between 0.10.3 and 0.10.4 */
 
331
  gst_bus_enable_sync_message_emission
 
332
  gst_bus_disable_sync_message_emission
 
333
  gst_pipeline_set_auto_flush_bus
 
334
  gst_pipeline_get_auto_flush_bus
 
335
  gst_query_set_formats
 
336
  gst_query_new_formats
 
337
  gst_query_parse_formats_length
 
338
  gst_query_parse_formats_nth
 
339
  gst_type_find_helper_for_buffer
 
340
  gst_uri_has_protocol
 
341
  GstBaseSrc__do_check_get_range
 
342
  GstBaseSrc__proxy_do_check_get_range
 
343
# endif
 
344
#warning Version smaller than .5
 
345
/* API Added between 0.10.4 and 0.10.5 */
 
346
 
 
347
#endif
 
348
%%
 
349
override-slot GstPluginFeature.tp_repr
 
350
static PyObject *
 
351
_wrap_gst_plugin_feature_tp_repr(PyObject *self)
 
352
{
 
353
    gchar *repr;
 
354
    PyObject *ret;
 
355
    GstPluginFeature *feature = GST_PLUGIN_FEATURE (pygobject_get (self));
 
356
 
 
357
    repr = g_strdup_printf ("<%s %s @ 0x%lx>",
 
358
               self->ob_type->tp_name, gst_plugin_feature_get_name (feature),
 
359
               (long) self);
 
360
    ret = PyString_FromString(repr);
 
361
    g_free (repr);
 
362
    return ret;
 
363
}
 
364
%%
 
365
override-slot GstPluginFeature.tp_str
 
366
static PyObject *
 
367
_wrap_gst_plugin_feature_tp_str(PyObject *self)
 
368
{
 
369
    gchar *repr;
 
370
    PyObject *ret;
 
371
    GstPluginFeature *feature = GST_PLUGIN_FEATURE (pygobject_get (self));
 
372
 
 
373
    repr = g_strdup_printf ("<%s %s (%d)>",
 
374
               self->ob_type->tp_name, gst_plugin_feature_get_name (feature),
 
375
               gst_plugin_feature_get_rank (feature));
 
376
    ret = PyString_FromString(repr);
 
377
    g_free (repr);
 
378
    return ret;
 
379
}
 
380
 
 
381
%%
 
382
override gst_type_find_factory_get_caps noargs
 
383
static PyObject *
 
384
_wrap_gst_type_find_factory_get_caps(PyGObject *self)
 
385
{
 
386
        GstCaps *ret = (GstCaps*)gst_type_find_factory_get_caps(GST_TYPE_FIND_FACTORY(self->obj));
 
387
        return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE);
 
388
}
 
389
%%
 
390
override-attr GError.domain
 
391
static PyObject *
 
392
_wrap_gst_g_error__get_domain(PyGObject *self, void *closure)
 
393
{
 
394
    return PyString_FromString(g_quark_to_string(((GError*)self->obj)->domain));
 
395
}
 
396
%%
 
397
override-slot GError.tp_str
 
398
static PyObject *
 
399
_wrap_gst_g_error_tp_str(PyGObject *self)
 
400
{
 
401
    GError *error = (GError*)self->obj;
 
402
    return PyString_FromString(gst_error_get_message (error->domain,
 
403
                                                      error->code));
 
404
}
 
405
%%
 
406
override-attr GstDate.day
 
407
static PyObject *
 
408
_wrap_gst_date__get_day(PyGObject *self, void *closure)
 
409
{
 
410
    return PyInt_FromLong(g_date_get_day((GDate*)self->obj));
 
411
}
 
412
 
 
413
static int
 
414
_wrap_gst_date__set_day(PyGObject *self, PyObject *value, void *closure)
 
415
{
 
416
    GDate       *date = (GDate *) self->obj;
 
417
    
 
418
    if (!(PyInt_Check(value)))
 
419
        return -1;
 
420
 
 
421
    g_date_set_day(date, (int) PyInt_AsLong(value));
 
422
    return 0;
 
423
}
 
424
%%
 
425
override-attr GstDate.month
 
426
static PyObject *
 
427
_wrap_gst_date__get_month(PyGObject *self, void *closure)
 
428
{
 
429
    return PyInt_FromLong(g_date_get_month((GDate*)self->obj));
 
430
}
 
431
static int
 
432
_wrap_gst_date__set_month(PyGObject *self, PyObject *value, void *closure)
 
433
{
 
434
    GDate       *date = (GDate *) self->obj;
 
435
    
 
436
    if (!(PyInt_Check(value)))
 
437
        return -1;
 
438
 
 
439
    g_date_set_month(date, (int) PyInt_AsLong(value));
 
440
    return 0;
 
441
}
 
442
%%
 
443
override-attr GstDate.year
 
444
static PyObject *
 
445
_wrap_gst_date__get_year(PyGObject *self, void *closure)
 
446
{
 
447
    return PyInt_FromLong(g_date_get_year((GDate*)self->obj));
 
448
}
 
449
static int
 
450
_wrap_gst_date__set_year(PyGObject *self, PyObject *value, void *closure)
 
451
{
 
452
    GDate       *date = (GDate *) self->obj;
 
453
    
 
454
    if (!(PyInt_Check(value)))
 
455
        return -1;
 
456
 
 
457
    g_date_set_year(date, (int) PyInt_AsLong(value));
 
458
    return 0;
 
459
}
 
460
%%
 
461
override-slot GstDate.tp_repr
 
462
static PyObject *
 
463
_wrap_gst_date_tp_repr(PyGObject *self)
 
464
{
 
465
    GDate       *date = (GDate *) self->obj;
 
466
 
 
467
    return PyString_FromFormat ("<GstDate: %2d/%2d/%4d>",
 
468
                                g_date_get_day(date),
 
469
                                g_date_get_month(date),
 
470
                                g_date_get_year(date));
 
471
}
 
472
%%
 
473
override gst_registry_get_path_list
 
474
static PyObject *
 
475
_wrap_gst_registry_get_path_list (PyGObject *self)
 
476
{
 
477
    GstRegistry *registry;
 
478
    GList *l, *paths;
 
479
    PyObject *list;
 
480
    gint i;
 
481
    
 
482
    registry = GST_REGISTRY (self->obj);
 
483
    
 
484
    paths = gst_registry_get_path_list (registry);
 
485
    
 
486
    list = PyList_New (g_list_length(paths));
 
487
    for (l = paths, i = 0; l; l = l->next, ++i) {
 
488
        gchar *path = (gchar *) l->data;
 
489
        PyList_SetItem (list, i, PyString_FromString(path));
 
490
    }
 
491
    g_list_free (paths);
 
492
    
 
493
    return list;
 
494
}
 
495
 
 
496
%%
 
497
override gst_registry_get_plugin_list
 
498
static PyObject *
 
499
_wrap_gst_registry_get_plugin_list (PyGObject *self)
 
500
{
 
501
        GstRegistry *registry;
 
502
        GList *l, *plugins;
 
503
        PyObject *list;
 
504
        gint i;
 
505
    
 
506
        registry = GST_REGISTRY (self->obj);
 
507
 
 
508
        plugins = gst_registry_get_plugin_list (registry);
 
509
 
 
510
        list = PyList_New (g_list_length(plugins));
 
511
        for (l = plugins, i = 0; l; l = l->next, ++i) {
 
512
                GstPlugin *plugin = (GstPlugin *) l->data;
 
513
                PyObject *object = pygstobject_new (G_OBJECT (plugin));
 
514
                gst_object_unref (plugin);
 
515
 
 
516
                PyList_SetItem (list, i, object);
 
517
        }
 
518
        g_list_free (plugins);
 
519
 
 
520
        return list;
 
521
}
 
522
 
 
523
%%
 
524
override gst_registry_get_feature_list kwargs
 
525
static PyObject *
 
526
_wrap_gst_registry_get_feature_list (PyGObject *self, PyObject *args, PyObject *kwargs)
 
527
{
 
528
    static char *kwlist[] = { "type", NULL };
 
529
    PyObject *py_type = NULL;
 
530
    GType type;
 
531
 
 
532
    GstRegistry *registry;
 
533
    GList *l, *features;
 
534
    PyObject *list;
 
535
    gint i;
 
536
        
 
537
 
 
538
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
539
            "O:GstRegistry.get_feature_list", kwlist, &py_type))
 
540
        return NULL;
 
541
    if ((type = pyg_type_from_object(py_type)) == 0)
 
542
        return NULL;
 
543
 
 
544
    registry = GST_REGISTRY (self->obj);
 
545
 
 
546
    features = gst_registry_get_feature_list (registry, type);
 
547
 
 
548
    list = PyList_New (g_list_length(features));
 
549
    for (l = features, i = 0; l; l = l->next, ++i) {
 
550
        GstPluginFeature *feature = (GstPluginFeature *) l->data;
 
551
        PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
 
552
        gst_object_unref (feature);
 
553
    }
 
554
    g_list_free (features);
 
555
        
 
556
    return list;
 
557
}
 
558
 
 
559
%%
 
560
override gst_registry_get_feature_list_by_plugin kwargs
 
561
static PyObject *
 
562
_wrap_gst_registry_get_feature_list_by_plugin (PyGObject *self, PyObject *args, PyObject *kwargs)
 
563
{
 
564
    static char *kwlist[] = { "name", NULL };
 
565
    gchar * name = NULL;
 
566
 
 
567
    GstRegistry *registry;
 
568
    GList *l, *features;
 
569
    PyObject *list;
 
570
        gint i;
 
571
 
 
572
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
573
            "s:GstRegistry.get_feature_list_by_plugin", kwlist, &name))
 
574
        return NULL;
 
575
 
 
576
    registry = GST_REGISTRY (self->obj);
 
577
 
 
578
    features = gst_registry_get_feature_list_by_plugin (registry, name);
 
579
 
 
580
    list = PyList_New (g_list_length(features));
 
581
    for (l = features, i = 0; l; l = l->next, ++i) {
 
582
        GstPluginFeature *feature = (GstPluginFeature *) l->data;
 
583
        PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
 
584
    }
 
585
    g_list_free (features);
 
586
        
 
587
    return list;
 
588
}
 
589
 
 
590
%%
 
591
override gst_xml_new noargs
 
592
 
 
593
extern PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
 
594
extern PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
 
595
 
 
596
/* libxml2 available check */
 
597
static PyObject *
 
598
_gst_get_libxml2_module(void)
 
599
{
 
600
    PyObject *xml = NULL;
 
601
    
 
602
    xml = PyImport_ImportModule("libxml2");
 
603
    if (!xml) {
 
604
        PyErr_Clear();
 
605
        PyErr_SetString(PyExc_RuntimeError,"libxml2 bindings required");
 
606
        return NULL;
 
607
    }
 
608
    
 
609
    return xml;
 
610
 }
 
611
 
 
612
static int
 
613
_wrap_gst_xml_new(PyGObject *self)
 
614
{
 
615
    PyObject *xml = _gst_get_libxml2_module();
 
616
    
 
617
    if(!xml)
 
618
        return -1;
 
619
       
 
620
    self->obj = (GObject *)gst_xml_new();
 
621
    
 
622
    if (!self->obj) {
 
623
        PyErr_SetString(PyExc_RuntimeError, "could not create GstXML object");
 
624
        return -1;
 
625
    }
 
626
    
 
627
    pygobject_register_wrapper((PyObject *)self);
 
628
    
 
629
    return 0;
 
630
}
 
631
%%
 
632
override gst_xml_get_topelements noargs
 
633
static PyObject *
 
634
_wrap_gst_xml_get_topelements(PyGObject *self)
 
635
{
 
636
    GList *l, *xml_elements;
 
637
    PyObject *py_list;
 
638
    gint i;
 
639
 
 
640
    xml_elements = gst_xml_get_topelements(GST_XML(self->obj));
 
641
    py_list = PyList_New(g_list_length(xml_elements));
 
642
    for (l = xml_elements, i = 0; l; l = l->next, ++i) {
 
643
        GstElement *element = (GstElement*)l->data;
 
644
        PyList_SetItem(py_list, i, pygstobject_new(G_OBJECT(element)));
 
645
        gst_object_unref (element);
 
646
    }
 
647
       
 
648
    return py_list;
 
649
}
 
650
%%
 
651
override gst_xml_parse_memory kwargs
 
652
static PyObject * 
 
653
_wrap_gst_xml_parse_memory(PyGObject *self, PyObject *args, PyObject *kwargs)
 
654
{
 
655
    static char *kwlist[] = { "buffer", "root", NULL };
 
656
    int buffer_len, ret;
 
657
    char *root = NULL;
 
658
    guchar *buffer;
 
659
 
 
660
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
661
                                    "s#|s:GstXML.parse_memory",
 
662
                                    kwlist, &buffer, &buffer_len, &root))
 
663
        return NULL;
 
664
    
 
665
    ret = gst_xml_parse_memory(GST_XML(self->obj),
 
666
                               buffer, buffer_len, root);
 
667
    
 
668
    return PyBool_FromLong(ret);
 
669
}
 
670
%%
 
671
override gst_tag_setter_get_tag_list noargs
 
672
static PyObject *
 
673
_wrap_gst_tag_setter_get_tag_list(PyGObject *self)
 
674
{
 
675
    GstTagList *ret;
 
676
 
 
677
    ret = (GstTagList*)gst_tag_setter_get_tag_list(GST_TAG_SETTER(self->obj));
 
678
    /* pyg_boxed_new handles NULL checking */
 
679
    return pyg_boxed_new(GST_TYPE_TAG_LIST, ret, TRUE, TRUE);
 
680
}
 
681
%%
 
682
override gst_element_register kwargs
 
683
 
 
684
static GstPlugin *
 
685
_pygst_get_plugin(void)
 
686
{
 
687
  PyObject *dict = NULL, *module = NULL, *pyplugin = NULL;
 
688
  GstPlugin *ret;
 
689
  
 
690
  if (!(module = PyImport_ImportModule ("gst")))
 
691
    goto err;
 
692
  if (!(dict = PyModule_GetDict (module)))
 
693
    goto err;
 
694
  if (!(pyplugin = PyDict_GetItemString (dict, "__plugin__")))
 
695
    goto err;
 
696
  ret = pyg_boxed_get (pyplugin, GstPlugin);
 
697
  
 
698
  Py_DECREF (module);
 
699
  return ret;
 
700
  
 
701
err:
 
702
  Py_XDECREF (module);
 
703
  PyErr_Clear ();
 
704
  return NULL;
 
705
}
 
706
 
 
707
static PyObject *
 
708
_wrap_gst_element_register(PyObject *self, PyObject *args, PyObject *kwargs)
 
709
{
 
710
    static char *kwlist[] = { "type", "elementname", "rank", NULL };
 
711
    PyObject *py_type = NULL;
 
712
    guint rank = GST_RANK_NONE;
 
713
    char *elementname = NULL;
 
714
    int ret;
 
715
    GType type;
 
716
 
 
717
    /* FIXME: can we make the name optional, too? Anyone know a good default? */
 
718
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|I:element_register", kwlist,
 
719
        &py_type, &elementname, &rank))
 
720
        return NULL;
 
721
    if ((type = pyg_type_from_object(py_type)) == 0)
 
722
        return NULL;
 
723
    
 
724
    ret = gst_element_register(_pygst_get_plugin(), elementname, rank, type);
 
725
    return PyBool_FromLong(ret);
 
726
}
 
727
%%
 
728
override-attr GError.domain
 
729
static PyObject *
 
730
_wrap_gst_g_error__get_domain(PyGObject *self, void *closure)
 
731
{
 
732
    return PyString_FromString(g_quark_to_string(((GError*)self->obj)->domain));
 
733
}
 
734
%%
 
735
override-slot GError.tp_str
 
736
static PyObject *
 
737
_wrap_gst_g_error_tp_str(PyGObject *self)
 
738
{
 
739
    GError *error = (GError*)self->obj;
 
740
    return PyString_FromString(gst_error_get_message (error->domain,
 
741
                                                      error->code));
 
742
}
 
743
%%
 
744
override gst_uri_handler_get_protocols noargs
 
745
static PyObject *
 
746
_wrap_gst_uri_handler_get_protocols (PyGObject *self)
 
747
{
 
748
    gchar       **tab;
 
749
    int         i, len;
 
750
    PyObject    *ret;
 
751
 
 
752
    tab = gst_uri_handler_get_protocols (GST_URI_HANDLER (self->obj));
 
753
    if (!tab) {
 
754
        Py_INCREF (Py_None);
 
755
        return Py_None;
 
756
    }
 
757
    
 
758
    len = g_strv_length (tab);
 
759
    ret = PyList_New(len);
 
760
    for (i = 0; i < len; i++) {
 
761
        PyList_SetItem(ret, i, PyString_FromString(tab[i]));
 
762
    }
 
763
 
 
764
    return ret;
 
765
}
 
766
%%
 
767
override gst_flow_get_name kwargs
 
768
static PyObject *
 
769
_wrap_gst_flow_get_name(PyObject *self, PyObject *args, PyObject *kwargs)
 
770
{
 
771
    static char *kwlist[] = { "ret", NULL };
 
772
    PyObject *py_ret = NULL;
 
773
    const gchar *ret;
 
774
    gchar       *nret;
 
775
    GstFlowReturn flow;
 
776
 
 
777
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gst_flow_get_name", kwlist, &py_ret))
 
778
        return NULL;
 
779
    if (pyg_enum_get_value(GST_TYPE_FLOW_RETURN, py_ret, (gint *)&flow))
 
780
        return NULL;
 
781
    ret = gst_flow_get_name(flow);
 
782
    if (ret) {
 
783
        nret = g_strdup(ret);
 
784
        return PyString_FromString(nret);
 
785
    }
 
786
    Py_INCREF(Py_None);
 
787
    return Py_None;
 
788
}
 
789
 
 
790
%%
 
791
override gst_log args
 
792
static PyObject *
 
793
_wrap_gst_log (PyObject *whatever, PyObject *string)
 
794
{
 
795
    return pygst_debug_log (whatever, string, GST_LEVEL_LOG, FALSE);
 
796
}
 
797
%%
 
798
override gst_debug args
 
799
static PyObject *
 
800
_wrap_gst_debug (PyObject *whatever, PyObject *string)
 
801
{
 
802
    return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, FALSE);
 
803
}
 
804
%%
 
805
override gst_info args
 
806
static PyObject *
 
807
_wrap_gst_info (PyObject *whatever, PyObject *string)
 
808
{
 
809
    return pygst_debug_log (whatever, string, GST_LEVEL_INFO, FALSE);
 
810
}
 
811
%%
 
812
override gst_warning args
 
813
static PyObject *
 
814
_wrap_gst_warning (PyObject *whatever, PyObject *string)
 
815
{
 
816
    return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, FALSE);
 
817
}
 
818
%%
 
819
override gst_error args
 
820
static PyObject *
 
821
_wrap_gst_error (PyObject *whatever, PyObject *string)
 
822
{
 
823
    return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, FALSE);
 
824
}
 
825
 
 
826
%%
 
827
override gst_object_log args
 
828
static PyObject *
 
829
_wrap_gst_object_log (PyObject *whatever, PyObject *string)
 
830
{
 
831
    return pygst_debug_log (whatever, string, GST_LEVEL_LOG, TRUE);
 
832
}
 
833
%%
 
834
override gst_object_debug args
 
835
static PyObject *
 
836
_wrap_gst_object_debug (PyObject *whatever, PyObject *string)
 
837
{
 
838
    return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, TRUE);
 
839
}
 
840
%%
 
841
override gst_object_info args
 
842
static PyObject *
 
843
_wrap_gst_object_info (PyObject *whatever, PyObject *string)
 
844
{
 
845
    return pygst_debug_log (whatever, string, GST_LEVEL_INFO, TRUE);
 
846
}
 
847
%%
 
848
override gst_object_warning args
 
849
static PyObject *
 
850
_wrap_gst_object_warning (PyObject *whatever, PyObject *string)
 
851
{
 
852
    return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, TRUE);
 
853
}
 
854
%%
 
855
override gst_object_error args
 
856
static PyObject *
 
857
_wrap_gst_object_error (PyObject *whatever, PyObject *string)
 
858
{
 
859
    return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, TRUE);
 
860
}
 
861
%%
 
862
override GST_TIME_ARGS kwargs
 
863
static PyObject *
 
864
_wrap_GST_TIME_ARGS(PyObject *self, PyObject *args, PyObject *kwargs)
 
865
{
 
866
    static char *kwlist[] = { "time", NULL };
 
867
    PyObject *py_time = NULL;
 
868
    PyObject *string;
 
869
    gchar *ret;
 
870
    guint64 time;
 
871
 
 
872
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:time_to_string", kwlist, &py_time))
 
873
        return NULL;
 
874
    time = PyInt_AsUnsignedLongLongMask(py_time);
 
875
    if (GST_CLOCK_TIME_IS_VALID (time))
 
876
        ret = g_strdup_printf("%"GST_TIME_FORMAT, GST_TIME_ARGS(time));
 
877
    else
 
878
        ret = g_strdup ("CLOCK_TIME_NONE");
 
879
 
 
880
    if (!ret) {
 
881
        Py_INCREF(Py_None);
 
882
        return Py_None;
 
883
    }
 
884
 
 
885
    if (!(string = PyString_FromString(ret))) {
 
886
        g_free(ret);
 
887
        return NULL;
 
888
    }
 
889
    g_free(ret);
 
890
    return string;
 
891
}
 
892
%%
 
893
override gst_type_find_factory_get_list noargs
 
894
static PyObject *
 
895
_wrap_gst_type_find_factory_get_list (PyObject *self)
 
896
{
 
897
    GList       *l, *list;
 
898
    PyObject    *py_list;
 
899
    int         i = 0;
 
900
 
 
901
    list = gst_type_find_factory_get_list ();
 
902
 
 
903
    py_list = PyList_New(g_list_length(list));
 
904
    for (l = list; l ; l = g_list_next(l), i++) {
 
905
        GstTypeFindFactory *fact = (GstTypeFindFactory*) l->data;
 
906
 
 
907
        PyList_SetItem(py_list, i,
 
908
                       pygstobject_new (G_OBJECT (fact)));
 
909
    }
 
910
    g_list_free (list);
 
911
 
 
912
    return py_list;
 
913
}
 
914
%%
 
915
override gst_get_gst_version noargs
 
916
static PyObject *
 
917
_wrap_gst_get_gst_version (PyObject *self)
 
918
{
 
919
    guint       major, minor, micro, nano;
 
920
    PyObject    *py_tuple;
 
921
 
 
922
    gst_version (&major, &minor, &micro, &nano);
 
923
    py_tuple = PyTuple_New(4);
 
924
    PyTuple_SetItem(py_tuple, 0, PyInt_FromLong(major));
 
925
    PyTuple_SetItem(py_tuple, 1, PyInt_FromLong(minor));
 
926
    PyTuple_SetItem(py_tuple, 2, PyInt_FromLong(micro));
 
927
    PyTuple_SetItem(py_tuple, 3, PyInt_FromLong(nano));
 
928
 
 
929
    return py_tuple;
 
930
}
 
931
%%
 
932
override gst_get_pygst_version noargs
 
933
static PyObject *
 
934
_wrap_gst_get_pygst_version (PyObject *self)
 
935
{
 
936
    PyObject    *py_tuple;
 
937
 
 
938
    py_tuple = Py_BuildValue ("(iiii)", PYGST_MAJOR_VERSION, PYGST_MINOR_VERSION,
 
939
                              PYGST_MICRO_VERSION, PYGST_NANO_VERSION);
 
940
 
 
941
    return py_tuple;
 
942
}
 
943
%%
 
944
override gst_clock_get_calibration noargs
 
945
static PyObject *
 
946
_wrap_gst_clock_get_calibration (PyGObject * self)
 
947
{
 
948
    PyObject            *ret;
 
949
    GstClockTime        internal;
 
950
    GstClockTime        external;
 
951
    GstClockTime        rate_num;
 
952
    GstClockTime        rate_denom;
 
953
 
 
954
    gst_clock_get_calibration (GST_CLOCK (self->obj),
 
955
                               &internal,
 
956
                               &external,
 
957
                               &rate_num,
 
958
                               &rate_denom);
 
959
 
 
960
    ret = PyTuple_New(4);
 
961
    PyTuple_SetItem(ret, 0, PyLong_FromUnsignedLongLong(internal));
 
962
    PyTuple_SetItem(ret, 1, PyLong_FromUnsignedLongLong(external));
 
963
    PyTuple_SetItem(ret, 2, PyLong_FromUnsignedLongLong(rate_num));
 
964
    PyTuple_SetItem(ret, 3, PyLong_FromUnsignedLongLong(rate_denom));
 
965
    
 
966
    return ret;
 
967
}
 
968
%%
 
969
override gst_type_find_helper_for_buffer kwargs
 
970
static PyObject *
 
971
_wrap_gst_type_find_helper_for_buffer (PyObject *self, PyObject *args, PyObject *kwargs)
 
972
{
 
973
    static char *kwlist[] = { "object", "buffer", NULL };
 
974
    PyGObject *py_object;
 
975
    PyGstMiniObject *py_buffer;
 
976
    PyObject *py_ret;
 
977
    GstTypeFindProbability prob = 0;
 
978
    GstCaps *caps = NULL;
 
979
 
 
980
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:type_find_helper_for_buffer",
 
981
                                     kwlist, &PyGstObject_Type, &py_object,
 
982
                                     &PyGstBuffer_Type, &py_buffer))
 
983
        return NULL;
 
984
    
 
985
    caps = gst_type_find_helper_for_buffer (GST_OBJECT (py_object->obj),
 
986
                                            GST_BUFFER (py_buffer->obj),
 
987
                                            &prob);
 
988
    py_ret = PyTuple_New(2);
 
989
    if (caps)
 
990
        PyTuple_SetItem(py_ret, 0, pyg_boxed_new (GST_TYPE_CAPS, caps, FALSE, TRUE));
 
991
    else {
 
992
        Py_INCREF(Py_None);
 
993
        PyTuple_SetItem(py_ret, 0, Py_None);
 
994
    }
 
995
 
 
996
    if (prob)
 
997
        PyTuple_SetItem(py_ret, 1, pyg_enum_from_gtype(GST_TYPE_TYPE_FIND_PROBABILITY, prob));
 
998
    else {
 
999
        Py_INCREF(Py_None);
 
1000
        PyTuple_SetItem(py_ret, 1, Py_None);
 
1001
    }
 
1002
    
 
1003
    return py_ret;
 
1004
}