From: <tho...@fr...> - 2005-09-08 15:13:19
|
CVS Root: /cvs/gstreamer Module: gst-python Changes by: thomasvs Date: Thu Sep 08 2005 08:13:18 PDT Log message: wrap gst.Element.get_state, returning a tuple add tests for it Modified files: . : ChangeLog gst : gstelement.override testsuite : test_bin.py Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/ChangeLog.diff?r1=1.227&r2=1.228 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/gst/gstelement.override.diff?r1=1.10&r2=1.11 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-python/testsuite/test_bin.py.diff?r1=1.2&r2=1.3 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-python/ChangeLog,v retrieving revision 1.227 retrieving revision 1.228 diff -u -d -r1.227 -r1.228 --- ChangeLog 8 Sep 2005 14:08:31 -0000 1.227 +++ ChangeLog 8 Sep 2005 15:13:05 -0000 1.228 @@ -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: gstelement.override RCS file: /cvs/gstreamer/gst-python/gst/gstelement.override,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- gstelement.override 2 Sep 2005 16:21:45 -0000 1.10 +++ gstelement.override 8 Sep 2005 15:13:06 -0000 1.11 @@ -113,16 +113,45 @@ 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: test_bin.py RCS file: /cvs/gstreamer/gst-python/testsuite/test_bin.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test_bin.py 2 Sep 2005 22:59:20 -0000 1.2 +++ test_bin.py 8 Sep 2005 15:13:06 -0000 1.3 @@ -52,5 +52,23 @@ 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) + (ret, state, pending) = bin.get_state(timeout=0.1) if __name__ == "__main__": unittest.main() |