overrides: provide for gst-python style debug logging

Also provide a default debug category for the binding glue code.
This commit is contained in:
Mark Nauwelaerts 2012-09-27 14:41:29 +02:00
parent c4026f81f1
commit 93ab67c78b
2 changed files with 115 additions and 1 deletions

View file

@ -168,3 +168,12 @@ sys.argv = list(argv)
if not initialized:
raise RuntimeError("Gst couldn't be initialized")
# maybe more python and less C some day if core turns a bit more introspection
# and binding friendly in the debug area
Gst.log = _gi_gst.log
Gst.debug = _gi_gst.debug
Gst.info = _gi_gst.info
Gst.warning = _gi_gst.warning
Gst.error = _gi_gst.error
Gst.fixme = _gi_gst.fixme
Gst.memdump = _gi_gst.memdump

View file

@ -39,6 +39,10 @@ DL_EXPORT(void) init##symbol(void) \
module = Py_InitModule(modname, symbol##_functions);
#define PYGLIB_MODULE_END }
GST_DEBUG_CATEGORY_STATIC (python_debug);
GST_DEBUG_CATEGORY_STATIC (pygst_debug);
#define GST_CAT_DEFAULT pygst_debug
static PyObject *
gi_gst_fraction_from_value (const GValue * value)
{
@ -188,12 +192,113 @@ _pygst_element_init (gpointer gclass, PyTypeObject * pyclass)
return 0;
}
static PyMethodDef _gi_gst_functions[] = { {0,} };
#include <frameobject.h>
static PyObject *
pygst_debug_log (PyObject * pyobject, PyObject * string, GstDebugLevel level,
gboolean isgstobject)
{
#ifndef GST_DISABLE_GST_DEBUG
gchar *str;
gchar *function;
gchar *filename;
int lineno;
PyFrameObject *frame;
GObject *object = NULL;
if (!PyArg_ParseTuple (string, "s:gst.debug_log", &str)) {
PyErr_SetString (PyExc_TypeError, "Need a string!");
return NULL;
}
frame = PyEval_GetFrame ();
function = PyString_AsString (frame->f_code->co_name);
filename =
g_path_get_basename (PyString_AsString (frame->f_code->co_filename));
lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti);
/* gst_debug_log : category, level, file, function, line, object, format, va_list */
if (isgstobject)
object = G_OBJECT (pygobject_get (pyobject));
gst_debug_log (python_debug, level, filename, function, lineno, object,
"%s", str);
if (filename)
g_free (filename);
#endif
Py_INCREF (Py_None);
return Py_None;
}
static PyObject *
_wrap_gst_log (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_LOG, FALSE);
}
static PyObject *
_wrap_gst_debug (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_DEBUG, FALSE);
}
static PyObject *
_wrap_gst_info (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_INFO, FALSE);
}
static PyObject *
_wrap_gst_warning (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_WARNING, FALSE);
}
static PyObject *
_wrap_gst_error (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_ERROR, FALSE);
}
static PyObject *
_wrap_gst_fixme (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_FIXME, FALSE);
}
static PyObject *
_wrap_gst_memdump (PyObject * whatever, PyObject * string)
{
return pygst_debug_log (whatever, string, GST_LEVEL_MEMDUMP, FALSE);
}
static PyMethodDef _gi_gst_functions[] = {
{"log", (PyCFunction) _wrap_gst_log, METH_VARARGS,
NULL},
{"debug", (PyCFunction) _wrap_gst_debug, METH_VARARGS,
NULL},
{"info", (PyCFunction) _wrap_gst_info, METH_VARARGS,
NULL},
{"warning", (PyCFunction) _wrap_gst_warning, METH_VARARGS,
NULL},
{"error", (PyCFunction) _wrap_gst_error, METH_VARARGS,
NULL},
{"fixme", (PyCFunction) _wrap_gst_fixme, METH_VARARGS,
NULL},
{"memdump", (PyCFunction) _wrap_gst_memdump, METH_VARARGS,
NULL}
};
PYGLIB_MODULE_START (_gi_gst, "_gi_gst")
{
PyObject *d;
/* gst should have been initialized already */
/* Initialize debugging category */
GST_DEBUG_CATEGORY_INIT (pygst_debug, "pygst", 0,
"GStreamer python bindings");
GST_DEBUG_CATEGORY_INIT (python_debug, "python", GST_DEBUG_FG_GREEN,
"python code using gst-python");
pygobject_init (3, 0, 0);
d = PyModule_GetDict (module);