wrap gst.Element.get_state, returning a tuple add tests for it
authorThomas Vander Stichele <thomas@apestaart.org>
Thu, 8 Sep 2005 15:13:06 +0000 (15:13 +0000)
committerThomas Vander Stichele <thomas@apestaart.org>
Thu, 8 Sep 2005 15:13:06 +0000 (15:13 +0000)
Original commit message from CVS:
wrap gst.Element.get_state, returning a tuple
add tests for it

ChangeLog
gst/gstelement.override
testsuite/test_bin.py

index 5c680ba..9402097 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2005-09-08  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+       * gst/gstelement.override:
+       * testsuite/test_bin.py:
+         wrap gst.Element.get_state, returning a tuple
+         add tests for it
+
+2005-09-08  Thomas Vander Stichele  <thomas at apestaart dot org>
+
        * gst/gst.defs:
        * gst/gst.override:
        * testsuite/test_element.py:
index 084735f..6e3a615 100644 (file)
@@ -113,16 +113,45 @@ override gst_element_get_state kwargs
 static PyObject *
 _wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs)
 {
+    static char *kwlist[] = { "timeout", NULL };
     GstState state;
-    GstStateChangeReturn       ret;
+    GstState pending;
+    GstStateChangeReturn ret;
+    PyObject *timeout;
+    GTimeVal *timevalp = NULL;
+    GTimeVal timeval;
+    PyObject *tuple;
 
-       /* 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, "Element is in an error state");
-       return NULL;
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                                     "O:GstElement.get_state", kwlist,
+                                     &timeout)) {
+       PyErr_SetString(PyExc_RuntimeError, "Timeout not specified correctly");
+        return NULL;
     }
-    return pyg_enum_from_gtype(GST_TYPE_STATE, state);
+    if (timeout != Py_None) {
+        gdouble timeoutd;
+
+        if (!PyFloat_Check (timeout)) {
+            PyErr_SetString(PyExc_TypeError, "Timeout not specified as double");
+            return NULL;
+        }
+        timeoutd = PyFloat_AsDouble (timeout);
+
+        timeval.tv_sec = (glong) timeoutd;
+        timeval.tv_usec = (glong) ((timeoutd - (gdouble) timeval.tv_sec)
+                                   * 1000.0 * 1000.0);
+       timevalp = &timeval;
+    }
+       
+    ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, &pending,
+        &timeval);
+
+    tuple = Py_BuildValue("OOO",
+        pyg_enum_from_gtype (GST_TYPE_STATE_CHANGE_RETURN, ret),
+        pyg_enum_from_gtype (GST_TYPE_STATE, state),
+        pyg_enum_from_gtype (GST_TYPE_STATE, pending));
+
+    return tuple;
 }
 %%
 /* override gst_element_query kwargs */
index 750788b..1f381c3 100644 (file)
@@ -52,5 +52,23 @@ class BinSubclassTest(unittest.TestCase):
         bin.set_state(gst.STATE_PLAYING)
         self.failUnless(bin._state_changed)
 
+        # test get_state with no timeout
+        (ret, state, pending) = bin.get_state(None)
+        self.failIfEqual(ret, gst.STATE_CHANGE_FAILURE)
+
+        if ret == gst.STATE_CHANGE_SUCCESS:
+            self.assertEquals(state, gst.STATE_PLAYING)
+            self.assertEquals(pending, gst.STATE_VOID_PENDING)
+
+        # test get_state with a timeout
+        (ret, state, pending) = bin.get_state(0.1)
+        self.failIfEqual(ret, gst.STATE_CHANGE_FAILURE)
+
+        if ret == gst.STATE_CHANGE_SUCCESS:
+            self.assertEquals(state, gst.STATE_PLAYING)
+            self.assertEquals(pending, gst.STATE_VOID_PENDING)
+
+        (ret, state, pending) = bin.get_state(timeout=0.1)
+
 if __name__ == "__main__":
     unittest.main()