Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 211174
Collapse All | Expand All

(-)libmimic-1.0.4/acinclude.m4 (+32 lines)
Line 0 Link Here
1
dnl From msw.
2
dnl
3
dnl a macro to check for ability to create python extensions
4
dnl  AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
5
dnl function also defines PYTHON_INCLUDES
6
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
7
[AC_REQUIRE([AM_PATH_PYTHON])
8
AC_MSG_CHECKING(for headers required to compile python extensions)
9
dnl deduce PYTHON_INCLUDES
10
py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
11
py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
12
if test -x "$PYTHON-config"; then
13
    PYTHON_INCLUDES=`$PYTHON-config --includes 2>/dev/null`
14
else
15
    PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
16
    if test "$py_prefix" != "$py_exec_prefix"; then
17
      PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
18
    fi
19
fi
20
PYTHON_LIBS="-L${py_prefix}/libs -lpython${PYTHON_VERSION}"
21
AC_SUBST(PYTHON_INCLUDES)
22
AC_SUBST(PYTHON_LIBS)
23
dnl check if the headers exist:
24
save_CPPFLAGS="$CPPFLAGS"
25
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
26
AC_TRY_CPP([#include <Python.h>],dnl
27
[AC_MSG_RESULT(found)
28
$1],dnl
29
[AC_MSG_RESULT(not found)
30
$2])
31
CPPFLAGS="$save_CPPFLAGS"
32
])
(-)libmimic-1.0.4/configure.ac (+27 lines)
Lines 29-34 Link Here
29
AC_PROG_CC
29
AC_PROG_CC
30
AC_PROG_INSTALL
30
AC_PROG_INSTALL
31
31
32
dnl Python bindings
33
AC_ARG_ENABLE(python, [  --enable-python   build python bindings],enable_python=$enableval,enable_python=auto)
34
35
AC_MSG_CHECKING([whether to build python bindings])
36
37
BUILD_PYTHON=false
38
if test x$enable_python != xno; then
39
    AM_PATH_PYTHON
40
    if test -n "$PYTHON"; then
41
        BUILD_PYTHON=true
42
    fi
43
fi
44
45
if $BUILD_PYTHON; then
46
    AM_CHECK_PYTHON_HEADERS(,BUILD_PYTHON=false)
47
fi
48
49
if ! $BUILD_PYTHON; then
50
    AC_MSG_RESULT([Python bindings disabled])
51
fi
52
53
AC_SUBST(PYTHONREV)
54
AC_SUBST(PYTHON_MODULES)
55
AM_CONDITIONAL(BUILD_PYTHON_MODULES, $BUILD_PYTHON)
56
57
32
dnl Documentation.
58
dnl Documentation.
33
AC_ARG_ENABLE(doxygen-docs, [  --enable-doxygen-docs   build Doxygen documentation],enable_doxygen_docs=$enableval,enable_doxygen_docs=auto)
59
AC_ARG_ENABLE(doxygen-docs, [  --enable-doxygen-docs   build Doxygen documentation],enable_doxygen_docs=$enableval,enable_doxygen_docs=auto)
34
60
Lines 74-79 Link Here
74
Makefile
100
Makefile
75
doc/Makefile
101
doc/Makefile
76
doc/Doxyfile
102
doc/Doxyfile
103
python/Makefile
77
src/Makefile
104
src/Makefile
78
])
105
])
79
106
(-)libmimic-1.0.4/Makefile.am (-1 / +1 lines)
Lines 1-4 Link Here
1
SUBDIRS = src doc
1
SUBDIRS = src python doc
2
2
3
### all of the standard pc files we need to generate
3
### all of the standard pc files we need to generate
4
pcfiles = 							\
4
pcfiles = 							\
(-)libmimic-1.0.4/python/Makefile.am (+14 lines)
Line 0 Link Here
1
PYTHON_MODULES = libmimic.la
2
3
if BUILD_PYTHON_MODULES
4
5
pythonsiteexecdir = $(pyexecdir)
6
pythonsiteexec_LTLIBRARIES = $(PYTHON_MODULES)
7
8
libmimic_la_SOURCES = py_libmimic.c
9
libmimic_la_CPPFLAGS = -I$(top_srcdir)/src $(AM_CPPFLAGS)
10
libmimic_la_CFLAGS = $(PYTHON_INCLUDES) $(AM_CFLAGS) $(GLIB_CFLAGS)
11
libmimic_la_LDFLAGS = -module -avoid-version $(PYTHON_LIBS) $(PYTHON_LDFLAGS) $(AM_LDFLAGS)
12
libmimic_la_LIBADD = $(top_builddir)/src/libmimic.la $(LIBS)
13
14
endif
(-)libmimic-1.0.4/python/py_libmimic.c (+172 lines)
Line 0 Link Here
1
/*
2
 * This file is part of emesene.
3
 * 
4
 * Emesene is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *      
9
 * Emesene is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *      
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
 * MA 02110-1301, USA.
18
 * 
19
 * TODO:
20
 * - set useful exception messages
21
 */
22
23
#include <Python.h>
24
#include "py_libmimic.h"
25
26
/* init module */
27
PyMODINIT_FUNC 
28
initlibmimic(void) 
29
{
30
    PyObject* m;
31
    m = Py_InitModule("libmimic", LibmimicMethods);
32
}
33
static void close_decoder(void* ptr) {
34
    MimicDecoder* decoder;
35
    decoder = (MimicDecoder*)ptr;
36
    mimic_close(decoder->codec);
37
    free(decoder);
38
}
39
static PyObject* libmimic_new_decoder(PyObject *self, PyObject *args) {
40
    MimicDecoder* decoder;
41
42
    /* accept no arguments */
43
    if(!PyArg_ParseTuple(args, ""))
44
        return NULL;
45
    
46
    decoder = (MimicDecoder*)malloc(sizeof(MimicDecoder));
47
    if(!decoder) {
48
        PyErr_NoMemory();
49
        return NULL;
50
    }
51
    
52
    decoder->codec = mimic_open();
53
    decoder->is_init = 0;
54
55
    return PyCObject_FromVoidPtr(decoder, close_decoder);
56
}
57
static PyObject* libmimic_new_encoder(PyObject *self, PyObject *args) {
58
    MimicEncoder* encoder;
59
    unsigned char arg_resolution;
60
    MimicResEnum resolution;
61
    
62
    /* accept one argument, resolution: 0 = low, 1 = high */
63
    if(!PyArg_ParseTuple(args, "b", &arg_resolution))
64
        return NULL;
65
    
66
    encoder = (MimicEncoder*)malloc(sizeof(MimicEncoder));
67
    if(!encoder) {
68
        PyErr_NoMemory();
69
        return NULL;
70
    }
71
    
72
    encoder->codec = mimic_open();
73
    encoder->num_frames = 0;
74
    
75
    resolution = arg_resolution ? MIMIC_RES_HIGH : MIMIC_RES_LOW;
76
    mimic_encoder_init(encoder->codec, resolution);
77
78
    return PyCObject_FromVoidPtr(encoder, close_decoder);
79
}
80
static PyObject* libmimic_decode(PyObject *self, PyObject *args) {
81
    MimicDecoder* decoder;
82
    BYTE* output;
83
    unsigned int width, height, length;
84
85
    /* parameters */
86
    PyObject* pyobj = NULL;
87
    BYTE* input;
88
    int inputsize;
89
90
    if(!PyArg_ParseTuple(args, "Os#", &pyobj, &input, &inputsize))
91
        return NULL;
92
    
93
    decoder = PyCObject_AsVoidPtr(pyobj);
94
    if(!decoder) {
95
        /* TODO: ERROR */
96
        return NULL;
97
    }
98
    
99
    if (!decoder->is_init) {
100
        if (!mimic_decoder_init(decoder->codec, input + HEADER_SIZE)) {
101
            /* TODO: ERROR */
102
            return NULL;
103
        } else {
104
            decoder->is_init = 1;
105
        }
106
    }
107
    
108
    mimic_get_property(decoder->codec, "buffer_size", &length);
109
    mimic_get_property(decoder->codec, "width", &width);
110
    mimic_get_property(decoder->codec, "height", &height);
111
    
112
    output = (BYTE*)malloc(length);
113
    if(!output) {
114
        PyErr_NoMemory();
115
        return NULL;
116
    }
117
    
118
    if (!mimic_decode_frame(decoder->codec, input + HEADER_SIZE, output)) {
119
        /* TODO: ERROR */
120
        free(output);
121
        return NULL;
122
    }
123
    
124
    PyObject* val = Py_BuildValue("iis#", width, height, output, length);
125
    free(output);
126
    return val;
127
}
128
129
static PyObject* libmimic_encode(PyObject *self, PyObject *args) {
130
    MimicEncoder* encoder;
131
    BYTE* output;
132
    int length, width, height;
133
134
    /* parameters */
135
    PyObject* pyobj = NULL;
136
    BYTE* input;
137
    int inputsize;
138
139
    if(!PyArg_ParseTuple(args, "Os#", &pyobj, &input, &inputsize))
140
        return NULL;
141
    
142
    encoder = PyCObject_AsVoidPtr(pyobj);
143
    if(!encoder) {
144
        /* TODO: ERROR */
145
        return NULL;
146
    }
147
    
148
    mimic_get_property(encoder->codec, "buffer_size", &length);
149
    
150
    output = (BYTE*)malloc(length * 3);
151
    if(!output) {
152
        PyErr_NoMemory();
153
        return NULL;
154
    }
155
    
156
    if (!mimic_encode_frame(encoder->codec, input, output, &length, 
157
            encoder->num_frames % 10 == 0)) {
158
        /* TODO: ERROR */
159
        free(output);
160
        return NULL;
161
    }
162
    
163
    encoder->num_frames++;
164
    
165
    mimic_get_property(encoder->codec, "width", &width);
166
    mimic_get_property(encoder->codec, "height", &height);
167
    PyObject* val = Py_BuildValue("s#ii", output, length, width, height);
168
    free(output);
169
    
170
    return val;
171
}
172
(-)libmimic-1.0.4/python/py_libmimic.h (+59 lines)
Line 0 Link Here
1
/*
2
 * This file is part of emesene.
3
 * 
4
 * Emesene is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *      
9
 * Emesene is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *      
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17
 * MA 02110-1301, USA.
18
 */
19
20
#ifndef _LIBMIMIC_PYLIBMIMIC_H
21
#define _LIBMIMIC_PYLIBMIMIC_H
22
23
#include <Python.h>
24
#include "mimic.h"
25
26
#define HEADER_SIZE 24
27
28
typedef unsigned char BYTE;
29
typedef unsigned short WORD;
30
typedef unsigned int DWORD;
31
32
typedef struct MimicDecoder {
33
	MimCtx* codec;
34
	unsigned char is_init;
35
} MimicDecoder;
36
37
typedef struct MimicEncoder {
38
	MimCtx* codec;
39
	unsigned int num_frames;
40
} MimicEncoder;
41
42
PyMODINIT_FUNC initlibmimic(void);
43
44
static PyObject* libmimic_new_decoder(PyObject* self, PyObject* args);
45
static PyObject* libmimic_new_encoder(PyObject* self, PyObject* args);
46
47
static PyObject* libmimic_decode(PyObject* self, PyObject* args);
48
static PyObject* libmimic_encode(PyObject* self, PyObject* args);
49
50
/* method table */
51
static PyMethodDef LibmimicMethods[] = {
52
    {"new_decoder", libmimic_new_decoder, METH_VARARGS, "New decoder"},
53
    {"new_encoder", libmimic_new_encoder, METH_VARARGS, "New encoder"},
54
    {"decode", libmimic_decode, METH_VARARGS, "Decode a frame"},
55
    {"encode", libmimic_encode, METH_VARARGS, "Encode a frame"},
56
    {NULL, NULL, 0, NULL}  /* Sentinel */
57
};
58
59
#endif /* _LIBMIMIC_PYLIBMIMIC_H */

Return to bug 211174