Initial import to Tizen
[profile/ivi/gstreamer-python.git] / gst / pbutils.override
1 /* -*- Mode: C; c-basic-offset: 4 -*- */
2 /* gst-python
3  * Copyright (C) 2008 <edward.hervey@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 %%
21 headers
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #define NO_IMPORT_PYGOBJECT
28 #include "common.h"
29 #include "pygst.h"
30
31 #include <gst/gst.h>
32
33 #include <gst/pbutils/pbutils.h>
34 #include "pygstminiobject.h"
35 GST_DEBUG_CATEGORY_EXTERN (pygst_debug);
36 #define GST_CAT_DEFAULT pygst_debug
37
38 /* Boonky define that allows for backwards compatibility with Python 2.4 */
39 #if PY_VERSION_HEX < 0x02050000
40 #define Py_ssize_t int
41 #endif
42
43 static void
44 install_plugins_result_handler(GstInstallPluginsReturn result, gpointer user_data)
45 {
46     PyGILState_STATE state;
47     PyObject *callback, *args;
48     PyObject *py_user_data;
49     PyObject *py_result;
50     PyObject *ret;
51     gint i, len;
52     
53     if (user_data == NULL)
54         return;
55
56     state = pyg_gil_state_ensure();
57
58     py_user_data = (PyObject*) user_data;
59     py_result = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, result);
60
61     callback = PyTuple_GetItem(py_user_data, 0);
62     args = Py_BuildValue("(N)", py_result);
63
64     len = PyTuple_Size(py_user_data);
65     for (i = 1; i < len; ++i) {
66         PyObject *tuple = args;
67         args = PySequence_Concat(tuple, PyTuple_GetItem(py_user_data, i));
68         Py_DECREF(tuple);
69     }
70     
71     ret = PyObject_CallObject(callback, args);
72
73     if (PyErr_Occurred())
74         PyErr_Print();
75
76     Py_DECREF(args);
77     pyg_gil_state_release(state);
78
79 }
80 %%
81 modulename gst.pbutils
82 %%
83 import gobject.GObject as PyGObject_Type
84 import gst.Object as PyGstObject_Type
85 import gst.Structure as PyGstStructure_Type
86 import gst.Element as PyGstElement_Type
87 import gst.Message as PyGstMessage_Type
88 import gst.MiniObject as PyGstMiniObject_Type
89 %%
90 include
91   gstversion.override
92 %%
93 ignore-glob
94  _*
95  *init
96  *_free
97  *_get_type
98 %%
99 override gst_install_plugins_sync kwargs
100 static PyObject *
101 _wrap_gst_install_plugins_sync(PyGObject *self, PyObject *args, PyObject *kwargs)
102 {
103     static char *kwlist[] = { "details", "context", NULL };
104     PyObject *py_ctx;
105     GstInstallPluginsContext *ctx;
106     GstInstallPluginsReturn ret;
107     gchar **details;
108     gint len;
109     PyObject *py_ret;
110     PyObject *py_details;
111     Py_ssize_t i;
112
113     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:install_plugins_sync",
114                                      kwlist, &py_details, &py_ctx))
115         return NULL;
116
117     if (!pyg_boxed_check(py_ctx, GST_TYPE_INSTALL_PLUGINS_CONTEXT)) {
118         PyErr_SetString(PyExc_TypeError, "Argument 2 must be a gst.pbutils.InstallPluginsContext");
119         return NULL;
120     }
121
122     len = PySequence_Size(py_details);
123     if ((!PySequence_Check(py_details)) || (len < 1)) {
124         PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
125         Py_DECREF(py_details);
126         return NULL;
127     }
128
129     details = g_new0(gchar*, len+1);
130
131     /* Check all items in py_details are strings */
132     for (i = 0; i < len; i++) {
133         PyObject *py_str = PySequence_GetItem(py_details, i);
134         gchar *str;
135
136         if (!PyString_Check(py_str)) {
137             PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
138             Py_DECREF(py_str);
139             Py_DECREF(py_details);
140             g_strfreev(details);
141             return NULL;
142         }
143         if (!(str = PyString_AsString(py_str))) {
144             Py_DECREF(py_str);
145             Py_DECREF(py_details);
146             g_strfreev(details);
147             return NULL;
148         }
149         details[i] = g_strdup(str);
150         Py_DECREF(py_str);
151     }
152     
153     ctx = (GstInstallPluginsContext *) pyg_boxed_get(py_ctx, GstInstallPluginsContext);
154
155     pyg_begin_allow_threads;
156     ret = gst_install_plugins_sync(details, ctx);
157     pyg_end_allow_threads;
158
159     g_strfreev(details);
160
161     py_ret = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, ret);
162     return py_ret;
163 }
164 %%
165 override gst_install_plugins_async args
166 static PyObject *
167 _wrap_gst_install_plugins_async(PyGObject *self, PyObject *args)
168 {
169     PyObject *py_ctx, *py_ret, *py_details, *callback, *cbargs, *data;
170     GstInstallPluginsContext *ctx;
171     GstInstallPluginsReturn ret;
172     gchar **details;
173     gint len;
174     Py_ssize_t i;
175
176     if (PyTuple_Size(args) < 3) {
177         PyErr_SetString(PyExc_TypeError, "install_plugins_async requires at least 3 arguments");
178         return NULL;
179     }
180
181     py_ctx = PySequence_GetItem(args, 1);
182
183     if (!pyg_boxed_check(py_ctx, GST_TYPE_INSTALL_PLUGINS_CONTEXT)) {
184         PyErr_SetString(PyExc_TypeError, "Argument 2 must be a gst.pbutils.InstallPluginsContext");
185         Py_DECREF(py_ctx);
186         return NULL;
187     }
188
189     py_details = PySequence_GetItem(args, 0);
190     if ((!PySequence_Check(py_details)) || (PySequence_Size(py_details) < 1)) {
191         PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
192         Py_DECREF(py_ctx);
193         Py_DECREF(py_details);
194         return NULL;
195     }
196
197     len = PySequence_Size(py_details);
198     details = g_new0(gchar*, len+1);
199
200     /* Check all items in py_details are strings */
201     for (i = 0; i < len; i++) {
202         PyObject *py_str = PySequence_GetItem(py_details, i);
203         gchar *str;
204
205         if (!PyString_Check(py_str)) {
206             PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
207             Py_DECREF(py_str);
208             Py_DECREF(py_ctx);
209             Py_DECREF(py_details);
210             g_strfreev(details);
211             return NULL;
212         }
213         if (!(str = PyString_AsString(py_str))) {
214             Py_DECREF(py_str);
215             Py_DECREF(py_ctx);
216             Py_DECREF(py_details);
217             g_strfreev(details);
218             return NULL;
219         }
220         details[i] = g_strdup(str);
221         Py_DECREF(py_str);
222     }
223
224     callback = PySequence_GetItem(args, 2);
225     if (!PyCallable_Check(callback)) {
226         PyErr_SetString(PyExc_TypeError, "callback is not callable");
227         Py_DECREF(callback);
228         Py_DECREF(py_ctx);
229         Py_DECREF(py_details);
230         g_strfreev(details);
231     }
232     
233     if (!(cbargs = PySequence_GetSlice(args, 3, PyTuple_Size(args)))) {
234         Py_DECREF(callback);
235         Py_DECREF(py_ctx);
236         Py_DECREF(py_details);
237         g_strfreev(details);
238         return NULL;
239     }
240     if (!(data = Py_BuildValue("(ON)", callback, cbargs))) {
241         Py_DECREF(py_details);
242         Py_DECREF(py_ctx);
243         Py_DECREF(callback);
244         Py_DECREF(cbargs);
245     }
246
247     ctx = (GstInstallPluginsContext *) pyg_boxed_get(py_ctx, GstInstallPluginsContext);
248     pyg_begin_allow_threads;
249     ret = gst_install_plugins_async(details, ctx,
250                                     (GstInstallPluginsResultFunc) install_plugins_result_handler,
251                                     data);
252     pyg_end_allow_threads;
253
254     g_strfreev(details);
255
256     py_ret = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, ret);
257     return py_ret;
258 }
259 %%
260 override gst_plugins_base_version noargs
261 static PyObject *
262 _wrap_gst_plugins_base_version (PyObject *self)
263 {
264     guint       major, minor, micro, nano;
265     PyObject    *py_tuple;
266
267     gst_plugins_base_version (&major, &minor, &micro, &nano);
268     py_tuple = PyTuple_New(4);
269     PyTuple_SetItem(py_tuple, 0, PyInt_FromLong(major));
270     PyTuple_SetItem(py_tuple, 1, PyInt_FromLong(minor));
271     PyTuple_SetItem(py_tuple, 2, PyInt_FromLong(micro));
272     PyTuple_SetItem(py_tuple, 3, PyInt_FromLong(nano));
273
274     return py_tuple;
275 }
276 %%
277 override gst_discoverer_info_get_stream_list noargs
278 static PyObject *
279 _wrap_gst_discoverer_info_get_stream_list(PyGstMiniObject * self)
280 {
281     GList *res, *tmp;
282     PyObject *pyres;
283
284     res = gst_discoverer_info_get_stream_list(GST_DISCOVERER_INFO (self->obj));
285
286     pyres = PyList_New(0);
287     for (tmp = res; tmp; tmp = tmp->next) {
288         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
289     }
290     if (res)
291         gst_discoverer_stream_info_list_free(res);
292     return pyres;
293 }
294 %%
295 override gst_discoverer_info_get_streams kwargs
296 static PyObject *
297 _wrap_gst_discoverer_info_get_streams(PyGstMiniObject * self, PyObject *args, PyObject *kwargs)
298 {
299     static char *kwlist[] = { "type", NULL };
300     GList *res, *tmp;
301     PyObject *pyres, *py_type;
302     GType ftype;
303
304     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:GstDiscovererInfo.get_streams", kwlist, &py_type))
305         return NULL;
306     if ((ftype = pyg_type_from_object(py_type)) == 0)
307         return NULL;
308     res = gst_discoverer_info_get_streams(GST_DISCOVERER_INFO (self->obj), ftype);
309
310     pyres = PyList_New(0);
311     for (tmp = res; tmp; tmp = tmp->next) {
312         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
313     }
314     if (res)
315         gst_discoverer_stream_info_list_free(res);
316     return pyres;
317 }
318 %%
319 override gst_discoverer_info_get_audio_streams noargs
320 static PyObject *
321 _wrap_gst_discoverer_info_get_audio_streams(PyGstMiniObject * self)
322 {
323     GList *res, *tmp;
324     PyObject *pyres;
325
326     res = gst_discoverer_info_get_audio_streams(GST_DISCOVERER_INFO (self->obj));
327
328     pyres = PyList_New(0);
329     for (tmp = res; tmp; tmp = tmp->next) {
330         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
331     }
332     if (res)
333         gst_discoverer_stream_info_list_free(res);
334     return pyres;
335 }
336 %%
337 override gst_discoverer_info_get_video_streams noargs
338 static PyObject *
339 _wrap_gst_discoverer_info_get_video_streams(PyGstMiniObject * self)
340 {
341     GList *res, *tmp;
342     PyObject *pyres;
343
344     res = gst_discoverer_info_get_video_streams(GST_DISCOVERER_INFO (self->obj));
345
346     pyres = PyList_New(0);
347     for (tmp = res; tmp; tmp = tmp->next) {
348         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
349     }
350     if (res)
351         gst_discoverer_stream_info_list_free(res);
352     return pyres;
353 }
354 %%
355 override gst_discoverer_info_get_container_streams noargs
356 static PyObject *
357 _wrap_gst_discoverer_info_get_container_streams(PyGstMiniObject * self)
358 {
359     GList *res, *tmp;
360     PyObject *pyres;
361
362     res = gst_discoverer_info_get_container_streams(GST_DISCOVERER_INFO (self->obj));
363
364     pyres = PyList_New(0);
365     for (tmp = res; tmp; tmp = tmp->next) {
366         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
367     }
368     if (res)
369         gst_discoverer_stream_info_list_free(res);
370     return pyres;
371 }
372 %%
373 override gst_discoverer_container_info_get_streams noargs
374 static PyObject *
375 _wrap_gst_discoverer_container_info_get_streams(PyGstMiniObject * self)
376 {
377     GList *res, *tmp;
378     PyObject *pyres;
379
380     res = gst_discoverer_container_info_get_streams(GST_DISCOVERER_CONTAINER_INFO (self->obj));
381
382     pyres = PyList_New(0);
383     for (tmp = res; tmp; tmp = tmp->next) {
384         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
385     }
386     if (res)
387         gst_discoverer_stream_info_list_free(res);
388     return pyres;
389 }
390 %%
391 override gst_encoding_container_profile_get_profiles noargs
392 static PyObject *
393 _wrap_gst_encoding_container_profile_get_profiles(PyGstMiniObject * self)
394 {
395     GList *res, *tmp;
396     PyObject *pyres;
397
398     res = (GList*) gst_encoding_container_profile_get_profiles(GST_ENCODING_CONTAINER_PROFILE (self->obj));
399
400     pyres = PyList_New(0);
401     for (tmp = res; tmp; tmp = tmp->next) {
402         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
403     }
404     if (res)
405         g_list_free (res);
406     return pyres;
407 }
408 %%
409 override gst_encoding_target_get_profiles noargs
410 static PyObject *
411 _wrap_gst_encoding_target_get_profiles(PyGstMiniObject * self)
412 {
413     GList *res, *tmp;
414     PyObject *pyres;
415
416     res = (GList*) gst_encoding_target_get_profiles(GST_ENCODING_TARGET (self->obj));
417
418     pyres = PyList_New(0);
419     for (tmp = res; tmp; tmp = tmp->next) {
420         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
421     }
422     if (res)
423         g_list_free (res);
424     return pyres;
425 }
426 %%
427 override gst_encoding_list_all_targets kwargs
428 static PyObject *
429 _wrap_gst_encoding_list_all_targets(PyGstMiniObject * self, PyObject *args, PyObject *kwargs)
430 {
431     static char *kwlist[] = { "categoryname", NULL };
432     GList *res, *tmp;
433     const gchar *categoryname = NULL;
434     PyObject *pyres;
435
436     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"!s:GstDiscovererInfo.get_streams", kwlist, &categoryname))
437         return NULL;
438     res = (GList*) gst_encoding_list_all_targets(categoryname);
439
440     pyres = PyList_New(0);
441     for (tmp = res; tmp; tmp = tmp->next) {
442         PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
443     }
444     if (res)
445         g_list_free (res);
446     return pyres;
447 }
448 %%
449 override gst_encoding_list_available_categories noargs
450 static PyObject *
451 _wrap_gst_encoding_list_available_categories(PyGstMiniObject * self)
452 {
453     GList *res, *tmp;
454     PyObject *pyres;
455
456     res = (GList*) gst_encoding_list_available_categories();
457
458     pyres = PyList_New(0);
459     for (tmp = res; tmp; tmp = tmp->next) {
460         PyList_Append(pyres, PyString_FromString((const gchar*) tmp->data));
461         g_free (tmp->data);
462     }
463     if (res)
464         g_list_free (res);
465     return pyres;
466 }
467 %%
468 override gst_encoding_target_new kwargs
469 static int
470 _wrap_gst_encoding_target_new(PyGstMiniObject *self, PyObject *args, PyObject *kwargs)
471 {
472     static char *kwlist[] = { "name", "category", "description", NULL };
473     char *name, *description, *category;
474
475     if (!PyArg_ParseTupleAndKeywords(args, kwargs,"sss:GstEncodingContainerProfile.__init__", kwlist, &name, &category, &description))
476         return -1;
477
478     self->obj = (GstMiniObject *)gst_encoding_target_new(name, category, description, NULL);
479
480     if (!self->obj) {
481         PyErr_SetString(PyExc_RuntimeError, "could not create GstEncodingTarget miniobject");
482         return -1;
483     }
484     pygstminiobject_register_wrapper((PyObject *)self);
485     return 0;
486 }