Example #1
0
 def setUp(self):
     TestCase.setUp(self)
     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.src.set_active(True)
     self.sink.set_active(True)
     self.sink.set_chain_function(self._chain_func)
     self.buffers = []
Example #2
0
    def testConstructor(self):
        # first style uses gst_pad_new
        gst.debug('creating pad with name src')
        pad = gst.Pad("src", gst.PAD_SRC)
        self.failUnless(pad)
        self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 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"))
Example #3
0
    def testTagFullMessage(self):
        if hasattr(gst.Message, 'parse_tag_full'):
            p = gst.Pad("blahblah", gst.PAD_SRC)
            # Create a taglist
            t = gst.TagList()
            t['something'] = "else"
            t['another'] = 42

            # Create two messages using that same taglist
            m1 = gst.message_new_tag_full(self.element, p, t)
            assert m1
            m2 = gst.message_new_tag_full(self.element, p, t)
            assert m2

            # make sure the two messages have the same taglist
            p1, t1 = m1.parse_tag_full()
            assert t1
            keys = t1.keys()
            keys.sort()
            self.assertEquals(p1, p)
            self.assertEquals(keys, ['another', 'something'])
            self.assertEquals(t1['something'], "else")
            self.assertEquals(t1['another'], 42)
            p2, t2 = m2.parse_tag_full()
            assert t2
            keys = t2.keys()
            keys.sort()
            self.assertEquals(p2, p)
            self.assertEquals(keys, ['another', 'something'])
            self.assertEquals(t2['something'], "else")
            self.assertEquals(t2['another'], 42)
Example #4
0
    def test_target(self):
        src = gst.Pad("src", gst.PAD_SRC)

        ghost = gst.GhostPad("ghost_src", src)
        self.failUnless(ghost.get_target() is src)

        ghost.set_target(None)
        self.failUnless(ghost.get_target() is None)

        ghost.set_target(src)
        self.failUnless(ghost.get_target() is src)
Example #5
0
    def testStructureChangeMessage(self):
        if hasattr(gst, 'message_new_structure_change'):
            p = gst.Pad("blah", gst.PAD_SINK)
            m = gst.message_new_structure_change(
                p, gst.STRUCTURE_CHANGE_TYPE_PAD_LINK, self.element, True)

            self.assertEquals(m.type, gst.MESSAGE_STRUCTURE_CHANGE)
            sct, owner, busy = m.parse_structure_change()
            self.assertEquals(sct, gst.STRUCTURE_CHANGE_TYPE_PAD_LINK)
            self.assertEquals(owner, self.element)
            self.assertEquals(busy, True)
Example #6
0
    def testCallbackFlush(self):
        # check that the same block callback can be called more than once (weird
        # test but it was broken)

        def blocked_cb(pad, blocked):
            pad.push_event(gst.event_new_flush_start())

        pad = gst.Pad('src', gst.PAD_SRC)
        pad.set_active(True)
        pad.set_blocked_async(True, blocked_cb)

        for i in xrange(10):
            buf = gst.Buffer('ciao')
            pad.push(buf)
            pad.push_event(gst.event_new_flush_stop())
Example #7
0
    def testTypeFind(self):
        def application_awesome_type_find(typefind, arg1, arg2):
            self.failUnlessEqual(arg1, 'arg1')
            self.failUnlessEqual(arg2, 'arg2')

            data = typefind.peek(0, 5)
            self.failUnless(data == '', 'peek out of length??')

            data = typefind.peek(0, 0)
            self.failUnless(data == '', '0 peek??')

            data = typefind.peek(3, 1)
            self.failUnless(data == 'M')

            data = typefind.peek(0, 4)
            self.failUnless(data == 'AWSM')

            typefind.suggest(gst.TYPE_FIND_MAXIMUM,
                             gst.Caps('application/awesome'))

        res = gst.type_find_register('application/awesome', gst.RANK_PRIMARY,
                                     application_awesome_type_find, ['.twi'],
                                     gst.Caps('application/awesome'), 'arg1',
                                     'arg2')
        self.failUnless(res, 'type_find_register failed')

        factory = None
        factories = gst.type_find_factory_get_list()
        for typefind_factory in factories:
            if typefind_factory.get_name() == 'application/awesome':
                factory = typefind_factory
                break
        self.failUnless(factory is not None)

        obj = gst.Pad('src', gst.PAD_SRC)
        buffer = gst.Buffer('AWSM')
        caps, probability = gst.type_find_helper_for_buffer(obj, buffer)

        self.failUnlessEqual(str(caps), 'application/awesome')
        self.failUnlessEqual(probability, gst.TYPE_FIND_MAXIMUM)
Example #8
0
    def testCallbackRefcount(self):
        def blocked_cb(pad, blocked):
            pad.set_blocked_async(False, unblocked_cb)

        def unblocked_cb(pad, blocked):
            pass

        cb_refcount = sys.getrefcount(blocked_cb)
        # sys.getrefcount() returns refcount + 1
        self.assertEquals(cb_refcount, 2)

        pad = gst.Pad('src', gst.PAD_SRC)
        pad.set_active(True)
        pad.set_blocked_async(True, blocked_cb)
        # set_blocked_async refs the callback
        self.assertEquals(sys.getrefcount(blocked_cb), 3)

        buf = gst.Buffer('ciao')
        pad.push(buf)

        # in blocked_cb() we called set_blocked_async() with a different
        # callback, so blocked_cb() should have been unreffed
        cb_refcount_after = sys.getrefcount(blocked_cb)
        self.assertEquals(sys.getrefcount(blocked_cb), cb_refcount)
Example #9
0
    def testAddPad(self):
        # add a pad to an element
        e = gst.element_factory_make('fakesrc')
        self.assertEquals(sys.getrefcount(e), pygobject_2_13 and 2 or 3)
        self.assertEquals(e.__gstrefcount__, 1)

        gst.debug('creating pad with name mypad')
        pad = gst.Pad("mypad", gst.PAD_SRC)
        self.failUnless(pad)
        self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
        self.assertEquals(pad.__gstrefcount__, 1)

        gst.debug('adding pad to element')
        e.add_pad(pad)
        self.assertEquals(sys.getrefcount(e), pygobject_2_13 and 2 or 3)
        self.assertEquals(e.__gstrefcount__, 1)
        self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
        self.assertEquals(pad.__gstrefcount__, 2)  # added to element

        gst.debug('deleting element and collecting')
        self.gccollect()
        del e
        if not pygobject_2_13:
            # the element will be collected at 'del e' if we're using
            # pygobject >= 2.13.0
            self.assertEquals(self.gccollect(), 1)  # collected the element
        self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
        self.assertEquals(pad.__gstrefcount__, 1)  # removed from element

        gst.debug('deleting pad and collecting')
        del pad
        if not pygobject_2_13:
            # the pad will be collected at 'del pad' if we're using
            # pygobject >= 2.13.0
            self.assertEquals(self.gccollect(), 1)  # collected the pad
        gst.debug('going into teardown')
Example #10
0
 def setUp(self):
     TestCase.setUp(self)
     self.src = gst.Pad("src", gst.PAD_SRC)
     self.sink = gst.Pad("sink", gst.PAD_SINK)
Example #11
0
 def testInvalidIterator(self):
     p = gst.Pad("p", gst.PAD_SRC)
     # The C function will return NULL, we should
     # therefore have an exception raised
     self.assertRaises(TypeError, p.iterate_internal_links)
     del p