diff --git a/ChangeLog b/ChangeLog index 1693bb2a77..d43ad305fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,12 +3,12 @@ * configure.ac: back to development -=== gst-python 0.8.3 === +=== gst-python 0.9.3 === 2005-10-03 Thomas Vander Stichele * configure.ac: - Releasing 0.8.3, "For the Virgin" + Releasing 0.9.3, "For the Virgin" 2005-10-02 Johan Dahlin diff --git a/gst/gstelement.override b/gst/gstelement.override index 041c102ea2..c450558a42 100644 --- a/gst/gstelement.override +++ b/gst/gstelement.override @@ -81,36 +81,45 @@ _wrap_gst_element_get_state(PyGObject *self, PyObject *args, PyObject *kwargs) GstState state; GstState pending; GstStateChangeReturn ret; - PyObject *timeout = Py_None; + PyObject *timeout = NULL; + gdouble timeoutd; GTimeVal *timevalp = NULL; GTimeVal timeval; PyObject *tuple; + /* + * infinite timeout: timevalp == NULL + * 0 timeout: timeval set to 0, timevalp points to timeval + * x timeout: timeval set to gdouble conversion, timevalp points to timeval + */ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:GstElement.get_state", kwlist, &timeout)) { PyErr_SetString(PyExc_RuntimeError, "Timeout not specified correctly"); return NULL; } - if (timeout != Py_None) { - gdouble timeoutd; - - if (!PyFloat_Check (timeout)) { - PyErr_SetString(PyExc_TypeError, "Timeout not specified as double"); - return NULL; + if (timeout == Py_None) { + /* infinite timeout */ + } + else { + if (timeout == NULL) { + timeoutd = 0.0; + } else { + if (!PyFloat_Check (timeout)) { + PyErr_SetString(PyExc_TypeError, "Timeout not specified as double"); + return NULL; + } + timeoutd = PyFloat_AsDouble (timeout); } - timeoutd = PyFloat_AsDouble (timeout); timeval.tv_sec = (glong) timeoutd; timeval.tv_usec = (glong) ((timeoutd - (gdouble) timeval.tv_sec) * 1000.0 * 1000.0); timevalp = &timeval; - } else { - GST_TIME_TO_TIMEVAL (0, timeval); } ret = gst_element_get_state(GST_ELEMENT (self->obj), &state, &pending, - &timeval); + timevalp); tuple = Py_BuildValue("OOO", pyg_enum_from_gtype (GST_TYPE_STATE_CHANGE_RETURN, ret), diff --git a/testsuite/test_bin.py b/testsuite/test_bin.py index f4475d01e9..bacd2a42f7 100644 --- a/testsuite/test_bin.py +++ b/testsuite/test_bin.py @@ -121,6 +121,51 @@ class BinAddRemove(TestCase): self.assertRaises(gst.AddError, self.bin.add, src, sink) self.bin.remove(src, sink) self.assertRaises(gst.RemoveError, self.bin.remove, src, sink) + +class Preroll(TestCase): + def setUp(self): + TestCase.setUp(self) + self.bin = gst.Bin('bin') + + def tearDown(self): + del self.bin + TestCase.tearDown(self) + + def testFake(self): + src = gst.element_factory_make('fakesrc') + sink = gst.element_factory_make('fakesink') + self.bin.add(src) + + # bin will go to paused, src pad task will start and error out + self.bin.set_state(gst.STATE_PAUSED) + ret = self.bin.get_state(timeout=None) + self.assertEquals(ret[0], gst.STATE_CHANGE_SUCCESS) + self.assertEquals(ret[1], gst.STATE_PAUSED) + self.assertEquals(ret[2], gst.STATE_VOID_PENDING) + + # adding the sink will cause the bin to go in preroll mode + gst.debug('adding sink and setting to PAUSED, should cause preroll') + self.bin.add(sink) + sink.set_state(gst.STATE_PAUSED) + ret = self.bin.get_state(timeout=0.0) + self.assertEquals(ret[0], gst.STATE_CHANGE_ASYNC) + self.assertEquals(ret[1], gst.STATE_PAUSED) + self.assertEquals(ret[2], gst.STATE_VOID_PENDING) + print ret + + # to actually complete preroll, we need to link and re-enable fakesrc + src.set_state(gst.STATE_READY) + src.link(sink) + src.set_state(gst.STATE_PAUSED) + ret = self.bin.get_state(timeout=None) + self.assertEquals(ret[0], gst.STATE_CHANGE_SUCCESS) + self.assertEquals(ret[1], gst.STATE_PAUSED) + self.assertEquals(ret[2], gst.STATE_VOID_PENDING) + + print ret + + self.bin.set_state(gst.STATE_NULL) + self.bin.get_state(timeout=None) if __name__ == "__main__": unittest.main()