2004-06-21 08:38:23 +00:00
|
|
|
import os
|
2004-05-03 16:17:38 +00:00
|
|
|
import sys
|
2004-11-23 10:16:58 +00:00
|
|
|
from common import gst, unittest, testhelper
|
2004-05-03 16:17:38 +00:00
|
|
|
|
|
|
|
class EventTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
pipeline = gst.parse_launch('fakesrc ! fakesink name=sink')
|
|
|
|
self.sink = pipeline.get_by_name('sink')
|
2004-07-13 09:00:07 +00:00
|
|
|
pipeline.set_state(gst.STATE_PLAYING)
|
2004-05-03 16:17:38 +00:00
|
|
|
|
gst/: Added GError wrapping,
Original commit message from CVS:
* gst/gst-types.defs:
* gst/gst.defs:
Added GError wrapping,
Removed data field from Buffer,
Added virtual methods to object
Updated to latest API
* gst/gst.override:
wrapped gst_plugin_get_feature_list(), gst_uri_handler_get_protocols(),
gst_registry_pool_list()
* gst/gstbuffer.override:
gst.Buffer() works
get/setters fixed
wrapped gst_buffer_stamp()
* gst/gstbus.override:
wrapped gst_bus_set_sync_handler() and gst_bus_add_watch()
* gst/gstelement.override:
wrapped gst_element_send_event(), gst_element_factory_get_pad_templates()
gst_element_query_convert(), gst_element_get_query_types()
* gst/gstevent.override:
wrapped gst_event_discont_get_value()
* gst/gstmessage.override:
wrapped gst_message_parse_state_changed(), gst_message_parse_error(),
gst_message_parse_warning(), gst_message_parse_tag()
* gst/gstmodule.c:
Added registration of new fundamental type with pygtk
* gst/gstpad.override:
wrapped gst_pad_query(), gst_pad_[add|remove]_[data|event|buffer]_probe(),
gst_pad_query_position(), gst_pad_query_convert()
* gst/gstquery.override:
wrapped gst_query_parse_position(), gst_query_parse_convert(),
gst_query_parse_seeking_query(), gst_query_parse_seeking_reponse()
* gst/pygstminiobject.c:
fixes
* gst/Makefile.am:
added gstbus.override, gstmessage.override, gstquery.override
* testsuite/test_buffer.py:
* testsuite/test_element.py:
* testsuite/test_event.py:
* testsuite/test_pipeline.py:
Updating testsuites
2005-07-12 09:45:58 +00:00
|
|
|
## def testEventEmpty(self):
|
|
|
|
## event = gst.Event(gst.EVENT_EMPTY)
|
|
|
|
## self.sink.send_event(event)
|
2004-05-03 16:17:38 +00:00
|
|
|
|
|
|
|
def testEventSeek(self):
|
|
|
|
event = gst.event_new_seek(gst.SEEK_METHOD_CUR, 0)
|
gst/: Added GError wrapping,
Original commit message from CVS:
* gst/gst-types.defs:
* gst/gst.defs:
Added GError wrapping,
Removed data field from Buffer,
Added virtual methods to object
Updated to latest API
* gst/gst.override:
wrapped gst_plugin_get_feature_list(), gst_uri_handler_get_protocols(),
gst_registry_pool_list()
* gst/gstbuffer.override:
gst.Buffer() works
get/setters fixed
wrapped gst_buffer_stamp()
* gst/gstbus.override:
wrapped gst_bus_set_sync_handler() and gst_bus_add_watch()
* gst/gstelement.override:
wrapped gst_element_send_event(), gst_element_factory_get_pad_templates()
gst_element_query_convert(), gst_element_get_query_types()
* gst/gstevent.override:
wrapped gst_event_discont_get_value()
* gst/gstmessage.override:
wrapped gst_message_parse_state_changed(), gst_message_parse_error(),
gst_message_parse_warning(), gst_message_parse_tag()
* gst/gstmodule.c:
Added registration of new fundamental type with pygtk
* gst/gstpad.override:
wrapped gst_pad_query(), gst_pad_[add|remove]_[data|event|buffer]_probe(),
gst_pad_query_position(), gst_pad_query_convert()
* gst/gstquery.override:
wrapped gst_query_parse_position(), gst_query_parse_convert(),
gst_query_parse_seeking_query(), gst_query_parse_seeking_reponse()
* gst/pygstminiobject.c:
fixes
* gst/Makefile.am:
added gstbus.override, gstmessage.override, gstquery.override
* testsuite/test_buffer.py:
* testsuite/test_element.py:
* testsuite/test_event.py:
* testsuite/test_pipeline.py:
Updating testsuites
2005-07-12 09:45:58 +00:00
|
|
|
assert event
|
2004-05-03 16:17:38 +00:00
|
|
|
self.sink.send_event(event)
|
|
|
|
|
2004-06-21 08:38:23 +00:00
|
|
|
class EventFileSrcTest(unittest.TestCase):
|
|
|
|
filename = '/tmp/gst-python-test-file'
|
|
|
|
def setUp(self):
|
|
|
|
if os.path.exists(self.filename):
|
|
|
|
os.remove(self.filename)
|
|
|
|
open(self.filename, 'w').write(''.join(map(str, range(10))))
|
|
|
|
|
|
|
|
self.pipeline = gst.parse_launch('filesrc name=source location=%s blocksize=1 ! fakesink signal-handoffs=1 name=sink' % self.filename)
|
|
|
|
self.source = self.pipeline.get_by_name('source')
|
|
|
|
self.sink = self.pipeline.get_by_name('sink')
|
|
|
|
self.sink.connect('handoff', self.handoff_cb)
|
gst/: Added GError wrapping,
Original commit message from CVS:
* gst/gst-types.defs:
* gst/gst.defs:
Added GError wrapping,
Removed data field from Buffer,
Added virtual methods to object
Updated to latest API
* gst/gst.override:
wrapped gst_plugin_get_feature_list(), gst_uri_handler_get_protocols(),
gst_registry_pool_list()
* gst/gstbuffer.override:
gst.Buffer() works
get/setters fixed
wrapped gst_buffer_stamp()
* gst/gstbus.override:
wrapped gst_bus_set_sync_handler() and gst_bus_add_watch()
* gst/gstelement.override:
wrapped gst_element_send_event(), gst_element_factory_get_pad_templates()
gst_element_query_convert(), gst_element_get_query_types()
* gst/gstevent.override:
wrapped gst_event_discont_get_value()
* gst/gstmessage.override:
wrapped gst_message_parse_state_changed(), gst_message_parse_error(),
gst_message_parse_warning(), gst_message_parse_tag()
* gst/gstmodule.c:
Added registration of new fundamental type with pygtk
* gst/gstpad.override:
wrapped gst_pad_query(), gst_pad_[add|remove]_[data|event|buffer]_probe(),
gst_pad_query_position(), gst_pad_query_convert()
* gst/gstquery.override:
wrapped gst_query_parse_position(), gst_query_parse_convert(),
gst_query_parse_seeking_query(), gst_query_parse_seeking_reponse()
* gst/pygstminiobject.c:
fixes
* gst/Makefile.am:
added gstbus.override, gstmessage.override, gstquery.override
* testsuite/test_buffer.py:
* testsuite/test_element.py:
* testsuite/test_event.py:
* testsuite/test_pipeline.py:
Updating testsuites
2005-07-12 09:45:58 +00:00
|
|
|
self.bus = self.pipeline.get_bus()
|
2004-07-13 09:00:07 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2004-06-21 08:38:23 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
assert self.pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
if os.path.exists(self.filename):
|
|
|
|
os.remove(self.filename)
|
|
|
|
|
|
|
|
def handoff_cb(self, element, buffer, pad):
|
|
|
|
self.handoffs.append(str(buffer))
|
|
|
|
|
|
|
|
def playAndIter(self):
|
|
|
|
self.handoffs = []
|
|
|
|
assert self.pipeline.set_state(gst.STATE_PLAYING)
|
gst/: Added GError wrapping,
Original commit message from CVS:
* gst/gst-types.defs:
* gst/gst.defs:
Added GError wrapping,
Removed data field from Buffer,
Added virtual methods to object
Updated to latest API
* gst/gst.override:
wrapped gst_plugin_get_feature_list(), gst_uri_handler_get_protocols(),
gst_registry_pool_list()
* gst/gstbuffer.override:
gst.Buffer() works
get/setters fixed
wrapped gst_buffer_stamp()
* gst/gstbus.override:
wrapped gst_bus_set_sync_handler() and gst_bus_add_watch()
* gst/gstelement.override:
wrapped gst_element_send_event(), gst_element_factory_get_pad_templates()
gst_element_query_convert(), gst_element_get_query_types()
* gst/gstevent.override:
wrapped gst_event_discont_get_value()
* gst/gstmessage.override:
wrapped gst_message_parse_state_changed(), gst_message_parse_error(),
gst_message_parse_warning(), gst_message_parse_tag()
* gst/gstmodule.c:
Added registration of new fundamental type with pygtk
* gst/gstpad.override:
wrapped gst_pad_query(), gst_pad_[add|remove]_[data|event|buffer]_probe(),
gst_pad_query_position(), gst_pad_query_convert()
* gst/gstquery.override:
wrapped gst_query_parse_position(), gst_query_parse_convert(),
gst_query_parse_seeking_query(), gst_query_parse_seeking_reponse()
* gst/pygstminiobject.c:
fixes
* gst/Makefile.am:
added gstbus.override, gstmessage.override, gstquery.override
* testsuite/test_buffer.py:
* testsuite/test_element.py:
* testsuite/test_event.py:
* testsuite/test_pipeline.py:
Updating testsuites
2005-07-12 09:45:58 +00:00
|
|
|
while 42:
|
|
|
|
msg = self.bus.pop()
|
|
|
|
if msg and msg.type == gst.MESSAGE_EOS:
|
|
|
|
break
|
2004-06-21 08:38:23 +00:00
|
|
|
assert self.pipeline.set_state(gst.STATE_PAUSED)
|
|
|
|
handoffs = self.handoffs
|
|
|
|
self.handoffs = []
|
|
|
|
return handoffs
|
|
|
|
|
|
|
|
def sink_seek(self, offset, method=gst.SEEK_METHOD_SET):
|
|
|
|
method |= (gst.SEEK_FLAG_FLUSH | gst.FORMAT_BYTES)
|
|
|
|
self.source.send_event(gst.event_new_seek(method, offset))
|
|
|
|
self.source.send_event(gst.Event(gst.EVENT_FLUSH))
|
|
|
|
self.sink.send_event(gst.event_new_seek(method, offset))
|
|
|
|
self.sink.send_event(gst.Event(gst.EVENT_FLUSH))
|
|
|
|
|
|
|
|
def testSimple(self):
|
|
|
|
handoffs = self.playAndIter()
|
|
|
|
assert handoffs == map(str, range(10))
|
|
|
|
|
|
|
|
def testSeekCur(self):
|
|
|
|
self.sink_seek(8)
|
|
|
|
|
|
|
|
#print self.playAndIter()
|
|
|
|
|
2004-11-23 10:16:58 +00:00
|
|
|
class TestEmit(unittest.TestCase):
|
|
|
|
def testEmit(self):
|
|
|
|
object = testhelper.get_object()
|
|
|
|
object.connect('event', self._event_cb)
|
2004-06-21 08:38:23 +00:00
|
|
|
|
2004-11-23 10:16:58 +00:00
|
|
|
# First emit from C
|
|
|
|
testhelper.emit_event(object)
|
|
|
|
|
|
|
|
# Then emit from Python
|
|
|
|
object.emit('event', gst.Event(gst.EVENT_UNKNOWN))
|
|
|
|
|
|
|
|
def _event_cb(self, obj, event):
|
|
|
|
assert isinstance(event, gst.Event)
|
|
|
|
|
2004-06-21 08:38:23 +00:00
|
|
|
|
2004-05-03 16:17:38 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|