2005-09-01 10:36:07 +00:00
|
|
|
# -*- Mode: Python -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
|
|
|
#
|
|
|
|
# gst-python - Python bindings for GStreamer
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
# Copyright (C) 2004 Johan Dahlin
|
|
|
|
# Copyright (C) 2005 Edward Hervey
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2004-05-03 16:17:38 +00:00
|
|
|
import sys
|
2005-06-17 10:59:47 +00:00
|
|
|
import gc
|
2004-12-14 16:53:09 +00:00
|
|
|
from common import gobject, gst, unittest
|
2004-05-03 16:17:38 +00:00
|
|
|
|
|
|
|
class BufferTest(unittest.TestCase):
|
2004-05-04 14:20:28 +00:00
|
|
|
def testBufferBuffer(self):
|
|
|
|
buf = gst.Buffer('test')
|
|
|
|
assert str(buffer(buf)) == 'test'
|
|
|
|
|
|
|
|
def testBufferStr(self):
|
|
|
|
buffer = gst.Buffer('test')
|
|
|
|
assert str(buffer) == 'test'
|
2005-06-17 10:59:47 +00:00
|
|
|
|
|
|
|
def testBufferAlloc(self):
|
2005-09-01 14:41:28 +00:00
|
|
|
bla = 'mooooooo'
|
|
|
|
buffer = gst.Buffer(bla + '12345')
|
|
|
|
gc.collect ()
|
|
|
|
assert str(buffer) == 'mooooooo12345'
|
2005-06-17 10:59:47 +00:00
|
|
|
|
2004-05-04 14:20:28 +00:00
|
|
|
def testBufferBadConstructor(self):
|
|
|
|
self.assertRaises(TypeError, gst.Buffer, 'test', 0)
|
|
|
|
|
|
|
|
def testBufferStrNull(self):
|
|
|
|
test_string = 't\0e\0s\0t\0'
|
|
|
|
buffer = gst.Buffer(test_string)
|
|
|
|
assert str(buffer) == test_string
|
|
|
|
|
|
|
|
def testBufferSize(self):
|
|
|
|
test_string = 'a little string'
|
|
|
|
buffer = gst.Buffer(test_string)
|
|
|
|
assert len(buffer) == len(test_string)
|
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 hasattr(buffer, 'size')
|
|
|
|
assert buffer.size == len(buffer)
|
2004-05-03 16:17:38 +00:00
|
|
|
|
2004-05-04 14:20:28 +00:00
|
|
|
def testBufferCreateSub(self):
|
|
|
|
s = ''
|
|
|
|
for i in range(64):
|
|
|
|
s += '%02d' % i
|
|
|
|
|
|
|
|
buffer = gst.Buffer(s)
|
2005-09-01 14:41:28 +00:00
|
|
|
self.assertEquals(len(buffer), 128)
|
2004-05-04 14:20:28 +00:00
|
|
|
|
|
|
|
sub = buffer.create_sub(16, 16)
|
2005-09-01 14:41:28 +00:00
|
|
|
self.assertEquals(sub.size, 16)
|
2005-09-01 14:50:01 +00:00
|
|
|
self.assertEquals(sub.data, buffer.data[16:32])
|
2005-09-01 14:41:28 +00:00
|
|
|
self.assertEquals(sub.offset, gst.CLOCK_TIME_NONE)
|
2004-05-04 14:20:28 +00:00
|
|
|
|
|
|
|
def testBufferMerge(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
merged_buffer = buffer1.merge(buffer2)
|
|
|
|
assert str(merged_buffer) == 'foobar'
|
|
|
|
|
|
|
|
def testBufferJoin(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
joined_buffer = buffer1.merge(buffer2)
|
|
|
|
assert str(joined_buffer) == 'foobar'
|
|
|
|
|
|
|
|
def testBufferSpan(self):
|
|
|
|
buffer1 = gst.Buffer('foo')
|
|
|
|
buffer2 = gst.Buffer('bar')
|
|
|
|
|
|
|
|
spaned_buffer = buffer1.span(0L, buffer2, 6L)
|
|
|
|
assert str(spaned_buffer) == 'foobar'
|
|
|
|
|
2004-06-09 13:40:27 +00:00
|
|
|
def testBufferFlagIsSet(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
# Off by default
|
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 not buffer.flag_is_set(gst.BUFFER_FLAG_READONLY)
|
2004-06-09 13:40:27 +00:00
|
|
|
|
|
|
|
# Try switching on and off
|
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
|
|
|
buffer.flag_set(gst.BUFFER_FLAG_READONLY)
|
|
|
|
assert buffer.flag_is_set(gst.BUFFER_FLAG_READONLY)
|
|
|
|
buffer.flag_unset(gst.BUFFER_FLAG_READONLY)
|
|
|
|
assert not buffer.flag_is_set(gst.BUFFER_FLAG_READONLY)
|
2004-06-09 13:40:27 +00:00
|
|
|
|
|
|
|
# Try switching on and off
|
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
|
|
|
buffer.flag_set(gst.BUFFER_FLAG_IN_CAPS)
|
|
|
|
assert buffer.flag_is_set(gst.BUFFER_FLAG_IN_CAPS)
|
|
|
|
buffer.flag_unset(gst.BUFFER_FLAG_IN_CAPS)
|
|
|
|
assert not buffer.flag_is_set(gst.BUFFER_FLAG_IN_CAPS)
|
2004-06-09 13:40:27 +00:00
|
|
|
|
2004-12-14 16:53:09 +00:00
|
|
|
def testAttrFlags(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "flags")
|
|
|
|
assert isinstance(buffer.flags, int)
|
|
|
|
|
|
|
|
def testAttrTimestamp(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "timestamp")
|
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 isinstance(buffer.timestamp, long)
|
2004-12-14 16:53:09 +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
|
|
|
assert buffer.timestamp == gst.CLOCK_TIME_NONE
|
2004-12-14 16:53:09 +00:00
|
|
|
buffer.timestamp = 0
|
|
|
|
assert buffer.timestamp == 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
|
|
|
buffer.timestamp = 2**64 - 1
|
|
|
|
assert buffer.timestamp == 2**64 - 1
|
|
|
|
|
|
|
|
def testAttrDuration(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "duration")
|
|
|
|
assert isinstance(buffer.duration, long)
|
|
|
|
|
|
|
|
assert buffer.duration == gst.CLOCK_TIME_NONE
|
|
|
|
buffer.duration = 0
|
|
|
|
assert buffer.duration == 0
|
|
|
|
buffer.duration = 2**64 - 1
|
|
|
|
assert buffer.duration == 2**64 - 1
|
2004-12-14 16:53:09 +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 testAttrOffset(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "offset")
|
|
|
|
assert isinstance(buffer.offset, long)
|
|
|
|
|
|
|
|
assert buffer.offset == gst.CLOCK_TIME_NONE
|
|
|
|
buffer.offset = 0
|
|
|
|
assert buffer.offset == 0
|
|
|
|
buffer.offset = 2**64 - 1
|
|
|
|
assert buffer.offset == 2**64 - 1
|
|
|
|
|
|
|
|
def testAttrOffset_end(self):
|
|
|
|
buffer = gst.Buffer()
|
|
|
|
assert hasattr(buffer, "offset_end")
|
|
|
|
assert isinstance(buffer.offset_end, long)
|
|
|
|
|
|
|
|
assert buffer.offset_end == gst.CLOCK_TIME_NONE
|
|
|
|
buffer.offset_end = 0
|
|
|
|
assert buffer.offset_end == 0
|
|
|
|
buffer.offset_end = 2**64 - 1
|
|
|
|
assert buffer.offset_end == 2**64 - 1
|
|
|
|
|
|
|
|
|
2004-05-03 16:17:38 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|