gstreamer/gst/gsttaglist.override
Thomas Vander Stichele 26fa6dd184 wrap gst_tag_to_vorbis_comment; fix uint tag setting
Setting gst.TAG_TRACK_NUMBER was failing because GStreamer
expects a uint while Python object -> GValue conversion was
giving an int.  gst_tag_to_vorbis_comment was wrapped so
this conversion could be tested and failed on properly.
2009-06-01 22:02:47 +02:00

161 lines
4.3 KiB
C

/* -*- Mode: C; ; c-file-style: "python" -*- */
/* gst-python
* Copyright (C) 2005 Edward Hervey
*
* 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: Edward Hervey <edward@fluendo.com>
*/
%%
ignore-glob
gst_tag_list_get_*
%%
ignore
gst_tag_list_add
gst_tag_list_add_values
gst_tag_list_add_valist_values
gst_tag_list_copy_value
gst_tag_list_get
gst_tag_list_remove_tag
gst_tag_list_foreach
gst_is_tag_list
%%
define GstTagList.keys noargs
static void
tag_foreach_func_list (const GstTagList *list,
const gchar *tag,
PyObject *py_list)
{
int count;
count = gst_tag_list_get_tag_size(GST_TAG_LIST(list), tag);
if (count == 0)
PyErr_SetString(PyExc_KeyError, tag);
else if (count > 0)
PyList_Append(py_list, PyString_FromString(tag));
}
static PyObject*
_wrap_gst_tag_list_keys(PyGObject *self)
{
PyObject *dict;
dict = PyList_New(0);
gst_tag_list_foreach(GST_TAG_LIST(self->obj),
(GstTagForeachFunc)tag_foreach_func_list,
(gpointer)dict);
return dict;
}
%%
override-slot GstTagList.tp_as_mapping
static Py_ssize_t
_wrap_gst_tag_list_length(PyObject *self)
{
PyGObject *gself = (PyGObject *)self;
return gst_structure_n_fields((GstStructure*)gself->obj);
}
static PyObject *
_wrap_gst_tag_list_subscript(PyGObject *self, PyObject *py_key)
{
PyObject *v = NULL;
const char *field = PyString_AsString(py_key);
if (gst_structure_has_field((GstStructure*)self->obj, field)) {
const GValue *gvalue;
gvalue = gst_structure_get_value((GstStructure*)self->obj, field);
g_assert(gvalue != NULL);
v = pygst_value_as_pyobject(gvalue, TRUE);
} else {
PyErr_SetString(PyExc_KeyError, field);
}
return v;
}
static int
_wrap_gst_tag_list_ass_subscript(PyGObject *self,
PyObject *py_key,
PyObject *py_value)
{
const char *key;
GstStructure* structure;
GType tagtype;
structure = (GstStructure*)self->obj;
key = PyString_AsString(py_key);
if (py_value != NULL) {
GValue v = { 0, };
if (!pygst_value_init_for_pyobject (&v, py_value))
return -1;
if (pygst_value_from_pyobject(&v, py_value))
return -1;
/* some tags are supposed to be uint, but there is no unsigned
* int python type, so convert here if needed */
if (gst_tag_exists (key)) {
tagtype = gst_tag_get_type (key);
if (tagtype && tagtype != G_VALUE_TYPE (&v)) {
GValue w = { 0, };
g_value_init (&w, tagtype);
g_value_transform (&v, &w);
g_value_unset (&v);
g_value_init (&v, tagtype);
g_value_copy (&w, &v);
}
}
gst_structure_set_value(structure, key, &v);
g_value_unset(&v);
} else {
gst_structure_remove_field(structure, key);
}
return 0;
}
static PyMappingMethods _wrap_gst_tag_list_tp_as_mapping = {
_wrap_gst_tag_list_length, /* mp_length */
(binaryfunc)_wrap_gst_tag_list_subscript, /* mp_subscript */
(objobjargproc)_wrap_gst_tag_list_ass_subscript /* mp_ass_subscript */
};
%%
override-slot GstTagList.tp_as_sequence
static int
_wrap_gst_tag_list_contains(PyGObject *self, PyObject *py_key)
{
return gst_structure_has_field((GstStructure*)self->obj,
PyString_AsString(py_key));
}
static PySequenceMethods _wrap_gst_tag_list_tp_as_sequence = {
(lenfunc)NULL,
(binaryfunc)NULL,
(ssizeargfunc)NULL,
(ssizeargfunc)NULL,
(ssizessizeargfunc)NULL,
(ssizeobjargproc)NULL,
(ssizessizeobjargproc)NULL,
(objobjproc)_wrap_gst_tag_list_contains,
(binaryfunc)NULL,
(ssizeargfunc)NULL,
};