From 83f80e9942123c232bd3d19dbb3f642419e78b54 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 8 Sep 2005 15:13:06 +0000 Subject: [PATCH] wrap gst.Element.get_state, returning a tuple add tests for it Original commit message from CVS: wrap gst.Element.get_state, returning a tuple add tests for it --- ChangeLog | 7 +++++++ gst/gstelement.override | 43 ++++++++++++++++++++++++++++++++++++------- testsuite/test_bin.py | 18 ++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c680ba..9402097 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-09-08 Thomas Vander Stichele + * 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 + * gst/gst.defs: * gst/gst.override: * testsuite/test_element.py: diff --git a/gst/gstelement.override b/gst/gstelement.override index 084735f..6e3a615 100644 --- a/gst/gstelement.override +++ b/gst/gstelement.override @@ -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 */ diff --git a/testsuite/test_bin.py b/testsuite/test_bin.py index 750788b..1f381c3 100644 --- a/testsuite/test_bin.py +++ b/testsuite/test_bin.py @@ -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() -- 2.7.4