From 47a3d6fd28ba25a5afc04f7836ba71f829001d4c Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 19 Nov 2008 16:54:58 +0000 Subject: [PATCH] Wrap gst_type_find_peek. Original commit message from CVS: * gst/gst.override: * testsuite/test_typefind.py: Wrap gst_type_find_peek. --- ChangeLog | 6 ++++ gst/gst.override | 27 ++++++++++++++++ testsuite/test_typefind.py | 65 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 testsuite/test_typefind.py diff --git a/ChangeLog b/ChangeLog index b7633264de..1a6073d7ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-11-19 Alessandro Decina + + * gst/gst.override: + * testsuite/test_typefind.py: + Wrap gst_type_find_peek. + 2008-11-08 Alessandro Decina * gst/base.defs: diff --git a/gst/gst.override b/gst/gst.override index aecd3424cf..bacde83219 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -1276,6 +1276,33 @@ out: return py_res; } +%% +override gst_type_find_peek kwargs +static PyObject * +_wrap_gst_type_find_peek (PyObject * self, PyObject * args, PyObject * kwargs) +{ + static char *kwlist[] = { "offset", "size", NULL }; + gint64 offset; + guint size; + GstTypeFind *typefind; + guint8 *data; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"LI:GstTypeFind.peek", + kwlist, &offset, &size)) + return NULL; + + typefind = pyg_pointer_get(self, GstTypeFind); + pyg_begin_allow_threads; + data = gst_type_find_peek(typefind, offset, size); + pyg_end_allow_threads; + + if (data == NULL) + /* return the empty string */ + return PyString_FromStringAndSize(NULL, 0); + + return PyString_FromStringAndSize((char *) data, size); +} + %% override gst_segment_set_seek kwargs static PyObject * diff --git a/testsuite/test_typefind.py b/testsuite/test_typefind.py new file mode 100644 index 0000000000..f3a5e93872 --- /dev/null +++ b/testsuite/test_typefind.py @@ -0,0 +1,65 @@ +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 +# +# gst-python - Python bindings for GStreamer +# Copyright (C) 2008 Alessandro Decina +# +# 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, TestCase, pygobject_2_13 + +import sys +import time + +class TypeFindTest(TestCase): + 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)