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
|
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
from common import gst, unittest, TestCase
|
2005-09-28 12:17:29 +00:00
|
|
|
import sys
|
|
|
|
import gc
|
2004-07-13 09:00:07 +00:00
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
class PadTemplateTest(TestCase):
|
2005-09-08 13:34:29 +00:00
|
|
|
def testConstructor(self):
|
2005-09-28 12:17:29 +00:00
|
|
|
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)
|
2005-09-08 13:34:29 +00:00
|
|
|
|
2005-10-05 16:19:13 +00:00
|
|
|
class PadPushUnlinkedTest(TestCase):
|
|
|
|
def setUp(self):
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.setUp(self)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.src = gst.Pad("src", gst.PAD_SRC)
|
|
|
|
self.sink = gst.Pad("sink", gst.PAD_SINK)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.assertEquals(sys.getrefcount(self.src), 3)
|
|
|
|
self.assertEquals(self.src.__gstrefcount__, 1)
|
|
|
|
del self.src
|
|
|
|
self.assertEquals(sys.getrefcount(self.sink), 3)
|
|
|
|
self.assertEquals(self.sink.__gstrefcount__, 1)
|
|
|
|
del self.sink
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.tearDown(self)
|
2005-10-05 16:19:13 +00:00
|
|
|
|
|
|
|
def testNoProbe(self):
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_NOT_LINKED)
|
|
|
|
# pushing it takes a ref in the python wrapper to keep buffer
|
|
|
|
# alive afterwards; but the core unrefs the ref it receives
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
|
|
|
|
def testFalseProbe(self):
|
|
|
|
id = self.src.add_buffer_probe(self._probe_handler, False)
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK)
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.src.remove_buffer_probe(id)
|
|
|
|
|
|
|
|
def testTrueProbe(self):
|
|
|
|
id = self.src.add_buffer_probe(self._probe_handler, True)
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_NOT_LINKED)
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.src.remove_buffer_probe(id)
|
|
|
|
|
|
|
|
def _probe_handler(self, pad, buffer, ret):
|
|
|
|
return ret
|
|
|
|
|
|
|
|
class PadPushLinkedTest(TestCase):
|
|
|
|
def setUp(self):
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.setUp(self)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.src = gst.Pad("src", gst.PAD_SRC)
|
|
|
|
self.sink = gst.Pad("sink", gst.PAD_SINK)
|
|
|
|
caps = gst.caps_from_string("foo/bar")
|
|
|
|
self.src.set_caps(caps)
|
|
|
|
self.sink.set_caps(caps)
|
|
|
|
self.sink.set_chain_function(self._chain_func)
|
|
|
|
self.src.link(self.sink)
|
|
|
|
self.buffers = []
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.assertEquals(sys.getrefcount(self.src), 3)
|
|
|
|
self.assertEquals(self.src.__gstrefcount__, 1)
|
|
|
|
del self.src
|
|
|
|
self.assertEquals(sys.getrefcount(self.sink), 3)
|
|
|
|
self.assertEquals(self.sink.__gstrefcount__, 1)
|
|
|
|
del self.sink
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.tearDown(self)
|
2005-10-05 16:19:13 +00:00
|
|
|
|
|
|
|
def _chain_func(self, pad, buffer):
|
|
|
|
self.buffers.append(buffer)
|
|
|
|
|
|
|
|
return gst.FLOW_OK
|
|
|
|
|
|
|
|
def testNoProbe(self):
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
gst.debug('pushing buffer on linked pad, no probe')
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK)
|
|
|
|
gst.debug('pushed buffer on linked pad, no probe')
|
|
|
|
# pushing it takes a ref in the python wrapper to keep buffer
|
|
|
|
# alive afterwards; fakesink will get the buffer
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(len(self.buffers), 1)
|
|
|
|
|
|
|
|
def testFalseProbe(self):
|
|
|
|
id = self.src.add_buffer_probe(self._probe_handler, False)
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK)
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.src.remove_buffer_probe(id)
|
|
|
|
self.assertEquals(len(self.buffers), 0)
|
|
|
|
|
|
|
|
def testTrueProbe(self):
|
|
|
|
id = self.src.add_buffer_probe(self._probe_handler, True)
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK)
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.src.remove_buffer_probe(id)
|
|
|
|
self.assertEquals(len(self.buffers), 1)
|
|
|
|
|
|
|
|
def _probe_handler(self, pad, buffer, ret):
|
|
|
|
return ret
|
2005-10-05 16:22:26 +00:00
|
|
|
|
|
|
|
# a test to show that we can link a pad from the probe handler
|
|
|
|
|
|
|
|
class PadPushProbeLinkTest(TestCase):
|
|
|
|
def setUp(self):
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.setUp(self)
|
2005-10-05 16:22:26 +00:00
|
|
|
self.src = gst.Pad("src", gst.PAD_SRC)
|
|
|
|
self.sink = gst.Pad("sink", gst.PAD_SINK)
|
|
|
|
caps = gst.caps_from_string("foo/bar")
|
|
|
|
self.src.set_caps(caps)
|
|
|
|
self.sink.set_caps(caps)
|
|
|
|
self.sink.set_chain_function(self._chain_func)
|
|
|
|
self.buffers = []
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.assertEquals(sys.getrefcount(self.src), 3)
|
|
|
|
self.assertEquals(self.src.__gstrefcount__, 1)
|
|
|
|
del self.src
|
|
|
|
self.assertEquals(sys.getrefcount(self.sink), 3)
|
|
|
|
self.assertEquals(self.sink.__gstrefcount__, 1)
|
|
|
|
del self.sink
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.tearDown(self)
|
2005-10-05 16:22:26 +00:00
|
|
|
|
|
|
|
def _chain_func(self, pad, buffer):
|
|
|
|
self.buffers.append(buffer)
|
|
|
|
|
|
|
|
return gst.FLOW_OK
|
|
|
|
|
|
|
|
def testProbeLink(self):
|
|
|
|
id = self.src.add_buffer_probe(self._probe_handler)
|
|
|
|
self.buffer = gst.Buffer()
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
gst.debug('pushing buffer on linked pad, no probe')
|
|
|
|
self.assertEquals(self.src.push(self.buffer), gst.FLOW_OK)
|
|
|
|
gst.debug('pushed buffer on linked pad, no probe')
|
|
|
|
# pushing it takes a ref in the python wrapper to keep buffer
|
|
|
|
# alive afterwards; fakesink will get the buffer
|
|
|
|
self.assertEquals(self.buffer.__grefcount__, 1)
|
|
|
|
self.assertEquals(len(self.buffers), 1)
|
|
|
|
|
|
|
|
def _probe_handler(self, pad, buffer):
|
|
|
|
self.src.link(self.sink)
|
|
|
|
return True
|
|
|
|
|
2005-10-05 16:19:13 +00:00
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
class PadTest(TestCase):
|
2005-09-08 13:34:29 +00:00
|
|
|
def testConstructor(self):
|
|
|
|
# first style uses gst_pad_new
|
|
|
|
gst.debug('creating pad with name src')
|
2005-09-28 12:17:29 +00:00
|
|
|
pad = gst.Pad("src", gst.PAD_SRC)
|
|
|
|
self.failUnless(pad)
|
|
|
|
self.assertEquals(sys.getrefcount(pad), 3)
|
|
|
|
self.assertEquals(pad.__gstrefcount__, 1)
|
|
|
|
|
2005-09-08 13:34:29 +00:00
|
|
|
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()
|
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
class PadPipelineTest(TestCase):
|
2004-07-13 09:00:07 +00:00
|
|
|
def setUp(self):
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.setUp(self)
|
2004-07-13 09:00:07 +00:00
|
|
|
self.pipeline = gst.parse_launch('fakesrc name=source ! fakesink')
|
|
|
|
src = self.pipeline.get_by_name('source')
|
2005-09-01 15:50:46 +00:00
|
|
|
self.srcpad = src.get_pad('src')
|
2005-09-28 12:17:29 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
del self.pipeline
|
|
|
|
del self.srcpad
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.tearDown(self)
|
2004-07-13 09:00:07 +00:00
|
|
|
|
2005-09-01 15:50:46 +00:00
|
|
|
# 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
|
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
|
2005-10-05 16:19:13 +00:00
|
|
|
class PadProbePipeTest(TestCase):
|
2005-09-23 15:37:40 +00:00
|
|
|
def setUp(self):
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.setUp(self)
|
2005-09-23 15:37:40 +00:00
|
|
|
self.pipeline = gst.Pipeline()
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(self.pipeline.__gstrefcount__, 1)
|
|
|
|
self.assertEquals(sys.getrefcount(self.pipeline), 3)
|
|
|
|
|
2005-09-23 15:37:40 +00:00
|
|
|
self.fakesrc = gst.element_factory_make('fakesrc')
|
|
|
|
self.fakesink = gst.element_factory_make('fakesink')
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(self.fakesrc.__gstrefcount__, 1)
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesrc), 3)
|
|
|
|
|
2005-09-30 15:23:15 +00:00
|
|
|
self.pipeline.add(self.fakesrc, self.fakesink)
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(self.fakesrc.__gstrefcount__, 2) # added
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesrc), 3)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.assertEquals(self.fakesink.__gstrefcount__, 2) # added
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesink), 3)
|
2005-09-28 13:29:52 +00:00
|
|
|
|
2005-09-23 15:37:40 +00:00
|
|
|
self.fakesrc.link(self.fakesink)
|
|
|
|
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(self.pipeline.__gstrefcount__, 1)
|
|
|
|
self.assertEquals(sys.getrefcount(self.pipeline), 3)
|
|
|
|
self.assertEquals(self.fakesrc.__gstrefcount__, 2)
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesrc), 3)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.assertEquals(self.fakesink.__gstrefcount__, 2)
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesink), 3)
|
2005-09-28 13:29:52 +00:00
|
|
|
|
2005-09-28 12:17:29 +00:00
|
|
|
def tearDown(self):
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(self.pipeline.__gstrefcount__, 1)
|
|
|
|
self.assertEquals(sys.getrefcount(self.pipeline), 3)
|
|
|
|
self.assertEquals(self.fakesrc.__gstrefcount__, 2)
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesrc), 3)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.assertEquals(self.fakesink.__gstrefcount__, 2)
|
|
|
|
self.assertEquals(sys.getrefcount(self.fakesink), 3)
|
2005-09-28 13:29:52 +00:00
|
|
|
gst.debug('deleting pipeline')
|
2005-09-28 12:17:29 +00:00
|
|
|
del self.pipeline
|
2005-09-28 13:29:52 +00:00
|
|
|
self.gccollect()
|
|
|
|
|
|
|
|
self.assertEquals(self.fakesrc.__gstrefcount__, 1) # parent gone
|
2005-10-05 16:19:13 +00:00
|
|
|
self.assertEquals(self.fakesink.__gstrefcount__, 1) # parent gone
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(sys.getrefcount(self.fakesrc), 3)
|
2005-10-05 16:19:13 +00:00
|
|
|
self.assertEquals(sys.getrefcount(self.fakesink), 3)
|
2005-09-28 13:29:52 +00:00
|
|
|
gst.debug('deleting fakesrc')
|
2005-09-28 12:17:29 +00:00
|
|
|
del self.fakesrc
|
2005-09-28 13:29:52 +00:00
|
|
|
self.gccollect()
|
2005-10-05 16:19:13 +00:00
|
|
|
gst.debug('deleting fakesink')
|
2005-09-28 12:17:29 +00:00
|
|
|
del self.fakesink
|
2005-09-28 13:29:52 +00:00
|
|
|
self.gccollect()
|
|
|
|
|
2005-10-06 10:54:14 +00:00
|
|
|
TestCase.tearDown(self)
|
2005-09-28 12:17:29 +00:00
|
|
|
|
2005-10-05 16:19:13 +00:00
|
|
|
def testFakeSrcProbeOnceKeep(self):
|
2005-09-23 15:37:40 +00:00
|
|
|
self.fakesrc.set_property('num-buffers', 1)
|
|
|
|
|
2005-10-05 16:19:13 +00:00
|
|
|
self.fakesink.set_property('signal-handoffs', True)
|
|
|
|
self.fakesink.connect('handoff', self._handoff_callback_fakesink)
|
|
|
|
|
2005-09-23 15:37:40 +00:00
|
|
|
pad = self.fakesrc.get_pad('src')
|
2005-09-28 13:29:52 +00:00
|
|
|
id = pad.add_buffer_probe(self._probe_callback_fakesrc)
|
2005-09-23 15:37:40 +00:00
|
|
|
self._got_fakesrc_buffer = 0
|
2005-10-05 16:19:13 +00:00
|
|
|
self._got_fakesink_buffer = 0
|
2005-09-23 15:37:40 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2005-09-01 15:50:46 +00:00
|
|
|
while not self._got_fakesrc_buffer:
|
2005-10-06 10:54:14 +00:00
|
|
|
gst.debug('waiting for fakesrc buffer')
|
2005-09-01 15:50:46 +00:00
|
|
|
pass
|
2005-10-05 16:19:13 +00:00
|
|
|
while not self._got_fakesink_buffer:
|
2005-10-06 10:54:14 +00:00
|
|
|
gst.debug('waiting for fakesink buffer')
|
2005-10-05 16:19:13 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
self.assertEquals(self._got_fakesink_buffer, 1)
|
|
|
|
pad.remove_buffer_probe(id)
|
2005-09-01 15:50:46 +00:00
|
|
|
|
2005-09-23 15:37:40 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
|
|
|
|
|
|
|
def testFakeSrcProbeMany(self):
|
|
|
|
self.fakesrc.set_property('num-buffers', 1000)
|
|
|
|
|
|
|
|
pad = self.fakesrc.get_pad('src')
|
2005-10-05 16:19:13 +00:00
|
|
|
id = pad.add_buffer_probe(self._probe_callback_fakesrc)
|
2005-09-23 15:37:40 +00:00
|
|
|
self._got_fakesrc_buffer = 0
|
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
while not self._got_fakesrc_buffer == 1000:
|
2005-10-06 10:54:14 +00:00
|
|
|
import time
|
|
|
|
# allow for context switching; a busy loop here locks up the
|
|
|
|
# streaming thread too much
|
|
|
|
time.sleep(.0001)
|
2005-10-05 16:19:13 +00:00
|
|
|
pad.remove_buffer_probe(id)
|
2005-09-23 15:37:40 +00:00
|
|
|
|
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
|
|
|
|
2005-09-01 15:50:46 +00:00
|
|
|
def _probe_callback_fakesrc(self, pad, buffer):
|
|
|
|
self.failUnless(isinstance(pad, gst.Pad))
|
|
|
|
self.failUnless(isinstance(buffer, gst.Buffer))
|
2005-09-23 15:37:40 +00:00
|
|
|
self._got_fakesrc_buffer += 1
|
2005-10-06 10:54:14 +00:00
|
|
|
gst.debug('fakesrc sent buffer %r, %d total sent' % (
|
|
|
|
buffer, self._got_fakesrc_buffer))
|
2005-10-05 16:19:13 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def _handoff_callback_fakesink(self, sink, buffer, pad):
|
|
|
|
self.failUnless(isinstance(buffer, gst.Buffer))
|
|
|
|
self.failUnless(isinstance(pad, gst.Pad))
|
|
|
|
self._got_fakesink_buffer += 1
|
2005-10-06 10:54:14 +00:00
|
|
|
gst.debug('fakesink got buffer %r, %d total received' % (
|
|
|
|
buffer, self._got_fakesrc_buffer))
|
2005-10-05 16:19:13 +00:00
|
|
|
return True
|
2004-07-13 09:00:07 +00:00
|
|
|
|
2005-09-21 13:45:58 +00:00
|
|
|
def testRemovingProbe(self):
|
2005-09-23 15:37:40 +00:00
|
|
|
self.fakesrc.set_property('num-buffers', 10)
|
2005-09-21 13:45:58 +00:00
|
|
|
|
|
|
|
handle = None
|
|
|
|
self._num_times_called = 0
|
|
|
|
def buffer_probe(pad, buffer):
|
|
|
|
self._num_times_called += 1
|
|
|
|
pad.remove_buffer_probe(handle)
|
|
|
|
return True
|
|
|
|
|
2005-09-23 15:37:40 +00:00
|
|
|
pad = self.fakesrc.get_pad('src')
|
2005-09-21 13:45:58 +00:00
|
|
|
handle = pad.add_buffer_probe(buffer_probe)
|
2005-09-23 15:37:40 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
m = self.pipeline.get_bus().poll(gst.MESSAGE_EOS, -1)
|
2005-09-21 13:45:58 +00:00
|
|
|
assert m
|
|
|
|
assert self._num_times_called == 1
|
2005-09-23 15:37:40 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
2005-09-28 13:29:52 +00:00
|
|
|
# FIXME: having m going out of scope doesn't seem to be enough
|
|
|
|
# to get it gc collected, and it keeps a ref to the pipeline.
|
|
|
|
# Look for a way to not have to do this explicitly
|
|
|
|
del m
|
|
|
|
self.gccollect()
|
|
|
|
|
|
|
|
class PadRefCountTest(TestCase):
|
2005-09-28 12:17:29 +00:00
|
|
|
def testAddPad(self):
|
|
|
|
# add a pad to an element
|
|
|
|
e = gst.element_factory_make('fakesrc')
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(sys.getrefcount(e), 3)
|
|
|
|
self.assertEquals(e.__gstrefcount__, 1)
|
|
|
|
|
|
|
|
gst.debug('creating pad with name mypad')
|
|
|
|
pad = gst.Pad("mypad", gst.PAD_SRC)
|
2005-09-28 12:17:29 +00:00
|
|
|
self.failUnless(pad)
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(sys.getrefcount(pad), 3)
|
|
|
|
self.assertEquals(pad.__gstrefcount__, 1)
|
|
|
|
|
|
|
|
gst.debug('adding pad to element')
|
2005-09-28 12:17:29 +00:00
|
|
|
e.add_pad(pad)
|
2005-09-28 13:29:52 +00:00
|
|
|
self.assertEquals(sys.getrefcount(e), 3)
|
|
|
|
self.assertEquals(e.__gstrefcount__, 1)
|
|
|
|
self.assertEquals(sys.getrefcount(pad), 3)
|
|
|
|
self.assertEquals(pad.__gstrefcount__, 2) # added to element
|
|
|
|
|
|
|
|
gst.debug('deleting element and collecting')
|
2005-09-28 12:17:29 +00:00
|
|
|
gc.collect()
|
2005-09-28 13:29:52 +00:00
|
|
|
del e
|
|
|
|
self.assertEquals(gc.collect(), 1) # collected the element
|
|
|
|
self.assertEquals(sys.getrefcount(pad), 3)
|
|
|
|
self.assertEquals(pad.__gstrefcount__, 1) # removed from element
|
|
|
|
|
|
|
|
gst.debug('deleting pad and collecting')
|
|
|
|
del pad
|
|
|
|
self.assertEquals(gc.collect(), 1) # collected the pad
|
|
|
|
gst.debug('going into teardown')
|
2005-09-21 13:45:58 +00:00
|
|
|
|
2004-07-13 09:00:07 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|