Implement the glue code so GstFraction works

This commit is contained in:
Thibault Saunier 2012-08-08 14:00:05 -04:00
parent 7ee9ce29ea
commit 0f8f27e55c
5 changed files with 157 additions and 2 deletions

View file

@ -3,7 +3,7 @@
DIE=0
package=gst-python
srcfile=gst/gstmodule.c
srcfile=gi/overrides/gstmodule.c
# Make sure we have common
if test ! -f common/gst-autogen.sh;

View file

@ -38,6 +38,19 @@ AC_SUBST(ACLOCAL_AMFLAGS, "-I m4 -I common/m4")
dnl required versions of other packages
dnl Note that they are runtime requirements
AC_SUBST(GST_REQ, 0.11.92)
AC_SUBST(PYGOBJECT_REQ, 3.0)
AC_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
dnl find a compiler
AC_PROG_CC
AC_PROG_CC_STDC
dnl check if the compiler supports '-c' and '-o' options
AM_PROG_CC_C_O
dnl check for python
dnl AM_PATH_PYTHON(2.5)
@ -50,12 +63,14 @@ if sys.version_info < minver:
sys.exit(1)
sys.exit(0)"
if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
then
AC_MSG_RESULT(okay)
else
AC_MSG_ERROR(too old)
fi
AM_CHECK_PYTHON_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
AS_AC_EXPAND(PYTHONDIR, $pythondir)
AS_AC_EXPAND(PYEXECDIR, $pyexecdir)
@ -77,6 +92,23 @@ PYGI_OVERRIDES_DIR="$overrides_dir"
AC_SUBST(PYGI_OVERRIDES_DIR)
AC_MSG_RESULT($PYGI_OVERRIDES_DIR)
dnl check for GStreamer
GST_API_VERSION=1.0
AC_SUBST(GST_API_VERSION)
PKG_CHECK_MODULES(GST, gstreamer-$GST_API_VERSION >= $GST_REQ)
AC_DEFINE_UNQUOTED(GST_API_VERSION, "$GST_API_VERSION", [Gst API version])
GST_CFLAGS="$GST_CFLAGS $GLIB_EXTRA_CFLAGS"
AC_SUBST(GST_CFLAGS)
AC_SUBST(GST_LIBS)
dnl check for pygobject
PKG_CHECK_MODULES(PYGOBJECT, pygobject-3.0 >= $PYGOBJECT_REQ,
[
HAVE_PYGOBJECT="yes"
], HAVE_PYGOBJECT="no")
AC_SUBST(PYGOBJECT_CFLAGS)
dnl and set the override directory
AC_ARG_WITH([pygi_overrides_dir],
AC_HELP_STRING([--with-pygi-overrides-dir], [Path to pygobject overrides directory]))

View file

@ -161,7 +161,6 @@ __all__.append('Fraction')
initialized, argv = Gst.init_check(sys.argv)
import _gi_gst
print _gi_gst
sys.argv = list(argv)
if not initialized:

View file

@ -1,4 +1,20 @@
common_cflags = $(PYGOBJECT_CFLAGS) $(GST_CFLAGS) -fno-strict-aliasing
common_libadd = $(GST_LIBS) $(PYGOBJECT_LIBS)
common_ldflags = -module -avoid-version
# We install everything in the gi/overrides folder
pygioverridesdir = $(PYGI_OVERRIDES_DIR)
pygioverrides_PYTHON = Gst.py
pygioverridesexecdir = $(PYGI_OVERRIDES_DIR)
EXTRA_DIST = Gst.py
INCLUDES = $(PYTHON_INCLUDES)
pygioverridesexec_LTLIBRARIES = _gi_gst.la
_gi_gst_la_SOURCES = gstmodule.c
_gi_gst_la_CFLAGS = $(common_cflags)
_gi_gst_la_LIBADD = $(common_libadd)
_gi_gst_la_LDFLAGS = $(common_ldflags)

108
gi/overrides/gstmodule.c Normal file
View file

@ -0,0 +1,108 @@
/* -*- Mode: C; ; c-file-style: "k&r"; c-basic-offset: 4 -*- */
/* gst-python
* Copyright (C) 2002 David I. Lehn
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*
* Author: David I. Lehn <dlehn@users.sourceforge.net>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* include this first, before NO_IMPORT_PYGOBJECT is defined */
#include <Python.h>
#include <pygobject.h>
#include <gst/gst.h>
#include <locale.h>
#define PYGLIB_MODULE_START(symbol, modname) \
DL_EXPORT(void) init##symbol(void) \
{ \
PyObject *module; \
module = Py_InitModule(modname, symbol##_functions);
#define PYGLIB_MODULE_END }
static PyObject *
gi_gst_fraction_from_value (const GValue * value)
{
PyObject *module, *dict, *fraction_type, *args, *fraction;
gint numerator, denominator;
numerator = gst_value_get_fraction_numerator (value);
denominator = gst_value_get_fraction_denominator (value);
module = PyImport_ImportModule ("gi.repository.Gst");
dict = PyModule_GetDict (module);
/* For some reson we need this intermediary step */
module = PyMapping_GetItemString (dict, "_overrides_module");
dict = PyModule_GetDict (module);
fraction_type = PyMapping_GetItemString (dict, "Fraction");
args = Py_BuildValue ("(ii)", numerator, denominator);
fraction = PyObject_Call (fraction_type, args, NULL);
Py_DECREF (args);
Py_DECREF (fraction_type);
Py_DECREF (module);
return fraction;
}
static int
gi_gst_fraction_to_value (GValue * value, PyObject * object)
{
PyObject *numerator, *denominator;
numerator = PyObject_GetAttrString (object, "num");
if (numerator == NULL)
goto fail;
denominator = PyObject_GetAttrString (object, "denom");
if (denominator == NULL)
goto fail;
gst_value_set_fraction (value,
PyLong_AsLong (numerator), PyLong_AsLong (denominator));
return 0;
fail:
return -1;
}
void
gi_gst_register_types (PyObject * d)
{
pyg_register_gtype_custom (GST_TYPE_FRACTION,
gi_gst_fraction_from_value, gi_gst_fraction_to_value);
}
static PyMethodDef _gi_gst_functions[] = { {0,} };
PYGLIB_MODULE_START (_gi_gst, "_gi_gst")
{
PyObject *d;
pygobject_init (3, 0, 0);
d = PyModule_GetDict (module);
gi_gst_register_types (d);
}
PYGLIB_MODULE_END;