Return a Gst.*Range instead of a python range converting from GValue to python
authorThibault Saunier <thibault.saunier@osg.samsung.com>
Mon, 24 Jul 2017 21:06:06 +0000 (17:06 -0400)
committerThibault Saunier <thibault.saunier@osg.samsung.com>
Wed, 26 Jul 2017 19:27:21 +0000 (15:27 -0400)
Otherwise we lose the information about what type of range it is, which
is mandatory, especially when dealing with Structure and Caps.

gi/overrides/Gst.py
gi/overrides/gstmodule.c

index b440f0b..8d754f1 100644 (file)
@@ -248,6 +248,7 @@ class Structure(Gst.Structure):
     def __getitem__(self, key):
         return self.get_value(key)
 
+
     def __setitem__(self, key, value):
         return self.set_value(key, value)
 
@@ -369,6 +370,13 @@ class IntRange(Gst.IntRange):
             return '[%d,%d,%d]' % (self.range.start, self.range.stop,
                     self.range.step)
 
+    def __eq__(self, other):
+        if isinstance(other, range):
+            return self.range == other
+        elif isinstance(other, IntRange):
+            return self.range == other.range
+        return False
+
 if sys.version_info >= (3, 0):
     IntRange = override(IntRange)
     __all__.append('IntRange')
@@ -401,6 +409,12 @@ class Int64Range(Gst.Int64Range):
             return '(int64)[%d,%d,%d]' % (self.range.start, self.range.stop,
                     self.range.step)
 
+    def __eq__(self, other):
+        if isinstance(other, range):
+            return self.range == other
+        elif isinstance(other, IntRange):
+            return self.range == other.range
+        return False
 
 if sys.version_info >= (3, 0):
     Int64Range = override(Int64Range)
index a9f4cd1..73405c7 100644 (file)
@@ -137,13 +137,21 @@ static PyObject *
 gi_gst_int_range_from_value (const GValue * value)
 {
   gint min, max, step;
+  PyObject *int_range_type, *int_range, *range;
 
   min = gst_value_get_int_range_min (value);
   max = gst_value_get_int_range_max (value);
   step = gst_value_get_int_range_step (value);
 
-  return PyObject_CallFunction ((PyObject *) & PyRange_Type, "iii",
+  int_range_type = gi_gst_get_type ("IntRange");
+  range = PyObject_CallFunction ((PyObject *) & PyRange_Type, "iii",
       min, max, step);
+  int_range = PyObject_CallFunction (int_range_type, "O", range);
+
+  Py_DECREF (int_range_type);
+  Py_DECREF (range);
+
+  return int_range;
 }
 
 static int
@@ -182,13 +190,21 @@ static PyObject *
 gi_gst_int64_range_from_value (const GValue * value)
 {
   gint64 min, max, step;
+  PyObject *int64_range_type, *int64_range, *range;
 
   min = gst_value_get_int64_range_min (value);
   max = gst_value_get_int64_range_max (value);
   step = gst_value_get_int64_range_step (value);
 
-  return PyObject_CallFunction ((PyObject *) & PyRange_Type, "LLL",
+  range = PyObject_CallFunction ((PyObject *) & PyRange_Type, "LLL",
       min, max, step);
+  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;
 }
 
 static int