1 /* -*- Mode: C; c-basic-offset: 4 -*- */
3 * Copyright (C) 2008 <edward.hervey@collabora.co.uk>
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.
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.
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.
27 #define NO_IMPORT_PYGOBJECT
33 #include <gst/pbutils/pbutils.h>
34 #include "pygstminiobject.h"
35 GST_DEBUG_CATEGORY_EXTERN (pygst_debug);
36 #define GST_CAT_DEFAULT pygst_debug
38 /* Boonky define that allows for backwards compatibility with Python 2.4 */
39 #if PY_VERSION_HEX < 0x02050000
40 #define Py_ssize_t int
44 install_plugins_result_handler(GstInstallPluginsReturn result, gpointer user_data)
46 PyGILState_STATE state;
47 PyObject *callback, *args;
48 PyObject *py_user_data;
53 if (user_data == NULL)
56 state = pyg_gil_state_ensure();
58 py_user_data = (PyObject*) user_data;
59 py_result = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, result);
61 callback = PyTuple_GetItem(py_user_data, 0);
62 args = Py_BuildValue("(N)", py_result);
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));
71 ret = PyObject_CallObject(callback, args);
77 pyg_gil_state_release(state);
81 modulename gst.pbutils
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
99 override gst_install_plugins_sync kwargs
101 _wrap_gst_install_plugins_sync(PyGObject *self, PyObject *args, PyObject *kwargs)
103 static char *kwlist[] = { "details", "context", NULL };
105 GstInstallPluginsContext *ctx;
106 GstInstallPluginsReturn ret;
110 PyObject *py_details;
113 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:install_plugins_sync",
114 kwlist, &py_details, &py_ctx))
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");
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);
129 details = g_new0(gchar*, len+1);
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);
136 if (!PyString_Check(py_str)) {
137 PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
139 Py_DECREF(py_details);
143 if (!(str = PyString_AsString(py_str))) {
145 Py_DECREF(py_details);
149 details[i] = g_strdup(str);
153 ctx = (GstInstallPluginsContext *) pyg_boxed_get(py_ctx, GstInstallPluginsContext);
155 pyg_begin_allow_threads;
156 ret = gst_install_plugins_sync(details, ctx);
157 pyg_end_allow_threads;
161 py_ret = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, ret);
165 override gst_install_plugins_async args
167 _wrap_gst_install_plugins_async(PyGObject *self, PyObject *args)
169 PyObject *py_ctx, *py_ret, *py_details, *callback, *cbargs, *data;
170 GstInstallPluginsContext *ctx;
171 GstInstallPluginsReturn ret;
176 if (PyTuple_Size(args) < 3) {
177 PyErr_SetString(PyExc_TypeError, "install_plugins_async requires at least 3 arguments");
181 py_ctx = PySequence_GetItem(args, 1);
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");
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");
193 Py_DECREF(py_details);
197 len = PySequence_Size(py_details);
198 details = g_new0(gchar*, len+1);
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);
205 if (!PyString_Check(py_str)) {
206 PyErr_SetString(PyExc_TypeError, "Details need to be a non-empty list or tuple of strings");
209 Py_DECREF(py_details);
213 if (!(str = PyString_AsString(py_str))) {
216 Py_DECREF(py_details);
220 details[i] = g_strdup(str);
224 callback = PySequence_GetItem(args, 2);
225 if (!PyCallable_Check(callback)) {
226 PyErr_SetString(PyExc_TypeError, "callback is not callable");
229 Py_DECREF(py_details);
233 if (!(cbargs = PySequence_GetSlice(args, 3, PyTuple_Size(args)))) {
236 Py_DECREF(py_details);
240 if (!(data = Py_BuildValue("(ON)", callback, cbargs))) {
241 Py_DECREF(py_details);
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,
252 pyg_end_allow_threads;
256 py_ret = pyg_enum_from_gtype(GST_TYPE_INSTALL_PLUGINS_RETURN, ret);
260 override gst_plugins_base_version noargs
262 _wrap_gst_plugins_base_version (PyObject *self)
264 guint major, minor, micro, nano;
267 gst_plugins_base_version (&major, &minor, µ, &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));
277 override gst_discoverer_info_get_stream_list noargs
279 _wrap_gst_discoverer_info_get_stream_list(PyGstMiniObject * self)
284 res = gst_discoverer_info_get_stream_list(GST_DISCOVERER_INFO (self->obj));
286 pyres = PyList_New(0);
287 for (tmp = res; tmp; tmp = tmp->next) {
288 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
291 gst_discoverer_stream_info_list_free(res);
295 override gst_discoverer_info_get_streams kwargs
297 _wrap_gst_discoverer_info_get_streams(PyGstMiniObject * self, PyObject *args, PyObject *kwargs)
299 static char *kwlist[] = { "type", NULL };
301 PyObject *pyres, *py_type;
304 if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:GstDiscovererInfo.get_streams", kwlist, &py_type))
306 if ((ftype = pyg_type_from_object(py_type)) == 0)
308 res = gst_discoverer_info_get_streams(GST_DISCOVERER_INFO (self->obj), ftype);
310 pyres = PyList_New(0);
311 for (tmp = res; tmp; tmp = tmp->next) {
312 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
315 gst_discoverer_stream_info_list_free(res);
319 override gst_discoverer_info_get_audio_streams noargs
321 _wrap_gst_discoverer_info_get_audio_streams(PyGstMiniObject * self)
326 res = gst_discoverer_info_get_audio_streams(GST_DISCOVERER_INFO (self->obj));
328 pyres = PyList_New(0);
329 for (tmp = res; tmp; tmp = tmp->next) {
330 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
333 gst_discoverer_stream_info_list_free(res);
337 override gst_discoverer_info_get_video_streams noargs
339 _wrap_gst_discoverer_info_get_video_streams(PyGstMiniObject * self)
344 res = gst_discoverer_info_get_video_streams(GST_DISCOVERER_INFO (self->obj));
346 pyres = PyList_New(0);
347 for (tmp = res; tmp; tmp = tmp->next) {
348 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
351 gst_discoverer_stream_info_list_free(res);
355 override gst_discoverer_info_get_container_streams noargs
357 _wrap_gst_discoverer_info_get_container_streams(PyGstMiniObject * self)
362 res = gst_discoverer_info_get_container_streams(GST_DISCOVERER_INFO (self->obj));
364 pyres = PyList_New(0);
365 for (tmp = res; tmp; tmp = tmp->next) {
366 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
369 gst_discoverer_stream_info_list_free(res);
373 override gst_discoverer_container_info_get_streams noargs
375 _wrap_gst_discoverer_container_info_get_streams(PyGstMiniObject * self)
380 res = gst_discoverer_container_info_get_streams(GST_DISCOVERER_CONTAINER_INFO (self->obj));
382 pyres = PyList_New(0);
383 for (tmp = res; tmp; tmp = tmp->next) {
384 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
387 gst_discoverer_stream_info_list_free(res);
391 override gst_encoding_container_profile_get_profiles noargs
393 _wrap_gst_encoding_container_profile_get_profiles(PyGstMiniObject * self)
398 res = (GList*) gst_encoding_container_profile_get_profiles(GST_ENCODING_CONTAINER_PROFILE (self->obj));
400 pyres = PyList_New(0);
401 for (tmp = res; tmp; tmp = tmp->next) {
402 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
409 override gst_encoding_target_get_profiles noargs
411 _wrap_gst_encoding_target_get_profiles(PyGstMiniObject * self)
416 res = (GList*) gst_encoding_target_get_profiles(GST_ENCODING_TARGET (self->obj));
418 pyres = PyList_New(0);
419 for (tmp = res; tmp; tmp = tmp->next) {
420 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
427 override gst_encoding_list_all_targets kwargs
429 _wrap_gst_encoding_list_all_targets(PyGstMiniObject * self, PyObject *args, PyObject *kwargs)
431 static char *kwlist[] = { "categoryname", NULL };
433 const gchar *categoryname = NULL;
436 if (!PyArg_ParseTupleAndKeywords(args, kwargs,"!s:GstDiscovererInfo.get_streams", kwlist, &categoryname))
438 res = (GList*) gst_encoding_list_all_targets(categoryname);
440 pyres = PyList_New(0);
441 for (tmp = res; tmp; tmp = tmp->next) {
442 PyList_Append(pyres, pygstminiobject_new((GstMiniObject*) tmp->data));
449 override gst_encoding_list_available_categories noargs
451 _wrap_gst_encoding_list_available_categories(PyGstMiniObject * self)
456 res = (GList*) gst_encoding_list_available_categories();
458 pyres = PyList_New(0);
459 for (tmp = res; tmp; tmp = tmp->next) {
460 PyList_Append(pyres, PyString_FromString((const gchar*) tmp->data));
468 override gst_encoding_target_new kwargs
470 _wrap_gst_encoding_target_new(PyGstMiniObject *self, PyObject *args, PyObject *kwargs)
472 static char *kwlist[] = { "name", "category", "description", NULL };
473 char *name, *description, *category;
475 if (!PyArg_ParseTupleAndKeywords(args, kwargs,"sss:GstEncodingContainerProfile.__init__", kwlist, &name, &category, &description))
478 self->obj = (GstMiniObject *)gst_encoding_target_new(name, category, description, NULL);
481 PyErr_SetString(PyExc_RuntimeError, "could not create GstEncodingTarget miniobject");
484 pygstminiobject_register_wrapper((PyObject *)self);