From 835f29e2bb7496e3d87438bcc0755d0a49a38cb5 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 28 Jun 2005 16:13:53 +0000 Subject: [PATCH] codegen/codegen.py: let's not forget to wrap the MiniObject :) Original commit message from CVS: * codegen/codegen.py: (GstMiniObjectWrapper.constructor_tmpl): let's not forget to wrap the MiniObject :) * gst/gst-types.defs: * gst/gst.defs: Always keep up to date with the core * gst/gstelement.override: override for gst_element_query_position * gst/pygstminiobject.c: * gst/pygstminiobject.h: * gst/gst.override: PyGstMiniObject now properly wrap GstMiniObject and are referenced in a global hash table --- ChangeLog | 18 +++++++++ codegen/codegen.py | 1 + gst/gst-types.defs | 2 +- gst/gst.defs | 85 ++++++++++++++++++++++++++++++----------- gst/gst.override | 1 + gst/gstelement.override | 33 ++++++++++++++++ gst/pygstminiobject.c | 80 +++++++++++++++++++++++++++++--------- gst/pygstminiobject.h | 24 +++--------- 8 files changed, 183 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index b9ff1715e2..ec6f955777 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-06-28 Edward Hervey + + * codegen/codegen.py: (GstMiniObjectWrapper.constructor_tmpl): + let's not forget to wrap the MiniObject :) + + * gst/gst-types.defs: + * gst/gst.defs: + Always keep up to date with the core + + * gst/gstelement.override: + override for gst_element_query_position + + * gst/pygstminiobject.c: + * gst/pygstminiobject.h: + * gst/gst.override: + PyGstMiniObject now properly wrap GstMiniObject and are referenced in a + global hash table + 2005-06-26 Edward Hervey * codegen/argtypes.py: diff --git a/codegen/codegen.py b/codegen/codegen.py index cbc3680997..3da0e42acf 100644 --- a/codegen/codegen.py +++ b/codegen/codegen.py @@ -832,6 +832,7 @@ class GstMiniObjectWrapper(Wrapper): ' return -1;\n' \ ' }\n' \ '%(aftercreate)s' \ + ' pygstminiobject_register_wrapper((PyObject *)self);\n' \ ' return 0;\n' \ '}\n\n' method_tmpl = \ diff --git a/gst/gst-types.defs b/gst/gst-types.defs index d47a50dde5..be789369ae 100644 --- a/gst/gst-types.defs +++ b/gst/gst-types.defs @@ -673,7 +673,7 @@ '("ok" "GST_FLOW_OK") '("resend" "GST_FLOW_RESEND") '("error" "GST_FLOW_ERROR") - '("not-connected" "GST_FLOW_NOT_CONNECTED") + '("not-linked" "GST_FLOW_NOT_LINKED") '("not-negotiated" "GST_FLOW_NOT_NEGOTIATED") '("wrong-state" "GST_FLOW_WRONG_STATE") '("unexpected" "GST_FLOW_UNEXPECTED") diff --git a/gst/gst.defs b/gst/gst.defs index 2c9a0f3bd0..0d175c91ec 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -1031,6 +1031,18 @@ (return-type "GstIterator*") ) +(define-method iterate_src_pads + (of-object "GstElement") + (c-name "gst_element_iterate_src_pads") + (return-type "GstIterator*") +) + +(define-method iterate_sink_pads + (of-object "GstElement") + (c-name "gst_element_iterate_sink_pads") + (return-type "GstIterator*") +) + (define-method send_event (of-object "GstElement") (c-name "gst_element_send_event") @@ -2646,22 +2658,28 @@ ) ) -(define-method ref - (of-object "GstObject") +(define-function object_ref (c-name "gst_object_ref") - (return-type "GstObject*") + (return-type "gpointer") + (parameters + '("gpointer" "object") + ) ) -(define-method unref - (of-object "GstObject") +(define-function object_unref (c-name "gst_object_unref") - (return-type "GstObject*") + (return-type "none") + (parameters + '("gpointer" "object") + ) ) -(define-method sink - (of-object "GstObject") +(define-function object_sink (c-name "gst_object_sink") (return-type "none") + (parameters + '("gpointer" "object") + ) ) (define-function object_replace @@ -2772,16 +2790,7 @@ (c-name "gst_pad_set_active") (return-type "gboolean") (parameters - '("GstActivateMode" "mode") - ) -) - -(define-method peer_set_active - (of-object "GstPad") - (c-name "gst_pad_peer_set_active") - (return-type "gboolean") - (parameters - '("GstActivateMode" "mode") + '("gboolean" "active") ) ) @@ -2791,6 +2800,24 @@ (return-type "gboolean") ) +(define-method activate_pull + (of-object "GstPad") + (c-name "gst_pad_activate_pull") + (return-type "gboolean") + (parameters + '("gboolean" "active") + ) +) + +(define-method activate_push + (of-object "GstPad") + (c-name "gst_pad_activate_push") + (return-type "gboolean") + (parameters + '("gboolean" "active") + ) +) + (define-method set_blocked (of-object "GstPad") (c-name "gst_pad_set_blocked") @@ -2868,12 +2895,21 @@ ) ) -(define-method set_loop_function +(define-method set_activatepull_function (of-object "GstPad") - (c-name "gst_pad_set_loop_function") + (c-name "gst_pad_set_activatepull_function") (return-type "none") (parameters - '("GstPadLoopFunction" "loop") + '("GstPadActivateModeFunction" "activatepull") + ) +) + +(define-method set_activatepush_function + (of-object "GstPad") + (c-name "gst_pad_set_activatepush_function") + (return-type "none") + (parameters + '("GstPadActivateModeFunction" "activatepush") ) ) @@ -3322,7 +3358,7 @@ (is-constructor-of "GstPipeline") (return-type "GstElement*") (parameters - '("const-gchar*" "name") + '("const-gchar*" "name" (null-ok) (default "NULL")) ) ) @@ -5257,6 +5293,11 @@ (return-type "none") ) +(define-function gst_alloc_trace_print_live + (c-name "gst_alloc_trace_print_live") + (return-type "none") +) + (define-function alloc_trace_set_flags_all (c-name "gst_alloc_trace_set_flags_all") (return-type "none") diff --git a/gst/gst.override b/gst/gst.override index 1abdf129d9..2125f065fb 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -232,6 +232,7 @@ init #endif if (!pygst_value_init()) return; + pygst_miniobject_init(); } %% modulename gst diff --git a/gst/gstelement.override b/gst/gstelement.override index 2aee2a9003..5c867f96d6 100644 --- a/gst/gstelement.override +++ b/gst/gstelement.override @@ -92,6 +92,7 @@ _wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs) GstElementState state; GstElementStateReturn ret; + /* Only returns the state for the time being */ ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, NULL, NULL); if (!ret) { PyErr_SetString(PyExc_RuntimeError, "conversion could not be performed"); @@ -409,3 +410,35 @@ _wrap_gst_element_factory_get_pad_templates(PyGObject *self) return list; } +%% +override gst_element_query_position args +static PyObject * +_wrap_gst_element_query_position (PyGObject *self, PyObject *args) +{ + gint64 cur, end; + gint format; + PyObject *pformat; + PyObject *ret; + int i; + + pformat = (PyObject*)PyTuple_GetItem(args, 0); + if (pyg_enum_get_value (GST_TYPE_FORMAT, pformat, &format)) { + PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat"); + return NULL; + } + + ret = PyList_New(0); + if ((gst_element_query_position(GST_ELEMENT (self->obj), (GstFormat*) &format, &cur, &end))) { + PyList_Append(ret, PyLong_FromLong(cur)); + PyList_Append(ret, PyLong_FromLong(end)); + PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format )); + } else { + for (i = 0; i < 2; i++) { + Py_INCREF(Py_None); + PyList_Append(ret, Py_None); + } + PyList_Append(ret, pformat); + } + + return ret; +} diff --git a/gst/pygstminiobject.c b/gst/pygstminiobject.c index 05a17ccd07..22745218d5 100644 --- a/gst/pygstminiobject.c +++ b/gst/pygstminiobject.c @@ -31,6 +31,13 @@ static void pygstminiobject_dealloc(PyGstMiniObject *self); static int pygstminiobject_traverse(PyGstMiniObject *self, visitproc visit, void *arg); static int pygstminiobject_clear(PyGstMiniObject *self); +static GHashTable *miniobjs; + +void +pygst_miniobject_init() +{ + miniobjs = g_hash_table_new (NULL, NULL); +} /** * pygstminiobject_lookup_class: @@ -111,6 +118,31 @@ pygstminiobject_register_class(PyObject *dict, const gchar *type_name, PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type); } +/** + * pygstminiobject_register_wrapper: + * @self: the wrapper instance + * + * In the constructor of PyGTK wrappers, this function should be + * called after setting the obj member. It will tie the wrapper + * instance to the Gstminiobject so that the same wrapper instance will + * always be used for this Gstminiobject instance. It will also sink any + * floating references on the Gstminiobject. + */ +void +pygstminiobject_register_wrapper(PyObject *self) +{ + GstMiniObject *obj = ((PyGstMiniObject *)self)->obj; + + if (!pygstminiobject_wrapper_key) + pygstminiobject_wrapper_key=g_quark_from_static_string(pygstminiobject_wrapper_id); + + Py_INCREF(self); + g_hash_table_insert (miniobjs, (gpointer) obj, (gpointer) self); +/* gst_mini_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */ +/* pyg_destroy_notify); */ +} + + /** * pygstminiobject_new: * @obj: a GstMiniObject instance. @@ -135,25 +167,33 @@ pygstminiobject_new(GstMiniObject *obj) return Py_None; } - /* create wrapper */ - PyTypeObject *tp = pygstminiobject_lookup_class(G_OBJECT_TYPE(obj)); - /* need to bump type refcount if created with - pygstminiobject_new_with_interfaces(). fixes bug #141042 */ - if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE) - Py_INCREF(tp); - self = PyObject_GC_New(PyGstMiniObject, tp); - if (self == NULL) - return NULL; - self->obj = gst_mini_object_ref(obj); - - self->inst_dict = NULL; - self->weakreflist = NULL; - /* save wrapper pointer so we can access it later */ - Py_INCREF(self); - /* g_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */ -/* pyg_destroy_notify); */ - - PyObject_GC_Track((PyObject *)self); + /* we already have a wrapper for this object -- return it. */ + self = (PyGstMiniObject *)g_hash_table_lookup (miniobjs, (gpointer) obj); +/* self = (PyGstMiniObject *)gst_mini_object_get_qdata(obj, pygstminiobject_wrapper_key); */ + if (self != NULL) { + Py_INCREF(self); + } else { + /* create wrapper */ + PyTypeObject *tp = pygstminiobject_lookup_class(G_OBJECT_TYPE(obj)); + /* need to bump type refcount if created with + pygstminiobject_new_with_interfaces(). fixes bug #141042 */ + if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE) + Py_INCREF(tp); + self = PyObject_GC_New(PyGstMiniObject, tp); + if (self == NULL) + return NULL; + self->obj = gst_mini_object_make_writable(obj); + + self->inst_dict = NULL; + self->weakreflist = NULL; + /* save wrapper pointer so we can access it later */ + Py_INCREF(self); + g_hash_table_insert (miniobjs, (gpointer) obj, (gpointer) self); +/* gst_mini_object_set_qdata_full(obj, pygstminiobject_wrapper_key, self, */ +/* pyg_destroy_notify); */ + + PyObject_GC_Track((PyObject *)self); + } return (PyObject *)self; } @@ -177,6 +217,7 @@ pygstminiobject_dealloc(PyGstMiniObject *self) /* the following causes problems with subclassed types */ /* self->ob_type->tp_free((PyObject *)self); */ + g_hash_table_remove (miniobjs, (gpointer) self); PyObject_GC_Del(self); } @@ -242,6 +283,7 @@ pygstminiobject_clear(PyGstMiniObject *self) static void pygstminiobject_free(PyObject *op) { + g_hash_table_remove (miniobjs, (gpointer) op); PyObject_GC_Del(op); } diff --git a/gst/pygstminiobject.h b/gst/pygstminiobject.h index efabbd98bf..4e97ce573e 100644 --- a/gst/pygstminiobject.h +++ b/gst/pygstminiobject.h @@ -36,6 +36,11 @@ void pygstminiobject_register_class(PyObject *dict, const gchar *type_name, GType gtype, PyTypeObject *type, PyObject *bases); +void +pygstminiobject_register_wrapper(PyObject *self); + +void +pygst_miniobject_init(); #ifndef _INSIDE_PYGSTMINIOBJECT_ @@ -43,25 +48,6 @@ struct _PyGObject_Functions *_PyGObject_API; extern PyTypeObject PyGstMiniObject_Type; -#define init_pygstminiobject() { \ - PyObject *gstminiobject = PyImport_ImportModule("gstminiobject"); \ - if (gstminiobject != NULL) { \ - PyObject *mdict = PyModule_GetDict(gstminiobject); \ - PyObject *cobject = PyDict_GetItemString(mdict, "_PyGstMiniObject_API"); \ - if (PyCObject_Check(cobject)) \ - _PyGstMiniObject_API = (struct _PyGstMiniObject_Functions *)PyCObject_AsVoidPtr(cobject); \ - else { \ - PyErr_SetString(PyExc_RuntimeError, \ - "could not find _PyGstMiniObject_API object"); \ - return; \ - } \ - } else { \ - PyErr_SetString(PyExc_ImportError, \ - "could not import gst"); \ - return; \ - } \ -} - #endif /* !_INSIDE_PYGSTMINIOBJECT_ */ G_END_DECLS