diff options
author | Alessandro Decina <alessandro.d@gmail.com> | 2010-07-26 19:29:53 +0200 |
---|---|---|
committer | Alessandro Decina <alessandro.d@gmail.com> | 2010-07-26 19:42:34 +0200 |
commit | e20157bda2efe24f0847d38dd5810428347169b2 (patch) | |
tree | d3ea40009be1562e3cb9fce762f987781c12ddfb | |
parent | 04c94b91007e2a175684a8ea7f249d381881c1dd (diff) |
gst: implement getters and setters for GST_TYPE_FRACTION properties. Fixes #624882.
-rw-r--r-- | gst/gstmodule.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/gst/gstmodule.c b/gst/gstmodule.c index 8c637c6..cce52d3 100644 --- a/gst/gstmodule.c +++ b/gst/gstmodule.c @@ -88,6 +88,51 @@ sink_gstobject (GObject * object) } } +static PyObject * +pygst_fraction_from_value (const GValue * value) +{ + PyObject *module, *dict, *fraction_type, *args, *fraction; + gint numerator, denominator; + + numerator = gst_value_get_fraction_numerator (value); + denominator = gst_value_get_fraction_denominator (value); + + module = PyImport_ImportModule ("gst"); + dict = PyModule_GetDict (module); + fraction_type = PyMapping_GetItemString (dict, "Fraction"); + + args = Py_BuildValue ("(ii)", numerator, denominator); + fraction = PyObject_Call (fraction_type, args, NULL); + Py_DECREF (args); + Py_DECREF (fraction_type); + Py_DECREF (module); + + return fraction; +} + +static int +pygst_fraction_to_value (GValue * value, PyObject * object) +{ + PyObject *numerator, *denominator; + + numerator = PyObject_GetAttrString (object, "num"); + if (numerator == NULL) + goto fail; + + denominator = PyObject_GetAttrString (object, "denom"); + if (denominator == NULL) + goto fail; + + gst_value_set_fraction (value, + PyLong_AsLong (numerator), PyLong_AsLong (denominator)); + +out: + return 0; + +fail: + return -1; +} + DL_EXPORT (void) init_gst (void) { @@ -332,6 +377,9 @@ init_gst (void) PyModule_AddStringConstant (m, "STREAM_ERROR", (gchar *) g_quark_to_string (GST_STREAM_ERROR)); + pyg_register_gtype_custom (GST_TYPE_FRACTION, + pygst_fraction_from_value, pygst_fraction_to_value); + if (PyErr_Occurred ()) { Py_FatalError ("can't initialize module gst"); } |