mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
New guint8* ArgType. Wraps the various GstAdapter methods. Fixes #576505
This commit is contained in:
parent
0fd4db686b
commit
7aef2834cf
3 changed files with 120 additions and 0 deletions
|
@ -335,6 +335,40 @@ class StringArrayArg(ArgType):
|
|||
" }\n"
|
||||
" return PyTuple_New (0);\n")
|
||||
|
||||
class Uint8PArg(ArgType):
|
||||
"""guint8* arguments (strings)"""
|
||||
def write_param(self, ptype, pname, pdflt, pnull, keeprefcount, info):
|
||||
if pdflt:
|
||||
if pdflt != 'NULL': pdflt = '"' + pdflt + '"'
|
||||
info.varlist.add('guint8', '*' + pname + ' = ' + pdflt)
|
||||
else:
|
||||
info.varlist.add('guint8', '*' + pname)
|
||||
info.arglist.append(pname)
|
||||
if pnull:
|
||||
info.add_parselist('z', ['&' + pname], [pname])
|
||||
else:
|
||||
info.add_parselist('s', ['&' + pname], [pname])
|
||||
|
||||
def write_return(self, ptype, ownsreturn, info):
|
||||
if ownsreturn:
|
||||
# have to free result ...
|
||||
info.varlist.add('guint8', '*ret')
|
||||
info.codeafter.append(' if (ret) {\n' +
|
||||
' PyObject *py_ret = PyString_FromString((gchar*) ret);\n' +
|
||||
' g_free(ret);\n' +
|
||||
' return py_ret;\n' +
|
||||
' }\n' +
|
||||
' Py_INCREF(Py_None);\n' +
|
||||
' return Py_None;')
|
||||
else:
|
||||
info.varlist.add('const guint8', '*ret')
|
||||
info.codeafter.append(' if (ret)\n' +
|
||||
' return PyString_FromString((gchar*) ret);\n'+
|
||||
' Py_INCREF(Py_None);\n' +
|
||||
' return Py_None;')
|
||||
|
||||
|
||||
|
||||
matcher.register('GstClockTime', UInt64Arg())
|
||||
matcher.register('GstClockTimeDiff', Int64Arg())
|
||||
matcher.register('xmlNodePtr', XmlNodeArg())
|
||||
|
@ -343,6 +377,8 @@ matcher.register('GstCaps', GstCapsArg()) #FIXME: does this work?
|
|||
matcher.register('GstCaps*', GstCapsArg()) #FIXME: does this work?
|
||||
matcher.register('const-GstCaps*', GstCapsArg())
|
||||
matcher.register('GstIterator*', GstIteratorArg())
|
||||
matcher.register('guint8*', Uint8PArg())
|
||||
matcher.register('const-guint8*', Uint8PArg())
|
||||
|
||||
arg = PointerArg('gpointer', 'G_TYPE_POINTER')
|
||||
matcher.register('GstClockID', arg)
|
||||
|
|
|
@ -19,6 +19,7 @@ testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES)
|
|||
$(LINK) -rpath $(pkgpyexecdir) $(testhelper_la_LDFLAGS) $(testhelper_la_OBJECTS) $(testhelper_la_LIBADD) $(LIBS)
|
||||
|
||||
tests = \
|
||||
test_adapter.py \
|
||||
test_bin.py \
|
||||
test_buffer.py \
|
||||
test_caps.py \
|
||||
|
|
83
testsuite/test_adapter.py
Normal file
83
testsuite/test_adapter.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# -*- Mode: Python -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
#
|
||||
# gst-python - Python bindings for GStreamer
|
||||
# Copyright (C) 2009 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 gobject, gst, unittest, TestCase
|
||||
|
||||
class AdapterTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
TestCase.setUp(self)
|
||||
self.adapter = gst.Adapter()
|
||||
|
||||
def tearDown(self):
|
||||
self.adapter = None
|
||||
TestCase.tearDown(self)
|
||||
|
||||
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 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[:5], "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 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)[:5], "56789")
|
||||
|
||||
self.adapter.flush(5)
|
||||
self.assertEquals(self.adapter.available(), 0)
|
||||
|
||||
def testTake(self):
|
||||
self.adapter.push(gst.Buffer("0123456789"))
|
||||
self.assertEquals(self.adapter.available(), 10)
|
||||
|
||||
s = self.adapter.take(5)
|
||||
self.assertEquals(s[:5], "01234")
|
||||
self.assertEquals(self.adapter.available(), 5)
|
Loading…
Reference in a new issue