From: Thibault Saunier Date: Sun, 19 Aug 2012 06:25:13 +0000 (-0400) Subject: overrides: Make it possible to add metadatas and PadTemplates to GstElementClass X-Git-Tag: 1.19.3~485^2~227 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5adc55d50f3ba6f1783af5103fb02dcf60a98990;p=platform%2Fupstream%2Fgstreamer.git overrides: Make it possible to add metadatas and PadTemplates to GstElementClass --- diff --git a/gi/overrides/gstmodule.c b/gi/overrides/gstmodule.c index 1f10f51..3060460 100644 --- a/gi/overrides/gstmodule.c +++ b/gi/overrides/gstmodule.c @@ -1,6 +1,7 @@ /* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */ /* gst-python * Copyright (C) 2002 David I. Lehn + * Copyright (C) 2012 Thibault Saunier * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -16,7 +17,7 @@ * 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 */ @@ -31,8 +32,8 @@ #include -#define PYGLIB_MODULE_START(symbol, modname) \ -DL_EXPORT(void) init##symbol(void) \ +#define PYGLIB_MODULE_START(symbol, modname) \ +DL_EXPORT(void) init##symbol(void) \ { \ PyObject *module; \ module = Py_InitModule(modname, symbol##_functions); @@ -92,6 +93,102 @@ gi_gst_register_types (PyObject * d) gi_gst_fraction_from_value, gi_gst_fraction_to_value); } +static int +add_templates (gpointer gclass, PyObject * templates) +{ + gint i, len; + PyGObject *templ; + + if (PyTuple_Check (templates)) { + + len = PyTuple_Size (templates); + if (len == 0) + return 0; + + for (i = 0; i < len; i++) { + templ = (PyGObject *) PyTuple_GetItem (templates, i); + if (GST_IS_PAD_TEMPLATE (pygobject_get (templ)) == FALSE) { + 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; + + } + + if (GST_IS_PAD_TEMPLATE (pygobject_get (templ)) == FALSE) { + PyErr_SetString (PyExc_TypeError, + "entry for __gsttemplates__ must be of type GstPadTemplate"); + return -1; + } + + gst_element_class_add_pad_template (gclass, + GST_PAD_TEMPLATE (pygobject_get (templates))); + + return 0; +} + +static int +_pygst_element_set_metadata (gpointer gclass, PyObject * metadata) +{ + + const gchar *longname, *classification, *description, *author; + + if (!PyTuple_Check (metadata)) { + PyErr_SetString (PyExc_TypeError, "__gstmetadata__ must be a tuple"); + return -1; + } + if (PyTuple_Size (metadata) != 4) { + PyErr_SetString (PyExc_TypeError, + "__gstmetadata__ must contain 4 elements"); + return -1; + } + if (!PyArg_ParseTuple (metadata, "ssss", &longname, &classification, + &description, &author)) { + PyErr_SetString (PyExc_TypeError, "__gstmetadata__ must contain 4 strings"); + return -1; + } + GST_DEBUG + ("setting metadata on gclass %p from __gstmetadata__, longname %s", + gclass, longname); + + gst_element_class_set_metadata (gclass, longname, classification, + description, author); + return 0; +} + +static int +_pygst_element_init (gpointer gclass, PyTypeObject * pyclass) +{ + PyObject *templates, *metadata; + + GST_DEBUG ("_pygst_element_init for gclass %p", gclass); + templates = PyDict_GetItemString (pyclass->tp_dict, "__gsttemplates__"); + if (templates) { + if (add_templates (gclass, templates) != 0) + return -1; + } else { + PyErr_Clear (); + } + metadata = PyDict_GetItemString (pyclass->tp_dict, "__gstmetadata__"); + if (metadata) { + if (_pygst_element_set_metadata (gclass, metadata) != 0) + return -1; + PyDict_DelItemString (pyclass->tp_dict, "__gstmetadata__"); + } else { + PyErr_Clear (); + } + + return 0; +} + static PyMethodDef _gi_gst_functions[] = { {0,} }; PYGLIB_MODULE_START (_gi_gst, "_gi_gst") @@ -102,7 +199,7 @@ PYGLIB_MODULE_START (_gi_gst, "_gi_gst") d = PyModule_GetDict (module); gi_gst_register_types (d); - + pyg_register_class_init (GST_TYPE_ELEMENT, _pygst_element_init); } PYGLIB_MODULE_END;