mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 12:49:40 +00:00
gst: implement getters and setters for GST_TYPE_FRACTION properties. Fixes #624882.
This commit is contained in:
parent
04c94b9100
commit
e20157bda2
1 changed files with 48 additions and 0 deletions
|
@ -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)
|
DL_EXPORT (void)
|
||||||
init_gst (void)
|
init_gst (void)
|
||||||
{
|
{
|
||||||
|
@ -332,6 +377,9 @@ init_gst (void)
|
||||||
PyModule_AddStringConstant (m, "STREAM_ERROR",
|
PyModule_AddStringConstant (m, "STREAM_ERROR",
|
||||||
(gchar *) g_quark_to_string (GST_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 ()) {
|
if (PyErr_Occurred ()) {
|
||||||
Py_FatalError ("can't initialize module gst");
|
Py_FatalError ("can't initialize module gst");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue