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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
|
/* -*- Mode: C; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
* Copyright (C) 2004 Johan Dahlin
*
* 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.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
%%
headers
/* define this for all source files that don't run init_pygobject()
* before including pygobject.h */
#define NO_IMPORT_PYGOBJECT
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "common.h"
#include <gst/gst.h>
#include <gst/gsterror.h>
#include <gst/gsttypefind.h>
#include <gst/gsttagsetter.h>
#include <gst/controller/gstcontroller.h>
#include <gst/controller/gstlfocontrolsource.h>
#include <gst/dataprotocol/dataprotocol.h>
#include <gst/base/gstadapter.h>
#include <gst/base/gstbasesrc.h>
#include <gst/base/gstpushsrc.h>
#include <gst/base/gstbasesink.h>
#include <gst/base/gstbasetransform.h>
#include <gst/base/gstcollectpads.h>
#include <gst/base/gsttypefindhelper.h>
#if ((GST_VERSION_MICRO >= 11) || (GST_VERSION_MICRO == 10 && GST_VERSION_NANO > 0 ))
#include <gst/base/gstdataqueue.h>
#endif
#include <gst/net/gstnet.h>
#include "pygstvalue.h"
#include "pygstminiobject.h"
#include "pygstexception.h"
/* These headers have been included directly to get around multiple
* GetAttrString calls */
#include <compile.h>
#include <frameobject.h>
/* Boonky define that allows for backwards compatibility with Python 2.4 */
#if PY_VERSION_HEX < 0x02050000
#define Py_ssize_t int
#endif
GST_DEBUG_CATEGORY_EXTERN (python_debug);
GST_DEBUG_CATEGORY_EXTERN (pygst_debug);
#define GST_CAT_DEFAULT pygst_debug
/* This function checks if a former Python code threw an exception and if
* so, transforms this exception into an error on the given GstElement.
* This allows code run on the element to just raise an exception instead of
* returning GStreamer specific return values.
* The exception is cleared afterwards.
*/
gboolean
_pygst_element_check_error (GstElement *element)
{
PyObject *type, *value, *traceback, *lineno, *msg, *typemsg;
PyFrameObject *frame;
if (!PyErr_Occurred())
return FALSE;
PyErr_Fetch (&type, &value, &traceback);
if (traceback) {
frame = (PyFrameObject *) PyObject_GetAttrString (traceback, "tb_frame");
lineno = PyObject_GetAttrString (traceback, "tb_lineno");
} else {
frame = NULL;
lineno = NULL;
}
msg = PyObject_Str (value);
typemsg = PyObject_Str (type);
if (msg && PyString_Check (msg)) {
gst_element_message_full (element, GST_MESSAGE_ERROR,
GST_LIBRARY_ERROR,
GST_LIBRARY_ERROR_FAILED,
g_strdup (PyString_AsString (msg)),
typemsg ? g_strconcat (PyString_AsString (typemsg),
": ", PyString_AsString (msg), NULL)
: g_strdup (PyString_AsString (msg)),
frame ? PyString_AsString(frame->f_code->co_filename) : "???",
frame ? PyString_AsString(frame->f_code->co_name) : "???",
lineno ? PyInt_AsLong (lineno) : 0);
} else {
gst_element_message_full (element, GST_MESSAGE_ERROR,
GST_LIBRARY_ERROR,
GST_LIBRARY_ERROR_TOO_LAZY,
NULL, NULL,
frame ? PyString_AsString(frame->f_code->co_filename) : "???",
frame ? PyString_AsString(frame->f_code->co_name) : "???",
lineno ? PyInt_AsLong (lineno) : 0);
}
PyErr_Clear ();
Py_XDECREF (frame);
Py_XDECREF (lineno);
Py_DECREF (msg);
Py_DECREF (typemsg);
return TRUE;
}
PyTypeObject PyGstPadTemplate_Type;
static int
add_templates (gpointer gclass, PyObject *templates)
{
gint i, len;
PyGObject *templ;
if (pygobject_check(templates, &PyGstPadTemplate_Type)) {
gst_element_class_add_pad_template (gclass, GST_PAD_TEMPLATE (pygobject_get (templates)));
return 0;
}
if (!PyTuple_Check(templates)) {
PyErr_SetString(PyExc_TypeError, "__gsttemplates__ attribute neither a tuple nor a GstPadTemplate!");
return -1;
}
len = PyTuple_Size(templates);
if (len == 0)
return 0;
for (i = 0; i < len; i++) {
templ = (PyGObject*) PyTuple_GetItem(templates, i);
if (!pygobject_check(templ, &PyGstPadTemplate_Type)) {
PyErr_SetString(PyExc_TypeError, "entries for __gsttemplates__ must be of type GstPadTemplate");
return -1;
}
}
for (i = 0; i < len; i++) {
templ = (PyGObject*) PyTuple_GetItem(templates, i);
gst_element_class_add_pad_template (gclass, GST_PAD_TEMPLATE (templ->obj));
}
return 0;
}
static int
_pygst_element_set_details (gpointer gclass, PyObject *details)
{
GstElementDetails gstdetails = { 0, };
if (!PyTuple_Check (details)) {
PyErr_SetString(PyExc_TypeError, "__gstdetails__ must be a tuple");
return -1;
}
if (PyTuple_Size (details) != 4) {
PyErr_SetString(PyExc_TypeError, "__gstdetails__ must be contain 4 elements");
return -1;
}
if (!PyArg_ParseTuple (details, "ssss", &gstdetails.longname, &gstdetails.klass,
&gstdetails.description, &gstdetails.author)) {
PyErr_SetString (PyExc_TypeError, "__gstdetails__ must be contain 4 strings");
return -1;
}
gst_element_class_set_details (gclass, &gstdetails);
return 0;
}
static int
_pygst_element_init (gpointer gclass, PyTypeObject *pyclass)
{
PyObject *templates, *details;
templates = PyDict_GetItemString(pyclass->tp_dict, "__gsttemplates__");
if (templates) {
if (add_templates(gclass, templates) != 0)
return -1;
} else {
PyErr_Clear();
}
details = PyDict_GetItemString(pyclass->tp_dict, "__gstdetails__");
if (details) {
if (_pygst_element_set_details (gclass, details) != 0)
return -1;
PyDict_DelItemString(pyclass->tp_dict, "__gstdetails__");
} else {
PyErr_Clear();
}
return 0;
}
static PyObject *
pygst_debug_log (PyObject *pyobject, PyObject *string, GstDebugLevel level,
gboolean isgstobject)
{
#ifndef GST_DISABLE_GST_DEBUG
gchar *str;
gchar *function;
gchar *filename;
int lineno;
PyFrameObject *frame;
GObject *object = NULL;
if (!PyArg_ParseTuple(string, "s:gst.debug_log", &str)) {
PyErr_SetString(PyExc_TypeError, "Need a string!");
return NULL;
}
frame = PyEval_GetFrame();
function = PyString_AsString(frame->f_code->co_name);
filename = g_path_get_basename(PyString_AsString(frame->f_code->co_filename));
lineno = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
/* gst_debug_log : category, level, file, function, line, object, format, va_list */
if (isgstobject)
object = G_OBJECT (pygobject_get (pyobject));
gst_debug_log (python_debug, level, filename, function, lineno, object, "%s", str);
if (filename)
g_free(filename);
#endif
Py_INCREF (Py_None);
return Py_None;
}
%%
include
gstbin.override
gstbuffer.override
gstbus.override
gstcaps.override
gstelement.override
gstelementfactory.override
gstevent.override
gstmessage.override
gstobject.override
gstpad.override
gstquery.override
gststructure.override
gsttaglist.override
gstlibs.override
gstbase.override
gstversion.override
%%
init
{
pyg_register_class_init (GST_TYPE_ELEMENT, _pygst_element_init);
if (!pygst_value_init())
return;
gst_controller_init(NULL, NULL);
}
%%
modulename gst
%%
import gobject.GObject as PyGObject_Type
%%
ignore-glob
_*
*_copy
*_error_quark
*_free
*_get_type
*_private
*_thyself
*_valist
*_ref
*_unref
*_deinit
*_full
gst_class_*
gst_init*
gst_interface_*
gst_value_*
gst_param_spec_*
%%
ignore
gst_alloc_trace_list
gst_alloc_trace_get
gst_error_get_message
gst_parse_launchv
gst_trace_read_tsc
gst_debug_log
gst_debug_log_default
gst_iterator_new_list
gst_task_set_lock
gst_clock_id_compare_func
gst_print_pad_caps
gst_util_set_value_from_string
gst_print_element_args
gst_atomic_int_set
gst_caps_replace
gst_mini_object_replace
gst_filter_run
gst_flow_to_quark
gst_implements_interface_cast
gst_implements_interface_check
gst_plugin_get_module
gst_object_sink
gst_version
%%
override-slot GstPluginFeature.tp_repr
static PyObject *
_wrap_gst_plugin_feature_tp_repr(PyObject *self)
{
gchar *repr;
PyObject *ret;
GstPluginFeature *feature = GST_PLUGIN_FEATURE (pygobject_get (self));
repr = g_strdup_printf ("<%s %s @ 0x%lx>",
self->ob_type->tp_name, gst_plugin_feature_get_name (feature),
(long) self);
ret = PyString_FromString(repr);
g_free (repr);
return ret;
}
%%
override-slot GstPluginFeature.tp_str
static PyObject *
_wrap_gst_plugin_feature_tp_str(PyObject *self)
{
gchar *repr;
PyObject *ret;
GstPluginFeature *feature = GST_PLUGIN_FEATURE (pygobject_get (self));
repr = g_strdup_printf ("<%s %s (%d)>",
self->ob_type->tp_name, gst_plugin_feature_get_name (feature),
gst_plugin_feature_get_rank (feature));
ret = PyString_FromString(repr);
g_free (repr);
return ret;
}
%%
override gst_type_find_factory_get_caps noargs
static PyObject *
_wrap_gst_type_find_factory_get_caps(PyGObject *self)
{
GstCaps *ret = (GstCaps*)gst_type_find_factory_get_caps(GST_TYPE_FIND_FACTORY(self->obj));
return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE);
}
%%
override-attr GError.domain
static PyObject *
_wrap_gst_g_error__get_domain(PyGObject *self, void *closure)
{
return PyString_FromString(g_quark_to_string(((GError*)self->obj)->domain));
}
%%
override-slot GError.tp_str
static PyObject *
_wrap_gst_g_error_tp_str(PyGObject *self)
{
GError *error = (GError*)self->obj;
return PyString_FromString(gst_error_get_message (error->domain,
error->code));
}
%%
override-attr GstDate.day
static PyObject *
_wrap_gst_date__get_day(PyGObject *self, void *closure)
{
return PyInt_FromLong(g_date_get_day((GDate*)self->obj));
}
static int
_wrap_gst_date__set_day(PyGObject *self, PyObject *value, void *closure)
{
GDate *date = (GDate *) self->obj;
if (!(PyInt_Check(value)))
return -1;
g_date_set_day(date, (int) PyInt_AsLong(value));
return 0;
}
%%
override-attr GstDate.month
static PyObject *
_wrap_gst_date__get_month(PyGObject *self, void *closure)
{
return PyInt_FromLong(g_date_get_month((GDate*)self->obj));
}
static int
_wrap_gst_date__set_month(PyGObject *self, PyObject *value, void *closure)
{
GDate *date = (GDate *) self->obj;
if (!(PyInt_Check(value)))
return -1;
g_date_set_month(date, (int) PyInt_AsLong(value));
return 0;
}
%%
override-attr GstDate.year
static PyObject *
_wrap_gst_date__get_year(PyGObject *self, void *closure)
{
return PyInt_FromLong(g_date_get_year((GDate*)self->obj));
}
static int
_wrap_gst_date__set_year(PyGObject *self, PyObject *value, void *closure)
{
GDate *date = (GDate *) self->obj;
if (!(PyInt_Check(value)))
return -1;
g_date_set_year(date, (int) PyInt_AsLong(value));
return 0;
}
%%
override-slot GstDate.tp_repr
static PyObject *
_wrap_gst_date_tp_repr(PyGObject *self)
{
GDate *date = (GDate *) self->obj;
return PyString_FromFormat ("<GstDate: %2d/%2d/%4d>",
g_date_get_day(date),
g_date_get_month(date),
g_date_get_year(date));
}
%%
override gst_registry_get_path_list
static PyObject *
_wrap_gst_registry_get_path_list (PyGObject *self)
{
GstRegistry *registry;
GList *l, *paths;
PyObject *list;
gint i;
registry = GST_REGISTRY (self->obj);
paths = gst_registry_get_path_list (registry);
list = PyList_New (g_list_length(paths));
for (l = paths, i = 0; l; l = l->next, ++i) {
gchar *path = (gchar *) l->data;
PyList_SetItem (list, i, PyString_FromString(path));
}
g_list_free (paths);
return list;
}
%%
override gst_registry_get_plugin_list
static PyObject *
_wrap_gst_registry_get_plugin_list (PyGObject *self)
{
GstRegistry *registry;
GList *l, *plugins;
PyObject *list;
gint i;
registry = GST_REGISTRY (self->obj);
plugins = gst_registry_get_plugin_list (registry);
list = PyList_New (g_list_length(plugins));
for (l = plugins, i = 0; l; l = l->next, ++i) {
GstPlugin *plugin = (GstPlugin *) l->data;
PyObject *object = pygobject_new (G_OBJECT (plugin));
gst_object_unref (plugin);
PyList_SetItem (list, i, object);
}
g_list_free (plugins);
return list;
}
%%
override gst_registry_get_feature_list kwargs
static PyObject *
_wrap_gst_registry_get_feature_list (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "type", NULL };
PyObject *py_type = NULL;
GType type;
GstRegistry *registry;
GList *l, *features;
PyObject *list;
gint i;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O:GstRegistry.get_feature_list", kwlist, &py_type))
return NULL;
if ((type = pyg_type_from_object(py_type)) == 0)
return NULL;
registry = GST_REGISTRY (self->obj);
pyg_begin_allow_threads;
features = gst_registry_get_feature_list (registry, type);
pyg_end_allow_threads;
list = PyList_New (g_list_length(features));
for (l = features, i = 0; l; l = l->next, ++i) {
GstPluginFeature *feature = (GstPluginFeature *) l->data;
PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
gst_object_unref (feature);
}
g_list_free (features);
return list;
}
%%
override gst_registry_get_feature_list_by_plugin kwargs
static PyObject *
_wrap_gst_registry_get_feature_list_by_plugin (PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "name", NULL };
gchar * name = NULL;
GstRegistry *registry;
GList *l, *features;
PyObject *list;
gint i;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"s:GstRegistry.get_feature_list_by_plugin", kwlist, &name))
return NULL;
registry = GST_REGISTRY (self->obj);
pyg_begin_allow_threads;
features = gst_registry_get_feature_list_by_plugin (registry, name);
pyg_end_allow_threads;
list = PyList_New (g_list_length(features));
for (l = features, i = 0; l; l = l->next, ++i) {
GstPluginFeature *feature = (GstPluginFeature *) l->data;
PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
}
g_list_free (features);
return list;
}
%%
new-constructor GST_TYPE_XML
%%
override gst_xml_new noargs
extern PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
extern PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
/* libxml2 available check */
static PyObject *
_gst_get_libxml2_module(void)
{
PyObject *xml = NULL;
xml = PyImport_ImportModule("libxml2");
if (!xml) {
PyErr_Clear();
PyErr_SetString(PyExc_RuntimeError,"libxml2 bindings required");
return NULL;
}
return xml;
}
static int
_wrap_gst_xml_new(PyGObject *self)
{
PyObject *xml = _gst_get_libxml2_module();
if(!xml)
return -1;
self->obj = (GObject *)gst_xml_new();
if (!self->obj) {
PyErr_SetString(PyExc_RuntimeError, "could not create GstXML object");
return -1;
}
pygobject_register_wrapper((PyObject *)self);
return 0;
}
%%
override gst_xml_get_topelements noargs
static PyObject *
_wrap_gst_xml_get_topelements(PyGObject *self)
{
GList *l, *xml_elements;
PyObject *py_list;
gint i;
xml_elements = gst_xml_get_topelements(GST_XML(self->obj));
py_list = PyList_New(g_list_length(xml_elements));
for (l = xml_elements, i = 0; l; l = l->next, ++i) {
GstElement *element = (GstElement*)l->data;
PyList_SetItem(py_list, i, pygobject_new(G_OBJECT(element)));
}
return py_list;
}
%%
override gst_xml_parse_memory kwargs
static PyObject *
_wrap_gst_xml_parse_memory(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "buffer", "root", NULL };
int buffer_len, ret;
char *root = NULL;
guchar *buffer;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"s#|s:GstXML.parse_memory",
kwlist, &buffer, &buffer_len, &root))
return NULL;
ret = gst_xml_parse_memory(GST_XML(self->obj),
buffer, buffer_len, root);
return PyBool_FromLong(ret);
}
%%
override gst_tag_setter_get_tag_list noargs
static PyObject *
_wrap_gst_tag_setter_get_tag_list(PyGObject *self)
{
GstTagList *ret;
ret = (GstTagList*)gst_tag_setter_get_tag_list(GST_TAG_SETTER(self->obj));
/* pyg_boxed_new handles NULL checking */
return pyg_boxed_new(GST_TYPE_TAG_LIST, ret, TRUE, TRUE);
}
%%
override gst_element_register kwargs
static GstPlugin *
_pygst_get_plugin(void)
{
PyObject *dict = NULL, *module = NULL, *pyplugin = NULL;
GstPlugin *ret;
if (!(module = PyImport_ImportModule ("gst")))
goto err;
if (!(dict = PyModule_GetDict (module)))
goto err;
if (!(pyplugin = PyDict_GetItemString (dict, "__plugin__")))
goto err;
ret = pyg_boxed_get (pyplugin, GstPlugin);
Py_DECREF (module);
return ret;
err:
Py_XDECREF (module);
PyErr_Clear ();
return NULL;
}
static PyObject *
_wrap_gst_element_register(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "type", "elementname", "rank", NULL };
PyObject *py_type = NULL;
guint rank = GST_RANK_NONE;
char *elementname = NULL;
int ret;
GType type;
/* FIXME: can we make the name optional, too? Anyone know a good default? */
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|I:element_register", kwlist,
&py_type, &elementname, &rank))
return NULL;
if ((type = pyg_type_from_object(py_type)) == 0)
return NULL;
ret = gst_element_register(_pygst_get_plugin(), elementname, rank, type);
return PyBool_FromLong(ret);
}
%%
override-attr GError.domain
static PyObject *
_wrap_gst_g_error__get_domain(PyGObject *self, void *closure)
{
return PyString_FromString(g_quark_to_string(((GError*)self->obj)->domain));
}
%%
override-slot GError.tp_str
static PyObject *
_wrap_gst_g_error_tp_str(PyGObject *self)
{
GError *error = (GError*)self->obj;
return PyString_FromString(gst_error_get_message (error->domain,
error->code));
}
%%
override gst_flow_get_name kwargs
static PyObject *
_wrap_gst_flow_get_name(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "ret", NULL };
PyObject *py_ret = NULL;
const gchar *ret;
gchar *nret;
GstFlowReturn flow;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gst_flow_get_name", kwlist, &py_ret))
return NULL;
if (pyg_enum_get_value(GST_TYPE_FLOW_RETURN, py_ret, (gint *)&flow))
return NULL;
ret = gst_flow_get_name(flow);
if (ret) {
nret = g_strdup(ret);
return PyString_FromString(nret);
}
Py_INCREF(Py_None);
return Py_None;
}
%%
override gst_log args
static PyObject *
_wrap_gst_log (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_LOG, FALSE);
}
%%
override gst_debug args
static PyObject *
_wrap_gst_debug (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, FALSE);
}
%%
override gst_info args
static PyObject *
_wrap_gst_info (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_INFO, FALSE);
}
%%
override gst_warning args
static PyObject *
_wrap_gst_warning (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, FALSE);
}
%%
override gst_error args
static PyObject *
_wrap_gst_error (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, FALSE);
}
%%
override gst_object_log args
static PyObject *
_wrap_gst_object_log (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_LOG, TRUE);
}
%%
override gst_object_debug args
static PyObject *
_wrap_gst_object_debug (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, TRUE);
}
%%
override gst_object_info args
static PyObject *
_wrap_gst_object_info (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_INFO, TRUE);
}
%%
override gst_object_warning args
static PyObject *
_wrap_gst_object_warning (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, TRUE);
}
%%
override gst_object_error args
static PyObject *
_wrap_gst_object_error (PyObject *whatever, PyObject *string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, TRUE);
}
%%
override GST_TIME_ARGS kwargs
static PyObject *
_wrap_GST_TIME_ARGS(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "time", NULL };
PyObject *py_time = NULL;
PyObject *string;
gchar *ret;
guint64 time;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:time_to_string", kwlist, &py_time))
return NULL;
time = PyInt_AsUnsignedLongLongMask(py_time);
if (GST_CLOCK_TIME_IS_VALID (time))
ret = g_strdup_printf("%"GST_TIME_FORMAT, GST_TIME_ARGS(time));
else
ret = g_strdup ("CLOCK_TIME_NONE");
if (!ret) {
Py_INCREF(Py_None);
return Py_None;
}
if (!(string = PyString_FromString(ret))) {
g_free(ret);
return NULL;
}
g_free(ret);
return string;
}
%%
override gst_type_find_factory_get_list noargs
static PyObject *
_wrap_gst_type_find_factory_get_list (PyObject *self)
{
GList *l, *list;
PyObject *py_list;
int i = 0;
list = gst_type_find_factory_get_list ();
py_list = PyList_New(g_list_length(list));
for (l = list; l ; l = g_list_next(l), i++) {
GstTypeFindFactory *fact = (GstTypeFindFactory*) l->data;
PyList_SetItem(py_list, i,
pygobject_new (G_OBJECT (fact)));
}
g_list_free (list);
return py_list;
}
%%
override gst_get_gst_version noargs
static PyObject *
_wrap_gst_get_gst_version (PyObject *self)
{
guint major, minor, micro, nano;
PyObject *py_tuple;
gst_version (&major, &minor, µ, &nano);
py_tuple = PyTuple_New(4);
PyTuple_SetItem(py_tuple, 0, PyInt_FromLong(major));
PyTuple_SetItem(py_tuple, 1, PyInt_FromLong(minor));
PyTuple_SetItem(py_tuple, 2, PyInt_FromLong(micro));
PyTuple_SetItem(py_tuple, 3, PyInt_FromLong(nano));
return py_tuple;
}
%%
override gst_get_pygst_version noargs
static PyObject *
_wrap_gst_get_pygst_version (PyObject *self)
{
PyObject *py_tuple;
py_tuple = Py_BuildValue ("(iiii)", PYGST_MAJOR_VERSION, PYGST_MINOR_VERSION,
PYGST_MICRO_VERSION, PYGST_NANO_VERSION);
return py_tuple;
}
%%
override gst_clock_get_calibration noargs
static PyObject *
_wrap_gst_clock_get_calibration (PyGObject * self)
{
PyObject *ret;
GstClockTime internal;
GstClockTime external;
GstClockTime rate_num;
GstClockTime rate_denom;
gst_clock_get_calibration (GST_CLOCK (self->obj),
&internal,
&external,
&rate_num,
&rate_denom);
ret = PyTuple_New(4);
PyTuple_SetItem(ret, 0, PyLong_FromUnsignedLongLong(internal));
PyTuple_SetItem(ret, 1, PyLong_FromUnsignedLongLong(external));
PyTuple_SetItem(ret, 2, PyLong_FromUnsignedLongLong(rate_num));
PyTuple_SetItem(ret, 3, PyLong_FromUnsignedLongLong(rate_denom));
return ret;
}
%%
override gst_clock_add_observation kwargs
static PyObject *
_wrap_gst_clock_add_observation (PyGObject *self, PyObject * args, PyObject * kwargs)
{
static char *kwlist[] = { "slave", "master", NULL};
GstClockTime master, slave;
gdouble squared = 1.0;
PyObject *py_ret;
gboolean ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "KK:GstClock.add_observation",
kwlist, &master, &slave))
return NULL;
ret = gst_clock_add_observation (GST_CLOCK (self->obj), master, slave,
&squared);
py_ret = PyList_New(2);
PyList_SetItem(py_ret, 0, PyBool_FromLong(ret));
PyList_SetItem(py_ret, 1, PyFloat_FromDouble(squared));
return py_ret;
}
%%
override gst_type_find_helper_for_buffer kwargs
static PyObject *
_wrap_gst_type_find_helper_for_buffer (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "object", "buffer", NULL };
PyGObject *py_object;
PyGstMiniObject *py_buffer;
PyObject *py_ret;
GstTypeFindProbability prob = 0;
GstCaps *caps = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!O!:type_find_helper_for_buffer",
kwlist, &PyGstObject_Type, &py_object,
&PyGstBuffer_Type, &py_buffer))
return NULL;
caps = gst_type_find_helper_for_buffer (GST_OBJECT (py_object->obj),
GST_BUFFER (py_buffer->obj),
&prob);
py_ret = PyTuple_New(2);
if (caps)
PyTuple_SetItem(py_ret, 0, pyg_boxed_new (GST_TYPE_CAPS, caps, FALSE, TRUE));
else {
Py_INCREF(Py_None);
PyTuple_SetItem(py_ret, 0, Py_None);
}
if (prob)
PyTuple_SetItem(py_ret, 1, pyg_enum_from_gtype(GST_TYPE_TYPE_FIND_PROBABILITY, prob));
else {
Py_INCREF(Py_None);
PyTuple_SetItem(py_ret, 1, Py_None);
}
return py_ret;
}
%%
override gst_type_find_new kwargs
static guint8 *
gst_type_find_peek_handler (gpointer data, gint64 offset, guint size)
{
PyGILState_STATE state;
guint8 * ret = NULL;
PyObject *py_data;
PyObject *callback, *args;
PyObject *py_ret;
GST_DEBUG ("mkay");
g_return_val_if_fail (data != NULL, NULL);
py_data = (PyObject *) data;
g_assert (PyTuple_Check (py_data));
state = pyg_gil_state_ensure ();
/* Figure out the callback and create the arguments */
if (!(callback = PyTuple_GetItem(py_data, 1)))
goto beach;
args = Py_BuildValue ("(OLI)",
PyTuple_GetItem(py_data, 0),
offset, size);
if (!args)
goto beach;
/* Call python method */
py_ret = PyObject_CallObject (callback, args);
/* transform return value (a string) */
if (!py_ret) {
Py_DECREF (args);
goto beach;
}
if (!PyString_Check(py_ret)) {
Py_DECREF (py_ret);
Py_DECREF (args);
goto beach;
} else {
gchar *str;
Py_ssize_t len;
if ((PyString_AsStringAndSize(py_ret, &str, &len)) == -1) {
Py_DECREF (py_ret);
Py_DECREF (args);
goto beach;
}
GST_DEBUG ("got string of len %d", len);
if (len)
ret = g_memdup((gconstpointer) str, (guint) len);
}
Py_DECREF (py_ret);
Py_DECREF (args);
beach:
pyg_gil_state_release (state);
return ret;
}
static void
gst_type_find_suggest_handler (gpointer data, guint probability, const GstCaps * caps)
{
PyGILState_STATE state;
PyObject *py_data;
PyObject *callback, *args;
GST_DEBUG ("mkay");
if (!data)
return;
py_data = (PyObject *) data;
g_assert (PyTuple_Check (py_data));
state = pyg_gil_state_ensure ();
/* Figure out the callback and create the arguments */
if (!(callback = PyTuple_GetItem(py_data, 2)))
goto beach;
args = Py_BuildValue ("(OIN)",
PyTuple_GetItem(py_data, 0),
probability, pyg_boxed_new (GST_TYPE_CAPS, (GstCaps*) caps, TRUE, TRUE));
if (!args)
goto beach;
/* Call python method */
PyObject_CallObject (callback, args);
Py_DECREF (args);
beach:
pyg_gil_state_release (state);
return;
}
static guint64
gst_type_find_get_length_handler (gpointer data)
{
guint64 ret = 0;
/* Call python method */
return ret;
}
static PyObject *
_wrap_gst_type_find_new (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "data", "peekfunction", "suggestfunction", "getlengthfunction", NULL };
PyObject *py_data;
gpointer data;
PyObject *peekfunction;
PyObject *suggestfunction;
PyObject *getlengthfunction = NULL;
PyObject *pytypefind = NULL;
GstTypeFind *typefind = NULL;
GST_DEBUG ("poeut");
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO|O:type_find_new",
kwlist, &py_data, &peekfunction,
&suggestfunction, &getlengthfunction)) {
PyErr_SetString (PyExc_TypeError, "Error parsing values ...");
return NULL;
}
if (!PyCallable_Check(peekfunction)) {
PyErr_SetString (PyExc_TypeError, "peekfunction is not callable");
return NULL;
}
if (!PyCallable_Check(suggestfunction)) {
PyErr_SetString (PyExc_TypeError, "suggestfunction is not callable");
return NULL;
}
if (getlengthfunction && (!PyCallable_Check(suggestfunction))) {
PyErr_SetString (PyExc_TypeError, "getlengthfunction is not callable");
return NULL;
}
/* Create a python list to put in typefind->data */
if (getlengthfunction)
data = Py_BuildValue("(OOOO)", py_data, peekfunction, suggestfunction, getlengthfunction);
else
data = Py_BuildValue("(OOO)", py_data, peekfunction, suggestfunction);
typefind = g_new0(GstTypeFind, 1);
typefind->peek = gst_type_find_peek_handler;
typefind->suggest = gst_type_find_suggest_handler;
typefind->data = data;
if (getlengthfunction)
typefind->get_length = gst_type_find_get_length_handler;
pytypefind = pyg_pointer_new (GST_TYPE_TYPE_FIND, typefind);
if (!pytypefind) {
PyErr_SetString (PyExc_TypeError, "pyg_pointer_new failed");
}
GST_DEBUG ("poeut : %p", pytypefind);
return pytypefind;
}
%%
override gst_segment_set_seek kwargs
static PyObject *
_wrap_gst_segment_set_seek (PyObject * self, PyObject * args, PyObject * kwargs)
{
static char *kwlist[] = { "rate", "format", "flags", "start_type", "start",
"stop_type", "stop", NULL };
GstSeekType start_type, stop_type;
PyObject *py_format = NULL, *py_flags = NULL, *py_start_type = NULL;
PyObject *py_stop_type = NULL, *py_ret;
double rate;
GstFormat format;
gint64 start, stop;
GstSeekFlags flags;
gboolean update = FALSE;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"dOOOLOL:GstSegment.set_seek",
kwlist, &rate, &py_format, &py_flags,
&py_start_type, &start, &py_stop_type,
&stop))
return NULL;
if (pyg_enum_get_value(GST_TYPE_FORMAT, py_format, (gint *)&format))
return NULL;
if (pyg_flags_get_value(GST_TYPE_SEEK_FLAGS, py_flags, (gint *)&flags))
return NULL;
if (pyg_enum_get_value(GST_TYPE_SEEK_TYPE, py_start_type, (gint *)&start_type))
return NULL;
if (pyg_enum_get_value(GST_TYPE_SEEK_TYPE, py_stop_type, (gint *)&stop_type))
return NULL;
pyg_begin_allow_threads;
gst_segment_set_seek(pyg_boxed_get(self, GstSegment), rate, format, flags,
start_type, start, stop_type, stop, &update);
pyg_end_allow_threads;
py_ret = PyBool_FromLong(update);
return py_ret;
}
%%
override gst_segment_clip kwargs
static PyObject *
_wrap_gst_segment_clip (PyObject * self, PyObject * args, PyObject * kwargs)
{
static char *kwlist[] = { "format", "start", "stop", NULL};
GstFormat format;
gint64 start, stop;
gint64 cstart = -1;
gint64 cstop = -1;
gboolean ret;
PyObject *py_ret, *py_format;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OLL:GstSegment.clip",
kwlist, &py_format, &start, &stop))
return NULL;
if (pyg_enum_get_value(GST_TYPE_FORMAT, py_format, (gint *)&format))
return NULL;
pyg_begin_allow_threads;
ret = gst_segment_clip (pyg_boxed_get(self, GstSegment), format, start, stop,
&cstart, &cstop);
pyg_end_allow_threads;
/* Returns gboolean ret, gint64 clip_start, gint64 clip_stop */
py_ret = PyList_New(3);
PyList_SetItem(py_ret, 0, PyBool_FromLong(ret));
PyList_SetItem(py_ret, 1, PyLong_FromLongLong(cstart));
PyList_SetItem(py_ret, 2, PyLong_FromLongLong(cstop));
return py_ret;
}
%%
override GstURIHandler__proxy_do_get_type_full
static guint
_wrap_GstURIHandler__proxy_do_get_type_full (GType type)
{
PyGILState_STATE __py_state;
PyTypeObject *py_class;
PyObject *py_method;
PyObject *py_retval;
guint retval;
__py_state = pyg_gil_state_ensure();
py_class = pygobject_lookup_class (type);
if (py_class == NULL) {
pyg_gil_state_release (__py_state);
return GST_URI_UNKNOWN;
}
py_method = PyObject_GetAttrString((PyObject *) py_class, "do_get_type_full");
Py_DECREF (py_class);
if (!py_method) {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
return GST_URI_UNKNOWN;
}
py_retval = PyObject_CallObject(py_method, NULL);
Py_DECREF (py_method);
if (!py_retval) {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
return GST_URI_UNKNOWN;
}
retval = PyLong_AsLong (py_retval);
Py_DECREF(py_retval);
pyg_gil_state_release(__py_state);
return retval;
}
%%
override GstURIHandler__proxy_do_get_protocols_full
static gchar **
_wrap_GstURIHandler__proxy_do_get_protocols_full (GType type)
{
PyGILState_STATE __py_state;
PyTypeObject *py_class;
PyObject *py_method;
PyObject *py_retval;
Py_ssize_t ret_size, i;
gchar **retval;
__py_state = pyg_gil_state_ensure();
py_class = pygobject_lookup_class (type);
if (py_class == NULL) {
pyg_gil_state_release (__py_state);
return NULL;
}
py_method = PyObject_GetAttrString((PyObject *) py_class, "do_get_protocols_full");
Py_DECREF (py_class);
if (!py_method) {
if (PyErr_Occurred())
PyErr_Print();
pyg_gil_state_release(__py_state);
return NULL;
}
py_retval = PyObject_CallObject(py_method, NULL);
Py_DECREF (py_method);
if (!py_retval) {
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF (py_retval);
pyg_gil_state_release(__py_state);
return NULL;
}
if (!PySequence_Check (py_retval)) {
PyErr_SetString (PyExc_TypeError, "GstURIHandler.do_get_protocols_full "
"must return a sequence of strings");
Py_DECREF (py_retval);
return NULL;
}
ret_size = PySequence_Size (py_retval);
if (ret_size == -1) {
Py_DECREF (py_retval);
pyg_gil_state_release(__py_state);
return NULL;
}
retval = g_new (gchar *, ret_size + 1);
retval[ret_size] = NULL;
for (i = 0; i < PySequence_Size (py_retval); ++i) {
PyObject *item = PySequence_GetItem (py_retval, i);
if (!item) {
if (PyErr_Occurred ())
PyErr_Print ();
g_strfreev (retval);
Py_DECREF (py_retval);
pyg_gil_state_release(__py_state);
return NULL;
}
if (!PyString_Check (item)) {
PyErr_SetString (PyExc_TypeError, "GstURIHandler.do_get_protocols_full "
"must return a sequence of strings");
Py_DECREF (item);
g_strfreev (retval);
Py_DECREF (py_retval);
pyg_gil_state_release(__py_state);
return NULL;
}
retval [i] = PyString_AsString (item);
if (!retval [i]) {
if (PyErr_Occurred ())
PyErr_Print ();
g_strfreev (retval);
Py_DECREF (item);
Py_DECREF (py_retval);
pyg_gil_state_release(__py_state);
return NULL;
}
Py_DECREF (item);
}
Py_DECREF(py_retval);
pyg_gil_state_release(__py_state);
return retval;
}
%%
override g_error_new kwargs
static int
_wrap_g_error_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "domain", "code", "message", NULL };
int code;
gchar *message;
gchar *domain;
GQuark domainq;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"sis:GError.__init__", kwlist, &domain, &code, &message))
return -1;
domainq = g_quark_from_string(domain);
self->gtype = GST_TYPE_G_ERROR;
self->free_on_dealloc = FALSE;
self->boxed = g_error_new(domainq, code, message);
if (!self->boxed) {
PyErr_SetString(PyExc_RuntimeError, "could not create GError object");
return -1;
}
self->free_on_dealloc = TRUE;
return 0;
}
|