diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/acinclude.m4 libmimic-1.0.4.new/acinclude.m4 --- libmimic-1.0.4/acinclude.m4 1970-01-01 01:00:00.000000000 +0100 +++ libmimic-1.0.4.new/acinclude.m4 2009-07-09 19:59:15.000000000 +0200 @@ -0,0 +1,32 @@ +dnl From msw. +dnl +dnl a macro to check for ability to create python extensions +dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE]) +dnl function also defines PYTHON_INCLUDES +AC_DEFUN([AM_CHECK_PYTHON_HEADERS], +[AC_REQUIRE([AM_PATH_PYTHON]) +AC_MSG_CHECKING(for headers required to compile python extensions) +dnl deduce PYTHON_INCLUDES +py_prefix=`$PYTHON -c "import sys; print sys.prefix"` +py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"` +if test -x "$PYTHON-config"; then + PYTHON_INCLUDES=`$PYTHON-config --includes 2>/dev/null` +else + PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}" + if test "$py_prefix" != "$py_exec_prefix"; then + PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}" + fi +fi +PYTHON_LIBS="-L${py_prefix}/libs -lpython${PYTHON_VERSION}" +AC_SUBST(PYTHON_INCLUDES) +AC_SUBST(PYTHON_LIBS) +dnl check if the headers exist: +save_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES" +AC_TRY_CPP([#include ],dnl +[AC_MSG_RESULT(found) +$1],dnl +[AC_MSG_RESULT(not found) +$2]) +CPPFLAGS="$save_CPPFLAGS" +]) diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/configure.ac libmimic-1.0.4.new/configure.ac --- libmimic-1.0.4/configure.ac 2009-07-09 19:59:14.000000000 +0200 +++ libmimic-1.0.4.new/configure.ac 2009-07-09 19:59:24.000000000 +0200 @@ -29,6 +29,32 @@ AC_PROG_CC AC_PROG_INSTALL +dnl Python bindings +AC_ARG_ENABLE(python, [ --enable-python build python bindings],enable_python=$enableval,enable_python=auto) + +AC_MSG_CHECKING([whether to build python bindings]) + +BUILD_PYTHON=false +if test x$enable_python != xno; then + AM_PATH_PYTHON + if test -n "$PYTHON"; then + BUILD_PYTHON=true + fi +fi + +if $BUILD_PYTHON; then + AM_CHECK_PYTHON_HEADERS(,BUILD_PYTHON=false) +fi + +if ! $BUILD_PYTHON; then + AC_MSG_RESULT([Python bindings disabled]) +fi + +AC_SUBST(PYTHONREV) +AC_SUBST(PYTHON_MODULES) +AM_CONDITIONAL(BUILD_PYTHON_MODULES, $BUILD_PYTHON) + + dnl Documentation. AC_ARG_ENABLE(doxygen-docs, [ --enable-doxygen-docs build Doxygen documentation],enable_doxygen_docs=$enableval,enable_doxygen_docs=auto) @@ -74,6 +100,7 @@ Makefile doc/Makefile doc/Doxyfile +python/Makefile src/Makefile ]) diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/Makefile.am libmimic-1.0.4.new/Makefile.am --- libmimic-1.0.4/Makefile.am 2006-02-07 10:53:40.000000000 +0100 +++ libmimic-1.0.4.new/Makefile.am 2009-07-09 19:59:15.000000000 +0200 @@ -1,4 +1,4 @@ -SUBDIRS = src doc +SUBDIRS = src python doc ### all of the standard pc files we need to generate pcfiles = \ diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/python/Makefile.am libmimic-1.0.4.new/python/Makefile.am --- libmimic-1.0.4/python/Makefile.am 1970-01-01 01:00:00.000000000 +0100 +++ libmimic-1.0.4.new/python/Makefile.am 2009-07-09 19:59:15.000000000 +0200 @@ -0,0 +1,14 @@ +PYTHON_MODULES = libmimic.la + +if BUILD_PYTHON_MODULES + +pythonsiteexecdir = $(pyexecdir) +pythonsiteexec_LTLIBRARIES = $(PYTHON_MODULES) + +libmimic_la_SOURCES = py_libmimic.c +libmimic_la_CPPFLAGS = -I$(top_srcdir)/src $(AM_CPPFLAGS) +libmimic_la_CFLAGS = $(PYTHON_INCLUDES) $(AM_CFLAGS) $(GLIB_CFLAGS) +libmimic_la_LDFLAGS = -module -avoid-version $(PYTHON_LIBS) $(PYTHON_LDFLAGS) $(AM_LDFLAGS) +libmimic_la_LIBADD = $(top_builddir)/src/libmimic.la $(LIBS) + +endif diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/python/py_libmimic.c libmimic-1.0.4.new/python/py_libmimic.c --- libmimic-1.0.4/python/py_libmimic.c 1970-01-01 01:00:00.000000000 +0100 +++ libmimic-1.0.4.new/python/py_libmimic.c 2009-07-09 19:59:15.000000000 +0200 @@ -0,0 +1,172 @@ +/* + * This file is part of emesene. + * + * Emesene is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Emesene 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * TODO: + * - set useful exception messages + */ + +#include +#include "py_libmimic.h" + +/* init module */ +PyMODINIT_FUNC +initlibmimic(void) +{ + PyObject* m; + m = Py_InitModule("libmimic", LibmimicMethods); +} +static void close_decoder(void* ptr) { + MimicDecoder* decoder; + decoder = (MimicDecoder*)ptr; + mimic_close(decoder->codec); + free(decoder); +} +static PyObject* libmimic_new_decoder(PyObject *self, PyObject *args) { + MimicDecoder* decoder; + + /* accept no arguments */ + if(!PyArg_ParseTuple(args, "")) + return NULL; + + decoder = (MimicDecoder*)malloc(sizeof(MimicDecoder)); + if(!decoder) { + PyErr_NoMemory(); + return NULL; + } + + decoder->codec = mimic_open(); + decoder->is_init = 0; + + return PyCObject_FromVoidPtr(decoder, close_decoder); +} +static PyObject* libmimic_new_encoder(PyObject *self, PyObject *args) { + MimicEncoder* encoder; + unsigned char arg_resolution; + MimicResEnum resolution; + + /* accept one argument, resolution: 0 = low, 1 = high */ + if(!PyArg_ParseTuple(args, "b", &arg_resolution)) + return NULL; + + encoder = (MimicEncoder*)malloc(sizeof(MimicEncoder)); + if(!encoder) { + PyErr_NoMemory(); + return NULL; + } + + encoder->codec = mimic_open(); + encoder->num_frames = 0; + + resolution = arg_resolution ? MIMIC_RES_HIGH : MIMIC_RES_LOW; + mimic_encoder_init(encoder->codec, resolution); + + return PyCObject_FromVoidPtr(encoder, close_decoder); +} +static PyObject* libmimic_decode(PyObject *self, PyObject *args) { + MimicDecoder* decoder; + BYTE* output; + unsigned int width, height, length; + + /* parameters */ + PyObject* pyobj = NULL; + BYTE* input; + int inputsize; + + if(!PyArg_ParseTuple(args, "Os#", &pyobj, &input, &inputsize)) + return NULL; + + decoder = PyCObject_AsVoidPtr(pyobj); + if(!decoder) { + /* TODO: ERROR */ + return NULL; + } + + if (!decoder->is_init) { + if (!mimic_decoder_init(decoder->codec, input + HEADER_SIZE)) { + /* TODO: ERROR */ + return NULL; + } else { + decoder->is_init = 1; + } + } + + mimic_get_property(decoder->codec, "buffer_size", &length); + mimic_get_property(decoder->codec, "width", &width); + mimic_get_property(decoder->codec, "height", &height); + + output = (BYTE*)malloc(length); + if(!output) { + PyErr_NoMemory(); + return NULL; + } + + if (!mimic_decode_frame(decoder->codec, input + HEADER_SIZE, output)) { + /* TODO: ERROR */ + free(output); + return NULL; + } + + PyObject* val = Py_BuildValue("iis#", width, height, output, length); + free(output); + return val; +} + +static PyObject* libmimic_encode(PyObject *self, PyObject *args) { + MimicEncoder* encoder; + BYTE* output; + int length, width, height; + + /* parameters */ + PyObject* pyobj = NULL; + BYTE* input; + int inputsize; + + if(!PyArg_ParseTuple(args, "Os#", &pyobj, &input, &inputsize)) + return NULL; + + encoder = PyCObject_AsVoidPtr(pyobj); + if(!encoder) { + /* TODO: ERROR */ + return NULL; + } + + mimic_get_property(encoder->codec, "buffer_size", &length); + + output = (BYTE*)malloc(length * 3); + if(!output) { + PyErr_NoMemory(); + return NULL; + } + + if (!mimic_encode_frame(encoder->codec, input, output, &length, + encoder->num_frames % 10 == 0)) { + /* TODO: ERROR */ + free(output); + return NULL; + } + + encoder->num_frames++; + + mimic_get_property(encoder->codec, "width", &width); + mimic_get_property(encoder->codec, "height", &height); + PyObject* val = Py_BuildValue("s#ii", output, length, width, height); + free(output); + + return val; +} + diff -Nur -x '*.orig' -x '*~' libmimic-1.0.4/python/py_libmimic.h libmimic-1.0.4.new/python/py_libmimic.h --- libmimic-1.0.4/python/py_libmimic.h 1970-01-01 01:00:00.000000000 +0100 +++ libmimic-1.0.4.new/python/py_libmimic.h 2009-07-09 19:59:15.000000000 +0200 @@ -0,0 +1,59 @@ +/* + * This file is part of emesene. + * + * Emesene is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Emesene 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef _LIBMIMIC_PYLIBMIMIC_H +#define _LIBMIMIC_PYLIBMIMIC_H + +#include +#include "mimic.h" + +#define HEADER_SIZE 24 + +typedef unsigned char BYTE; +typedef unsigned short WORD; +typedef unsigned int DWORD; + +typedef struct MimicDecoder { + MimCtx* codec; + unsigned char is_init; +} MimicDecoder; + +typedef struct MimicEncoder { + MimCtx* codec; + unsigned int num_frames; +} MimicEncoder; + +PyMODINIT_FUNC initlibmimic(void); + +static PyObject* libmimic_new_decoder(PyObject* self, PyObject* args); +static PyObject* libmimic_new_encoder(PyObject* self, PyObject* args); + +static PyObject* libmimic_decode(PyObject* self, PyObject* args); +static PyObject* libmimic_encode(PyObject* self, PyObject* args); + +/* method table */ +static PyMethodDef LibmimicMethods[] = { + {"new_decoder", libmimic_new_decoder, METH_VARARGS, "New decoder"}, + {"new_encoder", libmimic_new_encoder, METH_VARARGS, "New encoder"}, + {"decode", libmimic_decode, METH_VARARGS, "Decode a frame"}, + {"encode", libmimic_encode, METH_VARARGS, "Encode a frame"}, + {NULL, NULL, 0, NULL} /* Sentinel */ +}; + +#endif /* _LIBMIMIC_PYLIBMIMIC_H */