def testAvailable(self): # starts empty self.assertEquals(self.adapter.available(), 0) self.assertEquals(self.adapter.available_fast(), 0) # let's give it 4 bytes self.adapter.push(gst.Buffer("1234")) self.assertEquals(self.adapter.available_fast(), 4) # let's give it another 5 bytes self.adapter.push(gst.Buffer("56789")) # we now have 9 bytes self.assertEquals(self.adapter.available(), 9) # but can only do a fast take of 4 bytes (the first buffer) self.assertEquals(self.adapter.available_fast(), 4)
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 testTake(self): self.adapter.push(gst.Buffer("0123456789")) self.assertEquals(self.adapter.available(), 10) s = self.adapter.take(5) self.assertEquals(s, "01234") self.assertEquals(self.adapter.available(), 5)
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 testBufferCaps(self): buffer = gst.Buffer() caps = gst.caps_from_string('foo/blah') gst.info("before settings caps") buffer.set_caps(caps) gst.info("after settings caps") c = buffer.get_caps() gst.info("after getting caps") self.assertEquals(caps, c)
def testAttrTimestamp(self): buffer = gst.Buffer() assert hasattr(buffer, "timestamp") assert isinstance(buffer.timestamp, long) assert buffer.timestamp == gst.CLOCK_TIME_NONE buffer.timestamp = 0 assert buffer.timestamp == 0 buffer.timestamp = 2**64 - 1 assert buffer.timestamp == 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
def testBufferCopyOnWrite(self): s = 'test_vector' buffer = gst.Buffer(s) sub = buffer.create_sub(0, buffer.size) self.assertEquals(sub.size, buffer.size) out = sub.copy_on_write() self.assertEquals(out.size, sub.size) assert str(out) == str(buffer) out[5] = 'w' assert str(out) == 'test_wector'
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
def testCapsContainingMiniObjects(self): # buffer contains hex encoding of ascii 'abcd' caps = gst.Caps("video/x-raw-yuv, buf=(buffer)61626364") buf = caps[0]['buf'] assert isinstance(buf, gst.Buffer) assert buf.data == "abcd" buf = gst.Buffer("1234") caps[0]['buf2'] = buf buf2 = caps[0]['buf2'] assert buf2 == buf
def testBufferCreateSub(self): s = '' for i in range(64): s += '%02d' % i buffer = gst.Buffer(s) self.assertEquals(len(buffer), 128) sub = buffer.create_sub(16, 16) self.assertEquals(sub.size, 16) self.assertEquals(sub.data, buffer.data[16:32]) self.assertEquals(sub.offset, gst.CLOCK_TIME_NONE)
def testFlush(self): self.adapter.push(gst.Buffer("0123456789")) self.assertEquals(self.adapter.available(), 10) self.adapter.flush(5) self.assertEquals(self.adapter.available(), 5) # it flushed the first 5 bytes self.assertEquals(self.adapter.peek(5), "56789") self.adapter.flush(5) self.assertEquals(self.adapter.available(), 0)
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') # one refcount is held by our scope, another is held on # self.buffers through _chain_func self.assertEquals(self.buffer.__grefcount__, 2) self.assertEquals(len(self.buffers), 1) self.buffers = None self.assertEquals(self.buffer.__grefcount__, 1)
def testPeek(self): self.adapter.push(gst.Buffer("0123456789")) # let's peek at 5 bytes b = self.adapter.peek(5) # it can return more than 5 bytes self.assert_(len(b) >= 5) self.assertEquals(b, "01234") # it's still 10 bytes big self.assertEquals(self.adapter.available(), 10) # if we try to peek more than what's available, we'll have None self.assertEquals(self.adapter.peek(11), None)
def testNoProbe(self): self.buffer = gst.Buffer() gst.debug('created new buffer %r, id %x' % (self.buffer, id(self.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') # one refcount is held by our scope, another is held on # self.buffers through _chain_func self.assertEquals(self.buffer.__grefcount__, 2) self.assertEquals(len(self.buffers), 1) self.buffers = None self.assertEquals(self.buffer.__grefcount__, 1)
def testBufferclip(self): assert hasattr(gst.audio, "buffer_clip") # create a segment segment = gst.Segment() gst.debug("Created the new segment") # we'll put a new segment of 500ms to 1000ms segment.set_newsegment(False, 1.0, gst.FORMAT_TIME, 0, -1, 0) gst.debug("Initialized the new segment") # create a new dummy buffer b = gst.Buffer("this is a really useless line") gst.debug("Created the buffer") # clip... which shouldn't do anything b2 = gst.audio.buffer_clip(b, segment, 44100, 8) gst.debug("DONE !")
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())
def testBufferFlagIsSet(self): buffer = gst.Buffer() # Off by default assert not buffer.flag_is_set(gst.BUFFER_FLAG_READONLY) # Try switching on and off 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) # Try switching on and off 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)
def testTrueProbe(self): probe_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) # one refcount is held by our scope, another is held on # self.buffers through _chain_func self.assertEquals(self.buffer.__grefcount__, 2) # they are not the same Python object ... self.failIf(self.buffer is self.buffers[0]) self.failIf(id(self.buffer) == id(self.buffers[0])) # ... but they wrap the same GstBuffer self.failUnless(self.buffer == self.buffers[0]) self.assertEquals(repr(self.buffer), repr(self.buffers[0])) self.src.remove_buffer_probe(probe_id) self.assertEquals(len(self.buffers), 1) self.buffers = None self.assertEquals(self.buffer.__grefcount__, 1)
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)
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)
def testWrongEvent(self): buffer = gst.Buffer() self.assertRaises(TypeError, self.sink.send_event, buffer) number = 1 self.assertRaises(TypeError, self.sink.send_event, number)
def testBufferSpan(self): buffer1 = gst.Buffer('foo') buffer2 = gst.Buffer('bar') spaned_buffer = buffer1.span(0L, buffer2, 6L) assert str(spaned_buffer) == 'foobar'
def testBufferJoin(self): buffer1 = gst.Buffer('foo') buffer2 = gst.Buffer('bar') joined_buffer = buffer1.merge(buffer2) assert str(joined_buffer) == 'foobar'
def testBufferMerge(self): buffer1 = gst.Buffer('foo') buffer2 = gst.Buffer('bar') merged_buffer = buffer1.merge(buffer2) assert str(merged_buffer) == 'foobar'
def testBufferSize(self): test_string = 'a little string' buffer = gst.Buffer(test_string) assert len(buffer) == len(test_string) assert hasattr(buffer, 'size') assert buffer.size == len(buffer)
def testBufferStrNull(self): test_string = 't\0e\0s\0t\0' buffer = gst.Buffer(test_string) assert str(buffer) == test_string
def testBufferAlloc(self): bla = 'mooooooo' buffer = gst.Buffer(bla + '12345') gc.collect() assert str(buffer) == 'mooooooo12345'
def testBufferStr(self): buffer = gst.Buffer('test') assert str(buffer) == 'test'