Thomas Vander Stichele 5768672390 gst/: add/move some code to handle wrapping/refcounting of possible
Original commit message from CVS:
* gst/Makefile.am:
* gst/common.h:
* gst/pygstobject.c: (pygstobject_sink), (pygstobject_new),
(pygst_object_unref):
* gst/pygstobject.h:
* gst/gstmodule.c: (init_gst):
add/move some code to handle wrapping/refcounting of possible
GstObject
* codegen/argtypes.py:
* gst/gstbin.override:
* gst/gstbus.override:
* gst/gstelement.override:
* gst/gstpad.override:
* gst/interfaces.override:
use this reffing code
* gst/gst-types.defs:
* gst/gst.override:
add a __gstrefcount__ field to GstObject types
add tp_traverse, tp_dealloc and tp_clear, so we handle refcounting
properly related to garbage collection
* testsuite/test_element.py:
* testsuite/test_pad.py:
add more tests, add some refcount checks
2005-09-28 12:17:29 +00:00

177 lines
6.2 KiB
Python

# -*- 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
from common import gst, unittest
import sys
import gc
class PadTemplateTest(unittest.TestCase):
def tearDown(self):
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
def testConstructor(self):
template = gst.PadTemplate("template", gst.PAD_SINK,
gst.PAD_ALWAYS, gst.caps_from_string("audio/x-raw-int"))
self.failUnless(template)
self.assertEquals(sys.getrefcount(template), 3)
#self.assertEquals(template.__gstrefcount__, 1)
class PadTest(unittest.TestCase):
def tearDown(self):
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
#elements = [o for o in gc.get_objects() if isinstance(o, gst.Element)]
#self.failIf(elements, elements)
#pads = [o for o in gc.get_objects() if isinstance(o, gst.Pad)]
#self.failIf(pads, pads)
def testConstructor(self):
# first style uses gst_pad_new
gst.debug('creating pad with name src')
print "creating pad with src"
pad = gst.Pad("src", gst.PAD_SRC)
print pad
self.failUnless(pad)
self.assertEquals(sys.getrefcount(pad), 3)
self.assertEquals(pad.__gstrefcount__, 1)
gst.debug('creating pad with no name')
self.failUnless(gst.Pad(None, gst.PAD_SRC))
self.failUnless(gst.Pad(name=None, direction=gst.PAD_SRC))
self.failUnless(gst.Pad(direction=gst.PAD_SRC, name=None))
self.failUnless(gst.Pad(direction=gst.PAD_SRC, name="src"))
# second uses gst_pad_new_from_template
#template = gst.PadTemplate()
class PadPipelineTest(unittest.TestCase):
def setUp(self):
self.pipeline = gst.parse_launch('fakesrc name=source ! fakesink')
src = self.pipeline.get_by_name('source')
self.srcpad = src.get_pad('src')
def tearDown(self):
del self.pipeline
del self.srcpad
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
#elements = [o for o in gc.get_objects() if isinstance(o, gst.Element)]
#self.failIf(elements, elements)
# FIXME: now that GstQuery is a miniobject with various _new_ factory
# functions, we need to figure out a way to deal with them in python
# def testQuery(self):
# assert self.sink.query(gst.QUERY_TOTAL, gst.FORMAT_BYTES) == -1
# assert self.srcpad.query(gst.QUERY_POSITION, gst.FORMAT_BYTES) == 0
# assert self.srcpad.query(gst.QUERY_POSITION, gst.FORMAT_TIME) == 0
class PadProbeTest(unittest.TestCase):
def setUp(self):
self.pipeline = gst.Pipeline()
self.fakesrc = gst.element_factory_make('fakesrc')
self.fakesink = gst.element_factory_make('fakesink')
self.pipeline.add_many(self.fakesrc, self.fakesink)
self.fakesrc.link(self.fakesink)
def tearDown(self):
del self.pipeline
del self.fakesrc
del self.fakesink
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
def testFakeSrcProbeOnce(self):
self.fakesrc.set_property('num-buffers', 1)
pad = self.fakesrc.get_pad('src')
pad.add_buffer_probe(self._probe_callback_fakesrc)
self._got_fakesrc_buffer = 0
self.pipeline.set_state(gst.STATE_PLAYING)
while not self._got_fakesrc_buffer:
pass
self.pipeline.set_state(gst.STATE_NULL)
def testFakeSrcProbeMany(self):
self.fakesrc.set_property('num-buffers', 1000)
pad = self.fakesrc.get_pad('src')
pad.add_buffer_probe(self._probe_callback_fakesrc)
self._got_fakesrc_buffer = 0
self.pipeline.set_state(gst.STATE_PLAYING)
while not self._got_fakesrc_buffer == 1000:
pass
self.pipeline.set_state(gst.STATE_NULL)
def _probe_callback_fakesrc(self, pad, buffer):
self.failUnless(isinstance(pad, gst.Pad))
self.failUnless(isinstance(buffer, gst.Buffer))
self._got_fakesrc_buffer += 1
def testRemovingProbe(self):
self.fakesrc.set_property('num-buffers', 10)
handle = None
self._num_times_called = 0
def buffer_probe(pad, buffer):
self._num_times_called += 1
pad.remove_buffer_probe(handle)
return True
pad = self.fakesrc.get_pad('src')
handle = pad.add_buffer_probe(buffer_probe)
self.pipeline.set_state(gst.STATE_PLAYING)
m = self.pipeline.get_bus().poll(gst.MESSAGE_EOS, -1)
assert m
assert self._num_times_called == 1
self.pipeline.set_state(gst.STATE_NULL)
class PadRefCountTest(unittest.TestCase):
def tearDown(self):
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
def testAddPad(self):
# add a pad to an element
e = gst.element_factory_make('fakesrc')
gst.debug('creating pad with name mpypad')
pad = gst.Pad("mpypad", gst.PAD_SRC)
self.failUnless(pad)
e.add_pad(pad)
gst.debug('deleting element')
del e
gst.debug('garbage collecting')
gc.collect()
gst.debug('done garbage collecting')
if __name__ == "__main__":
unittest.main()