2012-08-08 18:00:05 +00:00
|
|
|
/* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */
|
|
|
|
/* gst-python
|
|
|
|
* Copyright (C) 2002 David I. Lehn
|
2012-08-19 06:25:13 +00:00
|
|
|
* Copyright (C) 2012 Thibault Saunier <thibault.saunier@collabora.com>
|
2012-08-08 18:00:05 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2013-11-25 17:01:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2013-12-12 11:20:12 +00:00
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-08-19 06:25:13 +00:00
|
|
|
*
|
2012-08-08 18:00:05 +00:00
|
|
|
* Author: David I. Lehn <dlehn@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
|
|
|
|
#include <Python.h>
|
|
|
|
#include <pygobject.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
2013-09-30 10:45:59 +00:00
|
|
|
#define PYGLIB_MODULE_START(symbol, modname) \
|
|
|
|
static struct PyModuleDef _##symbol##module = { \
|
|
|
|
PyModuleDef_HEAD_INIT, \
|
|
|
|
modname, \
|
|
|
|
NULL, \
|
|
|
|
-1, \
|
|
|
|
symbol##_functions, \
|
|
|
|
NULL, \
|
|
|
|
NULL, \
|
|
|
|
NULL, \
|
|
|
|
NULL \
|
|
|
|
}; \
|
|
|
|
PyMODINIT_FUNC PyInit_##symbol(void); \
|
|
|
|
PyMODINIT_FUNC PyInit_##symbol(void) \
|
|
|
|
{ \
|
|
|
|
PyObject *module; \
|
|
|
|
module = PyModule_Create(&_##symbol##module);
|
|
|
|
#define PYGLIB_MODULE_END return module; }
|
2012-08-08 18:00:05 +00:00
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (python_debug);
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (pygst_debug);
|
|
|
|
#define GST_CAT_DEFAULT pygst_debug
|
|
|
|
|
2012-08-08 18:00:05 +00:00
|
|
|
static PyObject *
|
2019-11-28 13:18:44 +00:00
|
|
|
gi_gst_get_type (const gchar * type_name)
|
2012-08-08 18:00:05 +00:00
|
|
|
{
|
2017-03-27 18:52:24 +00:00
|
|
|
PyObject *module, *dict;
|
2012-08-08 18:00:05 +00:00
|
|
|
|
|
|
|
module = PyImport_ImportModule ("gi.repository.Gst");
|
2013-08-24 01:42:37 +00:00
|
|
|
|
|
|
|
if (module == NULL) {
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Could not get module for gi.repository.Gst");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-08 18:00:05 +00:00
|
|
|
dict = PyModule_GetDict (module);
|
2013-08-24 01:42:37 +00:00
|
|
|
Py_DECREF (module);
|
|
|
|
|
2019-11-19 13:07:09 +00:00
|
|
|
/* For some reason we need this intermediary step */
|
2012-08-08 18:00:05 +00:00
|
|
|
module = PyMapping_GetItemString (dict, "_overrides_module");
|
2013-08-24 01:42:37 +00:00
|
|
|
if (module == NULL) {
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Could not get module for _overrides_module");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-08 18:00:05 +00:00
|
|
|
dict = PyModule_GetDict (module);
|
2017-03-27 18:52:24 +00:00
|
|
|
return PyMapping_GetItemString (dict, type_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
gi_gst_fraction_from_value (const GValue * value)
|
|
|
|
{
|
|
|
|
PyObject *fraction_type, *args, *fraction;
|
|
|
|
gint numerator, denominator;
|
|
|
|
|
|
|
|
numerator = gst_value_get_fraction_numerator (value);
|
|
|
|
denominator = gst_value_get_fraction_denominator (value);
|
|
|
|
|
|
|
|
fraction_type = gi_gst_get_type ("Fraction");
|
2012-08-08 18:00:05 +00:00
|
|
|
|
|
|
|
args = Py_BuildValue ("(ii)", numerator, denominator);
|
|
|
|
fraction = PyObject_Call (fraction_type, args, NULL);
|
|
|
|
Py_DECREF (args);
|
|
|
|
|
|
|
|
return fraction;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_fraction_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
2021-11-17 02:36:10 +00:00
|
|
|
glong numerator, denominator;
|
|
|
|
PyObject *numerator_obj, *denominator_obj, *is_integer;
|
2012-08-08 18:00:05 +00:00
|
|
|
|
2021-11-17 02:36:10 +00:00
|
|
|
numerator_obj = PyObject_GetAttrString (object, "num");
|
|
|
|
if (numerator_obj == NULL)
|
2012-08-08 18:00:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2021-11-17 02:36:10 +00:00
|
|
|
is_integer = PyObject_CallMethod (numerator_obj, "is_integer", NULL);
|
|
|
|
if (is_integer != Py_True) {
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
"numerator %f is not an integer.", PyFloat_AsDouble (numerator_obj));
|
|
|
|
Py_DECREF (is_integer);
|
2012-08-08 18:00:05 +00:00
|
|
|
goto fail;
|
2021-11-17 02:36:10 +00:00
|
|
|
}
|
|
|
|
Py_DECREF (is_integer);
|
|
|
|
|
|
|
|
numerator = PyFloat_AsDouble (numerator_obj);
|
|
|
|
if (numerator < -G_MAXINT || numerator > G_MAXINT) {
|
|
|
|
PyErr_Format (PyExc_ValueError,
|
|
|
|
"numerator %" G_GINT64_FORMAT " is out of bound. [-%d - %d]",
|
|
|
|
numerator, G_MAXINT, G_MAXINT);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
denominator_obj = PyObject_GetAttrString (object, "denom");
|
|
|
|
if (denominator_obj == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
is_integer = PyObject_CallMethod (denominator_obj, "is_integer", NULL);
|
|
|
|
if (is_integer != Py_True) {
|
|
|
|
PyErr_Format (PyExc_TypeError,
|
|
|
|
"denominator %f is not an integer.",
|
|
|
|
PyFloat_AsDouble (denominator_obj));
|
|
|
|
Py_DECREF (is_integer);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
Py_DECREF (is_integer);
|
|
|
|
|
|
|
|
denominator = PyFloat_AsDouble (denominator_obj);
|
|
|
|
if (denominator == 0) {
|
|
|
|
PyErr_SetString (PyExc_ValueError, "denominator is 0.");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (denominator < -G_MAXINT || denominator > G_MAXINT) {
|
|
|
|
PyErr_Format (PyExc_ValueError,
|
|
|
|
"denominator %" G_GINT64_FORMAT " is out of bound. [-%d - %d]",
|
|
|
|
denominator, G_MAXINT, G_MAXINT);
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-08-08 18:00:05 +00:00
|
|
|
|
2021-11-17 02:36:10 +00:00
|
|
|
gst_value_set_fraction (value, numerator, denominator);
|
2012-08-08 18:00:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
static PyObject *
|
|
|
|
gi_gst_int_range_from_value (const GValue * value)
|
|
|
|
{
|
|
|
|
gint min, max, step;
|
2017-07-24 21:06:06 +00:00
|
|
|
PyObject *int_range_type, *int_range, *range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
|
|
|
|
min = gst_value_get_int_range_min (value);
|
|
|
|
max = gst_value_get_int_range_max (value);
|
|
|
|
step = gst_value_get_int_range_step (value);
|
|
|
|
|
2017-07-24 21:06:06 +00:00
|
|
|
int_range_type = gi_gst_get_type ("IntRange");
|
|
|
|
range = PyObject_CallFunction ((PyObject *) & PyRange_Type, "iii",
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
min, max, step);
|
2017-07-24 21:06:06 +00:00
|
|
|
int_range = PyObject_CallFunction (int_range_type, "O", range);
|
|
|
|
|
|
|
|
Py_DECREF (int_range_type);
|
|
|
|
Py_DECREF (range);
|
|
|
|
|
|
|
|
return int_range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_int_range_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
PyObject *range, *min, *max, *step;
|
|
|
|
|
|
|
|
range = PyObject_GetAttrString (object, "range");
|
|
|
|
if (range == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
min = PyObject_GetAttrString (range, "start");
|
|
|
|
if (min == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
max = PyObject_GetAttrString (range, "stop");
|
|
|
|
if (max == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
step = PyObject_GetAttrString (range, "step");
|
|
|
|
if (step == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
gst_value_set_int_range_step (value, PyLong_AsLong (min),
|
|
|
|
PyLong_AsLong (max), PyLong_AsLong (step));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.IntRange");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
gi_gst_int64_range_from_value (const GValue * value)
|
|
|
|
{
|
|
|
|
gint64 min, max, step;
|
2017-07-24 21:06:06 +00:00
|
|
|
PyObject *int64_range_type, *int64_range, *range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
|
|
|
|
min = gst_value_get_int64_range_min (value);
|
|
|
|
max = gst_value_get_int64_range_max (value);
|
|
|
|
step = gst_value_get_int64_range_step (value);
|
|
|
|
|
2017-07-24 21:06:06 +00:00
|
|
|
range = PyObject_CallFunction ((PyObject *) & PyRange_Type, "LLL",
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
min, max, step);
|
2017-07-24 21:06:06 +00:00
|
|
|
int64_range_type = gi_gst_get_type ("Int64Range");
|
|
|
|
int64_range = PyObject_CallFunction (int64_range_type, "O", range);
|
|
|
|
|
|
|
|
Py_DECREF (int64_range_type);
|
|
|
|
Py_DECREF (range);
|
|
|
|
|
|
|
|
return int64_range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_int64_range_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
PyObject *range, *min, *max, *step;
|
|
|
|
|
|
|
|
range = PyObject_GetAttrString (object, "range");
|
|
|
|
if (range == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
min = PyObject_GetAttrString (range, "start");
|
|
|
|
if (min == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
max = PyObject_GetAttrString (range, "stop");
|
|
|
|
if (max == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
step = PyObject_GetAttrString (range, "step");
|
|
|
|
if (step == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
gst_value_set_int64_range_step (value, PyLong_AsLongLong (min),
|
|
|
|
PyLong_AsLongLong (max), PyLong_AsLongLong (step));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.Int64Range");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
gi_gst_double_range_from_value (const GValue * value)
|
|
|
|
{
|
2017-03-27 18:52:24 +00:00
|
|
|
PyObject *double_range_type, *double_range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
gdouble min, max;
|
|
|
|
|
|
|
|
min = gst_value_get_double_range_min (value);
|
|
|
|
max = gst_value_get_double_range_max (value);
|
|
|
|
|
2017-03-27 18:52:24 +00:00
|
|
|
double_range_type = gi_gst_get_type ("DoubleRange");
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
double_range = PyObject_CallFunction (double_range_type, "dd", min, max);
|
|
|
|
|
|
|
|
Py_DECREF (double_range_type);
|
|
|
|
|
|
|
|
return double_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_double_range_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
PyObject *min, *max;
|
|
|
|
|
|
|
|
min = PyObject_GetAttrString (object, "start");
|
|
|
|
if (min == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
max = PyObject_GetAttrString (object, "stop");
|
|
|
|
if (max == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
gst_value_set_double_range (value, PyFloat_AsDouble (min),
|
|
|
|
PyFloat_AsDouble (max));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.DoubleRange");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
gi_gst_fraction_range_from_value (const GValue * value)
|
|
|
|
{
|
2017-03-27 18:52:24 +00:00
|
|
|
PyObject *min, *max, *fraction_range_type, *fraction_range;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
const GValue *fraction;
|
|
|
|
|
|
|
|
fraction = gst_value_get_fraction_range_min (value);
|
|
|
|
min = gi_gst_fraction_from_value (fraction);
|
|
|
|
|
|
|
|
fraction = gst_value_get_fraction_range_max (value);
|
|
|
|
max = gi_gst_fraction_from_value (fraction);
|
|
|
|
|
2017-03-27 18:52:24 +00:00
|
|
|
fraction_range_type = gi_gst_get_type ("FractionRange");
|
|
|
|
fraction_range = PyObject_CallFunction (fraction_range_type, "NN", min, max);
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
|
|
|
|
Py_DECREF (fraction_range_type);
|
|
|
|
|
|
|
|
return fraction_range;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_fraction_range_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
PyObject *min, *max;
|
|
|
|
GValue vmin = G_VALUE_INIT, vmax = G_VALUE_INIT;
|
|
|
|
|
|
|
|
min = PyObject_GetAttrString (object, "start");
|
|
|
|
if (min == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
max = PyObject_GetAttrString (object, "stop");
|
|
|
|
if (max == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
g_value_init (&vmin, GST_TYPE_FRACTION);
|
|
|
|
if (gi_gst_fraction_to_value (&vmin, min) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
g_value_init (&vmax, GST_TYPE_FRACTION);
|
|
|
|
if (gi_gst_fraction_to_value (&vmax, max) < 0) {
|
|
|
|
g_value_unset (&vmin);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_value_set_fraction_range (value, &vmin, &vmax);
|
|
|
|
g_value_unset (&vmin);
|
|
|
|
g_value_unset (&vmax);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.FractionRange");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
gi_gst_array_from_value (const GValue * value)
|
|
|
|
{
|
2017-03-27 18:59:24 +00:00
|
|
|
PyObject *list, *array_type, *array;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
list = PyList_New (gst_value_array_get_size (value));
|
|
|
|
|
|
|
|
for (i = 0; i < gst_value_array_get_size (value); i++) {
|
|
|
|
const GValue *v = gst_value_array_get_value (value, i);
|
|
|
|
PyList_SET_ITEM (list, i, pyg_value_as_pyobject (v, TRUE));
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:59:24 +00:00
|
|
|
array_type = gi_gst_get_type ("ValueArray");
|
|
|
|
array = PyObject_CallFunction (array_type, "N", list);
|
|
|
|
|
|
|
|
Py_DECREF (array_type);
|
|
|
|
|
|
|
|
return array;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_array_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
gint len, i;
|
|
|
|
|
|
|
|
len = PySequence_Length (object);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GValue v = G_VALUE_INIT;
|
|
|
|
GType type;
|
|
|
|
PyObject *item;
|
|
|
|
|
|
|
|
item = PySequence_GetItem (object, i);
|
|
|
|
|
|
|
|
if (item == Py_None)
|
|
|
|
type = G_TYPE_POINTER;
|
|
|
|
else
|
|
|
|
type = pyg_type_from_object ((PyObject *) Py_TYPE (item));
|
|
|
|
|
|
|
|
if (type == G_TYPE_NONE) {
|
|
|
|
Py_DECREF (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_init (&v, type);
|
|
|
|
|
|
|
|
if (pyg_value_from_pyobject (&v, item) < 0) {
|
|
|
|
Py_DECREF (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_value_array_append_and_take_value (value, &v);
|
|
|
|
Py_DECREF (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.ValueArray");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-25 20:17:54 +00:00
|
|
|
static PyObject *
|
|
|
|
gi_gst_bitmask_from_value (const GValue * value)
|
|
|
|
{
|
|
|
|
PyObject *val, *bitmask_type;
|
|
|
|
|
|
|
|
bitmask_type = gi_gst_get_type ("Bitmask");
|
|
|
|
val = PyObject_CallFunction (bitmask_type, "L",
|
|
|
|
gst_value_get_bitmask (value));
|
|
|
|
Py_DECREF (bitmask_type);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_bitmask_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
PyObject *v = PyObject_GetAttrString (object, "v");
|
|
|
|
if (v == NULL)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
gst_value_set_bitmask (value, PyLong_AsLong (v));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError, "Object is not compatible with Gst.Bitmask");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
static PyObject *
|
|
|
|
gi_gst_list_from_value (const GValue * value)
|
|
|
|
{
|
2017-03-27 18:59:24 +00:00
|
|
|
PyObject *list, *value_list_type, *value_list;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
list = PyList_New (gst_value_list_get_size (value));
|
|
|
|
|
|
|
|
for (i = 0; i < gst_value_list_get_size (value); i++) {
|
|
|
|
const GValue *v = gst_value_list_get_value (value, i);
|
|
|
|
PyList_SET_ITEM (list, i, pyg_value_as_pyobject (v, TRUE));
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:59:24 +00:00
|
|
|
value_list_type = gi_gst_get_type ("ValueList");
|
|
|
|
value_list = PyObject_CallFunction (value_list_type, "N", list);
|
|
|
|
|
|
|
|
Py_DECREF (value_list_type);
|
|
|
|
|
|
|
|
return value_list;
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gi_gst_list_to_value (GValue * value, PyObject * object)
|
|
|
|
{
|
|
|
|
gint len, i;
|
|
|
|
|
|
|
|
len = PySequence_Length (object);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GValue v = G_VALUE_INIT;
|
|
|
|
GType type;
|
|
|
|
PyObject *item;
|
|
|
|
|
|
|
|
item = PySequence_GetItem (object, i);
|
|
|
|
|
|
|
|
if (item == Py_None)
|
|
|
|
type = G_TYPE_POINTER;
|
|
|
|
else
|
|
|
|
type = pyg_type_from_object ((PyObject *) Py_TYPE (item));
|
|
|
|
|
|
|
|
if (type == G_TYPE_NONE) {
|
|
|
|
Py_DECREF (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_value_init (&v, type);
|
|
|
|
|
|
|
|
if (pyg_value_from_pyobject (&v, item) < 0) {
|
|
|
|
Py_DECREF (item);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_value_list_append_and_take_value (value, &v);
|
|
|
|
Py_DECREF (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
PyErr_SetString (PyExc_KeyError,
|
|
|
|
"Object is not compatible with Gst.ValueList");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-28 13:18:44 +00:00
|
|
|
static void
|
2012-08-08 18:00:05 +00:00
|
|
|
gi_gst_register_types (PyObject * d)
|
|
|
|
{
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_FRACTION,
|
|
|
|
gi_gst_fraction_from_value, gi_gst_fraction_to_value);
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
pyg_register_gtype_custom (GST_TYPE_INT_RANGE,
|
|
|
|
gi_gst_int_range_from_value, gi_gst_int_range_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_INT64_RANGE,
|
|
|
|
gi_gst_int64_range_from_value, gi_gst_int64_range_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_DOUBLE_RANGE,
|
|
|
|
gi_gst_double_range_from_value, gi_gst_double_range_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_FRACTION_RANGE,
|
|
|
|
gi_gst_fraction_range_from_value, gi_gst_fraction_range_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_ARRAY,
|
|
|
|
gi_gst_array_from_value, gi_gst_array_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_LIST,
|
|
|
|
gi_gst_list_from_value, gi_gst_list_to_value);
|
|
|
|
#if 0
|
|
|
|
/* TODO */
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_DATE_TIME,
|
|
|
|
gi_gst_date_time_from_value, gi_gst_date_time_to_value);
|
|
|
|
pyg_register_gtype_custom (GST_TYPE_FLAG_SET,
|
|
|
|
gi_gst_flag_set_from_value, gi_gst_flag_set_to_value);
|
2017-07-25 20:17:54 +00:00
|
|
|
#endif
|
overrides: Add more GstValue overrides
This patch adds overrides to support IntRange, Int64Range, DoubleRange,
FractionRange, Array and List. For integer ranges, it maps this
to python 'range'. Gst.IntRange() and Gst.Int64Range() are simple cast
to let the underlying code know which GType to use. To set such range in
python you will do:
structure["range"] = Gst.IntRange(range(0,10,2)))
Same for the 64 bit variant. And when you do:
r = structure.get_value("range")
A range will be returned directly, without the wrapper. For DoubleRange
and FractionRange, there is no native support in python. So the usage
will be:
structure["range"] = Gst.DoubleRange(0,10.0)
structure["range"] =
Gst.FractionRange(Gst.Fraction(1/30), Gst.Fraction(1/5)
When getting this value, Gst.DoubleRange and Gst.FractionRange class are
returned. They both have start/stop members. The naming was taken from
range type.
For Array and List, both uses the native list type, though they can be
constructed from any python sequence. So again, the class is just like
a cast, to let it pick the right GType and python list are being
returned.
structure["list"] = Gst.ValueList([1,2,3,4])
structure["array"] = Gst.ValueArray([1,2,3,4)
Using string and tuple could also work. Since Gst.ValueList/Array are
sequence, you can convert one to the other with:
list = Gst.ValueList([1,2,3,4])
array = Gst.ValueArray (list)
https://bugzilla.gnome.org/show_bug.cgi?id=753754
2017-03-23 16:21:32 +00:00
|
|
|
pyg_register_gtype_custom (GST_TYPE_BITMASK,
|
|
|
|
gi_gst_bitmask_from_value, gi_gst_bitmask_to_value);
|
2012-08-08 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
2012-08-19 06:25:13 +00:00
|
|
|
static int
|
|
|
|
add_templates (gpointer gclass, PyObject * templates)
|
|
|
|
{
|
|
|
|
if (PyTuple_Check (templates)) {
|
2012-08-29 17:05:37 +00:00
|
|
|
gint i, len;
|
|
|
|
PyGObject *templ;
|
2012-08-19 06:25:13 +00:00
|
|
|
|
|
|
|
len = PyTuple_Size (templates);
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
templ = (PyGObject *) PyTuple_GetItem (templates, i);
|
2016-02-19 16:13:57 +00:00
|
|
|
|
|
|
|
if (!pygobject_check (templ, &PyGObject_Type)) {
|
|
|
|
PyObject *repr = PyObject_Repr ((PyObject *) templ);
|
|
|
|
#if PY_VERSION_HEX < 0x03000000
|
|
|
|
PyErr_Format (PyExc_TypeError, "expected GObject but got %s",
|
|
|
|
PyString_AsString (repr));
|
|
|
|
#else
|
|
|
|
PyErr_Format (PyExc_TypeError, "expected GObject but got %s",
|
|
|
|
_PyUnicode_AsString (repr));
|
|
|
|
#endif
|
|
|
|
Py_DECREF (repr);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
} else if (!GST_IS_PAD_TEMPLATE (pygobject_get (templ))) {
|
|
|
|
gchar *error =
|
|
|
|
g_strdup_printf
|
|
|
|
("entries for __gsttemplates__ must be of type GstPadTemplate (%s)",
|
|
|
|
G_OBJECT_TYPE_NAME (pygobject_get (templ)));
|
|
|
|
PyErr_SetString (PyExc_TypeError, error);
|
|
|
|
g_free (error);
|
|
|
|
|
2012-08-19 06:25:13 +00:00
|
|
|
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;
|
|
|
|
|
2016-02-15 22:26:06 +00:00
|
|
|
} else if (!pygobject_check (templates, &PyGObject_Type) ||
|
|
|
|
GST_IS_PAD_TEMPLATE (pygobject_get (templates)) == FALSE) {
|
2012-08-19 06:25:13 +00:00
|
|
|
PyErr_SetString (PyExc_TypeError,
|
|
|
|
"entry for __gsttemplates__ must be of type GstPadTemplate");
|
2016-02-15 22:26:06 +00:00
|
|
|
|
2012-08-19 06:25:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
#include <frameobject.h>
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
pygst_debug_log (PyObject * pyobject, PyObject * string, GstDebugLevel level,
|
|
|
|
gboolean isgstobject)
|
|
|
|
{
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
gchar *str;
|
|
|
|
gchar *function;
|
|
|
|
gchar *filename;
|
|
|
|
int lineno;
|
|
|
|
PyFrameObject *frame;
|
|
|
|
GObject *object = NULL;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple (string, "s:gst.debug_log", &str)) {
|
|
|
|
PyErr_SetString (PyExc_TypeError, "Need a string!");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame = PyEval_GetFrame ();
|
2013-09-30 10:45:59 +00:00
|
|
|
{
|
2022-02-04 14:53:45 +00:00
|
|
|
#if PY_VERSION_HEX < 0x030a0000
|
|
|
|
PyCodeObject *code = frame->f_code;
|
|
|
|
#else
|
|
|
|
PyCodeObject *code = PyFrame_GetCode (frame);
|
|
|
|
#endif
|
2013-09-30 10:45:59 +00:00
|
|
|
PyObject *utf8;
|
|
|
|
const gchar *utf8_str;
|
|
|
|
|
2022-02-04 14:53:45 +00:00
|
|
|
utf8 = PyUnicode_AsUTF8String (code->co_name);
|
2013-09-30 10:45:59 +00:00
|
|
|
utf8_str = PyBytes_AS_STRING (utf8);
|
|
|
|
|
|
|
|
function = g_strdup (utf8_str);
|
|
|
|
Py_DECREF (utf8);
|
|
|
|
|
2022-02-04 14:53:45 +00:00
|
|
|
utf8 = PyUnicode_AsUTF8String (code->co_filename);
|
2013-09-30 10:45:59 +00:00
|
|
|
utf8_str = PyBytes_AS_STRING (utf8);
|
|
|
|
|
|
|
|
filename = g_strdup (utf8_str);
|
|
|
|
Py_DECREF (utf8);
|
2022-02-04 14:53:45 +00:00
|
|
|
#if PY_VERSION_HEX < 0x030a0000
|
|
|
|
lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti);
|
|
|
|
#else
|
|
|
|
lineno = PyFrame_GetLineNumber (frame);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if PY_VERSION_HEX >= 0x030a0000
|
|
|
|
Py_DECREF (code);
|
|
|
|
#endif
|
2013-09-30 10:45:59 +00:00
|
|
|
}
|
2022-02-04 14:53:45 +00:00
|
|
|
|
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
/* gst_debug_log : category, level, file, function, line, object, format, va_list */
|
|
|
|
if (isgstobject)
|
|
|
|
object = G_OBJECT (pygobject_get (pyobject));
|
|
|
|
gst_debug_log (python_debug, level, filename, function, lineno, object,
|
|
|
|
"%s", str);
|
2013-09-30 10:45:59 +00:00
|
|
|
if (function)
|
|
|
|
g_free (function);
|
2012-09-27 12:41:29 +00:00
|
|
|
if (filename)
|
|
|
|
g_free (filename);
|
|
|
|
#endif
|
|
|
|
Py_INCREF (Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
2015-11-08 10:56:28 +00:00
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_trace (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_TRACE, FALSE);
|
|
|
|
}
|
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_log (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_LOG, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_debug (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_info (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_INFO, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_warning (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_error (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_fixme (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_FIXME, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_wrap_gst_memdump (PyObject * whatever, PyObject * string)
|
|
|
|
{
|
|
|
|
return pygst_debug_log (whatever, string, GST_LEVEL_MEMDUMP, FALSE);
|
|
|
|
}
|
|
|
|
|
2019-04-05 13:58:38 +00:00
|
|
|
static PyObject *
|
|
|
|
_remap (GstMapInfo * mapinfo, PyObject * py_mapinfo)
|
|
|
|
{
|
2020-05-08 20:25:03 +00:00
|
|
|
PyObject *success = NULL;
|
|
|
|
PyObject *py_cmapinfo = NULL;
|
|
|
|
PyObject *py_mview = NULL;
|
|
|
|
PyObject *py_memory = NULL;
|
|
|
|
PyObject *py_flags = NULL;
|
|
|
|
PyObject *py_size = NULL;
|
|
|
|
PyObject *py_maxsize = NULL;
|
|
|
|
|
|
|
|
/* Fill and encapsulating the mapinfo pointer */
|
|
|
|
py_cmapinfo = PyCapsule_New (mapinfo, "__cmapinfo", NULL);
|
|
|
|
if (!py_cmapinfo
|
|
|
|
|| PyObject_SetAttrString (py_mapinfo, "__cmapinfo", py_cmapinfo))
|
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 20:25:03 +00:00
|
|
|
/* Fill and create memoryview with compatible flags */
|
2019-04-05 13:58:38 +00:00
|
|
|
int flags;
|
|
|
|
flags = (mapinfo->flags & GST_MAP_WRITE) ? PyBUF_WRITE : PyBUF_READ;
|
2020-05-08 20:25:03 +00:00
|
|
|
py_mview =
|
2019-04-05 13:58:38 +00:00
|
|
|
PyMemoryView_FromMemory ((char *) mapinfo->data, mapinfo->size, flags);
|
2020-05-08 20:25:03 +00:00
|
|
|
if (!py_mview || PyObject_SetAttrString (py_mapinfo, "data", py_mview))
|
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 20:25:03 +00:00
|
|
|
/* Fill and box GstMemory into a Gst.Memory */
|
2020-06-14 15:34:50 +00:00
|
|
|
py_memory = pyg_boxed_new (_gst_memory_type, mapinfo->memory, FALSE, FALSE);
|
2020-05-08 20:25:03 +00:00
|
|
|
if (!py_memory || PyObject_SetAttrString (py_mapinfo, "memory", py_memory))
|
|
|
|
goto err;
|
|
|
|
|
2019-04-05 13:58:38 +00:00
|
|
|
/* Fill out Gst.MapInfo with values corresponding to GstMapInfo */
|
2020-05-08 20:25:03 +00:00
|
|
|
py_flags = Py_BuildValue ("i", mapinfo->flags);
|
|
|
|
if (!py_flags || PyObject_SetAttrString (py_mapinfo, "flags", py_flags))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
py_size = Py_BuildValue ("i", mapinfo->size);
|
|
|
|
if (!py_size || PyObject_SetAttrString (py_mapinfo, "size", py_size))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
py_maxsize = Py_BuildValue ("i", mapinfo->maxsize);
|
|
|
|
if (!py_maxsize || PyObject_SetAttrString (py_mapinfo, "maxsize", py_maxsize))
|
|
|
|
goto err;
|
|
|
|
|
2020-02-26 12:53:17 +00:00
|
|
|
Py_INCREF (Py_True);
|
2020-05-08 20:25:03 +00:00
|
|
|
success = Py_True;
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
err:
|
|
|
|
GST_ERROR ("Could not map the Gst.MapInfo PyObject with GstMapInfo");
|
|
|
|
if (py_mview)
|
|
|
|
PyObject_CallMethod (py_mview, "release", NULL);
|
|
|
|
|
|
|
|
end:
|
|
|
|
Py_XDECREF (py_cmapinfo);
|
|
|
|
Py_XDECREF (py_mview);
|
|
|
|
Py_XDECREF (py_memory);
|
|
|
|
Py_XDECREF (py_flags);
|
|
|
|
Py_XDECREF (py_size);
|
|
|
|
Py_XDECREF (py_maxsize);
|
|
|
|
return success;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
static PyObject *
|
|
|
|
_unmap (GstMapInfo ** mapinfo, PyObject * py_mapinfo)
|
|
|
|
{
|
|
|
|
PyObject *py_cmapinfo = NULL, *py_mview = NULL, *success = NULL;
|
|
|
|
|
|
|
|
if (!PyObject_HasAttrString (py_mapinfo, "__cmapinfo"))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Extract attributes from Gst.MapInfo */
|
|
|
|
py_mview = PyObject_GetAttrString (py_mapinfo, "data");
|
|
|
|
if (!py_mview)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Call the memoryview.release() Python method, there is no C API */
|
|
|
|
if (!PyObject_CallMethod (py_mview, "release", NULL))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
py_cmapinfo = PyObject_GetAttrString (py_mapinfo, "__cmapinfo");
|
|
|
|
if (!py_cmapinfo)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Reconstruct GstMapInfo from Gst.MapInfo contents */
|
|
|
|
*mapinfo = PyCapsule_GetPointer (py_cmapinfo, "__cmapinfo");
|
|
|
|
if (!*mapinfo)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (PyObject_DelAttrString (py_mapinfo, "__cmapinfo") == -1)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
done:
|
|
|
|
Py_INCREF (Py_True);
|
|
|
|
success = Py_True;
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
err:
|
|
|
|
GST_ERROR ("Could not unmap the GstMapInfo from Gst.MapInfo PyObject");
|
|
|
|
Py_INCREF (Py_False);
|
|
|
|
success = Py_False;
|
|
|
|
|
|
|
|
end:
|
|
|
|
Py_XDECREF (py_mview);
|
|
|
|
Py_XDECREF (py_cmapinfo);
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2019-04-05 13:58:38 +00:00
|
|
|
static PyObject *
|
|
|
|
_gst_memory_override_map (PyObject * self, PyObject * args)
|
|
|
|
{
|
|
|
|
PyTypeObject *gst_memory_type;
|
2019-12-10 19:59:16 +00:00
|
|
|
PyObject *py_memory, *py_mapinfo, *success;
|
2019-04-05 13:58:38 +00:00
|
|
|
int flags;
|
|
|
|
GstMemory *memory;
|
|
|
|
GstMapInfo *mapinfo;
|
|
|
|
_Bool ok;
|
|
|
|
|
|
|
|
/* Look up Gst.memory, Gst.MapInfo, and Gst.MapFlags parameters */
|
|
|
|
gst_memory_type = pygobject_lookup_class (_gst_memory_type);
|
|
|
|
if (!PyArg_ParseTuple (args, "O!Oi", gst_memory_type, &py_memory,
|
|
|
|
&py_mapinfo, &flags))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Since Python does only support r/o or r/w it has to be changed to either */
|
|
|
|
flags = (flags & GST_MAP_WRITE) ? GST_MAP_READWRITE : GST_MAP_READ;
|
|
|
|
|
|
|
|
/* Extract GstMemory from Gst.Memory parameter */
|
|
|
|
memory = GST_MEMORY_CAST (pygobject_get (py_memory));
|
|
|
|
|
|
|
|
/* Map the memory, fill out GstMapInfo */
|
|
|
|
mapinfo = g_new0 (GstMapInfo, 1);
|
|
|
|
ok = gst_memory_map (memory, mapinfo, flags);
|
|
|
|
if (!ok) {
|
|
|
|
g_free (mapinfo);
|
2020-02-26 12:53:17 +00:00
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:59:16 +00:00
|
|
|
success = _remap (mapinfo, py_mapinfo);
|
2019-04-05 13:58:38 +00:00
|
|
|
if (!success) {
|
|
|
|
gst_memory_unmap (memory, mapinfo);
|
|
|
|
g_free (mapinfo);
|
|
|
|
}
|
|
|
|
return success;
|
2020-02-26 12:53:17 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
Py_INCREF (Py_False);
|
|
|
|
return Py_False;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_gst_memory_override_unmap (PyObject * self, PyObject * args)
|
|
|
|
{
|
|
|
|
PyTypeObject *gst_memory_type;
|
2020-05-08 21:01:50 +00:00
|
|
|
PyObject *py_memory, *py_mapinfo, *success;
|
2019-04-05 13:58:38 +00:00
|
|
|
GstMemory *memory;
|
2020-05-08 21:01:50 +00:00
|
|
|
GstMapInfo *mapinfo = NULL;
|
2019-04-05 13:58:38 +00:00
|
|
|
|
|
|
|
/* Look up Gst.Buffer and Gst.Mapinfo parameters */
|
|
|
|
gst_memory_type = pygobject_lookup_class (_gst_memory_type);
|
2019-12-10 14:58:01 +00:00
|
|
|
if (!PyArg_ParseTuple (args, "O!O", gst_memory_type, &py_memory, &py_mapinfo)) {
|
|
|
|
PyErr_BadArgument ();
|
2019-04-05 13:58:38 +00:00
|
|
|
return NULL;
|
2019-12-10 14:58:01 +00:00
|
|
|
}
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
success = _unmap (&mapinfo, py_mapinfo);
|
|
|
|
if (PyBool_Check (success) && mapinfo) {
|
|
|
|
/* Extract GstBuffer from Gst.Buffer parameter */
|
|
|
|
memory = GST_MEMORY_CAST (pygobject_get (py_memory));
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
/* Unmap the buffer, using reconstructed GstMapInfo */
|
|
|
|
gst_memory_unmap (memory, mapinfo);
|
|
|
|
g_free (mapinfo);
|
|
|
|
}
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
return success;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_gst_buffer_override_map_range (PyObject * self, PyObject * args)
|
|
|
|
{
|
|
|
|
PyTypeObject *gst_buffer_type;
|
2019-12-10 19:59:16 +00:00
|
|
|
PyObject *py_buffer, *py_mapinfo, *success;
|
2019-04-05 13:58:38 +00:00
|
|
|
int flags, range;
|
|
|
|
unsigned int idx;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMapInfo *mapinfo;
|
|
|
|
_Bool ok;
|
|
|
|
|
|
|
|
/* Look up Gst.Buffer, Gst.MapInfo, idx, range, and Gst.MapFlags parameters */
|
|
|
|
gst_buffer_type = pygobject_lookup_class (_gst_buffer_type);
|
|
|
|
if (!PyArg_ParseTuple (args, "O!OIii", gst_buffer_type, &py_buffer,
|
|
|
|
&py_mapinfo, &idx, &range, &flags))
|
2020-02-26 12:53:17 +00:00
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
|
|
|
|
/* Since Python does only support r/o or r/w it has to be changed to either */
|
|
|
|
flags = (flags & GST_MAP_WRITE) ? GST_MAP_READWRITE : GST_MAP_READ;
|
|
|
|
|
|
|
|
/* Extract GstBuffer from Gst.Buffer parameter */
|
|
|
|
buffer = GST_BUFFER (pygobject_get (py_buffer));
|
|
|
|
|
|
|
|
/* Map the buffer, fill out GstMapInfo */
|
|
|
|
mapinfo = g_new0 (GstMapInfo, 1);
|
|
|
|
ok = gst_buffer_map_range (buffer, idx, range, mapinfo, flags);
|
|
|
|
if (!ok) {
|
|
|
|
g_free (mapinfo);
|
2020-02-26 12:53:17 +00:00
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:59:16 +00:00
|
|
|
success = _remap (mapinfo, py_mapinfo);
|
2019-04-05 13:58:38 +00:00
|
|
|
if (!success) {
|
|
|
|
gst_buffer_unmap (buffer, mapinfo);
|
|
|
|
g_free (mapinfo);
|
|
|
|
}
|
|
|
|
return success;
|
2020-02-26 12:53:17 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
Py_INCREF (Py_False);
|
|
|
|
return Py_False;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_gst_buffer_override_map (PyObject * self, PyObject * args)
|
|
|
|
{
|
|
|
|
PyTypeObject *gst_buffer_type;
|
2019-12-10 19:59:16 +00:00
|
|
|
PyObject *py_buffer, *py_mapinfo, *success;
|
2019-04-05 13:58:38 +00:00
|
|
|
int flags;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstMapInfo *mapinfo;
|
|
|
|
_Bool ok;
|
|
|
|
|
|
|
|
/* Look up Gst.Buffer, Gst.MapInfo, and Gst.MapFlags parameters */
|
|
|
|
gst_buffer_type = pygobject_lookup_class (_gst_buffer_type);
|
|
|
|
if (!PyArg_ParseTuple (args, "O!Oi", gst_buffer_type, &py_buffer, &py_mapinfo,
|
2019-12-10 14:58:01 +00:00
|
|
|
&flags)) {
|
|
|
|
PyErr_BadArgument ();
|
2019-04-05 13:58:38 +00:00
|
|
|
return NULL;
|
2019-12-10 14:58:01 +00:00
|
|
|
}
|
2019-04-05 13:58:38 +00:00
|
|
|
|
|
|
|
/* Since Python does only support r/o or r/w it has to be changed to either */
|
|
|
|
flags = (flags & GST_MAP_WRITE) ? GST_MAP_READWRITE : GST_MAP_READ;
|
|
|
|
|
|
|
|
/* Extract GstBuffer from Gst.Buffer parameter */
|
|
|
|
buffer = GST_BUFFER (pygobject_get (py_buffer));
|
|
|
|
|
|
|
|
/* Map the buffer, fill out GstMapInfo */
|
|
|
|
mapinfo = g_new0 (GstMapInfo, 1);
|
|
|
|
ok = gst_buffer_map (buffer, mapinfo, flags);
|
|
|
|
if (!ok) {
|
|
|
|
g_free (mapinfo);
|
2020-02-26 12:53:17 +00:00
|
|
|
goto err;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 19:59:16 +00:00
|
|
|
success = _remap (mapinfo, py_mapinfo);
|
2019-04-05 13:58:38 +00:00
|
|
|
if (!success) {
|
|
|
|
gst_buffer_unmap (buffer, mapinfo);
|
|
|
|
g_free (mapinfo);
|
|
|
|
}
|
|
|
|
return success;
|
2020-02-26 12:53:17 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
Py_INCREF (Py_False);
|
|
|
|
return Py_False;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_gst_buffer_override_unmap (PyObject * self, PyObject * args)
|
|
|
|
{
|
|
|
|
PyTypeObject *gst_buf_type;
|
2020-05-08 21:01:50 +00:00
|
|
|
PyObject *py_buffer, *py_mapinfo, *success;
|
2019-04-05 13:58:38 +00:00
|
|
|
GstBuffer *buffer;
|
2020-05-08 21:01:50 +00:00
|
|
|
GstMapInfo *mapinfo = NULL;
|
2019-04-05 13:58:38 +00:00
|
|
|
|
|
|
|
/* Look up Gst.Buffer and Gst.Mapinfo parameters */
|
|
|
|
gst_buf_type = pygobject_lookup_class (_gst_buffer_type);
|
2019-12-10 14:58:01 +00:00
|
|
|
if (!PyArg_ParseTuple (args, "O!O", gst_buf_type, &py_buffer, &py_mapinfo)) {
|
|
|
|
PyErr_BadArgument ();
|
2019-04-05 13:58:38 +00:00
|
|
|
return NULL;
|
2019-12-10 14:58:01 +00:00
|
|
|
}
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
success = _unmap (&mapinfo, py_mapinfo);
|
|
|
|
if (PyBool_Check (success) && mapinfo) {
|
|
|
|
/* Extract GstBuffer from Gst.Buffer parameter */
|
|
|
|
buffer = GST_BUFFER (pygobject_get (py_buffer));
|
2019-12-10 14:58:01 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
/* Unmap the buffer, using reconstructed GstMapInfo */
|
|
|
|
gst_buffer_unmap (buffer, mapinfo);
|
|
|
|
g_free (mapinfo);
|
2019-12-10 14:58:01 +00:00
|
|
|
}
|
2019-04-05 13:58:38 +00:00
|
|
|
|
2020-05-08 21:01:50 +00:00
|
|
|
return success;
|
2019-04-05 13:58:38 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
static PyMethodDef _gi_gst_functions[] = {
|
2015-11-08 10:56:28 +00:00
|
|
|
{"trace", (PyCFunction) _wrap_gst_trace, METH_VARARGS,
|
|
|
|
NULL},
|
2012-09-27 12:41:29 +00:00
|
|
|
{"log", (PyCFunction) _wrap_gst_log, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"debug", (PyCFunction) _wrap_gst_debug, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"info", (PyCFunction) _wrap_gst_info, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"warning", (PyCFunction) _wrap_gst_warning, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"error", (PyCFunction) _wrap_gst_error, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"fixme", (PyCFunction) _wrap_gst_fixme, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"memdump", (PyCFunction) _wrap_gst_memdump, METH_VARARGS,
|
2016-02-27 11:16:00 +00:00
|
|
|
NULL},
|
2019-04-05 13:58:38 +00:00
|
|
|
{"buffer_override_map_range", (PyCFunction) _gst_buffer_override_map_range,
|
|
|
|
METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"buffer_override_map", (PyCFunction) _gst_buffer_override_map, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"buffer_override_unmap", (PyCFunction) _gst_buffer_override_unmap,
|
|
|
|
METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"memory_override_map", (PyCFunction) _gst_memory_override_map, METH_VARARGS,
|
|
|
|
NULL},
|
|
|
|
{"memory_override_unmap", (PyCFunction) _gst_memory_override_unmap,
|
|
|
|
METH_VARARGS,
|
|
|
|
NULL},
|
2016-02-27 11:16:00 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2012-09-27 12:41:29 +00:00
|
|
|
};
|
2012-08-08 18:00:05 +00:00
|
|
|
|
|
|
|
PYGLIB_MODULE_START (_gi_gst, "_gi_gst")
|
|
|
|
{
|
|
|
|
PyObject *d;
|
|
|
|
|
2012-09-27 12:41:29 +00:00
|
|
|
/* gst should have been initialized already */
|
|
|
|
|
|
|
|
/* Initialize debugging category */
|
|
|
|
GST_DEBUG_CATEGORY_INIT (pygst_debug, "pygst", 0,
|
|
|
|
"GStreamer python bindings");
|
|
|
|
GST_DEBUG_CATEGORY_INIT (python_debug, "python", GST_DEBUG_FG_GREEN,
|
|
|
|
"python code using gst-python");
|
|
|
|
|
2012-08-08 18:00:05 +00:00
|
|
|
pygobject_init (3, 0, 0);
|
|
|
|
|
|
|
|
d = PyModule_GetDict (module);
|
|
|
|
gi_gst_register_types (d);
|
2012-08-19 06:25:13 +00:00
|
|
|
pyg_register_class_init (GST_TYPE_ELEMENT, _pygst_element_init);
|
2012-08-08 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PYGLIB_MODULE_END;
|